daily pastebin goal
9%
SHARE
TWEET

Untitled

a guest Oct 17th, 2017 111 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const test = require('tape')
  2. const request = require('supertest')
  3. const app = require('./server').app
  4. const logLevels = require('../shared/log-levels')
  5. const languageSpec = require('../shared/languages')('pt')
  6. const moment = require('moment')
  7.  
  8. let token = null
  9.  
  10. test('Execute test for endpoint: /login with method: post - should return 200', async (assert) => {
  11.   const response = await request(app)
  12.   .post('/login')
  13.   .send({ username: 'challenge', password: 'ch@113ng3' })
  14.  
  15.   assert.equals(response.status, 200)
  16.   assert.equals(response.body.username, 'challenge')
  17.   assert.ok(response.body.token)
  18.   assert.equals(response.body.role, 0)
  19.   token = response.body.token
  20.   assert.end()
  21. })
  22.  
  23. test('Execute test for endpoint: /login with method: post - should return 400 (invalid body, missing username)', async (assert) => {
  24.   const response = await request(app)
  25.   .post('/login')
  26.   .send({ password: 'ch@113ng3' })
  27.  
  28.   assert.equals(response.status, 400)
  29.   assert.equals(response.body.level, logLevels.WARNING)
  30.   assert.equals(response.body.message, languageSpec.validationParametersMessage)
  31.   assert.end()
  32. })
  33.  
  34. test('Execute test for endpoint: /login with method: post - should return 400 (bad user)', async (assert) => {
  35.   const response = await request(app)
  36.   .post('/login')
  37.   .send({ username: 'challenge', password: '12345' })
  38.  
  39.   assert.equals(response.status, 400)
  40.   assert.equals(response.body.level, logLevels.WARNING)
  41.   assert.equals(response.body.message, languageSpec.badUserMessage)
  42.   assert.end()
  43. })
  44.  
  45. test('Execute test for endpoint: /impros/08-08/date-in with method: put - should return 400 (bad plate)', async (assert) => {
  46.   const response = await request(app)
  47.   .put('/impros/08-08/date-in')
  48.   .set('Authorization', `Bearer ${token}`)
  49.   .send({ dateIn: moment('2017-10-05 09:15:00').toDate() })
  50.  
  51.   assert.equals(response.status, 400)
  52.   assert.equals(response.body.level, logLevels.WARNING)
  53.   assert.equals(response.body.message, languageSpec.validationParametersMessage)
  54.   assert.end()
  55. })
  56.  
  57. test('Execute test for endpoint: /impros/08-08-AM/date-in with method: put - should return 400 (bad date)', async (assert) => {
  58.   const response = await request(app)
  59.   .put('/impros/08-08-AM/date-in')
  60.   .set('Authorization', `Bearer ${token}`)
  61.   .send({ dateIn: moment('2017-10-TS').toDate() })
  62.  
  63.   assert.equals(response.status, 400)
  64.   assert.equals(response.body.level, logLevels.WARNING)
  65.   assert.equals(response.body.message, languageSpec.validationParametersMessage)
  66.   assert.end()
  67. })
  68.  
  69. test('Execute test for endpoint: /impros/08-08-AM/date-in with method: put - should return 200', async (assert) => {
  70.   const response = await request(app)
  71.   .put('/impros/08-08-AM/date-in')
  72.   .set('Authorization', `Bearer ${token}`)
  73.   .send({ dateIn: moment('2017-10-05 09:15:00').toDate() })
  74.  
  75.   assert.equals(response.status, 200)
  76.   assert.equals(response.body.level, logLevels.SUCCESS)
  77.   assert.equals(response.body.message, languageSpec.dateRegisteredWithSuccess)
  78.   assert.end()
  79. })
  80.  
  81. test('Execute test for endpoint: /impro-types with method: get - should return 200', async (assert) => {
  82.   const response = await request(app)
  83.   .get('/impro-types')
  84.   .set('Authorization', `Bearer ${token}`)
  85.  
  86.   assert.equals(response.status, 200)
  87.   assert.equals([ 5, 15, 22, 23, 24, 25 ].filter(id => response.body.includes(id)).length, 6)
  88.   assert.end()
  89. })
  90.  
  91.  
  92. test('Execute test for endpoint: /car-shops with method: get - should return 200 and 4 car shops', async (assert) => {
  93.   const response = await request(app)
  94.   .get('/car-shops')
  95.   .set('Authorization', `Bearer ${token}`)
  96.  
  97.   assert.equals(response.status, 200)
  98.   assert.equals(response.body.length, 4)
  99.   assert.equals(response.body[0].id, 5)
  100.   assert.equals(response.body[0].name, 'AUMERI')
  101.   assert.equals(response.body[0].zoneId, 123213)
  102.   assert.equals(response.body[0].zoneName, 'Manutenção Centro')
  103.   assert.end()
  104. })
  105.  
  106. test('Execute test for endpoint: /parts-nr-days with method: get - should return 200 and the value 5', async (assert) => {
  107.   const response = await request(app)
  108.   .get('/parts-nr-days')
  109.   .set('Authorization', `Bearer ${token}`)
  110.  
  111.   assert.equals(response.status, 200)
  112.   assert.equals(response.body, 5)
  113.   assert.end()
  114. })
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top