SponsorBlockServer/test/cases/oldSubmitSponsorTimes.ts

58 lines
2.3 KiB
TypeScript
Raw Normal View History

2021-01-06 01:43:28 +01:00
import fetch from 'node-fetch';
2020-10-17 20:56:54 +02:00
import {Done, getbaseURL} from '../utils';
import {db} from '../../src/databases/databases';
describe('postVideoSponsorTime (Old submission method)', () => {
it('Should be able to submit a time (GET)', (done: Done) => {
2021-01-06 01:43:28 +01:00
fetch(getbaseURL()
+ "/api/postVideoSponsorTimes?videoID=dQw4w9WgXcQ&startTime=1&endTime=10&userID=test")
2021-03-02 03:37:35 +01:00
.then(async res => {
2021-01-06 01:43:28 +01:00
if (res.status === 200) {
2021-03-07 06:21:56 +01:00
let row = await db.prepare('get', `SELECT "startTime", "endTime", "category" FROM "sponsorTimes" WHERE "videoID" = ?`, ["dQw4w9WgXcQ"]);
2021-01-06 01:43:28 +01:00
if (row.startTime === 1 && row.endTime === 10 && row.category === "sponsor") {
done();
2020-10-17 20:56:54 +02:00
} else {
2021-01-06 01:43:28 +01:00
done("Submitted times were not saved. Actual submission: " + JSON.stringify(row));
2020-10-17 20:56:54 +02:00
}
2021-01-06 01:43:28 +01:00
} else {
done("Status code was " + res.status);
}
})
.catch(err => done(err));
2020-10-17 20:56:54 +02:00
});
it('Should be able to submit a time (POST)', (done: Done) => {
2021-01-06 01:43:28 +01:00
fetch(getbaseURL()
+ "/api/postVideoSponsorTimes?videoID=dQw4w9WgXcE&startTime=1&endTime=11&userID=test", {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
})
2021-03-02 03:37:35 +01:00
.then(async res => {
2021-01-06 01:43:28 +01:00
if (res.status === 200) {
2021-03-07 06:21:56 +01:00
let row = await db.prepare('get', `SELECT "startTime", "endTime", "category" FROM "sponsorTimes" WHERE "videoID" = ?`, ["dQw4w9WgXcE"]);
2021-01-06 01:43:28 +01:00
if (row.startTime === 1 && row.endTime === 11 && row.category === "sponsor") {
done();
2020-10-17 20:56:54 +02:00
} else {
2021-01-06 01:43:28 +01:00
done("Submitted times were not saved. Actual submission: " + JSON.stringify(row));
2020-10-17 20:56:54 +02:00
}
2021-01-06 01:43:28 +01:00
} else {
done("Status code was " + res.status);
}
})
.catch(err => done(err));
2020-10-17 20:56:54 +02:00
});
it('Should return 400 for missing params', (done: Done) => {
2021-01-06 01:43:28 +01:00
fetch(getbaseURL()
+ "/api/postVideoSponsorTimes?startTime=1&endTime=10&userID=test")
2021-03-02 03:37:35 +01:00
.then(async res => {
2021-01-06 01:43:28 +01:00
if (res.status === 400) done();
else done("Status code was: " + res.status);
})
.catch(err => done(err));
2020-10-17 20:56:54 +02:00
});
});