forked from ker0olos/fable
-
Notifications
You must be signed in to change notification settings - Fork 0
/
customizeCharacter.test.ts
112 lines (92 loc) · 2.76 KB
/
customizeCharacter.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
// 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 } 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('db.setCharacterNickname()', () => {
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('set new nickname', async () => {
const { insertedId } = await client.characters().insertOne({
userId: 'user-id',
guildId: 'guild-id',
characterId: 'character-id',
} as any);
const character = await db.setCharacterNickname(
'user-id',
'guild-id',
'character-id',
'new-nickname',
);
assertEquals(character!._id, insertedId);
assertEquals(character!.nickname, 'new-nickname');
});
it('reset nickname', async () => {
const { insertedId } = await client.characters().insertOne({
userId: 'user-id',
guildId: 'guild-id',
characterId: 'character-id',
nickname: 'nickname',
} as any);
const character = await db.setCharacterNickname(
'user-id',
'guild-id',
'character-id',
);
assertEquals(character!._id, insertedId);
assertEquals(character!.nickname, undefined);
});
});
describe('db.setCharacterImage()', () => {
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('set new image', async () => {
const { insertedId } = await client.characters().insertOne({
userId: 'user-id',
guildId: 'guild-id',
characterId: 'character-id',
} as any);
const character = await db.setCharacterImage(
'user-id',
'guild-id',
'character-id',
'new-image-url',
);
assertEquals(character!._id, insertedId);
assertEquals(character!.image, 'new-image-url');
});
it('reset image', async () => {
const { insertedId } = await client.characters().insertOne({
userId: 'user-id',
guildId: 'guild-id',
characterId: 'character-id',
Image: 'image-url',
} as any);
const character = await db.setCharacterImage(
'user-id',
'guild-id',
'character-id',
);
assertEquals(character!._id, insertedId);
assertEquals(character!.image, undefined);
});
});