-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
43 lines (38 loc) · 1.27 KB
/
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
const { expect } = require('chai');
const { MongoClient } = require('mongodb');
describe('middleware', () => {
let healthInfo; let
db;
beforeAll((done) => {
MongoClient.connect(
'mongodb+srv://numanzor:[email protected]/chronos-access', { useNewUrlParser: true }, (err, client) => {
if (err) throw new Error(err);
done();
db = client.db('chronos-access');
healthInfo = db.collection('healthinfos');
},
);
});
test('should have records in the "healthinfos" collection', (done) => {
healthInfo.countDocuments((err, num) => {
expect(err).to.not.exist;
expect(num).to.be.above(0);
done();
});
});
test('should have the right string and date-time fields', (done) => {
healthInfo.find().toArray((err, data) => {
expect(err).to.not.exist;
expect(data).to.be.an('Array');
const dataPoint = data[0];
expect(dataPoint.currentMicroservice).to.be.a('string').and.not.eql('');
expect(dataPoint.targetedEndpoint).to.be.a('string').and.not.eql('');
expect(dataPoint.reqType).to.be.a('string').and.not.eql('');
expect(dataPoint.timeSent).to.be.a('date').and.not.eql('');
done();
});
});
afterAll(() => {
db.close();
});
});