-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unit tests for like/dislike routes
- Loading branch information
Showing
2 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { prismaMock } from '@/__test__/singleton'; | ||
import { generateMockRequest } from '@/__test__/utils'; | ||
import { PUT } from './route'; | ||
import { NextRequest } from 'next/server'; | ||
import { verifySession } from '@/lib/session'; | ||
|
||
jest.mock('@/lib/session', () => ({ | ||
verifySession: jest.fn(), | ||
})); | ||
|
||
const mockVerifySession = verifySession as jest.Mock; | ||
|
||
test("Liked songs fails if session isn't valid", async () => { | ||
mockVerifySession.mockResolvedValue({ | ||
isAuth: false, | ||
}); | ||
|
||
prismaMock.song.upsert.mockResolvedValue({ id: 1, trackID: 'test' }); | ||
|
||
const req = generateMockRequest({ | ||
trackId: 'test', | ||
}); | ||
|
||
const response = await PUT(req as NextRequest); | ||
const data = await response.json(); | ||
|
||
expect(data.error).toEqual('Invalid session'); | ||
}); | ||
|
||
test('Liked songs succeeds for valid session', async () => { | ||
mockVerifySession.mockResolvedValue({ | ||
isAuth: true, | ||
uid: 2, | ||
}); | ||
|
||
prismaMock.song.upsert.mockResolvedValue({ id: 1, trackID: 'test' }); | ||
|
||
const req = generateMockRequest({ | ||
trackId: 'test', | ||
}); | ||
|
||
const response = await PUT(req as NextRequest); | ||
const data = await response.json(); | ||
|
||
expect(data.success).toEqual(true); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { prismaMock } from '@/__test__/singleton'; | ||
import { generateMockRequest } from '@/__test__/utils'; | ||
import { PUT } from './route'; | ||
import { NextRequest } from 'next/server'; | ||
import { verifySession } from '@/lib/session'; | ||
|
||
jest.mock('@/lib/session', () => ({ | ||
verifySession: jest.fn(), | ||
})); | ||
|
||
const mockVerifySession = verifySession as jest.Mock; | ||
|
||
test("Liked songs fails if session isn't valid", async () => { | ||
mockVerifySession.mockResolvedValue({ | ||
isAuth: false, | ||
}); | ||
|
||
prismaMock.song.upsert.mockResolvedValue({ id: 1, trackID: 'test' }); | ||
|
||
const req = generateMockRequest({ | ||
trackId: 'test', | ||
}); | ||
|
||
const response = await PUT(req as NextRequest); | ||
const data = await response.json(); | ||
|
||
expect(data.error).toEqual('Invalid session'); | ||
}); | ||
|
||
test('Liked songs succeeds for valid session', async () => { | ||
mockVerifySession.mockResolvedValue({ | ||
isAuth: true, | ||
uid: 2, | ||
}); | ||
|
||
prismaMock.song.upsert.mockResolvedValue({ id: 1, trackID: 'test' }); | ||
|
||
const req = generateMockRequest({ | ||
trackId: 'test', | ||
}); | ||
|
||
const response = await PUT(req as NextRequest); | ||
const data = await response.json(); | ||
|
||
expect(data.success).toEqual(true); | ||
}); |