Skip to content

Commit

Permalink
Import space collection and WS root properties
Browse files Browse the repository at this point in the history
  • Loading branch information
JiriLojda committed Aug 12, 2024
1 parent 6491e05 commit 2a3a744
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 3 deletions.
14 changes: 14 additions & 0 deletions src/modules/importExport/importExportEntities/entities/spaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import chalk from "chalk";

import { logInfo } from "../../../../log.js";
import { serially } from "../../../../utils/requests.js";
import { getRequired } from "../../import/utils.js";
import { EntityDefinition } from "../entityDefinition.js";

export const spacesEntity: EntityDefinition<ReadonlyArray<SpaceContracts.ISpaceContract>> = {
Expand All @@ -21,6 +22,19 @@ export const spacesEntity: EntityDefinition<ReadonlyArray<SpaceContracts.ISpaceC
.withData({
name: importSpace.name,
codename: importSpace.codename,
collections: importSpace.collections?.map(c => ({
id: getRequired(context.collectionIdsByOldIds, c.id ?? "missing-collection-id", "collection"),
})),
web_spotlight_root_item: importSpace.web_spotlight_root_item
? {
id:
getRequired(
context.contentItemContextByOldIds,
importSpace.web_spotlight_root_item.id ?? "missing-ws-root-id",
"item",
).selfId,
}
: undefined,
}).toPromise();
}));

Expand Down
10 changes: 7 additions & 3 deletions tests/integration/importExport/import.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
expectNoItems,
expectNoPreviewUrls,
expectNoSnippets,
expectNoSpaces,
expectNoTaxonomies,
expectNoTypes,
expectNoWebhooks,
Expand Down Expand Up @@ -48,16 +49,17 @@ describe("import command", () => {
"Imports only entities specified in the include parameter",
withTestEnvironment(EMPTY_TEST_ENVIRONMENT_ID, async environmentId => {
const command =
`import -e=${environmentId} -f=tests/integration/importExport/data/exportSnapshot.zip -k=${API_KEY} --include collections languages spaces taxonomies`;
`import -e=${environmentId} -f=tests/integration/importExport/data/exportSnapshot.zip -k=${API_KEY} --include collections languages taxonomies`;

await runCommand(command);

await expectSameEnvironments(environmentId, EXPORT_IMPORT_TEST_DATA_ENVIRONMENT_ID, {
include: ["collections", "languages", "spaces", "taxonomies"],
include: ["collections", "languages", "taxonomies"],
});

await expectNoAssetFolders(environmentId);
await expectNoAssets(environmentId);
await expectNoSpaces(environmentId);
await expectNoSnippets(environmentId);
await expectNoTypes(environmentId);
await expectNoItems(environmentId);
Expand All @@ -71,13 +73,14 @@ describe("import command", () => {
"Imports all entities except those specified in the exclude parameter",
withTestEnvironment(EMPTY_TEST_ENVIRONMENT_ID, async environmentId => {
const command =
`import -e=${environmentId} -f=tests/integration/importExport/data/exportSnapshot.zip -k=${API_KEY} --exclude assets contentTypes contentTypeSnippets taxonomies contentItems languageVariants workflows previewUrls webhooks`;
`import -e=${environmentId} -f=tests/integration/importExport/data/exportSnapshot.zip -k=${API_KEY} --exclude assets spaces webSpotlight contentTypes contentTypeSnippets taxonomies contentItems languageVariants workflows previewUrls webhooks`;

await runCommand(command);

await expectSameEnvironments(environmentId, EXPORT_IMPORT_TEST_DATA_ENVIRONMENT_ID, {
exclude: [
"assets",
"spaces",
"roles",
"types",
"snippets",
Expand All @@ -93,6 +96,7 @@ describe("import command", () => {
await expectNoAssets(environmentId);
await expectNoTypes(environmentId);
await expectNoSnippets(environmentId);
await expectNoSpaces(environmentId);
await expectNoTaxonomies(environmentId);
await expectNoItems(environmentId);
await expectNoWorkflows(environmentId);
Expand Down
4 changes: 4 additions & 0 deletions tests/integration/importExport/utils/compare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ type PrepareReferencesFnc<T> = (entity: T) => T;
const createPrepareSpaceReferences: PrepareReferencesCreator<SpaceContracts.ISpaceContract> = data => space => ({
...space,
id: "-",
collections: space.collections?.map(c => ({ id: data.collections.find(col => col.id === c.id)?.codename })),
web_spotlight_root_item: space.web_spotlight_root_item
? { id: data.items.find(i => i.id === space.web_spotlight_root_item?.id)?.codename }
: undefined,
Expand Down Expand Up @@ -469,6 +470,9 @@ const createPrepareItemReferences: PrepareReferencesCreator<ContentItemContracts
last_modified: new Date(1316, 4, 14),
type: { id: data.types.find(t => t.id === item.type.id)?.codename ?? "non-existing-type" },
collection: { id: data.collections.find(c => c.id === item.collection.id)?.codename ?? "non-existing-collection" },
spaces: (item as any).spaces.map((s: any) => ({ // TODO: remove both any types once the SDK types are fixed
id: data.spaces.find(sp => sp.id === s.id)?.codename ?? "non-existing-space",
})),
});

const createPrepareVariantReferences: PrepareReferencesCreator<LanguageVariantContracts.ILanguageVariantModelContract> =
Expand Down
11 changes: 11 additions & 0 deletions tests/integration/importExport/utils/isEmpty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,17 @@ export const expectNoSnippets = async (envId: string) => {
expect(assets).toStrictEqual([]);
};

export const expectNoSpaces = async (envId: string) => {
const client = makeClientFor(envId);

const spaces = await client
.listSpaces()
.toPromise()
.then(res => res.data);

expect(spaces).toStrictEqual([]);
};

export const expectNoTypes = async (envId: string) => {
const client = makeClientFor(envId);

Expand Down

0 comments on commit 2a3a744

Please sign in to comment.