forked from ker0olos/fable
-
Notifications
You must be signed in to change notification settings - Fork 0
/
acquireSkill.test.ts
154 lines (134 loc) · 3.36 KB
/
acquireSkill.test.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
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
143
144
145
146
147
148
149
150
151
152
153
154
// deno-lint-ignore-file no-explicit-any no-non-null-assertion
import { MongoMemoryServer } from 'mongodb-memory-server';
import { afterEach, beforeEach, describe, it } from '$std/testing/bdd.ts';
import {
assertEquals,
assertObjectMatch,
assertRejects,
} from '$std/assert/mod.ts';
import db, { Mongo } from '~/db/mod.ts';
import config from '~/src/config.ts';
let mongod: MongoMemoryServer;
let client: Mongo;
describe({
name: 'db.acquireSkill()',
// WORKAROUND fails to clean up properly in github ci
// causing an error unrelated to test results
sanitizeExit: false,
sanitizeResources: false,
sanitizeOps: false,
fn: () => {
beforeEach(async () => {
mongod = await MongoMemoryServer.create();
client = new Mongo(mongod.getUri());
config.mongoUri = mongod.getUri();
});
afterEach(async () => {
delete config.mongoUri;
await client.close();
await mongod.stop();
});
it('normal', async () => {
const { insertedId } = await client.characters().insertOne({
userId: 'user-id',
guildId: 'guild-id',
characterId: 'character-id',
combat: {
skillPoints: 2,
skills: {
crit: {
level: 1,
},
},
},
} as any);
const skill = await db.acquireSkill(
'user-id',
'guild-id',
'character-id',
'crit',
);
const character = await client.characters().findOne({ _id: insertedId });
assertEquals(character!._id, insertedId);
assertEquals(skill.level, 2);
assertObjectMatch(character!, {
combat: {
skillPoints: 0,
skills: {
crit: {
level: 2,
},
},
},
});
});
it('no skill points', async () => {
const { insertedId } = await client.characters().insertOne({
userId: 'user-id',
guildId: 'guild-id',
characterId: 'character-id',
combat: {
skillPoints: 1,
skills: {
crit: {
level: 1,
},
},
},
} as any);
await assertRejects(() =>
db.acquireSkill(
'user-id',
'guild-id',
'character-id',
'crit',
)
);
const character = await client.characters().findOne({ _id: insertedId });
assertObjectMatch(character!, {
combat: {
skillPoints: 1,
skills: {
crit: {
level: 1,
},
},
},
});
});
it('max level', async () => {
const { insertedId } = await client.characters().insertOne({
userId: 'user-id',
guildId: 'guild-id',
characterId: 'character-id',
combat: {
skillPoints: 999,
skills: {
crit: {
level: 3,
},
},
},
} as any);
await assertRejects(() =>
db.acquireSkill(
'user-id',
'guild-id',
'character-id',
'crit',
)
);
const character = await client.characters().findOne({ _id: insertedId });
assertObjectMatch(character!, {
combat: {
skillPoints: 999,
skills: {
crit: {
level: 3,
},
},
},
});
});
},
});