From 071015caefc2abeffba8d37d658cacb4ba870bc7 Mon Sep 17 00:00:00 2001 From: Jiralite <33201955+Jiralite@users.noreply.github.com> Date: Sun, 5 Jan 2025 00:22:58 +0000 Subject: [PATCH] test: Add `with_response` overload tests (#10685) test: add overload tests Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> --- packages/core/__tests__/types.test.ts | 66 +++++++++++++++++++++++++++ packages/core/tsconfig.json | 2 +- vitest.d.ts | 8 ++++ 3 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 packages/core/__tests__/types.test.ts create mode 100644 vitest.d.ts diff --git a/packages/core/__tests__/types.test.ts b/packages/core/__tests__/types.test.ts new file mode 100644 index 000000000..8537c30f8 --- /dev/null +++ b/packages/core/__tests__/types.test.ts @@ -0,0 +1,66 @@ +import { REST } from '@discordjs/rest'; +import type { + APIActionRowComponent, + APIModalActionRowComponent, + RESTPostAPIInteractionCallbackWithResponseResult, +} from 'discord-api-types/v10'; +import { assertType, describe, test } from 'vitest'; +import { API } from '../src/index.js'; + +const rest = new REST(); +const api = new API(rest); +const SNOWFLAKE = '123456789012345678' as const; +const TOKEN = 'token' as const; +const MODAL_COMPONENTS: APIActionRowComponent[] = [] as const; + +describe('Interaction with_response overloads.', () => { + test('Replying returns RESTPostAPIInteractionCallbackWithResponseResult.', () => + assertType>( + api.interactions.reply(SNOWFLAKE, TOKEN, { with_response: true }), + )); + + test('Replying returns undefined.', () => assertType>(api.interactions.reply(SNOWFLAKE, TOKEN, {}))); + + test('Defer returns RESTPostAPIInteractionCallbackWithResponseResult.', () => + assertType>( + api.interactions.defer(SNOWFLAKE, TOKEN, { with_response: true }), + )); + + test('Defer returns undefined.', () => assertType>(api.interactions.defer(SNOWFLAKE, TOKEN, {}))); + + test('Defer message update returns RESTPostAPIInteractionCallbackWithResponseResult.', () => + assertType>( + api.interactions.deferMessageUpdate(SNOWFLAKE, TOKEN, { with_response: true }), + )); + + test('Defer message update returns undefined.', () => assertType>(api.interactions.deferMessageUpdate(SNOWFLAKE, TOKEN, {}))); + + test('Update message returns RESTPostAPIInteractionCallbackWithResponseResult.', () => + assertType>( + api.interactions.updateMessage(SNOWFLAKE, TOKEN, { with_response: true }), + )); + + test('Update message returns undefined.', () => assertType>(api.interactions.updateMessage(SNOWFLAKE, TOKEN, {}))); + + test('Create autocomplete response returns RESTPostAPIInteractionCallbackWithResponseResult.', () => + assertType>( + api.interactions.createAutocompleteResponse(SNOWFLAKE, TOKEN, { with_response: true }), + )); + + test('Create autocomplete response returns undefined.', () => assertType>(api.interactions.createAutocompleteResponse(SNOWFLAKE, TOKEN, {}))); + + test('Create modal returns RESTPostAPIInteractionCallbackWithResponseResult.', () => + assertType>( + api.interactions.createModal(SNOWFLAKE, TOKEN, { + title: '', + custom_id: '', + components: MODAL_COMPONENTS, + with_response: true, + }), + )); + + test('Create modal returns undefined.', () => + assertType>( + api.interactions.createModal(SNOWFLAKE, TOKEN, { title: '', custom_id: '', components: MODAL_COMPONENTS }), + )); +}); diff --git a/packages/core/tsconfig.json b/packages/core/tsconfig.json index b6ea137a0..f7144f4eb 100644 --- a/packages/core/tsconfig.json +++ b/packages/core/tsconfig.json @@ -1,6 +1,6 @@ { "$schema": "https://json.schemastore.org/tsconfig.json", "extends": "../../tsconfig.json", - "include": ["src/**/*.ts", "src/**/*.js", "src/**/*.cjs", "src/**/*.mjs", "bin"], + "include": ["src/**/*.ts", "src/**/*.js", "src/**/*.cjs", "src/**/*.mjs", "bin", "__tests__", "../../vitest.d.ts"], "exclude": ["node_modules"] } diff --git a/vitest.d.ts b/vitest.d.ts new file mode 100644 index 000000000..e600d9db9 --- /dev/null +++ b/vitest.d.ts @@ -0,0 +1,8 @@ +/* eslint-disable @typescript-eslint/no-empty-interface */ +// This file only exists because of https://github.com/vitejs/vite/issues/9813. +declare interface Worker {} +declare interface WebSocket {} + +declare namespace WebAssembly { + interface Module {} +}