This repository has been archived by the owner on Dec 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathScoreData.test.js
78 lines (77 loc) · 1.88 KB
/
ScoreData.test.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/* eslint-env jest */
const ScoreData = require('./ScoreData')
describe('ScoreData', () => {
describe('updating', () => {
it('records score', () => {
const result = ScoreData.update(null, {
score: 505050,
combo: 91,
total: 93,
count: [ 90, 3, 0, 0, 0 ]
})
expect(result.recordedAt).toBeInstanceOf(Date)
delete result.recordedAt
expect(result).toEqual({
playCount: 1,
playNumber: 1,
combo: 91,
total: 93,
count: [ 90, 3, 0, 0, 0 ],
score: 505050
})
})
it('only changes the playCount if not beaten', () => {
const oldData = {
playCount: 1,
playNumber: 1,
combo: 91,
total: 93,
count: [ 90, 3, 0, 0, 0 ],
score: 505050,
recordedAt: new Date()
}
const result = ScoreData.update(oldData, {
score: 505049,
combo: 90,
total: 93,
count: [ 90, 2, 1, 0, 0 ]
})
expect(result).toEqual({
playCount: 2,
playNumber: 1,
combo: 91,
total: 93,
count: [ 90, 3, 0, 0, 0 ],
score: 505050,
recordedAt: oldData.recordedAt
})
})
it('records new data if beaten', () => {
const oldData = {
playCount: 2,
playNumber: 1,
combo: 91,
total: 93,
count: [ 90, 3, 0, 0, 0 ],
score: 505050,
recordedAt: new Date(0)
}
const result = ScoreData.update(oldData, {
score: 535251,
combo: 92,
total: 93,
count: [ 91, 2, 0, 0, 0 ]
})
expect(+result.recordedAt).toBeGreaterThan(+oldData.recordedAt)
delete result.recordedAt
expect(result).toEqual({
playCount: 3,
playNumber: 3,
combo: 92,
total: 93,
count: [ 91, 2, 0, 0, 0 ],
score: 535251
})
})
})
})