-
-
Notifications
You must be signed in to change notification settings - Fork 284
/
CheckCalendarIdMiddleware.spec.ts
56 lines (50 loc) · 1.66 KB
/
CheckCalendarIdMiddleware.spec.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import {TestContext} from "@tsed/testing";
import * as Sinon from "sinon";
import {expect} from "chai";
import {NotFound} from "ts-httpexceptions";
import {CalendarsService} from "../services/calendars/CalendarsService";
import {CheckCalendarIdMiddleware} from "./CheckCalendarIdMiddleware";
describe("CheckCalendarIdMiddleware", () => {
describe("when calendar isn\'t found", () => {
before(() => TestContext.create());
after(() => TestContext.reset());
it("should do nothing when calendar is found", async () => {
// GIVEN
const calendarsService = {
find: Sinon.stub().resolves({})
};
const middleware: CheckCalendarIdMiddleware = await TestContext.invoke(CheckCalendarIdMiddleware, [{
provide: CalendarsService,
use: calendarsService
}]);
// WHEN
const result = await middleware.use("1");
// THEN
// @ts-ignore
calendarsService.find.should.be.calledWithExactly("1");
expect(result).to.eq(undefined);
});
it("should throw an error", async () => {
// GIVEN
const calendarsService = {
find: Sinon.stub().resolves()
};
const middleware: CheckCalendarIdMiddleware = await TestContext.invoke(CheckCalendarIdMiddleware, [{
provide: CalendarsService,
use: calendarsService
}]);
// WHEN
let actualError;
try {
await middleware.use("1");
} catch (er) {
actualError = er;
}
// THEN
// @ts-ignore
calendarsService.find.should.be.calledWithExactly("1");
actualError.should.instanceOf(NotFound);
actualError.message.should.eq("Calendar not found");
});
});
});