This repository was archived by the owner on Aug 28, 2020. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 83
/
Copy pathGatewayStore.ts
93 lines (74 loc) · 2.27 KB
/
GatewayStore.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
import unknownTest, { TestInterface } from 'ava';
import { Cache } from '@klasa/cache';
import { createClient } from './lib/SettingsClient';
import {
Gateway,
GatewayStore,
KlasaClient
} from '../src';
const ava = unknownTest as TestInterface<{
client: KlasaClient
}>;
ava.beforeEach(async (test): Promise<void> => {
test.context = {
client: createClient()
};
});
ava('GatewayDriver Properties', (test): void => {
test.plan(3);
const { client } = test.context;
const gatewayDriver = new GatewayStore(client);
test.true(gatewayDriver instanceof Cache);
test.is(gatewayDriver.client, client);
// No gateway is registered
test.is(gatewayDriver.size, 0);
});
ava('GatewayDriver (From Client)', (test): void => {
test.plan(6);
const { client } = test.context;
test.true(client.gateways instanceof Cache);
test.is(client.gateways.client, client);
// clientStorage, guilds, users
test.is(client.gateways.size, 3);
test.true(client.gateways.get('clientStorage') instanceof Gateway);
test.true(client.gateways.get('guilds') instanceof Gateway);
test.true(client.gateways.get('users') instanceof Gateway);
});
ava('GatewayDriver#register', (test): void => {
test.plan(2);
const client = createClient();
const gateway = new Gateway(client, 'someCustomGateway');
test.is(client.gateways.register(gateway), client.gateways);
test.is(client.gateways.get('someCustomGateway'), gateway);
});
ava('GatewayDriver#init', async (test): Promise<void> => {
test.plan(7);
const client = createClient();
test.false((client.gateways.get('guilds') as Gateway).ready);
test.false((client.gateways.get('users') as Gateway).ready);
test.false((client.gateways.get('clientStorage') as Gateway).ready);
test.is(await client.gateways.init(), undefined);
test.true((client.gateways.get('guilds') as Gateway).ready);
test.true((client.gateways.get('users') as Gateway).ready);
test.true((client.gateways.get('clientStorage') as Gateway).ready);
});
ava('GatewayDriver#toJSON', (test): void => {
const client = createClient();
test.deepEqual(client.gateways.toJSON(), {
guilds: {
name: 'guilds',
provider: 'json',
schema: {}
},
users: {
name: 'users',
provider: 'json',
schema: {}
},
clientStorage: {
name: 'clientStorage',
provider: 'json',
schema: {}
}
});
});