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

@@ -237,9 +237,9 @@ describe('ChatInput Commands', () => {
});
test('GIVEN valid names THEN does not throw error', () => {
expect(() => getBuilder().setName('hi_there').setDescription(':3')).not.toThrowError();
expect(() => getBuilder().setName('o_comandă').setDescription(':3')).not.toThrowError();
expect(() => getBuilder().setName('どうも').setDescription(':3')).not.toThrowError();
expect(() => getBuilder().setName('hi_there').setDescription(':3').toJSON()).not.toThrowError();
expect(() => getBuilder().setName('o_comandă').setDescription(':3').toJSON()).not.toThrowError();
expect(() => getBuilder().setName('どうも').setDescription(':3').toJSON()).not.toThrowError();
});
test('GIVEN invalid returns for builder THEN throw error', () => {
@@ -384,8 +384,12 @@ describe('ChatInput Commands', () => {
};
test('GIVEN valid name localizations THEN does not throw error', () => {
expect(() => getBuilder().setNameLocalization(Locale.EnglishUS, 'foobar')).not.toThrowError();
expect(() => getBuilder().setNameLocalizations({ [Locale.EnglishUS]: 'foobar' })).not.toThrowError();
expect(() => getNamedBuilder().setNameLocalization(Locale.EnglishUS, 'foobar').toJSON()).not.toThrowError();
expect(() =>
getNamedBuilder()
.setNameLocalizations({ [Locale.EnglishUS]: 'foobar' })
.toJSON(),
).not.toThrowError();
});
test('GIVEN invalid name localizations THEN does throw error', () => {
@@ -451,19 +455,19 @@ describe('ChatInput Commands', () => {
describe('permissions', () => {
test('GIVEN valid permission string THEN does not throw error', () => {
expect(() => getNamedBuilder().setDefaultMemberPermissions('1')).not.toThrowError();
expect(() => getNamedBuilder().setDefaultMemberPermissions('1').toJSON()).not.toThrowError();
});
test('GIVEN valid permission bitfield THEN does not throw error', () => {
expect(() =>
getNamedBuilder().setDefaultMemberPermissions(
PermissionFlagsBits.AddReactions | PermissionFlagsBits.AttachFiles,
),
getNamedBuilder()
.setDefaultMemberPermissions(PermissionFlagsBits.AddReactions | PermissionFlagsBits.AttachFiles)
.toJSON(),
).not.toThrowError();
});
test('GIVEN null permissions THEN does not throw error', () => {
expect(() => getNamedBuilder().clearDefaultMemberPermissions()).not.toThrowError();
expect(() => getNamedBuilder().clearDefaultMemberPermissions().toJSON()).not.toThrowError();
});
test('GIVEN invalid inputs THEN does throw error', () => {
@@ -476,7 +480,7 @@ describe('ChatInput Commands', () => {
getNamedBuilder().addBooleanOptions(getBooleanOption()).setDefaultMemberPermissions('1').toJSON(),
).not.toThrowError();
expect(() => getNamedBuilder().addChannelOptions(getChannelOption())).not.toThrowError();
expect(() => getNamedBuilder().addChannelOptions(getChannelOption()).toJSON()).not.toThrowError();
});
});

View File

@@ -21,10 +21,10 @@ describe('Context Menu Commands', () => {
expect(() => getBuilder().setName('A COMMAND').toJSON()).not.toThrowError();
// Translation: a_command
expect(() => getBuilder().setName('o_comandă')).not.toThrowError();
expect(() => getBuilder().setName('o_comandă').toJSON()).not.toThrowError();
// Translation: thx (according to GTranslate)
expect(() => getBuilder().setName('どうも')).not.toThrowError();
expect(() => getBuilder().setName('どうも').toJSON()).not.toThrowError();
expect(() => getBuilder().setName('🎉').toJSON()).not.toThrowError();
expect(() => getBuilder().setName('🫆').toJSON()).not.toThrowError();
@@ -41,8 +41,15 @@ describe('Context Menu Commands', () => {
};
test('GIVEN valid name localizations THEN does not throw error', () => {
expect(() => getBuilder().setNameLocalization(Locale.EnglishUS, 'foobar')).not.toThrowError();
expect(() => getBuilder().setNameLocalizations({ [Locale.EnglishUS]: 'foobar' })).not.toThrowError();
expect(() =>
getBuilder().setName('test').setNameLocalization(Locale.EnglishUS, 'foobar').toJSON(),
).not.toThrowError();
expect(() =>
getBuilder()
.setName('test')
.setNameLocalizations({ [Locale.EnglishUS]: 'foobar' })
.toJSON(),
).not.toThrowError();
});
test('GIVEN invalid name localizations THEN does throw error', () => {
@@ -71,12 +78,15 @@ describe('Context Menu Commands', () => {
describe('permissions', () => {
test('GIVEN valid permission string THEN does not throw error', () => {
expect(() => getBuilder().setDefaultMemberPermissions('1')).not.toThrowError();
expect(() => getBuilder().setName('test').setDefaultMemberPermissions('1').toJSON()).not.toThrowError();
});
test('GIVEN valid permission bitfield THEN does not throw error', () => {
expect(() =>
getBuilder().setDefaultMemberPermissions(PermissionFlagsBits.AddReactions | PermissionFlagsBits.AttachFiles),
getBuilder()
.setName('test')
.setDefaultMemberPermissions(PermissionFlagsBits.AddReactions | PermissionFlagsBits.AttachFiles)
.toJSON(),
).not.toThrowError();
});
@@ -90,11 +100,14 @@ describe('Context Menu Commands', () => {
describe('contexts', () => {
test('GIVEN a builder with valid contexts THEN does not throw an error', () => {
expect(() =>
getBuilder().setContexts([InteractionContextType.Guild, InteractionContextType.BotDM]),
getBuilder()
.setName('test')
.setContexts([InteractionContextType.Guild, InteractionContextType.BotDM])
.toJSON(),
).not.toThrowError();
expect(() =>
getBuilder().setContexts(InteractionContextType.Guild, InteractionContextType.BotDM),
getBuilder().setName('test').setContexts(InteractionContextType.Guild, InteractionContextType.BotDM).toJSON(),
).not.toThrowError();
});
@@ -110,17 +123,17 @@ describe('Context Menu Commands', () => {
describe('integration types', () => {
test('GIVEN a builder with valid integration types THEN does not throw an error', () => {
expect(() =>
getBuilder().setIntegrationTypes([
ApplicationIntegrationType.GuildInstall,
ApplicationIntegrationType.UserInstall,
]),
getBuilder()
.setName('test')
.setIntegrationTypes([ApplicationIntegrationType.GuildInstall, ApplicationIntegrationType.UserInstall])
.toJSON(),
).not.toThrowError();
expect(() =>
getBuilder().setIntegrationTypes(
ApplicationIntegrationType.GuildInstall,
ApplicationIntegrationType.UserInstall,
),
getBuilder()
.setName('test')
.setIntegrationTypes(ApplicationIntegrationType.GuildInstall, ApplicationIntegrationType.UserInstall)
.toJSON(),
).not.toThrowError();
});