Skip to content

Commit

Permalink
fix(builders): allow negative min/max value of number/integer option (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
skick1234 committed Feb 20, 2022
1 parent ba31203 commit 3baa340
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
Expand Up @@ -39,15 +39,15 @@ const getIntegerOption = () =>
.setName('owo')
.setDescription('Testing 123')
.setRequired(true)
.setMinValue(1)
.setMinValue(-1)
.setMaxValue(10);

const getNumberOption = () =>
new SlashCommandNumberOption()
.setName('owo')
.setDescription('Testing 123')
.setRequired(true)
.setMinValue(1)
.setMinValue(-1.23)
.setMaxValue(10);

const getUserOption = () => new SlashCommandUserOption().setName('owo').setDescription('Testing 123').setRequired(true);
Expand Down Expand Up @@ -84,7 +84,7 @@ describe('Application Command toJSON() results', () => {
type: ApplicationCommandOptionType.Integer,
required: true,
max_value: 10,
min_value: 1,
min_value: -1,
});

expect(getIntegerOption().setAutocomplete(true).setChoices().toJSON()).toEqual<APIApplicationCommandIntegerOption>({
Expand All @@ -93,7 +93,7 @@ describe('Application Command toJSON() results', () => {
type: ApplicationCommandOptionType.Integer,
required: true,
max_value: 10,
min_value: 1,
min_value: -1,
autocomplete: true,
// @ts-expect-error TODO: you *can* send an empty array with autocomplete: true, should correct that in types
choices: [],
Expand All @@ -107,7 +107,7 @@ describe('Application Command toJSON() results', () => {
type: ApplicationCommandOptionType.Integer,
required: true,
max_value: 10,
min_value: 1,
min_value: -1,
choices: [{ name: 'uwu', value: 1 }],
});
});
Expand All @@ -128,7 +128,7 @@ describe('Application Command toJSON() results', () => {
type: ApplicationCommandOptionType.Number,
required: true,
max_value: 10,
min_value: 1,
min_value: -1.23,
});

expect(getNumberOption().setAutocomplete(true).setChoices().toJSON()).toEqual<APIApplicationCommandNumberOption>({
Expand All @@ -137,7 +137,7 @@ describe('Application Command toJSON() results', () => {
type: ApplicationCommandOptionType.Number,
required: true,
max_value: 10,
min_value: 1,
min_value: -1.23,
autocomplete: true,
// @ts-expect-error TODO: you *can* send an empty array with autocomplete: true, should correct that in types
choices: [],
Expand All @@ -149,7 +149,7 @@ describe('Application Command toJSON() results', () => {
type: ApplicationCommandOptionType.Number,
required: true,
max_value: 10,
min_value: 1,
min_value: -1.23,
choices: [{ name: 'uwu', value: 1 }],
});
});
Expand Down
Expand Up @@ -5,7 +5,7 @@ import { ApplicationCommandNumericOptionMinMaxValueMixin } from '../mixins/Appli
import { ApplicationCommandOptionBase } from '../mixins/ApplicationCommandOptionBase';
import { ApplicationCommandOptionWithChoicesAndAutocompleteMixin } from '../mixins/ApplicationCommandOptionWithChoicesAndAutocompleteMixin';

const numberValidator = z.number().int().nonnegative();
const numberValidator = z.number().int();

@mix(ApplicationCommandNumericOptionMinMaxValueMixin, ApplicationCommandOptionWithChoicesAndAutocompleteMixin)
export class SlashCommandIntegerOption
Expand Down
Expand Up @@ -5,7 +5,7 @@ import { ApplicationCommandNumericOptionMinMaxValueMixin } from '../mixins/Appli
import { ApplicationCommandOptionBase } from '../mixins/ApplicationCommandOptionBase';
import { ApplicationCommandOptionWithChoicesAndAutocompleteMixin } from '../mixins/ApplicationCommandOptionWithChoicesAndAutocompleteMixin';

const numberValidator = z.number().nonnegative();
const numberValidator = z.number();

@mix(ApplicationCommandNumericOptionMinMaxValueMixin, ApplicationCommandOptionWithChoicesAndAutocompleteMixin)
export class SlashCommandNumberOption
Expand Down

0 comments on commit 3baa340

Please sign in to comment.