From 513ccb0d6d48ab3bb471f24bf600a2411c688cf4 Mon Sep 17 00:00:00 2001 From: Daniel Pokorny Date: Tue, 9 Apr 2024 16:08:51 +0200 Subject: [PATCH] add tests --- tests/integration/importExport/clean.test.ts | 66 ++++++++++++++++--- .../integration/importExport/utils/compare.ts | 4 +- 2 files changed, 59 insertions(+), 11 deletions(-) diff --git a/tests/integration/importExport/clean.test.ts b/tests/integration/importExport/clean.test.ts index 55c41e89..47bd8675 100644 --- a/tests/integration/importExport/clean.test.ts +++ b/tests/integration/importExport/clean.test.ts @@ -1,7 +1,8 @@ -import { describe, it } from "@jest/globals"; +import { describe, expect, it } from "@jest/globals"; import { config as dotenvConfig } from "dotenv"; -import { runCommand } from "../utils/runCommand"; +import { expectHelpText } from "../utils/expectations"; +import { CommandError, runCommand } from "../utils/runCommand"; import { withTestEnvironment } from "../utils/setup"; import { expectSameEnvironments } from "./utils/compare"; import { @@ -29,11 +30,15 @@ if (!API_KEY) { describe("clean command", () => { it.concurrent( - "Cleans all entities in the target environment.", + "Cleans all entities in the target environment, prints info on manual WSL removal.", withTestEnvironment(async (environmentId) => { const command = `clean -e=${environmentId} -k=${API_KEY}`; - await runCommand(command); + const result = await runCommand(command); + + expect(result.stdout).toContain( + "⚠ Some types couldn't be deleted because Web Spotlight is enabled on the environment.", + ); await expectNoAssetFolders(environmentId); await expectNoAssets(environmentId); @@ -49,25 +54,26 @@ describe("clean command", () => { it.concurrent( "Cleans only entities specified in the include parameter.", withTestEnvironment(async (environmentId) => { - const command = `clean -e=${environmentId} -k=${API_KEY} --include spaces contentItems taxonomies`; + const command = + `clean -e=${environmentId} -k=${API_KEY} --include spaces contentItems contentTypes contentTypeSnippets`; await runCommand(command); await expectSameEnvironments(environmentId, CLEAN_TEST_DATA_ENVIRONMENT_ID, { - exclude: ["spaces", "items", "taxonomies", "previewUrls"], + exclude: ["spaces", "items", "types", "snippets", "previewUrls", "variants"], }); - await expectNoTaxonomies(environmentId); await expectNoItems(environmentId); await expectNoPreviewUrls(environmentId); + await expectNoSnippets(environmentId); + await expectNoTypes(environmentId, true); }, false), ); it.concurrent( "Cleans only entities not specified in the exclude parameter.", withTestEnvironment(async (environmentId) => { - const command = - `clean -e=${environmentId} -k=${API_KEY} --exclude languages collections`; + const command = `clean -e=${environmentId} -k=${API_KEY} --exclude languages collections`; await runCommand(command); @@ -82,4 +88,46 @@ describe("clean command", () => { await expectNoAssetFolders(environmentId); }, false), ); + + it.concurrent("Errors when removing types with existing items, prints message.", async () => { + withTestEnvironment(async (environmentId) => { + const command = `clean -e=${environmentId} -k=${API_KEY} --include contentTypes`; + + await runCommand(command); + + + }) + }); + + it.concurrent("Errors with help when both include and exclude are provided", async () => { + const command = "clean --include collections contentTypes --exclude contentTypes -e test -k test"; + + const result = await runCommand(command).catch(err => err as CommandError); + + expect(result.stdout).toBe(""); + await expectHelpText(result.stderr, "clean"); + expect(result.stderr).toContain("Arguments include and exclude are mutually exclusive"); + }); + + it.concurrent("Errors with help when include contains invalid entity names", async () => { + const command = "clean --include collections invalidEntity -k test -e test"; + + const result = await runCommand(command).catch(err => err as CommandError); + + expect(result.stdout).toBe(""); + await expectHelpText(result.stderr, "clean"); + expect(result.stderr).toContain("Invalid values"); + expect(result.stderr).toContain("include, Given: \"invalidEntity\", Choices: "); + }); + + it.concurrent("Errors with help when exclude contains invalid entity names", async () => { + const command = "clean --exclude collections invalidEntity -k test -e test"; + + const result = await runCommand(command).catch(err => err as CommandError); + + expect(result.stdout).toBe(""); + await expectHelpText(result.stderr, "clean"); + expect(result.stderr).toContain("Invalid values"); + expect(result.stderr).toContain("exclude, Given: \"invalidEntity\", Choices: "); + }); }); diff --git a/tests/integration/importExport/utils/compare.ts b/tests/integration/importExport/utils/compare.ts index 35919158..b0f0058e 100644 --- a/tests/integration/importExport/utils/compare.ts +++ b/tests/integration/importExport/utils/compare.ts @@ -62,7 +62,7 @@ export const expectSameAllEnvData = ( has("taxonomies") && expect(sortByCodename(data1.taxonomies)).toStrictEqual(sortByCodename(data2.taxonomies)); has("assetFolders") && expect(data1.assetFolders).toStrictEqual(data2.assetFolders); has("assets") && expect(sortByCodename(data1.assets)).toStrictEqual(sortByCodename(data2.assets)); - has("roles") && expect(data1.roles).toStrictEqual(data2.roles); + has("roles") && expect(sortBy(data1.roles, r => r.name)).toStrictEqual(sortBy(data2.roles, r => r.name)); has("workflows") && expect(sortByCodename(data1.workflows)).toStrictEqual(sortByCodename(data2.workflows)); has("snippets") && expect(sortByCodename(data1.snippets)).toStrictEqual(sortByCodename(data2.snippets)); has("types") && expect(sortByCodename(data1.types)).toStrictEqual(sortByCodename(data2.types)); @@ -640,7 +640,7 @@ const createPrepareVariantElementReferences: PrepareReferencesCreator = role => ({ ...role, - id: "-" + id: "-", }); const getAllTerms = (