test: Add toJSON() to tests (#11321)

test: fix validation

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
Jiralite
2025-11-30 16:41:48 +00:00
committed by GitHub
parent ace834b274
commit 8162ae8ce0
5 changed files with 117 additions and 62 deletions

View File

@@ -19,7 +19,7 @@ const longStr =
describe('Button Components', () => {
describe('Assertion Tests', () => {
test('GIVEN valid fields THEN builder does not throw', () => {
expect(() => new PrimaryButtonBuilder().setCustomId('custom').setLabel('test')).not.toThrowError();
expect(() => new PrimaryButtonBuilder().setCustomId('custom').setLabel('test').toJSON()).not.toThrowError();
expect(() => {
const button = new PrimaryButtonBuilder()

View File

@@ -51,26 +51,49 @@ function mapStringSelectMenuOptionBuildersToJson(selectMenu: StringSelectMenuBui
describe('Select Menu Components', () => {
describe('Assertion Tests', () => {
test('GIVEN valid inputs THEN Select Menu does not throw', () => {
expect(() => selectMenu().setCustomId('foo')).not.toThrowError();
expect(() => selectMenu().setMaxValues(10)).not.toThrowError();
expect(() => selectMenu().setMinValues(3)).not.toThrowError();
expect(() => selectMenu().setDisabled(true)).not.toThrowError();
expect(() => selectMenu().setDisabled()).not.toThrowError();
expect(() => selectMenu().setPlaceholder('description')).not.toThrowError();
expect(() =>
selectMenu().setCustomId('foo').addOptions({ label: 'test', value: 'test' }).toJSON(),
).not.toThrowError();
expect(() =>
selectMenuWithId().setMaxValues(10).addOptions({ label: 'test', value: 'test' }).toJSON(),
).not.toThrowError();
expect(() =>
selectMenuWithId()
.setMinValues(3)
.addOptions(
{ label: 'test1', value: 'test1' },
{ label: 'test2', value: 'test2' },
{ label: 'test3', value: 'test3' },
)
.toJSON(),
).not.toThrowError();
expect(() =>
selectMenuWithId().setDisabled(true).addOptions({ label: 'test', value: 'test' }).toJSON(),
).not.toThrowError();
expect(() =>
selectMenuWithId().setDisabled().addOptions({ label: 'test', value: 'test' }).toJSON(),
).not.toThrowError();
expect(() =>
selectMenuWithId().setPlaceholder('description').addOptions({ label: 'test', value: 'test' }).toJSON(),
).not.toThrowError();
const option = selectMenuOption()
.setLabel('test')
.setValue('test')
.setDefault(true)
.setEmoji({ name: 'test' })
.setDescription('description');
expect(() => selectMenu().addOptions(option)).not.toThrowError();
expect(() => selectMenu().setOptions(option)).not.toThrowError();
expect(() => selectMenu().setOptions({ label: 'test', value: 'test' })).not.toThrowError();
expect(() => selectMenu().addOptions([option])).not.toThrowError();
expect(() => selectMenu().setOptions([option])).not.toThrowError();
expect(() => selectMenu().setOptions([{ label: 'test', value: 'test' }])).not.toThrowError();
expect(() => selectMenuWithId().addOptions(option).toJSON()).not.toThrowError();
expect(() => selectMenuWithId().setOptions(option).toJSON()).not.toThrowError();
expect(() => selectMenuWithId().setOptions({ label: 'test', value: 'test' }).toJSON()).not.toThrowError();
expect(() => selectMenuWithId().addOptions([option]).toJSON()).not.toThrowError();
expect(() => selectMenuWithId().setOptions([option]).toJSON()).not.toThrowError();
expect(() =>
selectMenu()
selectMenuWithId()
.setOptions([{ label: 'test', value: 'test' }])
.toJSON(),
).not.toThrowError();
expect(() =>
selectMenuWithId()
.addOptions({
label: 'test',
value: 'test',
@@ -90,26 +113,37 @@ describe('Select Menu Components', () => {
animated: true,
},
},
]),
])
.toJSON(),
).not.toThrowError();
const options = Array.from<APISelectMenuOption>({ length: 25 }).fill({ label: 'test', value: 'test' });
expect(() => selectMenu().addOptions(...options)).not.toThrowError();
expect(() => selectMenu().setOptions(...options)).not.toThrowError();
expect(() => selectMenu().addOptions(options)).not.toThrowError();
expect(() => selectMenu().setOptions(options)).not.toThrowError();
expect(() =>
selectMenu()
.addOptions({ label: 'test', value: 'test' })
.addOptions(...Array.from<APISelectMenuOption>({ length: 24 }).fill({ label: 'test', value: 'test' })),
selectMenuWithId()
.addOptions(...options)
.toJSON(),
).not.toThrowError();
expect(() =>
selectMenu()
selectMenuWithId()
.setOptions(...options)
.toJSON(),
).not.toThrowError();
expect(() => selectMenuWithId().addOptions(options).toJSON()).not.toThrowError();
expect(() => selectMenuWithId().setOptions(options).toJSON()).not.toThrowError();
expect(() =>
selectMenuWithId()
.addOptions({ label: 'test', value: 'test' })
.addOptions(...Array.from<APISelectMenuOption>({ length: 24 }).fill({ label: 'test', value: 'test' }))
.toJSON(),
).not.toThrowError();
expect(() =>
selectMenuWithId()
.addOptions([{ label: 'test', value: 'test' }])
.addOptions(Array.from<APISelectMenuOption>({ length: 24 }).fill({ label: 'test', value: 'test' })),
.addOptions(Array.from<APISelectMenuOption>({ length: 24 }).fill({ label: 'test', value: 'test' }))
.toJSON(),
).not.toThrowError();
});
@@ -212,13 +246,17 @@ describe('Select Menu Components', () => {
test('GIVEN valid option types THEN does not throw', () => {
expect(() =>
selectMenu().addOptions({
label: 'test',
value: 'test',
}),
selectMenuWithId()
.addOptions({
label: 'test',
value: 'test',
})
.toJSON(),
).not.toThrowError();
expect(() => selectMenu().addOptions(selectMenuOption().setLabel('test').setValue('test'))).not.toThrowError();
expect(() =>
selectMenuWithId().addOptions(selectMenuOption().setLabel('test').setValue('test')).toJSON(),
).not.toThrowError();
});
test('GIVEN valid JSON input THEN valid JSON history is correct', () => {

View File

@@ -64,11 +64,11 @@ const containerWithSeparatorDataNoColor: APIContainerComponent = {
describe('Container Components', () => {
describe('Assertion Tests', () => {
test('GIVEN valid components THEN do not throw', () => {
expect(() => new ContainerBuilder().addSeparatorComponents(new SeparatorBuilder())).not.toThrowError();
expect(() => new ContainerBuilder().spliceComponents(0, 0, new SeparatorBuilder())).not.toThrowError();
expect(() => new ContainerBuilder().addSeparatorComponents([new SeparatorBuilder()])).not.toThrowError();
expect(() => new ContainerBuilder().addSeparatorComponents(new SeparatorBuilder()).toJSON()).not.toThrowError();
expect(() => new ContainerBuilder().spliceComponents(0, 0, new SeparatorBuilder()).toJSON()).not.toThrowError();
expect(() => new ContainerBuilder().addSeparatorComponents([new SeparatorBuilder()]).toJSON()).not.toThrowError();
expect(() =>
new ContainerBuilder().spliceComponents(0, 0, [{ type: ComponentType.Separator }]),
new ContainerBuilder().spliceComponents(0, 0, [{ type: ComponentType.Separator }]).toJSON(),
).not.toThrowError();
});