UNPKG

authenzify

Version:

server to manage authentication authorization of users and more

58 lines (48 loc) 1.65 kB
import getPort from 'get-port' import { before, after } from 'mocha' import { getConfig } from '../../util/settings.js' import { dropDatabase } from '../../util/mongodb-util.js' import { usersManagementServer } from '../../../src/app.js' import { factory } from '../../../src/adapters/factories/index.js' import { ConfigService } from '../../../src/services/config.service.js' describe('Change Password', async () => { let token let server let config 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() .body(credentials) .post('/v1/users/sign-in') const tokenRes = res.json() token = tokenRes.token }) after(async () => { await server?.close() }) describe(`Verify change password to the same password`, () => { it('Should change the password and return true', async () => { const payload = { password: credentials.password, newPassword: '!23Qqw12', } const cookies = { [config.authorizationCookieKey]: token } server .inject() .body(payload) .cookies(cookies) .post('/v1/users/change-password') }) }) })