it('should report error when email and password are not provided', () => { return request(app) .post('/v1/auth/register') .send({}) .expect(httpStatus.BAD_REQUEST) .then((res) => { const { field } = res.body.errors[0]; const { location } = res.body.errors[0]; const { messages } = res.body.errors[0]; expect(field).to.be.equal('email'); expect(location).to.be.equal('body'); expect(messages).to.include('"email" is required'); }); });
it('should report error when password is not provided', () => { return request(app) .post('/v1/auth/reset-password') .send({ email: dbUser.email, resetToken: resetToken.resetToken }) .expect(httpStatus.BAD_REQUEST) .then((res) => { const field1 = res.body.errors[0].field; const location1 = res.body.errors[0].location; const messages1 = res.body.errors[0].messages; expect(field1).to.be.equal('password'); expect(location1).to.be.equal('body'); expect(messages1).to.include('"password" is required'); }); });
it('should report error user when password length is less than 6', async () => { const id = (await User.findOne({}))._id; user.password = '12345'; return request(app) .put(`/v1/users/${id}`) .set('Authorization', `Bearer ${adminAccessToken}`) .send(user) .expect(httpStatus.BAD_REQUEST) .then((res) => { const { field } = res.body.errors[0]; const { location } = res.body.errors[0]; const { messages } = res.body.errors[0]; expect(field).to.be.equal('password'); expect(location).to.be.equal('body'); expect(messages).to.include('"password" length must be at least 6 characters long'); }); });
it('should report error when email is not provided', () => { delete user.email; return request(app) .post('/v1/users') .set('Authorization', `Bearer ${adminAccessToken}`) .send(user) .expect(httpStatus.BAD_REQUEST) .then((res) => { const { field } = res.body.errors[0]; const { location } = res.body.errors[0]; const { messages } = res.body.errors[0]; expect(field).to.be.equal('email'); expect(location).to.be.equal('body'); expect(messages).to.include('"email" is required'); }); });
return request(app) .post('/v1/auth/google') .expect(httpStatus.BAD_REQUEST) .then((res) => { const { field } = res.body.errors[0];
it('should report error when email is not provided', async () => { const id = (await User.findOne({}))._id; delete user.email; return request(app) .put(`/v1/users/${id}`) .set('Authorization', `Bearer ${adminAccessToken}`) .send(user) .expect(httpStatus.BAD_REQUEST) .then((res) => { const { field } = res.body.errors[0]; const { location } = res.body.errors[0]; const { messages } = res.body.errors[0]; expect(field).to.be.equal('email'); expect(location).to.be.equal('body'); expect(messages).to.include('"email" is required'); }); });
.post('/v1/auth/send-password-reset') .send({}) .expect(httpStatus.BAD_REQUEST) .then((res) => { const field1 = res.body.errors[0].field;
.post('/v1/auth/login') .send({}) .expect(httpStatus.BAD_REQUEST) .then((res) => { const { field } = res.body.errors[0]; .post('/v1/auth/login') .send(user) .expect(httpStatus.BAD_REQUEST) .then((res) => { const { field } = res.body.errors[0];
it('should report error when email and refreshToken are not provided', () => { return request(app) .post('/v1/auth/refresh-token') .send({}) .expect(httpStatus.BAD_REQUEST) .then((res) => { const field1 = res.body.errors[0].field; const location1 = res.body.errors[0].location; const messages1 = res.body.errors[0].messages; const field2 = res.body.errors[1].field; const location2 = res.body.errors[1].location; const messages2 = res.body.errors[1].messages; expect(field1).to.be.equal('email'); expect(location1).to.be.equal('body'); expect(messages1).to.include('"email" is required'); expect(field2).to.be.equal('refreshToken'); expect(location2).to.be.equal('body'); expect(messages2).to.include('"refreshToken" is required'); }); });
it('should report error when password length is less than 6', () => { user.password = '12345'; return request(app) .post('/v1/users') .set('Authorization', `Bearer ${adminAccessToken}`) .send(user) .expect(httpStatus.BAD_REQUEST) .then((res) => { const { field } = res.body.errors[0]; const { location } = res.body.errors[0]; const { messages } = res.body.errors[0]; expect(field).to.be.equal('password'); expect(location).to.be.equal('body'); expect(messages).to.include('"password" length must be at least 6 characters long'); }); });
it('should report error when pagination\'s parameters are not a number', () => { return request(app) .get('/v1/users') .set('Authorization', `Bearer ${adminAccessToken}`) .query({ page: '?', perPage: 'whaat' }) .expect(httpStatus.BAD_REQUEST) .then((res) => { const { field } = res.body.errors[0]; const { location } = res.body.errors[0]; const { messages } = res.body.errors[0]; expect(field).to.be.equal('page'); expect(location).to.be.equal('query'); expect(messages).to.include('"page" must be a number'); return Promise.resolve(res); }) .then((res) => { const { field } = res.body.errors[1]; const { location } = res.body.errors[1]; const { messages } = res.body.errors[1]; expect(field).to.be.equal('perPage'); expect(location).to.be.equal('query'); expect(messages).to.include('"perPage" must be a number'); }); });
it('should report error when reset token is not provided', () => { return request(app) .post('/v1/auth/reset-password') .send({ email: dbUser.email, password: 'updatedPassword' }) .expect(httpStatus.BAD_REQUEST) .then((res) => { const field1 = res.body.errors[0].field; const location1 = res.body.errors[0].location; const messages1 = res.body.errors[0].messages; expect(field1).to.be.equal('resetToken'); expect(location1).to.be.equal('body'); expect(messages1).to.include('"resetToken" is required'); }); });
it('should report error when email is not provided', () => { return request(app) .post('/v1/auth/reset-password') .send({ password: 'updatedPassword', resetToken: resetToken.resetToken }) .expect(httpStatus.BAD_REQUEST) .then((res) => { const field1 = res.body.errors[0].field; const location1 = res.body.errors[0].location; const messages1 = res.body.errors[0].messages; expect(field1).to.be.equal('email'); expect(location1).to.be.equal('body'); expect(messages1).to.include('"email" is required'); }); });
it('should report error when the email provided is not valid', () => { user.email = 'this_is_not_an_email'; return request(app) .post('/v1/auth/register') .send(user) .expect(httpStatus.BAD_REQUEST) .then((res) => { const { field } = res.body.errors[0]; const { location } = res.body.errors[0]; const { messages } = res.body.errors[0]; expect(field).to.be.equal('email'); expect(location).to.be.equal('body'); expect(messages).to.include('"email" must be a valid email'); }); });
return request(app) .post('/v1/auth/facebook') .expect(httpStatus.BAD_REQUEST) .then((res) => { const { field } = res.body.errors[0];