-
Notifications
You must be signed in to change notification settings - Fork 0
/
config-test.ts
38 lines (29 loc) · 922 Bytes
/
config-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
import { expect } from "chai";
import * as fs from "fs";
import "mocha";
import * as sinon from "sinon";
import { Env } from "../src/common";
import { ConfigService } from "../src/config";
describe("ConfigService", () => {
let sandbox: sinon.SinonSandbox;
beforeEach(() => {
sandbox = sinon.createSandbox();
});
afterEach(() => {
sandbox.restore();
});
it("can be constructed from a file", () => {
sandbox.stub(fs, "readFileSync").returns(`
ENV=TEST
PORT=10001
`);
const configService = ConfigService.fromFile(".env");
expect(configService.env).to.eql(Env.Test);
expect(configService.port).to.eql(10001);
});
it("can be constructed for testing", () => {
const configService = ConfigService.forTesting();
expect(() => configService.env).to.throw;
expect(() => configService.port).to.throw;
});
});