Skip to content

Commit f023203

Browse files
committed
GET /bookmarks test case
1 parent 9df5168 commit f023203

File tree

4 files changed

+64
-2
lines changed

4 files changed

+64
-2
lines changed

tests/auth/external-api-auth-error.test.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
import { prisma } from '@/lib/db';
12
import { IntegrationHarness } from '@/tests/utils/integration';
23
import { OasisTestContext } from '@/tests/utils/setup';
3-
import { expect, test } from 'vitest';
4+
import { afterAll, expect, test } from 'vitest';
45

56
test('EXTERNAL API AUTH ERROR', async (ctx: OasisTestContext) => {
67
ctx.apiToken = 'INVALID API TOKEN';
@@ -22,3 +23,7 @@ test('EXTERNAL API AUTH ERROR', async (ctx: OasisTestContext) => {
2223
expect(success).toBe(false);
2324
expect(error).toBe('Unauthorized: Invalid API Token');
2425
});
26+
27+
afterAll(async () => {
28+
await prisma.apiToken.deleteMany({});
29+
});

tests/auth/internal-api-auth-error.test.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
import { prisma } from '@/lib/db';
12
import { IntegrationHarness } from '@/tests/utils/integration';
23
import { OasisTestContext } from '@/tests/utils/setup';
3-
import { expect, test } from 'vitest';
4+
import { afterAll, expect, test } from 'vitest';
45

56
test('INTERNAL API AUTH ERROR', async (ctx: OasisTestContext) => {
67
const h = new IntegrationHarness(ctx);
@@ -20,3 +21,7 @@ test('INTERNAL API AUTH ERROR', async (ctx: OasisTestContext) => {
2021
expect(success).toBe(false);
2122
expect(error).toBe('Unauthorized');
2223
});
24+
25+
afterAll(async () => {
26+
await prisma.apiToken.deleteMany({});
27+
});

tests/bookmarks/get-bookmarks.test.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { prisma } from '@/lib/db';
2+
import { IntegrationHarness } from '@/tests/utils/integration';
3+
import { OasisTestContext, getSetupData } from '@/tests/utils/setup';
4+
import { Bookmark } from '@prisma/client';
5+
import { afterAll, expect, test } from 'vitest';
6+
7+
test('GET /bookmarks', async (ctx: OasisTestContext) => {
8+
const { user, apiToken } = await getSetupData();
9+
ctx.apiToken = apiToken;
10+
11+
const h = new IntegrationHarness(ctx);
12+
const { http } = await h.init();
13+
14+
const createdBookmarks = (
15+
await prisma.bookmark.createManyAndReturn({
16+
data: [
17+
{
18+
userId: user.id,
19+
url: 'https://www.youtube.com/',
20+
title: 'Youtube',
21+
},
22+
{
23+
userId: user.id,
24+
url: 'https://github.com/',
25+
title: 'Github',
26+
},
27+
],
28+
})
29+
).map((bookmark) => ({
30+
...bookmark,
31+
createdAt: bookmark.createdAt.toISOString(),
32+
updatedAt: bookmark.updatedAt.toISOString(),
33+
}));
34+
35+
const {
36+
status,
37+
data: { success, message, data: fetchedBookmarks },
38+
} = await http.get<Bookmark[]>({
39+
path: '/bookmarks',
40+
});
41+
42+
expect(status).toBe(200);
43+
expect(success).toBe(true);
44+
expect(message).toBe('Bookmarks gathered successfully.');
45+
expect(createdBookmarks).toEqual(fetchedBookmarks);
46+
});
47+
48+
afterAll(async () => {
49+
await prisma.bookmark.deleteMany({});
50+
await prisma.apiToken.deleteMany({});
51+
});

vitest.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ export default defineConfig({
88
reporters: ['verbose'],
99
testTimeout: 50000,
1010
setupFiles: './tests/utils/setup.ts',
11+
fileParallelism: false,
1112
},
1213
});

0 commit comments

Comments
 (0)