-
Notifications
You must be signed in to change notification settings - Fork 20
/
app.test.js
45 lines (38 loc) · 1.01 KB
/
app.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
const express = require('express');
const { expect } = require('chai');
const supertest = require('supertest');
const app = require('./app');
describe('Customer API', () => {
let server;
let request;
let port;
before(async () => {
const getPort = await import('get-port');
port = await getPort.default();
server = app.listen(port);
request = supertest(app);
});
after((done) => {
server.close(done);
});
it('should return customer data when authenticated', (done) => {
request
.get('/customer')
.set('Authorization', 'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJub25lIn0.eyJ1c2VybmFtZSI6Impkb2UifQ')
.expect(200)
.end((err, res) => {
expect(err).to.be.null;
expect(res.body).to.have.property('username');
done();
});
});
it('should return 401 unauthorized when not authenticated', (done) => {
request
.get('/customer')
.expect(401)
.end((err, res) => {
expect(err).to.be.null;
done();
});
});
});