UNPKG

authenzify

Version:

server to manage authentication authorization of users and more

62 lines (54 loc) 1.93 kB
import getPort from 'get-port' import * as assert from 'assert' import { before, after } from 'mocha' import { getConfig } from '../../util/settings.js' import { usersManagementServer } from '../../../src/app.js' import { dropDatabase } from '../../util/mongodb-util.js' import { factory } from '../../../src/adapters/factories/index.js' import { ConfigService } from '../../../src/services/config.service.js' import { CHANGE_PASSWORD_ERRORS } from '../../../src/errors/error-codes.js' describe('Change Password', async () => { let token let config let server let credentials before(async () => { const port = await getPort() config = await getConfig({ port }) const { USER_EMAIL, USER_PASSWORD } = process.env credentials = { email: USER_EMAIL, password: USER_PASSWORD } const storageConfig = config.storage await dropDatabase(storageConfig) const configService = new ConfigService(config) const usersManagement = await factory(configService) await usersManagement.signUp(credentials) server = (await usersManagementServer(config)).server const res = await server .inject() .post('/v1/users/sign-in') .body(credentials) const tokenRes = res.json() token = tokenRes.token }) after(async () => { await server?.close() }) describe(`Verify change password to the same password`, () => { it('Should throw an exception the same password already used', async () => { const payload = { password: credentials.password, newPassword: credentials.password, } const cookies = { [config.authorizationCookieKey]: token } const user = await server .inject() .body(payload) .cookies(cookies) .post('/v1/users/change-password') assert.equal( user.json().code, CHANGE_PASSWORD_ERRORS.CANNOT_CHANGE_TO_THE_EXISTING_PASSWORD.code, ) }) }) })