This repository has been archived on 2025-11-04. You can view files and clone it, but you cannot make any changes to its state, such as pushing and creating new issues, pull requests or comments.
know-it-all/server/tests/auth/ResetPassword.test.js

58 lines
1.7 KiB
JavaScript

const supertest = require('supertest');
const { sequelize } = require('../../db/models/index');
const app = require('../../app');
const { createTestResetRequest } = require('../utils');
const errors = require('../../config/error.json');
describe('Reset Password', function () {
beforeEach(async () => {
try {
await sequelize.authenticate();
await sequelize.sync({ force: 'true' });
} catch (error) {
console.log('[ERROR]: Database connection failed');
}
});
it('[200] Successful reset password', async () => {
const resetRequest = await createTestResetRequest({
firstName: 'Test',
lastName: 'User',
password: 'password',
});
await supertest(app)
.patch(`/api/auth/reset/${resetRequest.id}`)
.send({
password: 'newPassword',
})
.expect('Content-Type', /text/)
.expect(200, 'OK');
});
it('[400] Missing password', async () => {
const resetRequest = await createTestResetRequest({
firstName: 'Test',
lastName: 'User',
password: 'password',
});
await supertest(app)
.patch(`/api/auth/reset/${resetRequest.reqID}`)
.send()
.expect('Content-Type', /json/)
.expect(400, errors.Incomplete);
});
it('[500] Reset request does not exist', async () => {
await supertest(app)
.patch(`/api/auth/reset/randomString`)
.send({
password: 'newPassword',
})
.expect('Content-Type', /json/)
.expect(500, errors.Generic);
});
});