From 3a017f48d7bbc27cdf7af60b8634959a3d3c9fb7 Mon Sep 17 00:00:00 2001 From: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com> Date: Wed, 5 May 2021 08:30:18 -0400 Subject: [PATCH 1/2] Delete test.ts --- test.ts | 75 --------------------------------------------------------- 1 file changed, 75 deletions(-) delete mode 100644 test.ts diff --git a/test.ts b/test.ts deleted file mode 100644 index 540dc8902..000000000 --- a/test.ts +++ /dev/null @@ -1,75 +0,0 @@ -const config = { - maxConcurrency: 16, - maxShards: 1120, - maxClusters: 140, - shardsPerCluster: 8, -}; - -function sleep(ms: number) { - return new Promise((resolve) => setTimeout(resolve, ms)); -} - -function organizeClusters() { - const clusters = new Map(); - const buckets = new Map(); - const shardClusters = new Map(); - let cluster = 0; - - for (let i = 0; i < config.maxShards; i++) { - const shards = clusters.get(cluster); - if (!shards) clusters.set(cluster, [i]); - else { - if (shards.length < config.shardsPerCluster) shards.push(i); - else { - cluster++; - clusters.set(cluster, [i]); - } - } - - shardClusters.set(i, cluster); - } - - for (let i = 0; i < config.maxShards; i++) { - const bucketID = i % config.maxConcurrency; - const bucket = buckets.get(bucketID); - if (!bucket) { - buckets.set(bucketID, [i]); - } else { - bucket.push(i); - } - } - - return { clusters, buckets }; -} - -function startup() { - const { clusters, buckets } = organizeClusters(); - - // SPREAD THIS OUT TO DIFFERENT CLUSTERS TO BEGIN STARTING UP - // FOREACH will have this concurrently - buckets.forEach(async (bucket, bucketID) => { - for (const queue of bucket) { - for (const shardID of queue) { - console.log( - `Bucket ID:`, - bucketID, - "Cluster ID:", - clusters.get(shardID), - "Shard ID:", - shardID, - ); - redis.publish( - "sharder", - JSON.stringify({ clusterID: clusters.get(shardID), shardID }), - ); - } - - // AFTER THIS QUEUE IS CREATED WE WAIT FOR ALL SHARDS TO LOAD BEFORE NEXT CLUSTER - // 5 SECONDS PER SHARD + EXTRA 10 TO BE SAFE - await sleep(config.shardsPerCluster * 5000 + 10000); - } - }); -} - -startup(); -setInterval(startup, 60000 * 5); From 02eb2de8f2458f41c6309a0d83e11179b4c4a955 Mon Sep 17 00:00:00 2001 From: rigormorrtiss Date: Wed, 5 May 2021 17:26:10 +0400 Subject: [PATCH 2/2] add(tests): validateSlashCommands (#899) * test(util): add missing tests for validateSlashCommands() * Summarize the name of the test suites * Add more tests * Concise and correct the suite name --- tests/deps.ts | 1 + tests/util/utils.ts | 54 ++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/tests/deps.ts b/tests/deps.ts index 9e4747cff..8ecc89d22 100644 --- a/tests/deps.ts +++ b/tests/deps.ts @@ -2,4 +2,5 @@ export { assertArrayIncludes, assertEquals, assertExists, + assertThrows, } from "https://deno.land/std@0.90.0/testing/asserts.ts"; diff --git a/tests/util/utils.ts b/tests/util/utils.ts index c8a0fb686..128d602a2 100644 --- a/tests/util/utils.ts +++ b/tests/util/utils.ts @@ -1,8 +1,11 @@ +import { ApplicationCommandOption } from "../../src/types/interactions/application_command_option.ts"; +import { DiscordApplicationCommandOptionTypes } from "../../src/types/interactions/application_command_option_types.ts"; import { camelKeysToSnakeCase, snakeKeysToCamelCase, + validateSlashCommands, } from "../../src/util/utils.ts"; -import { assertEquals } from "../deps.ts"; +import { assertEquals, assertThrows } from "../deps.ts"; const testSnakeObject = { // deno-lint-ignore camelcase @@ -74,3 +77,52 @@ Deno.test({ assertEquals(resultTwo, someElseOther); }, }); + +Deno.test({ + name: "[utils] validateSlashCommands(): validates name", + fn() { + assertThrows(() => + validateSlashCommands([{ + // The maximum length of the name of an application command is 32. + name: "a".repeat(33), + }]) + ); + + validateSlashCommands([{ + name: "workingname", + }]); + }, +}); + +Deno.test({ + name: "[utils] validateSlashCommands(): validates description", + fn() { + assertThrows(() => + // The maximum length of the description of an application command is 100. + validateSlashCommands([{ description: "a".repeat(101) }]) + ); + + validateSlashCommands([{ + description: "valid description (should not throw)", + }]); + }, +}); + +Deno.test({ + name: "[utils] validateSlashCommands(): validates number of options", + fn() { + const option = { + name: "option1", + description: "The description of the application command's option.", + type: DiscordApplicationCommandOptionTypes.STRING, + }; + // The maximum number of options an application command can "accomodate" is 25. + const options: ApplicationCommandOption[] = Array(26).fill(option); + + assertThrows(() => validateSlashCommands([{ options }])); + + validateSlashCommands([{ + options: [option], + }]); + }, +});