This repository has been archived by the owner on Aug 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcore.promises.ts
109 lines (98 loc) · 4.84 KB
/
core.promises.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/// <reference path="../typings/chai-as-promised/chai-as-promised.d.ts"/>
/// <reference path="../typings/mocha/mocha.d.ts" />
/// <reference path="../typings/es6-polyfill/es6-polyfill.d.ts" />
import Promises = require('../core/src/promises');
import TestHelpers = require('./helpers');
import Chai = require('chai');
import ChaiAsPromised = require('chai-as-promised');
Chai.use(ChaiAsPromised);
describe('Promises', function () {
describe('beginGame', function () {
it('should resolve without error', function () {
return TestHelpers.testGameData().then(groupData => {
const player = TestHelpers.createPlayer0();
const promises = TestHelpers.createPromises();
const timestampMs = Date.now();
return Promises.beginGame(
'begingame',
player,
timestampMs,
groupData,
promises);
});
})
});
describe('endGame', function () {
it('should resolve without error', function () {
const player = TestHelpers.createPlayer0();
const promises = TestHelpers.createPromises();
return promises.addPlayer(player).then(player =>
Promises.endGame(player.email, promises));
})
});
describe('resign', function () {
it('should resolve without error', function () {
const player = TestHelpers.createPlayer0();
const promises = TestHelpers.createPromises();
return promises.addPlayer(player).then(player =>
TestHelpers.testGameData()
).then(groupData => {
return Promises.resign(
'resign',
player.email,
groupData,
promises);
});
})
});
describe('child', function () {
it('should resolve without error', function () {
const player = TestHelpers.createPlayer0();
const promises = TestHelpers.createPromises();
const childIndex = 0;
const timestampMs = Date.now();
return TestHelpers.testGameData().then(narrative => {
const message = TestHelpers.createMessage(
'children_expired',
player.email,
narrative);
const state = {
player,
message,
timestampMs,
narrative,
promises,
};
return Promises.child(state, childIndex);
});
})
});
describe('reply', function () {
it('should resolve without error', function () {
const player = TestHelpers.createPlayer0();
const promises = TestHelpers.createPromises();
const replyIndex = 0;
const timestampMs = Date.now();
return TestHelpers.testGameData().then(narrative => {
const message = TestHelpers.createMessage(
'reply_expired',
player.email,
narrative);
message.reply = {
body: '',
timestampMs: 0,
index: replyIndex,
sent: [],
};
const state = {
player,
message,
timestampMs,
narrative,
promises,
};
return Promises.reply(state, replyIndex)
});
})
});
});