authentification.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. process.env.NODE_ENV = 'test';
  2. const config = require('../config');
  3. let server = require('../app');
  4. let chai = require('chai');
  5. let chaiHttp = require('chai-http');
  6. const {
  7. expect
  8. } = require('chai');
  9. let should = chai.should();
  10. chai.use(chaiHttp);
  11. describe('Authentification.js', () => {
  12. /*
  13. * Test the /GET route
  14. */
  15. describe('/get POST to check authentification.js middleware', () => {
  16. it('it should return "Please send the password API." : we are not sending any password post', (done) => {
  17. chai.request(server)
  18. .post('/get')
  19. .set('content-type', 'application/x-www-form-urlencoded')
  20. .end((err, res) => {
  21. res.should.have.status(401);
  22. res.should.to.be.json;
  23. res.body.should.have.property('error').eql('Please send the password API.');
  24. done();
  25. });
  26. });
  27. it('it should return "The password you sent is empty." : we are not sending an empty password', (done) => {
  28. chai.request(server)
  29. .post('/get')
  30. .set('content-type', 'application/x-www-form-urlencoded')
  31. .send({
  32. password: ' '
  33. })
  34. .end((err, res) => {
  35. res.should.have.status(401);
  36. res.should.to.be.json;
  37. res.body.should.have.property('error').eql('The password you sent is empty.');
  38. done();
  39. });
  40. });
  41. it('it should return "Invalid password." : we are sending a bad password', (done) => {
  42. chai.request(server)
  43. .post('/get')
  44. .set('content-type', 'application/x-www-form-urlencoded')
  45. .send({
  46. password: 'badpassword'
  47. })
  48. .end((err, res) => {
  49. res.should.have.status(401);
  50. res.should.to.be.json;
  51. res.body.should.have.property('error').eql('Invalid password.');
  52. done();
  53. });
  54. });
  55. it('it should return be good : no error', (done) => {
  56. chai.request(server)
  57. .post('/get')
  58. .set('content-type', 'application/x-www-form-urlencoded')
  59. .send({
  60. password: config.apipassword
  61. })
  62. .end((err, res) => {
  63. res.should.have.status(200);
  64. res.should.to.be.json;
  65. done();
  66. });
  67. });
  68. });
  69. });