feat: migrate from express to fastify
This commit is contained in:
66
src/services/users/reset-password/__test__/post.test.ts
Normal file
66
src/services/users/reset-password/__test__/post.test.ts
Normal file
@ -0,0 +1,66 @@
|
||||
import ms from 'ms'
|
||||
|
||||
import { application } from '../../../../application.js'
|
||||
import { userExample } from '../../../../models/User.js'
|
||||
import { userSettingsExample } from '../../../../models/UserSettings.js'
|
||||
import { prismaMock } from '../../../../__test__/setup.js'
|
||||
|
||||
describe('POST /users/reset-password', () => {
|
||||
it('succeeds', async () => {
|
||||
prismaMock.user.findUnique.mockResolvedValue(userExample)
|
||||
prismaMock.userSetting.findFirst.mockResolvedValue(userSettingsExample)
|
||||
const response = await application.inject({
|
||||
method: 'POST',
|
||||
url: '/users/reset-password?redirectURI=https://redirecturi.com',
|
||||
payload: { email: userExample.email }
|
||||
})
|
||||
expect(response.statusCode).toEqual(200)
|
||||
})
|
||||
|
||||
it("fails with email that doesn't exist", async () => {
|
||||
const response = await application.inject({
|
||||
method: 'POST',
|
||||
url: '/users/reset-password?redirectURI=https://redirecturi.com',
|
||||
payload: { email: userExample.email }
|
||||
})
|
||||
expect(response.statusCode).toEqual(400)
|
||||
})
|
||||
|
||||
it('fails with unconfirmed account', async () => {
|
||||
prismaMock.user.findUnique.mockResolvedValue({
|
||||
...userExample,
|
||||
isConfirmed: false
|
||||
})
|
||||
const response = await application.inject({
|
||||
method: 'POST',
|
||||
url: '/users/reset-password?redirectURI=https://redirecturi.com',
|
||||
payload: { email: userExample.email }
|
||||
})
|
||||
expect(response.statusCode).toEqual(400)
|
||||
})
|
||||
|
||||
it("fails if userSettings doenst' exist", async () => {
|
||||
prismaMock.user.findUnique.mockResolvedValue(userExample)
|
||||
prismaMock.userSetting.findFirst.mockResolvedValue(null)
|
||||
const response = await application.inject({
|
||||
method: 'POST',
|
||||
url: '/users/reset-password?redirectURI=https://redirecturi.com',
|
||||
payload: { email: userExample.email }
|
||||
})
|
||||
expect(response.statusCode).toEqual(400)
|
||||
})
|
||||
|
||||
it('fails with a request already in progress', async () => {
|
||||
prismaMock.user.findUnique.mockResolvedValue({
|
||||
...userExample,
|
||||
temporaryExpirationToken: new Date(Date.now() + ms('1 hour'))
|
||||
})
|
||||
prismaMock.userSetting.findFirst.mockResolvedValue(userSettingsExample)
|
||||
const response = await application.inject({
|
||||
method: 'POST',
|
||||
url: '/users/reset-password?redirectURI=https://redirecturi.com',
|
||||
payload: { email: userExample.email }
|
||||
})
|
||||
expect(response.statusCode).toEqual(400)
|
||||
})
|
||||
})
|
36
src/services/users/reset-password/__test__/put.test.ts
Normal file
36
src/services/users/reset-password/__test__/put.test.ts
Normal file
@ -0,0 +1,36 @@
|
||||
import ms from 'ms'
|
||||
|
||||
import { application } from '../../../../application.js'
|
||||
import { userExample } from '../../../../models/User.js'
|
||||
import { prismaMock } from '../../../../__test__/setup.js'
|
||||
|
||||
describe('PUT /users/reset-password', () => {
|
||||
it('succeeds', async () => {
|
||||
prismaMock.user.findFirst.mockResolvedValue({
|
||||
...userExample,
|
||||
temporaryExpirationToken: new Date(Date.now() + ms('1 hour'))
|
||||
})
|
||||
const response = await application.inject({
|
||||
method: 'PUT',
|
||||
url: '/users/reset-password',
|
||||
payload: {
|
||||
password: 'new password',
|
||||
temporaryToken: userExample.temporaryToken
|
||||
}
|
||||
})
|
||||
expect(response.statusCode).toEqual(200)
|
||||
})
|
||||
|
||||
it('fails with expired temporaryToken', async () => {
|
||||
prismaMock.user.findFirst.mockResolvedValue(userExample)
|
||||
const response = await application.inject({
|
||||
method: 'PUT',
|
||||
url: '/users/reset-password',
|
||||
payload: {
|
||||
password: 'new password',
|
||||
temporaryToken: userExample.temporaryToken
|
||||
}
|
||||
})
|
||||
expect(response.statusCode).toEqual(400)
|
||||
})
|
||||
})
|
Reference in New Issue
Block a user