Advertisement
Guest User

Untitled

a guest
Sep 10th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. import * as supertest from 'supertest';
  2. import {assert} from 'chai';
  3. import app from '../../app/app';
  4. import {prepareTests} from "../../utils/prepareTests";
  5. import {errors} from "../../submodule/phyzeo-shared";
  6. import {shared} from "../shared";
  7.  
  8.  
  9. describe('POST /auth/login', () => {
  10.  
  11.  
  12. before(() => {
  13. prepareTests();
  14. });
  15.  
  16. it('should login when PT User exists', () =>
  17. supertest(app)
  18. .post('/auth/login')
  19. .send({
  20. email: 'testPT@mail.com',
  21. password: '123123'
  22. })
  23. .expect('Content-Type', /json/)
  24. .expect(200)
  25. .expect((res) => {
  26. const {
  27. message,
  28. token
  29. } = res.body;
  30.  
  31. assert.typeOf(message, 'string');
  32. assert.strictEqual(message, 'PT Login successful');
  33. assert.typeOf(token, 'string');
  34. shared.JWT_AUTH_TOKEN = token;
  35. })
  36. );
  37.  
  38. it("should throw unauthorized error when PT User doesn't exists", () =>
  39. supertest(app)
  40. .post('/auth/login')
  41. .send({
  42. email: 'badEmail@mail.com',
  43. password: '123123'
  44. })
  45. .expect('Content-Type', /json/)
  46. .expect(errors.unauthorized.statusCode)
  47. .expect((res) => {
  48. assert.deepStrictEqual(res.body,errors.unauthorized.body);
  49. })
  50. )
  51.  
  52. it("should throw unauthorized error when PA try to login", () =>
  53. supertest(app)
  54. .post('/auth/login')
  55. .send({
  56. email: 'testPA@mail.com',
  57. password: '123123'
  58. })
  59. .expect('Content-Type', /json/)
  60. .expect(errors.unauthorized.statusCode)
  61. .expect((res) => {
  62. assert.deepStrictEqual(res.body,errors.unauthorized.body);
  63. })
  64. )
  65.  
  66. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement