Skip to content

Commit d28cdeb

Browse files
committed
Create ttl-score-generator.spec.js
Added some unit tests for `service/ttl-score-generator`.
1 parent 7c86f40 commit d28cdeb

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
2+
const expect = require('chai').expect;
3+
const config = require('config');
4+
const sandbox = require("sinon").createSandbox();
5+
const ttlScoreGenerator = require('../../../../app/service/ttl-score-generator');
6+
7+
describe('service.ttl-score-generator', () => {
8+
9+
afterEach(() => {
10+
sandbox.restore();
11+
});
12+
13+
describe('getScore', () => {
14+
it('should handle an activity TTL', () => {
15+
const TTL = '12';
16+
const NOW = 55;
17+
sandbox.stub(Date, 'now').returns(NOW);
18+
sandbox.stub(config, 'get').returns(TTL);
19+
const score = ttlScoreGenerator.getScore();
20+
expect(score).to.equal(12055); // (TTL * 1000) + NOW
21+
});
22+
it('should handle a numeric TTL', () => {
23+
const TTL = 13;
24+
const NOW = 55;
25+
sandbox.stub(Date, 'now').returns(NOW);
26+
sandbox.stub(config, 'get').returns(TTL);
27+
const score = ttlScoreGenerator.getScore();
28+
expect(score).to.equal(13055); // (TTL * 1000) + NOW
29+
});
30+
it('should handle a null TTL', () => {
31+
const TTL = null;
32+
const NOW = 55;
33+
sandbox.stub(Date, 'now').returns(NOW);
34+
sandbox.stub(config, 'get').returns(TTL);
35+
const score = ttlScoreGenerator.getScore();
36+
expect(score).to.equal(55); // null TTL => 0
37+
});
38+
});
39+
40+
});

0 commit comments

Comments
 (0)