From d7670df82a8056dc415a71150134d3a532c9b4e1 Mon Sep 17 00:00:00 2001 From: Zita Szupera Date: Wed, 22 Nov 2023 14:54:35 +0100 Subject: [PATCH] Remove cleanup from tests, remove tests from tsconfig --- __tests__/block-lists.test.ts | 14 +-- __tests__/call-members.test.ts | 4 +- __tests__/call-types.test.ts | 21 +--- __tests__/call.test.ts | 10 +- __tests__/channel-types.test.ts | 21 +--- __tests__/channel.test.ts | 19 +--- __tests__/command.test.ts | 15 +-- __tests__/devices-push.test.ts | 8 +- __tests__/messages.test.ts | 8 +- __tests__/permissions-app-settings.test.ts | 17 +-- __tests__/user-compat.test.ts | 2 +- __tests__/users.test.ts | 24 +---- test-cleanup.js | 118 +++++++++++++++++++++ tsconfig.json | 1 - vite.config.ts | 2 + 15 files changed, 157 insertions(+), 127 deletions(-) create mode 100644 test-cleanup.js diff --git a/__tests__/block-lists.test.ts b/__tests__/block-lists.test.ts index 378f671..f6cde81 100644 --- a/__tests__/block-lists.test.ts +++ b/__tests__/block-lists.test.ts @@ -1,7 +1,8 @@ import { afterAll, beforeAll, describe, expect, it } from "vitest"; -import { BlockList, StreamClient } from "../"; import { v4 as uuidv4 } from "uuid"; import { createTestClient } from "./create-test-client"; +import { StreamClient } from "../src/StreamClient"; +import { BlockList } from "../src/gen/chat"; describe("block lists CRUD API", () => { let client: StreamClient; @@ -55,15 +56,4 @@ describe("block lists CRUD API", () => { }); expect(response).toBeDefined(); }); - - afterAll(async () => { - const blockLists = (await client.chat.listBlockLists()).blocklists; - const customBlockLists = blockLists.filter((b) => - b.name.startsWith("streamnodetest-F1") - ); - - await Promise.all( - customBlockLists.map((b) => client.chat.deleteBlockList({ name: b.name })) - ); - }); }); diff --git a/__tests__/call-members.test.ts b/__tests__/call-members.test.ts index cf6b077..4c34ce4 100644 --- a/__tests__/call-members.test.ts +++ b/__tests__/call-members.test.ts @@ -1,7 +1,9 @@ import { beforeAll, describe, expect, it } from "vitest"; import { v4 as uuidv4 } from "uuid"; -import { StreamCall, StreamClient, VideoOwnCapability } from "../"; import { createTestClient } from "./create-test-client"; +import { StreamCall } from "../src/StreamCall"; +import { StreamClient } from "../src/StreamClient"; +import { VideoOwnCapability } from "../src/gen/video"; describe("call members API", () => { let client: StreamClient; diff --git a/__tests__/call-types.test.ts b/__tests__/call-types.test.ts index bc5bd5a..7148c49 100644 --- a/__tests__/call-types.test.ts +++ b/__tests__/call-types.test.ts @@ -1,13 +1,13 @@ -import { afterAll, beforeAll, describe, expect, it } from "vitest"; +import { beforeAll, describe, expect, it } from "vitest"; import { v4 as uuidv4 } from "uuid"; +import { createTestClient } from "./create-test-client"; +import { StreamClient } from "../src/StreamClient"; import { - StreamClient, - VideoLayoutSettingsNameEnum, VideoOwnCapability, VideoRecordSettingsRequestModeEnum, VideoRecordSettingsRequestQualityEnum, -} from "../"; -import { createTestClient } from "./create-test-client"; + VideoLayoutSettingsNameEnum, +} from "../src/gen/video"; describe("call types CRUD API", () => { let client: StreamClient; @@ -162,15 +162,4 @@ describe("call types CRUD API", () => { client.video.getCallType({ name: callTypeName }) ).rejects.toThrowError(); }); - - afterAll(async () => { - const callTypes = (await client.video.listCallTypes()).call_types; - const customCallTypes = Object.keys(callTypes).filter( - (t) => t.startsWith("streamnodetest") || t.startsWith("calltype") - ); - - await Promise.all( - customCallTypes.map((t) => client.video.deleteCallType({ name: t })) - ); - }); }); diff --git a/__tests__/call.test.ts b/__tests__/call.test.ts index 70b1d5b..782e6d9 100644 --- a/__tests__/call.test.ts +++ b/__tests__/call.test.ts @@ -1,14 +1,12 @@ import { beforeAll, describe, expect, it } from "vitest"; import { v4 as uuidv4 } from "uuid"; +import { createTestClient } from "./create-test-client"; +import { StreamCall } from "../src/StreamCall"; +import { StreamClient } from "../src/StreamClient"; import { - StreamClient, - StreamCall, VideoRecordSettingsRequestModeEnum, VideoRecordSettingsRequestQualityEnum, -} from "../"; -import { createTestClient } from "./create-test-client"; - -const apiKey = process.env.STREAM_API_KEY!; +} from "../src/gen/video"; describe("call API", () => { let client: StreamClient; diff --git a/__tests__/channel-types.test.ts b/__tests__/channel-types.test.ts index 9d193c0..dea5dc7 100644 --- a/__tests__/channel-types.test.ts +++ b/__tests__/channel-types.test.ts @@ -1,7 +1,8 @@ -import { afterAll, beforeAll, describe, expect, it } from "vitest"; +import { beforeAll, describe, expect, it } from "vitest"; import { v4 as uuidv4 } from "uuid"; -import { CreateChannelTypeRequestAutomodEnum, StreamClient } from "../"; import { createTestClient } from "./create-test-client"; +import { CreateChannelTypeRequestAutomodEnum } from "../src/gen/chat/models"; +import { StreamClient } from "../src/StreamClient"; describe("channel types CRUD API", () => { let client: StreamClient; @@ -45,20 +46,4 @@ describe("channel types CRUD API", () => { const response = await client.chat.deleteChannelType({ name: channelType }); expect(response).toBeDefined(); }); - - // TODO: why does this doesn't work? - // afterAll(async () => { - // await new Promise((resolve) => setTimeout(resolve, 5000)); - - // const channelTypes = (await client.chat.listChannelTypes()).channel_types; - // const customChannelTypes = Object.keys(channelTypes).filter((type) => - // type.startsWith("streamnodetest") - // ); - - // await Promise.all( - // customChannelTypes.map((t) => - // client.chat.deleteChannelType({ name: channelType }) - // ) - // ); - // }); }); diff --git a/__tests__/channel.test.ts b/__tests__/channel.test.ts index e235447..2b0ae42 100644 --- a/__tests__/channel.test.ts +++ b/__tests__/channel.test.ts @@ -1,7 +1,8 @@ -import { afterAll, beforeAll, describe, expect, it } from "vitest"; +import { beforeAll, describe, expect, it } from "vitest"; import { v4 as uuidv4 } from "uuid"; -import { StreamClient, StreamChannel } from "../"; import { createTestClient } from "./create-test-client"; +import { StreamClient } from "../src/StreamClient"; +import { StreamChannel } from "../src/StreamChannel"; describe("channel API", () => { let client: StreamClient; @@ -137,18 +138,4 @@ describe("channel API", () => { it("delete", async () => { await channel.delete(); }); - - afterAll(async () => { - const channels = ( - await client.chat.queryChannels({ - filter_conditions: { name: { $autocomplete: "streamnodetest" } }, - }) - ).channels; - - await Promise.all( - channels.map((c) => - client.chat.channel(c.channel!.type, c.channel!.id).delete() - ) - ); - }); }); diff --git a/__tests__/command.test.ts b/__tests__/command.test.ts index 88f611b..fc790aa 100644 --- a/__tests__/command.test.ts +++ b/__tests__/command.test.ts @@ -1,7 +1,7 @@ -import { afterAll, beforeAll, describe, expect, it } from "vitest"; +import { beforeAll, describe, expect, it } from "vitest"; import { v4 as uuidv4 } from "uuid"; -import { StreamClient } from "../"; import { createTestClient } from "./create-test-client"; +import { StreamClient } from "../src/StreamClient"; describe("commands CRUD API", () => { let client: StreamClient; @@ -45,15 +45,4 @@ describe("commands CRUD API", () => { client.chat.getCommand({ name: commandName }) ).rejects.toThrowError(); }); - - afterAll(async () => { - const commands = (await client.chat.listCommands()).commands; - const customCommands = commands.filter((c) => - c.name.startsWith("stream-node-test-command") - ); - - await Promise.all( - customCommands.map((c) => client.chat.deleteCommand({ name: c.name })) - ); - }); }); diff --git a/__tests__/devices-push.test.ts b/__tests__/devices-push.test.ts index 186c310..517d57f 100644 --- a/__tests__/devices-push.test.ts +++ b/__tests__/devices-push.test.ts @@ -1,12 +1,12 @@ import { beforeAll, describe, expect, it } from "vitest"; +import { v4 as uuidv4 } from "uuid"; import { CreateDeviceRequest, CreateDeviceRequestPushProviderEnum, - StreamClient, -} from ".."; -import { v4 as uuidv4 } from "uuid"; -import { PushProviderRequest } from "../src/gen/chat"; + PushProviderRequest, +} from "../src/gen/chat"; import { createTestClient } from "./create-test-client"; +import { StreamClient } from "../src/StreamClient"; describe("devices and push", () => { let client: StreamClient; diff --git a/__tests__/messages.test.ts b/__tests__/messages.test.ts index 8daf85b..f42176c 100644 --- a/__tests__/messages.test.ts +++ b/__tests__/messages.test.ts @@ -1,11 +1,9 @@ import "dotenv/config"; import { beforeAll, describe, expect, it } from "vitest"; -import { - StreamClient, - StreamChannel, - TranslateMessageRequestLanguageEnum, -} from "../"; import { createTestClient } from "./create-test-client"; +import { StreamChannel } from "../src/StreamChannel"; +import { StreamClient } from "../src/StreamClient"; +import { TranslateMessageRequestLanguageEnum } from "../src/gen/chat"; describe("messages API", () => { let client: StreamClient; diff --git a/__tests__/permissions-app-settings.test.ts b/__tests__/permissions-app-settings.test.ts index 243d54a..ecfe649 100644 --- a/__tests__/permissions-app-settings.test.ts +++ b/__tests__/permissions-app-settings.test.ts @@ -1,7 +1,9 @@ -import { afterAll, beforeAll, describe, expect, it } from "vitest"; -import { CreateRoleRequest, StreamClient, VideoOwnCapability } from ".."; +import { beforeAll, describe, expect, it } from "vitest"; import { v4 as uuidv4 } from "uuid"; import { createTestClient } from "./create-test-client"; +import { StreamClient } from "../src/StreamClient"; +import { CreateRoleRequest } from "../src/gen/chat"; +import { VideoOwnCapability } from "../src/gen/video"; describe("permissions and app settings API", () => { let client: StreamClient; @@ -84,15 +86,4 @@ describe("permissions and app settings API", () => { expect(response.web).toBeDefined(); }); - - afterAll(async () => { - const roles = (await client.listRoles()).roles; - const customRoles = roles.filter((r) => - r.name.startsWith("streamnodetest") - ); - - await Promise.all( - customRoles.map((r) => client.deleteRole({ name: r.name })) - ); - }); }); diff --git a/__tests__/user-compat.test.ts b/__tests__/user-compat.test.ts index e48e6bd..9014426 100644 --- a/__tests__/user-compat.test.ts +++ b/__tests__/user-compat.test.ts @@ -1,7 +1,7 @@ import { beforeAll, describe, expect, it } from "vitest"; -import { StreamClient } from "../"; import { v4 as uuidv4 } from "uuid"; import { createTestClient } from "./create-test-client"; +import { StreamClient } from "../src/StreamClient"; describe("user-video compatibility API", () => { let client: StreamClient; diff --git a/__tests__/users.test.ts b/__tests__/users.test.ts index 80a30c2..3d37df6 100644 --- a/__tests__/users.test.ts +++ b/__tests__/users.test.ts @@ -1,11 +1,8 @@ -import { afterAll, beforeAll, describe, expect, it } from "vitest"; -import { - DeleteUsersRequestUserEnum, - StreamClient, - UserObjectRequest, -} from "../"; +import { beforeAll, describe, expect, it } from "vitest"; import { v4 as uuidv4 } from "uuid"; import { createTestClient } from "./create-test-client"; +import { StreamClient } from "../src/StreamClient"; +import { UserObjectRequest } from "../src/gen/chat"; describe("user API", () => { let client: StreamClient; @@ -195,19 +192,4 @@ describe("user API", () => { expect(response).toBeDefined(); }); - - afterAll(async () => { - const users = ( - await client.queryUsers({ - filter_conditions: { name: { $autocomplete: "streamnodetest" } }, - }) - ).users; - - if (users.length > 0) { - await client.deleteUsers({ - user_ids: users.map((u) => u.id), - user: DeleteUsersRequestUserEnum.HARD, - }); - } - }); }); diff --git a/test-cleanup.js b/test-cleanup.js new file mode 100644 index 0000000..4dad502 --- /dev/null +++ b/test-cleanup.js @@ -0,0 +1,118 @@ +require("dotenv/config"); +const { StreamClient, DeleteUsersRequestUserEnum } = require("./dist/index.cjs.js"); + +const apiKey = process.env.STREAM_API_KEY; +const secret = process.env.STREAM_SECRET; + +const createTestClient = () => { + return new StreamClient(apiKey, secret, { timeout: 7500 }); +}; + +const client = createTestClient(); + +const cleanupBlockLists = async () => { + const blockLists = (await client.chat.listBlockLists()).blocklists; + const customBlockLists = blockLists.filter((b) => + b.name.startsWith("streamnodetest-F1") + ); + + await Promise.all( + customBlockLists.map((b) => client.chat.deleteBlockList({ name: b.name })) + ); +}; + +const cleanupCallTypes = async () => { + const callTypes = (await client.video.listCallTypes()).call_types; + const customCallTypes = Object.keys(callTypes).filter( + (t) => t.startsWith("streamnodetest") || t.startsWith("calltype") + ); + + await Promise.all( + customCallTypes.map((t) => client.video.deleteCallType({ name: t })) + ); +}; + +const cleanUpChannelTypes = async () => { + const channelTypes = (await client.chat.listChannelTypes()).channel_types; + const customChannelTypes = Object.keys(channelTypes).filter((type) => + type.startsWith("streamnodetest") + ); + + await Promise.all( + customChannelTypes.map((channelType) => + client.chat.deleteChannelType({ name: channelType }) + ) + ); +}; + +const cleanUpChannels = async () => { + const channels = ( + await client.chat.queryChannels({ + filter_conditions: { name: { $autocomplete: "streamnodetest" } }, + }) + ).channels; + + await Promise.all( + channels.map((c) => + client.chat.channel(c.channel.type, c.channel.id).delete() + ) + ); +}; + +const cleanUpCommands = async () => { + const commands = (await client.chat.listCommands()).commands; + const customCommands = commands.filter((c) => + c.name.startsWith("stream-node-test-command") + ); + + await Promise.all( + customCommands.map((c) => client.chat.deleteCommand({ name: c.name })) + ); +}; + +const cleanUpRoles = async () => { + const roles = (await client.listRoles()).roles; + const customRoles = roles.filter((r) => r.name.startsWith("streamnodetest")); + + let grants = {}; + customRoles.forEach(r => { + grants[r.name] = [] + }); + await client.updateAppSettings({ + grants + }); + + await Promise.all( + customRoles.map((r) => client.deleteRole({ name: r.name })) + ); +}; + +const cleanUpUsers = async () => { + const users = ( + await client.queryUsers({ + filter_conditions: { name: { $autocomplete: "streamnodetest" } }, + }) + ).users; + + if (users.length > 0) { + await client.deleteUsers({ + user_ids: users.map((u) => u.id), + user: DeleteUsersRequestUserEnum.HARD, + }); + } +}; + +const cleanup = async () => { + await cleanupBlockLists(); + await cleanupCallTypes(); + await cleanUpChannelTypes(); + await cleanUpChannels(); + await cleanUpCommands(); + await cleanUpRoles(); + await cleanUpUsers(); +}; + +cleanup().then(() => { + console.log('cleanup done'); + process.exit(); +}); diff --git a/tsconfig.json b/tsconfig.json index 7708d01..8afdf9a 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -25,6 +25,5 @@ "./src", "index.ts", "version.ts", - "__tests__" ] } \ No newline at end of file diff --git a/vite.config.ts b/vite.config.ts index 62db389..55a43ea 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -7,5 +7,7 @@ export default defineConfig({ reporter: ["lcov"], }, testTimeout: 10000, + include: ["__tests__/**/*.test.ts"], + includeSource: ["src/**/*.ts"], }, });