Skip to content
Snippets Groups Projects
Unverified Commit 3d925f17 authored by Rodrigo Nascimento's avatar Rodrigo Nascimento
Browse files

Init API tests

parent e41b57d3
No related branches found
No related tags found
No related merge requests found
...@@ -60,7 +60,8 @@ ...@@ -60,7 +60,8 @@
}, },
"devDependencies": { "devDependencies": {
"chimp": "^0.44.0", "chimp": "^0.44.0",
"eslint": "^3.11.1" "eslint": "^3.11.1",
"supertest": "^2.0.1"
}, },
"dependencies": { "dependencies": {
"babel-runtime": "^6.18.0", "babel-runtime": "^6.18.0",
......
/* eslint-env mocha */
/* eslint no-unused-vars: false */
import supertest from 'supertest';
const request = supertest('http://localhost:3000');
const prefix = '/api/v1/';
function api(path) {
return prefix + path;
}
function log(res) {
console.log(res.req.path);
console.log({
body: res.body,
headers: res.headers
});
}
const credentials = {
['X-Auth-Token']: undefined,
['X-User-Id']: undefined
};
const login = {
user: process.env.ADMIN_USERNAME,
password: process.env.ADMIN_PASSWORD
};
describe('API', () => {
before((done) => {
request.post(api('/login'))
.send(login)
.expect('Content-Type', 'application/json')
.expect(200)
.expect((res) => {
credentials['X-Auth-Token'] = res.body.data.authToken;
credentials['X-User-Id'] = res.body.data.userId;
})
.end(done);
});
it('/login', () => {
expect(credentials).to.have.property('X-Auth-Token').with.length.at.least(1);
expect(credentials).to.have.property('X-User-Id').with.length.at.least(1);
});
it('/me', (done) => {
request.get(api('me'))
.set(credentials)
.expect('Content-Type', 'application/json')
.expect(200)
.expect((res) => {
expect(res.body).to.have.property('success', true);
expect(res.body).to.have.property('_id', credentials['X-User-Id']);
expect(res.body).to.have.property('username', login.user);
expect(res.body).to.have.property('active');
expect(res.body).to.have.property('name');
expect(res.body).to.have.deep.property('emails[0].address');
})
.end(done);
});
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment