Skip to content

Feature/forgotten pw #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions __tests__/userAuth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,60 @@ describe('User Authentication tests', () => {
.then((res) => expect(res.text).toBe('"Incorrect Password"'));
});
});

describe('/updatePassword', () => {
describe('POST', () => {
//testing update password
const testUsername = `supertest${Date.now()}`;
const testPassword = `password${Date.now()}`;
it('responds with status 200 and json string on valid password update (Success)', () => {
return request(app)
.post('/updatePassword')
.set('Content-Type', 'application/json')
.send({
username: testUsername,
password: testPassword
})
.expect(200)
.then((res) => expect(res.body.message).toBe('Success')); // might need to be res.text instead of res.body.message
});

it('responds with status 400 and json string if no password is provided (Password is required.)', () => {
return request(app)
.post('/updatePassword')
.send({ username: testUsername })
.set('Accept', 'application/json')
.expect('Content-Type', /json/)
.expect(400)
.then((res) => expect(res.body.error).toBe('Password is required.'));
});

it('responds with status 404 and json string if user is not found (User not found.)', () => {
return request(app)
.post('/updatePassword')
.send({ username: 'doesntexist', password: 'fakepassword' })
.set('Accept', 'application/json')
.expect('Content-Type', /json/)
.expect(404)
.then((res) => expect(res.body.error).toBe('User not found.'));
});

it('responds with status 400 and json string the provided password is the same as the current password (New password must be different from the current password.)', () => {
return request(app)
.post('/updatePassword')
.send({
username: testUsername,
password: testPassword
})
.set('Accept', 'application/json')
.expect('Content-Type', /json/)
.expect(400)
.then((res) =>
expect(res.body.error).toBe(
'New password must be different from the current password.'
)
);
});
});
});
});
Loading