Skip to content

Commit

Permalink
test: add unit, integration tests for new imgur upload functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
Xunnamius committed Aug 7, 2021
1 parent 1eaf424 commit 8e78046
Show file tree
Hide file tree
Showing 4 changed files with 264 additions and 58 deletions.
30 changes: 28 additions & 2 deletions test/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ import type {
InternalLimitedLogEntry,
InternalMeme,
InternalUser,
InternalInfo
InternalInfo,
InternalUpload
} from 'types/global';

import { toss } from 'toss-expression';
Expand All @@ -41,6 +42,7 @@ export type DummyDbData = {
keys: WithId<InternalApiKey>[];
memes: WithId<InternalMeme>[];
users: WithId<InternalUser>[];
uploads: WithId<InternalUpload>[];
info: WithId<InternalInfo>;
logs: WithId<InternalRequestLogEntry>[];
bans: WithId<InternalLimitedLogEntry>[];
Expand Down Expand Up @@ -92,10 +94,31 @@ export const dummyDbData: DummyDbData = {
imageUrl: null,
meta: { creator: DUMMY_KEY }
})),
uploads: [
{
_id: new ObjectId(),
uri: 'https://uri1',
hash: 'hash-1',
lastUsedAt: now - 1000
},
{
_id: new ObjectId(),
uri: 'https://uri2',
hash: 'hash-2',
lastUsedAt: now
},
{
_id: new ObjectId(),
uri: 'https://uri3',
hash: 'hash-3',
lastUsedAt: now + 1000
}
],
info: {
_id: new ObjectId(),
totalMemes: memes.length,
totalUsers: DUMMY_USER_COUNT
totalUsers: DUMMY_USER_COUNT,
totalUploads: 3
},
logs: [...Array(22)].map((_, ndx) => ({
_id: new ObjectId(),
Expand Down Expand Up @@ -218,6 +241,9 @@ export async function hydrateDb(db: Db, data: DummyDbData) {
...[newData.keys.length ? db.collection('keys').insertMany(newData.keys) : null],
...[newData.users.length ? db.collection('users').insertMany(newData.users) : null],
...[newData.memes.length ? db.collection('memes').insertMany(newData.memes) : null],
...[
newData.uploads.length ? db.collection('uploads').insertMany(newData.uploads) : null
],
...[newData.logs ? db.collection('request-log').insertMany(newData.logs) : null],
...[newData.bans ? db.collection('limited-log-mview').insertMany(newData.bans) : null]
]);
Expand Down
6 changes: 4 additions & 2 deletions test/unit-api-info.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ beforeEach(() => {
asMockedFunction(getSystemInfo).mockReturnValue(
Promise.resolve({
totalMemes: dummyDbData.memes.length,
totalUsers: dummyDbData.users.length
totalUsers: dummyDbData.users.length,
totalUploads: dummyDbData.uploads.length
})
);
});
Expand All @@ -35,7 +36,8 @@ describe('api/v1/info', () => {
expect(await fetch({ headers: { KEY } }).then((r) => r.json())).toStrictEqual({
success: true,
totalMemes: dummyDbData.memes.length,
totalUsers: dummyDbData.users.length
totalUsers: dummyDbData.users.length,
totalUploads: dummyDbData.uploads.length
});
}
});
Expand Down
Loading

0 comments on commit 8e78046

Please sign in to comment.