-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhealthcheck_test.ts
42 lines (33 loc) · 1.37 KB
/
healthcheck_test.ts
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
/// <reference path="../typings/globals/mocha/index.d.ts" />
import {assert} from "chai";
import {Notices} from "../src/notices/notices";
import * as healthcheck from "../src/healthcheck";
var sinon = require("sinon");
import * as request from "supertest";
import * as express from "express";
describe('healthcheck.router', function() {
var notices = sinon.mock(Notices.prototype);
var app = express().use("/healthcheck", healthcheck.router(notices.object));
beforeEach(() => {
notices.restore();
notices = sinon.mock(Notices.prototype);
});
describe("GET /healtcheck", () => {
it('Returns number of notices when the database is working', function(done) {
notices.expects("totalNotices").once().returns(Promise.resolve({count: 100}));
request(app)
.get('/healthcheck')
.set('Accept', 'application/json')
.expect({notices: 100})
.expect('Content-Type', /json/)
.expect(200, done);
});
it('Returns number of notices when the database is failing', function(done) {
notices.expects("totalNotices").once().returns(Promise.reject(new Error("stub")));
request(app)
.get('/healthcheck')
.set('Accept', 'application/json')
.expect(500, done);
});
});
});