mirror of
https://github.com/discordjs/discord.js.git
synced 2026-09-17 16:57:28 +00:00
test(structures): add test for Emoji structure (#11509)
* test(structures): add test for Emoji structure * test: use realistic snowflake ids * test(structures): getters that rely on isIdSet return null if no id set * style: compress into one test --------- Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
co-authored by
kodiakhq[bot]
parent
10f059e3ca
commit
5608023103
@@ -0,0 +1,66 @@
|
||||
import { DiscordSnowflake } from '@sapphire/snowflake';
|
||||
import type { APIEmoji, APIUser } from 'discord-api-types/v10';
|
||||
import { beforeEach, describe, expect, test } from 'vitest';
|
||||
import { Emoji } from '../src/emojis/Emoji.js';
|
||||
import { kPatch } from '../src/utils/symbols.js';
|
||||
|
||||
describe('Emoji structure', () => {
|
||||
const user: APIUser = {
|
||||
id: '1028645863041548409',
|
||||
username: 'username',
|
||||
discriminator: '0000',
|
||||
global_name: 'User',
|
||||
avatar: 'ae786a76a887687a6eaea877866768',
|
||||
};
|
||||
|
||||
const data: APIEmoji = {
|
||||
id: '300390514065276939',
|
||||
name: 'name',
|
||||
roles: ['222089694387765248'],
|
||||
user,
|
||||
require_colons: true,
|
||||
managed: true,
|
||||
animated: true,
|
||||
available: true,
|
||||
};
|
||||
|
||||
let instance: Emoji;
|
||||
|
||||
beforeEach(() => {
|
||||
instance = new Emoji(data);
|
||||
});
|
||||
|
||||
test('Emoji has all properties', () => {
|
||||
expect(instance.id).toBe(data.id);
|
||||
expect(instance.name).toBe(data.name);
|
||||
expect(instance.requireColons).toBe(data.require_colons);
|
||||
expect(instance.managed).toBe(data.managed);
|
||||
expect(instance.animated).toBe(data.animated);
|
||||
expect(instance.available).toBe(data.available);
|
||||
|
||||
const createdTimestamp = DiscordSnowflake.timestampFrom(data.id!);
|
||||
expect(instance.createdTimestamp).toBe(createdTimestamp);
|
||||
expect(instance.createdDate!.valueOf()).toBe(createdTimestamp);
|
||||
});
|
||||
|
||||
test('toJSON() is accurate', () => {
|
||||
expect(instance.toJSON()).toStrictEqual(data);
|
||||
});
|
||||
|
||||
test('Patching the Emoji works in place', () => {
|
||||
const patched = instance[kPatch]({
|
||||
available: false,
|
||||
});
|
||||
|
||||
expect(patched.available).toBe(false);
|
||||
|
||||
expect(patched.toJSON()).toEqual({ ...data, available: false });
|
||||
expect(patched).toBe(instance);
|
||||
});
|
||||
|
||||
test('createdTimestamp/createdAt returns null if id is not set', () => {
|
||||
const instanceWithNoId = new Emoji({ ...data, id: null });
|
||||
expect(instanceWithNoId.createdTimestamp).toBeNull();
|
||||
expect(instanceWithNoId.createdDate).toBeNull();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user