Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pokornyd committed Apr 10, 2024
1 parent 6625cb4 commit 513ccb0
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 11 deletions.
66 changes: 57 additions & 9 deletions tests/integration/importExport/clean.test.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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);
Expand All @@ -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);

Expand All @@ -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: ");
});
});
4 changes: 2 additions & 2 deletions tests/integration/importExport/utils/compare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -640,7 +640,7 @@ const createPrepareVariantElementReferences: PrepareReferencesCreator<ElementCon

const prepareRoleReferences: PrepareReferencesFnc<RoleContracts.IRoleContract> = role => ({
...role,
id: "-"
id: "-",
});

const getAllTerms = (
Expand Down

0 comments on commit 513ccb0

Please sign in to comment.