add 4xx tests

This commit is contained in:
Michael C
2022-09-25 03:31:25 -04:00
parent a469f2f382
commit c34de1baa4
5 changed files with 164 additions and 15 deletions

View File

@@ -104,6 +104,7 @@ describe("verifyToken mock tests", function() {
beforeEach(function() {
mock = new MockAdapter(axios, { onNoMatch: "throwException" });
mock.onPost("https://www.patreon.com/api/oauth2/token").reply(200, patreon.fakeOauth);
});
afterEach(function () {

View File

@@ -1,5 +1,7 @@
import assert from "assert";
import { client } from "../utils/httpClient";
import sinon from "sinon";
import { db } from "../../src/databases/databases";
const endpoint = "/api/getDaysSavedFormatted";
@@ -8,4 +10,18 @@ describe("getDaysSavedFormatted", () => {
const result = await client({ url: endpoint });
assert.ok(result.data.daysSaved >= 0);
});
it("returns 0 days saved if no segments", async () => {
const stub = sinon.stub(db, "prepare").resolves(undefined);
const result = await client({ url: endpoint });
assert.ok(result.data.daysSaved >= 0);
stub.restore();
});
it("returns days saved to 2 fixed points", async () => {
const stub = sinon.stub(db, "prepare").resolves({ daysSaved: 1.23456789 });
const result = await client({ url: endpoint });
assert.strictEqual(result.data.daysSaved, "1.23");
stub.restore();
});
});

View File

@@ -166,17 +166,77 @@ describe("getLockCategoriesByHash", () => {
.catch(err => done(err));
});
it("Should be able to get by actionType", (done) => {
getLockCategories(fakeHash.substring(0,5), [ActionType.Full])
it("should return 400 if invalid actionTypes", (done) => {
client.get(`${endpoint}/aaaa`, { params: { actionTypes: 3 } })
.then(res => {
assert.strictEqual(res.status, 400);
done();
})
.catch(err => done(err));
});
it("should return 400 if invalid actionTypes JSON", (done) => {
client.get(`${endpoint}/aaaa`, { params: { actionTypes: "{3}" } })
.then(res => {
assert.strictEqual(res.status, 400);
done();
})
.catch(err => done(err));
});
it("Should be able to get single lock", (done) => {
const videoID = "getLockHash2";
const hash = getHash(videoID, 1);
getLockCategories(hash.substring(0,6))
.then(res => {
assert.strictEqual(res.status, 200);
const expected = [{
videoID: "fakehash-2",
hash: fakeHash,
videoID,
hash,
categories: [
"sponsor"
"preview"
],
reason: "fake2-notshown"
reason: "2-reason"
}];
assert.deepStrictEqual(res.data, expected);
done();
})
.catch(err => done(err));
});
it("Should be able to get by actionType not in array", (done) => {
const videoID = "getLockHash2";
const hash = getHash(videoID, 1);
client.get(`${endpoint}/${hash.substring(0,6)}`, { params: { actionType: ActionType.Skip } })
.then(res => {
assert.strictEqual(res.status, 200);
const expected = [{
videoID,
hash,
categories: [
"preview"
],
reason: "2-reason"
}];
assert.deepStrictEqual(res.data, expected);
done();
})
.catch(err => done(err));
});
it("Should be able to get by no actionType", (done) => {
const videoID = "getLockHash2";
const hash = getHash(videoID, 1);
client.get(`${endpoint}/${hash.substring(0,6)}`)
.then(res => {
assert.strictEqual(res.status, 200);
const expected = [{
videoID,
hash,
categories: [
"preview"
],
reason: "2-reason"
}];
assert.deepStrictEqual(res.data, expected);
done();

View File

@@ -55,6 +55,45 @@ describe("getLockReason", () => {
.catch(err => done(err));
});
it("Should be able to get with actionTypes array", (done) => {
client.get(endpoint, { params: { videoID: "getLockReason", category: "selfpromo", actionTypes: '["full"]' } })
.then(res => {
assert.strictEqual(res.status, 200);
const expected = [
{ category: "selfpromo", locked: 1, reason: "selfpromo-reason", userID: vipUserID2, userName: vipUserName2 }
];
assert.deepStrictEqual(res.data, expected);
done();
})
.catch(err => done(err));
});
it("Should be able to get with actionType", (done) => {
client.get(endpoint, { params: { videoID: "getLockReason", category: "selfpromo", actionType: "full" } })
.then(res => {
assert.strictEqual(res.status, 200);
const expected = [
{ category: "selfpromo", locked: 1, reason: "selfpromo-reason", userID: vipUserID2, userName: vipUserName2 }
];
assert.deepStrictEqual(res.data, expected);
done();
})
.catch(err => done(err));
});
it("Should be able to get with actionType array", (done) => {
client.get(endpoint, { params: { videoID: "getLockReason", category: "selfpromo", actionType: ["full"] } })
.then(res => {
assert.strictEqual(res.status, 200);
const expected = [
{ category: "selfpromo", locked: 1, reason: "selfpromo-reason", userID: vipUserID2, userName: vipUserName2 }
];
assert.deepStrictEqual(res.data, expected);
done();
})
.catch(err => done(err));
});
it("Should be able to get empty locks", (done) => {
client.get(endpoint, { params: { videoID: "getLockReason", category: "intro" } })
.then(res => {
@@ -118,8 +157,10 @@ describe("getLockReason", () => {
})
.catch(err => done(err));
});
});
it("should return 400 if no videoID specified", (done) => {
describe("getLockReason 400", () => {
it("Should return 400 with missing videoID", (done) => {
client.get(endpoint)
.then(res => {
assert.strictEqual(res.status, 400);
@@ -128,15 +169,37 @@ describe("getLockReason", () => {
.catch(err => done(err));
});
it("should be able to get by actionType", (done) => {
client.get(endpoint, { params: { videoID: "getLockReason", actionType: "full" } })
it("Should return 400 with invalid actionTypes ", (done) => {
client.get(endpoint, { params: { videoID: "valid-videoid", actionTypes: 3 } })
.then(res => {
assert.strictEqual(res.status, 200);
const expected = [
{ category: "selfpromo", locked: 1, reason: "sponsor-reason", userID: vipUserID2, userName: vipUserName2 },
{ category: "sponsor", locked: 0, reason: "", userID: "", userName: "" }
];
partialDeepEquals(res.data, expected);
assert.strictEqual(res.status, 400);
done();
})
.catch(err => done(err));
});
it("Should return 400 with invalid actionTypes JSON ", (done) => {
client.get(endpoint, { params: { videoID: "valid-videoid", actionTypes: "{3}" } })
.then(res => {
assert.strictEqual(res.status, 400);
done();
})
.catch(err => done(err));
});
it("Should return 400 with invalid categories", (done) => {
client.get(endpoint, { params: { videoID: "valid-videoid", categories: 3 } })
.then(res => {
assert.strictEqual(res.status, 400);
done();
})
.catch(err => done(err));
});
it("Should return 400 with invalid categories JSON", (done) => {
client.get(endpoint, { params: { videoID: "valid-videoid", categories: "{3}" } })
.then(res => {
assert.strictEqual(res.status, 400);
done();
})
.catch(err => done(err));

View File

@@ -38,6 +38,15 @@ describe("getTopUsers", () => {
.catch(err => done(err));
});
it("Should return 400 if undefined sortType provided", (done) => {
client.get(endpoint)
.then(res => {
assert.strictEqual(res.status, 400);
done();
})
.catch(err => done(err));
});
it("Should be able to get by all sortTypes", (done) => {
client.get(endpoint, { params: { sortType: 0 } })// minutesSaved
.then(res => {