-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Expand file tree
/
Copy pathentitlement.test.ts
More file actions
62 lines (51 loc) · 2 KB
/
entitlement.test.ts
File metadata and controls
62 lines (51 loc) · 2 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
import { DiscordSnowflake } from '@sapphire/snowflake';
import { type APIEntitlement, EntitlementType } from 'discord-api-types/v10';
import { describe, expect, test } from 'vitest';
import { Entitlement } from '../src/entitlements/Entitlement.js';
import { kPatch } from '../src/utils/symbols.js';
describe('Entitlement structure', () => {
const data: APIEntitlement = {
id: '1',
sku_id: '1',
application_id: '1',
user_id: '1',
type: EntitlementType.Purchase,
deleted: false,
starts_at: '2020-10-10T13:50:17.209000+00:00',
ends_at: '2020-10-10T15:50:17.209000+00:00',
consumed: false,
// note guild_id is missing (to test kPatch)
};
const instance = new Entitlement(data);
test('Entitlement has all properties', () => {
expect(instance.id).toBe(data.id);
expect(instance.skuId).toBe(data.sku_id);
expect(instance.applicationId).toBe(data.application_id);
expect(instance.userId).toBe(data.user_id);
expect(instance.type).toBe(data.type);
expect(instance.consumed).toBe(data.consumed);
expect(instance.deleted).toBe(data.deleted);
expect(instance.guildId).toBeUndefined();
expect(instance.createdTimestamp).toBe(DiscordSnowflake.timestampFrom(instance.id!));
expect(instance.createdAt).toEqual(new Date(instance.createdTimestamp!));
expect(instance.startsTimestamp).toBe(new Date(data.starts_at!).getTime());
expect(instance.startsAt).toEqual(new Date(instance.startsTimestamp!));
expect(instance.endsTimestamp).toBe(new Date(data.ends_at!).getTime());
expect(instance.endsAt).toEqual(new Date(instance.endsTimestamp!));
});
test('toJSON() is accurate', () => {
expect(instance.toJSON()).toStrictEqual(data);
});
test('Patching the Entitlement works in place', () => {
const guildId = '111111';
const consumed = true;
const patched = instance[kPatch]({
guild_id: guildId,
consumed,
});
expect(patched.guildId).toEqual(guildId);
expect(patched.consumed).toEqual(consumed);
expect(patched.toJSON()).not.toEqual(data);
expect(patched).toBe(instance);
});
});