Skip to content

Commit c34de1b

Browse files
committed
add 4xx tests
1 parent a469f2f commit c34de1b

File tree

5 files changed

+164
-15
lines changed

5 files changed

+164
-15
lines changed

test/cases/generateVerifyToken.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ describe("verifyToken mock tests", function() {
104104

105105
beforeEach(function() {
106106
mock = new MockAdapter(axios, { onNoMatch: "throwException" });
107+
mock.onPost("https://www.patreon.com/api/oauth2/token").reply(200, patreon.fakeOauth);
107108
});
108109

109110
afterEach(function () {

test/cases/getDaysSavedFormatted.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import assert from "assert";
22
import { client } from "../utils/httpClient";
3+
import sinon from "sinon";
4+
import { db } from "../../src/databases/databases";
35

46
const endpoint = "/api/getDaysSavedFormatted";
57

@@ -8,4 +10,18 @@ describe("getDaysSavedFormatted", () => {
810
const result = await client({ url: endpoint });
911
assert.ok(result.data.daysSaved >= 0);
1012
});
13+
14+
it("returns 0 days saved if no segments", async () => {
15+
const stub = sinon.stub(db, "prepare").resolves(undefined);
16+
const result = await client({ url: endpoint });
17+
assert.ok(result.data.daysSaved >= 0);
18+
stub.restore();
19+
});
20+
21+
it("returns days saved to 2 fixed points", async () => {
22+
const stub = sinon.stub(db, "prepare").resolves({ daysSaved: 1.23456789 });
23+
const result = await client({ url: endpoint });
24+
assert.strictEqual(result.data.daysSaved, "1.23");
25+
stub.restore();
26+
});
1127
});

test/cases/getLockCategoriesByHash.ts

Lines changed: 66 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -166,17 +166,77 @@ describe("getLockCategoriesByHash", () => {
166166
.catch(err => done(err));
167167
});
168168

169-
it("Should be able to get by actionType", (done) => {
170-
getLockCategories(fakeHash.substring(0,5), [ActionType.Full])
169+
it("should return 400 if invalid actionTypes", (done) => {
170+
client.get(`${endpoint}/aaaa`, { params: { actionTypes: 3 } })
171+
.then(res => {
172+
assert.strictEqual(res.status, 400);
173+
done();
174+
})
175+
.catch(err => done(err));
176+
});
177+
178+
it("should return 400 if invalid actionTypes JSON", (done) => {
179+
client.get(`${endpoint}/aaaa`, { params: { actionTypes: "{3}" } })
180+
.then(res => {
181+
assert.strictEqual(res.status, 400);
182+
done();
183+
})
184+
.catch(err => done(err));
185+
});
186+
187+
it("Should be able to get single lock", (done) => {
188+
const videoID = "getLockHash2";
189+
const hash = getHash(videoID, 1);
190+
getLockCategories(hash.substring(0,6))
171191
.then(res => {
172192
assert.strictEqual(res.status, 200);
173193
const expected = [{
174-
videoID: "fakehash-2",
175-
hash: fakeHash,
194+
videoID,
195+
hash,
196+
categories: [
197+
"preview"
198+
],
199+
reason: "2-reason"
200+
}];
201+
assert.deepStrictEqual(res.data, expected);
202+
done();
203+
})
204+
.catch(err => done(err));
205+
});
206+
207+
it("Should be able to get by actionType not in array", (done) => {
208+
const videoID = "getLockHash2";
209+
const hash = getHash(videoID, 1);
210+
client.get(`${endpoint}/${hash.substring(0,6)}`, { params: { actionType: ActionType.Skip } })
211+
.then(res => {
212+
assert.strictEqual(res.status, 200);
213+
const expected = [{
214+
videoID,
215+
hash,
216+
categories: [
217+
"preview"
218+
],
219+
reason: "2-reason"
220+
}];
221+
assert.deepStrictEqual(res.data, expected);
222+
done();
223+
})
224+
.catch(err => done(err));
225+
});
226+
227+
it("Should be able to get by no actionType", (done) => {
228+
const videoID = "getLockHash2";
229+
const hash = getHash(videoID, 1);
230+
client.get(`${endpoint}/${hash.substring(0,6)}`)
231+
.then(res => {
232+
assert.strictEqual(res.status, 200);
233+
const expected = [{
234+
videoID,
235+
hash,
176236
categories: [
177-
"sponsor"
237+
"preview"
178238
],
179-
reason: "fake2-notshown"
239+
reason: "2-reason"
180240
}];
181241
assert.deepStrictEqual(res.data, expected);
182242
done();

test/cases/getLockReason.ts

Lines changed: 72 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,45 @@ describe("getLockReason", () => {
5555
.catch(err => done(err));
5656
});
5757

58+
it("Should be able to get with actionTypes array", (done) => {
59+
client.get(endpoint, { params: { videoID: "getLockReason", category: "selfpromo", actionTypes: '["full"]' } })
60+
.then(res => {
61+
assert.strictEqual(res.status, 200);
62+
const expected = [
63+
{ category: "selfpromo", locked: 1, reason: "selfpromo-reason", userID: vipUserID2, userName: vipUserName2 }
64+
];
65+
assert.deepStrictEqual(res.data, expected);
66+
done();
67+
})
68+
.catch(err => done(err));
69+
});
70+
71+
it("Should be able to get with actionType", (done) => {
72+
client.get(endpoint, { params: { videoID: "getLockReason", category: "selfpromo", actionType: "full" } })
73+
.then(res => {
74+
assert.strictEqual(res.status, 200);
75+
const expected = [
76+
{ category: "selfpromo", locked: 1, reason: "selfpromo-reason", userID: vipUserID2, userName: vipUserName2 }
77+
];
78+
assert.deepStrictEqual(res.data, expected);
79+
done();
80+
})
81+
.catch(err => done(err));
82+
});
83+
84+
it("Should be able to get with actionType array", (done) => {
85+
client.get(endpoint, { params: { videoID: "getLockReason", category: "selfpromo", actionType: ["full"] } })
86+
.then(res => {
87+
assert.strictEqual(res.status, 200);
88+
const expected = [
89+
{ category: "selfpromo", locked: 1, reason: "selfpromo-reason", userID: vipUserID2, userName: vipUserName2 }
90+
];
91+
assert.deepStrictEqual(res.data, expected);
92+
done();
93+
})
94+
.catch(err => done(err));
95+
});
96+
5897
it("Should be able to get empty locks", (done) => {
5998
client.get(endpoint, { params: { videoID: "getLockReason", category: "intro" } })
6099
.then(res => {
@@ -118,8 +157,10 @@ describe("getLockReason", () => {
118157
})
119158
.catch(err => done(err));
120159
});
160+
});
121161

122-
it("should return 400 if no videoID specified", (done) => {
162+
describe("getLockReason 400", () => {
163+
it("Should return 400 with missing videoID", (done) => {
123164
client.get(endpoint)
124165
.then(res => {
125166
assert.strictEqual(res.status, 400);
@@ -128,15 +169,37 @@ describe("getLockReason", () => {
128169
.catch(err => done(err));
129170
});
130171

131-
it("should be able to get by actionType", (done) => {
132-
client.get(endpoint, { params: { videoID: "getLockReason", actionType: "full" } })
172+
it("Should return 400 with invalid actionTypes ", (done) => {
173+
client.get(endpoint, { params: { videoID: "valid-videoid", actionTypes: 3 } })
133174
.then(res => {
134-
assert.strictEqual(res.status, 200);
135-
const expected = [
136-
{ category: "selfpromo", locked: 1, reason: "sponsor-reason", userID: vipUserID2, userName: vipUserName2 },
137-
{ category: "sponsor", locked: 0, reason: "", userID: "", userName: "" }
138-
];
139-
partialDeepEquals(res.data, expected);
175+
assert.strictEqual(res.status, 400);
176+
done();
177+
})
178+
.catch(err => done(err));
179+
});
180+
181+
it("Should return 400 with invalid actionTypes JSON ", (done) => {
182+
client.get(endpoint, { params: { videoID: "valid-videoid", actionTypes: "{3}" } })
183+
.then(res => {
184+
assert.strictEqual(res.status, 400);
185+
done();
186+
})
187+
.catch(err => done(err));
188+
});
189+
190+
it("Should return 400 with invalid categories", (done) => {
191+
client.get(endpoint, { params: { videoID: "valid-videoid", categories: 3 } })
192+
.then(res => {
193+
assert.strictEqual(res.status, 400);
194+
done();
195+
})
196+
.catch(err => done(err));
197+
});
198+
199+
it("Should return 400 with invalid categories JSON", (done) => {
200+
client.get(endpoint, { params: { videoID: "valid-videoid", categories: "{3}" } })
201+
.then(res => {
202+
assert.strictEqual(res.status, 400);
140203
done();
141204
})
142205
.catch(err => done(err));

test/cases/getTopUsers.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,15 @@ describe("getTopUsers", () => {
3838
.catch(err => done(err));
3939
});
4040

41+
it("Should return 400 if undefined sortType provided", (done) => {
42+
client.get(endpoint)
43+
.then(res => {
44+
assert.strictEqual(res.status, 400);
45+
done();
46+
})
47+
.catch(err => done(err));
48+
});
49+
4150
it("Should be able to get by all sortTypes", (done) => {
4251
client.get(endpoint, { params: { sortType: 0 } })// minutesSaved
4352
.then(res => {

0 commit comments

Comments
 (0)