-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdivinity.test.js
More file actions
142 lines (115 loc) · 3.52 KB
/
divinity.test.js
File metadata and controls
142 lines (115 loc) · 3.52 KB
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
const chai = require('chai');
const chaiAsPromised = require('chai-as-promised');
const {Divinity} = require('../divinity.js');
chai.use(chaiAsPromised);
chai.should();
describe('world-worldEvents_.js', () => {
describe('worldEvents', () => {
let g;
before(() => {
g = new Divinity('test', 1);
g.init();
});
after(() => {
g.endWorld();
});
it('should have emitted favor', async () => {
await new Promise(resolve => {
g.worldEvents.on('favor', favor => {
favor.corn.should.be.equal(0);
favor.gold.should.be.equal(0);
resolve();
});
});
});
it('should have emitted blessed', async () => {
await new Promise(resolve => {
g.worldEvents.on('blessing', blessing => {
blessing.corn.should.be.equal(0);
blessing.gold.should.be.equal(0);
resolve();
});
});
});
it('should have emitted retribution', async () => {
await new Promise(resolve => {
g.worldEvents.on('retribution', retribution => {
retribution.should.be.above(-1);
retribution.should.be.below(10000);
resolve();
});
});
});
});
describe('Divinity', () => {
let g;
before(() => {
g = new Divinity('test', 1);
});
after(() => {
g.endWorld();
});
it("should update divinity's corn", async () => {
g.corn.should.be.equal(0);
await g.offeringCorn(100);
g.corn.should.be.equal(100);
await g.offeringCorn(1000);
g.corn.should.be.equal(1100);
await g.offeringCorn(-1);
g.corn.should.be.equal(0);
await g
.offeringCorn('aze')
.should.be.rejectedWith(
Error,
/You didn't gave a number of corn to \b[a-zA-Z].*, Earth collapsed/
);
});
it("should update divinity's gold", async () => {
g.gold.should.be.equal(0);
await g.offeringGold(100);
g.gold.should.be.equal(100);
await g.offeringGold(1000);
g.gold.should.be.equal(1100);
await g.offeringGold(-1);
g.gold.should.be.equal(0);
await g
.offeringGold('aze')
.should.be.rejectedWith(
Error,
/You didn't gave a number of gold to \b[a-zA-Z].*, Earth collapsed/
);
});
});
describe('Updated values for Favor and Blessings', () => {
it('should have modified the values for favor', async () => {
const g = new Divinity('test', 1);
g.corn.should.be.equal(0);
g.gold.should.be.equal(0);
await Promise.all([g.offeringCorn(100), g.offeringGold(1000)]);
g.init();
await new Promise(resolve => {
g.worldEvents.on('favor', favor => {
favor.corn.should.be.equal(10);
favor.gold.should.be.equal(100);
g.endWorld();
resolve();
});
});
});
it('should have modified the values for blessings', async () => {
const g = new Divinity('test', 1);
g.corn.should.be.equal(0);
g.gold.should.be.equal(0);
await Promise.all([g.offeringCorn(100), g.offeringGold(1000)]);
g.init();
await new Promise(resolve => {
g.worldEvents.on('blessing', blessing => {
blessing.corn.should.be.equal(10000);
blessing.gold.should.be.equal(100000);
g.endWorld();
resolve();
});
});
});
});
});