Skip to content

Commit 26d3cab

Browse files
authored
Add tests (#15)
* Add config in package * Create embed for hello command * Add tests
1 parent bcb71a2 commit 26d3cab

File tree

3 files changed

+56
-2
lines changed

3 files changed

+56
-2
lines changed

package.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"start": "yarn build && yarn build:watch",
88
"build": "tsc",
99
"build:watch": "yarn tsc-watch --onSuccess 'node dist/App.js'",
10+
"test": "jest",
1011
"auto:changelog": "yarn auto changelog",
1112
"auto:version": "yarn version --`auto version`",
1213
"auto:release": "yarn auto:changelog && yarn auto:version",
@@ -34,6 +35,13 @@
3435
"tsc-watch": "^6.0.0",
3536
"typescript": "^5.0.2"
3637
},
38+
"jest": {
39+
"preset": "ts-jest",
40+
"testEnvironment": "node",
41+
"testMatch": [
42+
"**/src/**/*.test.ts"
43+
]
44+
},
3745
"engines": {
3846
"node": ">=16.13.0"
3947
}

src/commands/hello/index.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { generateHelloEmbed } from '.';
2+
3+
describe('Hello Command', () => {
4+
it('generates an embed correctly', () => {
5+
const embed = generateHelloEmbed();
6+
7+
expect(embed).not.toBeUndefined();
8+
});
9+
it('displays the correct fields in the embed', () => {
10+
const embed = generateHelloEmbed();
11+
12+
expect(embed.description).not.toBeUndefined();
13+
expect(embed.color).not.toBeUndefined();
14+
expect(embed.fields).not.toBeUndefined();
15+
expect(embed.fields && embed.fields.length).toBe(3);
16+
});
17+
});

src/commands/hello/index.ts

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,42 @@
1-
import { SlashCommandBuilder } from 'discord.js';
1+
import { APIEmbed, SlashCommandBuilder } from 'discord.js';
22
import { sendErrorLog } from '../../utils/helpers';
33
import { AppCommand, AppCommandOptions } from '../commands';
44

5+
export function generateHelloEmbed(): APIEmbed {
6+
const embed: APIEmbed = {
7+
title: 'Hello Command',
8+
color: 55296,
9+
description: 'Hi there! (◕ᴗ◕✿)',
10+
thumbnail: {
11+
url: 'https://cdn.discordapp.com/attachments/1089616880576245853/1094559253395689562/mitsuha.jpg',
12+
},
13+
fields: [
14+
{
15+
name: 'Field 1',
16+
value: 'This is a normal field!',
17+
},
18+
{
19+
name: 'Field 2',
20+
value: 'This is an inline field!',
21+
inline: true,
22+
},
23+
{
24+
name: 'Field 3',
25+
value: 'This is an inline field too!',
26+
inline: true,
27+
},
28+
],
29+
};
30+
return embed;
31+
}
32+
533
export default {
634
data: new SlashCommandBuilder().setName('hello').setDescription('Greets the user!'),
735
async execute({ interaction }: AppCommandOptions) {
836
try {
937
await interaction.deferReply();
10-
await interaction.editReply('Hello!');
38+
const embed = generateHelloEmbed();
39+
await interaction.editReply({ embeds: [embed] });
1140
} catch (error) {
1241
sendErrorLog({ error, interaction });
1342
}

0 commit comments

Comments
 (0)