Skip to content

Commit 5a7446f

Browse files
test: add test for autocomplete interactions
1 parent f651afa commit 5a7446f

File tree

4 files changed

+481
-5
lines changed

4 files changed

+481
-5
lines changed
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
import { ApplicationCommandOptionType } from 'discord.js';
2+
import type { TypedAutocompleteList, ReadonlyCommandList, BaseCommand, CommandOptionAnyData, BaseCommandList, Expand, CommandOptionBasicData } from '../src/index.js';
3+
import { typed } from '../src/index.js';
4+
5+
export const commands = [
6+
{
7+
name: '0-failsafe',
8+
description: 'failsafe type for test purposes',
9+
options: [
10+
{ name: 'failsafe-subcommand', type: ApplicationCommandOptionType.String, description: 'type-3', autocomplete: true }
11+
]
12+
},
13+
{
14+
name: '1-no-options',
15+
description: 'command with no options',
16+
},
17+
{
18+
name: '2-empty-options',
19+
description: 'command with empty options property value',
20+
options: [],
21+
},
22+
{
23+
name: '3-no-autocomplete',
24+
description: 'command with no autocomplete options',
25+
options: [
26+
{ name: '4-string-req', type: ApplicationCommandOptionType.String, description: 'type-3' },
27+
]
28+
},
29+
{
30+
name: '4-basic-options',
31+
description: 'command with all possible basic options',
32+
options: [
33+
{ name: '4-string', type: ApplicationCommandOptionType.String, description: 'type-3', autocomplete: true },
34+
{ name: '4-integer', type: ApplicationCommandOptionType.Integer, description: 'type-4', autocomplete: true },
35+
{ name: '4-number', type: ApplicationCommandOptionType.Number, description: 'type-10', autocomplete: true },
36+
],
37+
},
38+
{
39+
name: '5-basic-options-mixed',
40+
description: 'command with all possible basic options',
41+
options: [
42+
{ name: '5-string', type: ApplicationCommandOptionType.String, description: 'type-3', autocomplete: true },
43+
{ name: '5-integer', type: ApplicationCommandOptionType.Integer, description: 'type-4', autocomplete: false },
44+
{ name: '5-number', type: ApplicationCommandOptionType.Number, description: 'type-10' },
45+
{ name: '5-boolean', type: ApplicationCommandOptionType.Boolean, description: 'type-5' },
46+
{ name: '5-user', type: ApplicationCommandOptionType.User, description: 'type-6' }
47+
],
48+
},
49+
{
50+
name: '6-subcommand',
51+
description: 'command with a subcommand with basic options',
52+
options: [
53+
{
54+
name: '6-subcommand-1', type: ApplicationCommandOptionType.Subcommand, description: 'type-2', options: [
55+
{ name: '6-sub-1-string', type: ApplicationCommandOptionType.String, description: 'type-3', autocomplete: true },
56+
{ name: '6-sub-1-integer', type: ApplicationCommandOptionType.Integer, description: 'type-4', autocomplete: false },
57+
{ name: '6-sub-1-number', type: ApplicationCommandOptionType.Number, description: 'type-10' },
58+
],
59+
},
60+
{
61+
name: '6-subcommand-2', type: ApplicationCommandOptionType.Subcommand, description: 'type-2', options: [
62+
{ name: '6-sub-2-string', type: ApplicationCommandOptionType.String, description: 'type-3', autocomplete: true },
63+
{ name: '6-sub-2-integer', type: ApplicationCommandOptionType.Integer, description: 'type-4', autocomplete: true },
64+
{ name: '6-sub-2-number', type: ApplicationCommandOptionType.Number, description: 'type-10' },
65+
],
66+
},
67+
{
68+
name: '6-subcommand-3-no-auto', type: ApplicationCommandOptionType.Subcommand, description: 'type-2', options: [
69+
{ name: '6-sub-3-number', type: ApplicationCommandOptionType.Number, description: 'type-10' },
70+
],
71+
},
72+
{
73+
name: '6-subcommand-4-empty', type: ApplicationCommandOptionType.Subcommand, description: 'type-2', options: [],
74+
}
75+
]
76+
},
77+
{
78+
name: '7-subgroup',
79+
description: 'command with subcommand groups with subcommands with basic options',
80+
options: [
81+
{
82+
name: '7-subgroup-1', type: ApplicationCommandOptionType.SubcommandGroup, description: 'type-2', options: [
83+
{
84+
name: '7-subgroup-1-subcommand-1', type: ApplicationCommandOptionType.Subcommand, description: 'type-1', options: [
85+
{ name: '7-s1-s1-string', type: ApplicationCommandOptionType.String, description: 'type-3', autocomplete: true },
86+
{ name: '7-s1-s1-integer', type: ApplicationCommandOptionType.Integer, description: 'type-4' },
87+
]
88+
},
89+
{
90+
name: '7-subgroup-1-subcommand-2', type: ApplicationCommandOptionType.Subcommand, description: 'type-1', options: [
91+
{ name: '7-s1-s2-string', type: ApplicationCommandOptionType.String, description: 'type-3', autocomplete: true },
92+
{ name: '7-s1-s2-integer', type: ApplicationCommandOptionType.Integer, description: 'type-4' },
93+
]
94+
}
95+
]
96+
},
97+
{
98+
name: '7-subgroup-2', type: ApplicationCommandOptionType.SubcommandGroup, description: 'type-2', options: [
99+
{
100+
name: '7-subgroup-2-subcommand-1', type: ApplicationCommandOptionType.Subcommand, description: 'type-1', options: [
101+
{ name: '7-s2-s1-string', type: ApplicationCommandOptionType.String, description: 'type-3', autocomplete: true },
102+
{ name: '7-s2-s1-integer', type: ApplicationCommandOptionType.Integer, description: 'type-4' },
103+
]
104+
},
105+
{
106+
name: '7-subgroup-2-subcommand-2', type: ApplicationCommandOptionType.Subcommand, description: 'type-1', options: [
107+
{ name: '7-s2-s2-string', type: ApplicationCommandOptionType.String, description: 'type-3' },
108+
{ name: '7-s2-s2-integer', type: ApplicationCommandOptionType.Integer, description: 'type-4' },
109+
]
110+
}
111+
]
112+
},
113+
{
114+
name: '7-subgroup-3-no-auto-subcommand', type: ApplicationCommandOptionType.SubcommandGroup, description: 'type-1', options: [
115+
{
116+
name: '7-subgroup-3-subcommand-1', type: ApplicationCommandOptionType.Subcommand, description: 'type-2', options: [
117+
{ name: '7-s3-s1-string', type: ApplicationCommandOptionType.String, description: 'type-3' }
118+
]
119+
}
120+
]
121+
},
122+
{
123+
name: '7-subgroup-4-empty-subcommand', type: ApplicationCommandOptionType.SubcommandGroup, description: 'type-2', options: [
124+
{ name: '7-subgroup-4-empty-subcommand-1', type: ApplicationCommandOptionType.Subcommand, description: 'type-1' },
125+
{ name: '7-subgroup-4-empty-subcommand-2', type: ApplicationCommandOptionType.Subcommand, description: 'type-1' },
126+
]
127+
},
128+
]
129+
},
130+
{
131+
name: '8-subgroup-subcommand-sibling',
132+
description: 'command with subcommand groups and subcommands as siblings',
133+
options: [
134+
{
135+
name: '8-subgroup-1', type: ApplicationCommandOptionType.SubcommandGroup, description: 'type-2', options: [
136+
{
137+
name: '8-subgroup-1-subcommand-1', type: ApplicationCommandOptionType.Subcommand, description: 'type-1', options: [
138+
{ name: '8-s1-s1-string', type: ApplicationCommandOptionType.String, description: 'type-3', autocomplete: true },
139+
{ name: '8-s1-s1-integer', type: ApplicationCommandOptionType.Integer, description: 'type-4' },
140+
]
141+
},
142+
{
143+
name: '8-subgroup-1-subcommand-2', type: ApplicationCommandOptionType.Subcommand, description: 'type-1', options: [
144+
{ name: '8-s1-s2-string', type: ApplicationCommandOptionType.String, description: 'type-3', autocomplete: true },
145+
{ name: '8-s1-s2-integer', type: ApplicationCommandOptionType.Integer, description: 'type-4' },
146+
]
147+
}
148+
]
149+
},
150+
{
151+
name: '8-subcommand-sibling', type: ApplicationCommandOptionType.Subcommand, description: 'type-1', options: [
152+
{ name: '8-sib-str', type: ApplicationCommandOptionType.String, description: 'type-3', autocomplete: true },
153+
{ name: '8-sib-int', type: ApplicationCommandOptionType.Integer, description: 'type-3', autocomplete: true },
154+
]
155+
},
156+
{
157+
name: '8-subcommand-sibling-empty', type: ApplicationCommandOptionType.Subcommand, description: 'type-1'
158+
}
159+
]
160+
},
161+
] as const satisfies ReadonlyCommandList;
162+
163+
export const isTyped = typed(commands);
164+
export type Command = TypedAutocompleteList<typeof commands>;

test/commands.test-d.ts renamed to test/commands-default.test-d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,4 +220,4 @@ export const commands = [
220220
] as const satisfies ReadonlyCommandList;
221221

222222
export const isTyped = typed(commands);
223-
export type Command = TypedCommandList<typeof commands>;
223+
export type Command = TypedCommandList<typeof commands>;

0 commit comments

Comments
 (0)