Created
March 5, 2018 09:16
-
-
Save jbagaresgaray/4ec8bdc4dc5109c19cef82efe044d3fa to your computer and use it in GitHub Desktop.
unit test using Chai, Should and Mocha JS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let chai = require('chai'); | |
let chaiHttp = require('chai-http'); | |
let should = chai.should(); | |
let apiURL = 'http://54.252.206.198:4000/api/v1'; | |
let lastInsertID = null; | |
let token = null; | |
let user = { | |
username: '4LOOP.003', | |
password: '123456' | |
}; | |
let authdata = Buffer.from(user.username + ':' + user.password).toString('base64'); | |
chai.use(chaiHttp); | |
describe('HRIS ACCOUNTS API', () => { | |
describe('Authenticate to Access API', () => { | |
it('it should login an account to get Access Token', (done) => { | |
chai.request(apiURL) | |
.post('/login') | |
.set('authorization', 'Basic ' + authdata) | |
.send() | |
.end((err, res) => { | |
should.not.exist(err); | |
res.should.have.status(200); | |
res.body.response.should.have.property('success').eql(true); | |
res.body.response.result.should.have.property('token'); | |
if (res.body.statusCode == 200) { | |
token = res.body.response.result.token | |
} | |
done(); | |
}); | |
}); | |
}); | |
describe('Test all routes for ACCOUNTS API', () => { | |
it('it should GET a request for all ACCOUNT CLASS', (done) => { | |
chai.request(apiURL) | |
.get('/accountclass') | |
.set('authorization', 'Basic ' + authdata) | |
.set('auth_token', token) | |
.end((err, res) => { | |
should.not.exist(err); | |
res.should.have.status(200); | |
res.body.response.should.have.property('success').eql(true); | |
res.body.response.result.should.be.a('array'); | |
done(); | |
}); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment