-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathserver.spec.js
57 lines (53 loc) · 2.17 KB
/
server.spec.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
46
47
48
49
50
51
52
53
54
55
56
57
const Sinon = require('sinon');
const Path = require('path');
const AdServer = require('../src/server');
const { SERVER_STATUS, DEFAULT_SERVER_CONFIG } = require('../src/constants');
describe('Ad server', () => {
beforeEach(() => {
this.server;
this.sandbox = Sinon.createSandbox();
});
afterEach(() => {
if (this.server) {
this.server.stop();
}
this.sandbox.restore();
});
it('should start/stop with server configs provided', () => {
const serverConfig = {
port: 4000,
publicDirectories: [
Path.resolve(__dirname, 'public_directory'),
],
};
this.server = new AdServer(serverConfig);
expect(this.server.status).toEqual(SERVER_STATUS.INITIALIZING);
expect(this.server.port).toEqual(serverConfig.port);
this.server.start();
expect(this.server.status).toEqual(SERVER_STATUS.STARTED);
this.server.stop();
expect(this.server.status).toEqual(SERVER_STATUS.STOPPED);
});
it('should start/stop without providing server configs', () => {
this.server = new AdServer();
expect(this.server.status).toEqual(SERVER_STATUS.INITIALIZING);
expect(this.server.port).toEqual(DEFAULT_SERVER_CONFIG.port);
this.server.addPublicDirectory(Path.resolve(__dirname, 'public_directory'));
expect(Array.isArray(this.server.publicDirectories)).toBeTruthy();
this.server.start();
expect(this.server.status).toEqual(SERVER_STATUS.STARTED);
this.server.stop();
expect(this.server.status).toEqual(SERVER_STATUS.STOPPED);
});
it('should have no log manager configured by default', () => {
this.server = new AdServer();
expect(this.server.status).toEqual(SERVER_STATUS.INITIALIZING);
expect(this.server.logManager.loggers.size).toEqual(0);
this.server.addConsoleLogger();
expect(this.server.logManager.loggers.size).toEqual(1);
this.server.start();
expect(this.server.status).toEqual(SERVER_STATUS.STARTED);
this.server.stop();
expect(this.server.status).toEqual(SERVER_STATUS.STOPPED);
});
});