node-mongo-demo
node.js and mongodb demo
git clone https://9o.is/git/node-mongo-demo.git
lucky7-session-model.unit.test.js
(1539B)
1 import Lucky7Session from '../src/models/lucky7-session.js';
2 import { jest } from '@jest/globals';
3
4 describe('Lucky7Session Model', () => {
5 it('game intervals are set to 15 seconds', () => {
6 const session = new Lucky7Session();
7 expect(session.gameIntervalInSeconds).toBe(15);
8 });
9
10 it('expiration set to one day', () => {
11 const date1 = new Date('2024-01-01T00:00:00Z');
12 const date2 = new Date('2024-01-02T00:00:00Z');
13 const session = new Lucky7Session({
14 createdAt: date1,
15 });
16
17 const expiration = String(session.expiresAt);
18 expect(expiration).toBe(String(date2));
19 });
20
21 it('nextIntervalAt()', () => {
22 setTime('2024-01-01T00:00:01Z');
23
24 const session = new Lucky7Session({
25 createdAt: '2024-01-01T00:00:00Z',
26 });
27
28 const actual = session.nextIntervalAt().toISOString();
29 expect(actual).toBe('2024-01-01T00:00:15.000Z');
30 });
31
32 it('isPlayable() false', () => {
33 setTime('2024-01-01T00:00:10Z');
34
35 const session = new Lucky7Session({
36 createdAt: '2024-01-01T00:00:00Z',
37 });
38
39 expect(session.isPlayable()).toBe(false);
40 });
41
42 it('isPlayable() true', () => {
43 setTime('2024-01-01T00:00:09.999Z');
44
45 const session = new Lucky7Session({
46 createdAt: '2024-01-01T00:00:00Z',
47 });
48
49 expect(session.isPlayable()).toBe(true);
50 });
51 });
52
53 function setTime(dt) {
54 jest.useFakeTimers().setSystemTime(new Date(dt));
55 }
56