Skip to content

Commit 2c887b6

Browse files
authored
Merge pull request #2 from oslabs-beta/feature/ForgottenPW
Feature/forgotten pw
2 parents baef808 + 1605e74 commit 2c887b6

File tree

11 files changed

+1090
-463
lines changed

11 files changed

+1090
-463
lines changed

__tests__/userAuth.test.ts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,4 +147,60 @@ describe('User Authentication tests', () => {
147147
.then((res) => expect(res.text).toBe('"Incorrect Password"'));
148148
});
149149
});
150+
151+
describe('/updatePassword', () => {
152+
describe('POST', () => {
153+
//testing update password
154+
const testUsername = `supertest${Date.now()}`;
155+
const testPassword = `password${Date.now()}`;
156+
it('responds with status 200 and json string on valid password update (Success)', () => {
157+
return request(app)
158+
.post('/updatePassword')
159+
.set('Content-Type', 'application/json')
160+
.send({
161+
username: testUsername,
162+
password: testPassword
163+
})
164+
.expect(200)
165+
.then((res) => expect(res.body.message).toBe('Success')); // might need to be res.text instead of res.body.message
166+
});
167+
168+
it('responds with status 400 and json string if no password is provided (Password is required.)', () => {
169+
return request(app)
170+
.post('/updatePassword')
171+
.send({ username: testUsername })
172+
.set('Accept', 'application/json')
173+
.expect('Content-Type', /json/)
174+
.expect(400)
175+
.then((res) => expect(res.body.error).toBe('Password is required.'));
176+
});
177+
178+
it('responds with status 404 and json string if user is not found (User not found.)', () => {
179+
return request(app)
180+
.post('/updatePassword')
181+
.send({ username: 'doesntexist', password: 'fakepassword' })
182+
.set('Accept', 'application/json')
183+
.expect('Content-Type', /json/)
184+
.expect(404)
185+
.then((res) => expect(res.body.error).toBe('User not found.'));
186+
});
187+
188+
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.)', () => {
189+
return request(app)
190+
.post('/updatePassword')
191+
.send({
192+
username: testUsername,
193+
password: testPassword
194+
})
195+
.set('Accept', 'application/json')
196+
.expect('Content-Type', /json/)
197+
.expect(400)
198+
.then((res) =>
199+
expect(res.body.error).toBe(
200+
'New password must be different from the current password.'
201+
)
202+
);
203+
});
204+
});
205+
});
150206
});

0 commit comments

Comments
 (0)