-
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.
Create route to delete current user (#49)
* Create route to delete current user * Add tests for delete route
- Loading branch information
Showing
3 changed files
with
72 additions
and
1 deletion.
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,26 @@ | ||
import { prismaMock } from '@/__test__/singleton'; | ||
import { User } from '@prisma/client'; | ||
import { DELETE } from './route'; | ||
|
||
jest.mock('@/lib/session', () => ({ | ||
verifySession: jest.fn(() => ({ | ||
isAuth: true, | ||
uid: 2, | ||
})), | ||
deleteSession: jest.fn(() => {}), | ||
})); | ||
|
||
test('Delete succeeds if user is authenticated', async () => { | ||
const temporaryUser: User = { | ||
id: 1, | ||
username: 'test', | ||
createdAt: new Date(), | ||
updatedAt: new Date(), | ||
}; | ||
prismaMock.user.delete.mockResolvedValue(temporaryUser); | ||
|
||
const res = await DELETE(); | ||
const data = await res.json(); | ||
|
||
expect(data.success).toBe(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,16 @@ | ||
import { DELETE } from './route'; | ||
|
||
jest.mock('@/lib/session', () => ({ | ||
verifySession: jest.fn(() => ({ | ||
isAuth: false, | ||
})), | ||
deleteSession: jest.fn(() => {}), | ||
})); | ||
|
||
test('Delete fails for an invalid session', async () => { | ||
const res = await DELETE(); | ||
const data = await res.json(); | ||
|
||
expect(res.status).toEqual(400); | ||
expect(data.error).toBe('Invalid session'); | ||
}); |
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