From 0dca34217d2e4dba6a059ac0c7eaeeed8c68f38e Mon Sep 17 00:00:00 2001 From: John Whiles Date: Wed, 12 May 2021 16:04:49 +0200 Subject: [PATCH 1/9] feat: create an alias before running tests --- test/integration/index.ts | 14 +++++++++++++- test/integration/tasks/create-new-environment.ts | 5 ++++- .../tasks/delete-new-environment-alias.ts | 16 ++++++++++++++++ 3 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 test/integration/tasks/delete-new-environment-alias.ts diff --git a/test/integration/index.ts b/test/integration/index.ts index 1adfea56c8..fa77c921e4 100644 --- a/test/integration/index.ts +++ b/test/integration/index.ts @@ -10,6 +10,7 @@ import { } from './tasks/create-configuration-files' import createEnvironment from './tasks/create-new-environment' import deleteEnvironment from './tasks/delete-new-environment' +import deleteEnvironmentAlias from './tasks/delete-new-environment-alias' import deleteStaleEnvironments from './tasks/delete-stale-environments' import deployExtensions from './tasks/deploy-extensions' import runCypress from './tasks/run-cypress' @@ -46,9 +47,18 @@ function listAllEnvironmentVariables() { } let tempEnvironmentId: any +let tempAliasId: any const tempEntries: { environmentId: string; entryId: string }[] = [] const cleanup = async () => { + if (tempAliasId) { + try { + await asyncRetry(() => deleteEnvironmentAlias(tempAliasId), { retries: 3 }) + } catch (e) { + console.log(e) + throw new Error('Failed to remove environment alias') + } + } if (tempEnvironmentId) { try { await asyncRetry(() => deleteEnvironment(tempEnvironmentId), { retries: 3 }) @@ -77,12 +87,14 @@ const run = async () => { } try { - tempEnvironmentId = await asyncRetry( + const { environmentId, aliasId } = await asyncRetry( () => { return createEnvironment() }, { retries: 3 } ) + tempEnvironmentId = environmentId + tempAliasId = aliasId } catch (e) { console.log(e) throw new Error('Failed to create a new environment') diff --git a/test/integration/tasks/create-new-environment.ts b/test/integration/tasks/create-new-environment.ts index e6fb6facd0..1b8c59aba4 100644 --- a/test/integration/tasks/create-new-environment.ts +++ b/test/integration/tasks/create-new-environment.ts @@ -23,6 +23,9 @@ export default async () => { 'test-base' )) as any + const aliasId = nanoid() + const alias = (await space.createEnvironmentAliasWithId(aliasId, { environment })) as any + let status = environment.sys.status.sys.id while (status !== 'ready') { @@ -33,5 +36,5 @@ export default async () => { console.log(`New "${environmentId}" environment is created`) - return environmentId + return { environmentId, aliasId: alias.sys.id } } diff --git a/test/integration/tasks/delete-new-environment-alias.ts b/test/integration/tasks/delete-new-environment-alias.ts new file mode 100644 index 0000000000..c904e06a30 --- /dev/null +++ b/test/integration/tasks/delete-new-environment-alias.ts @@ -0,0 +1,16 @@ +import { getCurrentSpace } from '../contentful-client' +import { printStepTitle } from '../utils' + +export default async (aliasId: string) => { + printStepTitle('Remove previously created environment alias') + + const space = await getCurrentSpace() + + const alias = await space.getEnvironmentAlias(aliasId) + + await alias.delete() + + console.log(`"${aliasId}" alias is deleted`) + + return true +} From 89645506b52cf8fc94d3b34a7d7efaad3ae43db3 Mon Sep 17 00:00:00 2001 From: John Whiles Date: Wed, 12 May 2021 17:11:54 +0200 Subject: [PATCH 2/9] feat: alias id test --- .../integration/entry-editor-aliased.spec.ts | 40 +++++++++++++++++++ test/cypress/utils/paths.ts | 9 +++++ test/integration/index.ts | 3 ++ test/integration/local.ts | 2 + .../tasks/create-configuration-files.ts | 3 ++ 5 files changed, 57 insertions(+) create mode 100644 test/cypress/integration/entry-editor-aliased.spec.ts diff --git a/test/cypress/integration/entry-editor-aliased.spec.ts b/test/cypress/integration/entry-editor-aliased.spec.ts new file mode 100644 index 0000000000..2c5f89c9f1 --- /dev/null +++ b/test/cypress/integration/entry-editor-aliased.spec.ts @@ -0,0 +1,40 @@ +import { entryAliased } from '../utils/paths' +import { role } from '../utils/role' + +const post = { + id: Cypress.env('entries').onValueChanged, + title: 'My post to test onValueChanged', + body: 'body value', +} + +const iframeSelector = '[data-test-id="cf-ui-workbench-content"] iframe' +const entryExtensionSelector = 'cf-ui-card' + +context(`Aliased Entry editor extension (${role})`, () => { + beforeEach(() => { + cy.setupBrowserStorage() + cy.visit(entryAliased(post.id)) + cy.findByTestId('workbench-title').should(($title) => { + expect($title).to.exist + }) + + cy.waitForIframeWithTestId(entryExtensionSelector) + cy.get('[data-test-id="cf-ui-workbench-content"]').within(() => { + cy.get('iframe').captureIFrameAs('extension') + }) + }) + + it('verifies that onValueChanged is called with the initial value and updates', () => { + const aliasId = Cypress.env('activeAliasId') + const spaceId = Cypress.env('activeSpaceId') + cy.intercept({ + method: 'GET', + url: `/spaces/${spaceId}/environments/*/content_types`, + }).as('contentTypesRequest') + + cy.getSdk(iframeSelector).then(async (sdk) => { + sdk.space.getContentTypes() + cy.wait('@contentTypesRequest').its('request.url').should('include', aliasId) + }) + }) +}) diff --git a/test/cypress/utils/paths.ts b/test/cypress/utils/paths.ts index 78b17b74fe..29f9234900 100644 --- a/test/cypress/utils/paths.ts +++ b/test/cypress/utils/paths.ts @@ -2,11 +2,16 @@ import { role } from './role' const activeSpaceId = Cypress.env('activeSpaceId') const activeEnvironmentId = Cypress.env('activeEnvironmentId') +const activeAliasId = Cypress.env('activeAliasId') export function entriesList() { return `/spaces/${activeSpaceId}/environments/${activeEnvironmentId}/entries` } +export function entriesListAliased() { + return `/spaces/${activeSpaceId}/environments/${activeAliasId}/entries` +} + export function pageExtensionMaster(extensionId: string) { return `/spaces/${activeSpaceId}/extensions/${extensionId}` } @@ -19,6 +24,10 @@ export function entry(id: string) { return `${entriesList()}/${id}` } +export function entryAliased(id: string) { + return `${entriesListAliased()}/${id}` +} + export function assetsList() { return `/spaces/${activeSpaceId}/environments/${activeEnvironmentId}/assets` } diff --git a/test/integration/index.ts b/test/integration/index.ts index fa77c921e4..9e65768f67 100644 --- a/test/integration/index.ts +++ b/test/integration/index.ts @@ -114,6 +114,7 @@ const run = async () => { environmentId: tempEnvironmentId, role: 'admin', entries: entryIds, + aliasId: tempAliasId, }) await runCypress('admin') @@ -124,6 +125,7 @@ const run = async () => { environmentId: tempEnvironmentId, role: 'editor', entries: entryIds, + aliasId: tempAliasId, }) await runCypress('editor', true) @@ -139,6 +141,7 @@ const run = async () => { environmentId: 'master-test', role: 'editorMasterOnly', entries: newEntryIds, + aliasId: '', }) await runCypress('editorMasterOnly', true) } diff --git a/test/integration/local.ts b/test/integration/local.ts index 6eb2fcba89..95929ba106 100644 --- a/test/integration/local.ts +++ b/test/integration/local.ts @@ -14,6 +14,7 @@ const config = { spaceId: process.env.CONTENTFUL_SPACE_ID!, baseUrl: process.env.CONTENTFUL_APP!, environmentId: process.env.CONTENTFUL_LOCAL_TESTING_ENV!, + aliasId: process.env.CONTENTFUL_LOCAL_TESTING_ALIAS!, testLocalSdk: process.env.TEST_LOCAL_SDK === 'true', } @@ -59,6 +60,7 @@ async function run() { managementToken: config.managementToken, spaceId: config.spaceId, environmentId: config.environmentId, + aliasId: config.aliasId, role: 'admin', entries: entryIds, }) diff --git a/test/integration/tasks/create-configuration-files.ts b/test/integration/tasks/create-configuration-files.ts index ebf231ba14..b1698195f2 100644 --- a/test/integration/tasks/create-configuration-files.ts +++ b/test/integration/tasks/create-configuration-files.ts @@ -6,18 +6,21 @@ export async function createCypressConfiguration({ environmentId, role, entries, + aliasId, }: { managementToken: string spaceId: string environmentId: string role: string entries: Record + aliasId: string }) { printStepTitle(`${role}: Creating Cypress configuration based on environment variables`) writeJSONFile(resolvePath('cypress.env.json'), { managementToken, activeSpaceId: spaceId, activeEnvironmentId: environmentId, + activeAliasId: aliasId, role, entries, }) From 3a3d2ff5329d66734bb9aeeb12534f1694e65b8d Mon Sep 17 00:00:00 2001 From: John Whiles Date: Wed, 12 May 2021 17:35:49 +0200 Subject: [PATCH 3/9] feat: try to make it fail --- test/cypress/integration/entry-editor-aliased.spec.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/cypress/integration/entry-editor-aliased.spec.ts b/test/cypress/integration/entry-editor-aliased.spec.ts index 2c5f89c9f1..dbf45a9d11 100644 --- a/test/cypress/integration/entry-editor-aliased.spec.ts +++ b/test/cypress/integration/entry-editor-aliased.spec.ts @@ -25,7 +25,7 @@ context(`Aliased Entry editor extension (${role})`, () => { }) it('verifies that onValueChanged is called with the initial value and updates', () => { - const aliasId = Cypress.env('activeAliasId') + const environmentId = Cypress.env('activeEnvironmentId') const spaceId = Cypress.env('activeSpaceId') cy.intercept({ method: 'GET', @@ -34,7 +34,7 @@ context(`Aliased Entry editor extension (${role})`, () => { cy.getSdk(iframeSelector).then(async (sdk) => { sdk.space.getContentTypes() - cy.wait('@contentTypesRequest').its('request.url').should('include', aliasId) + cy.wait('@contentTypesRequest').its('request.url').should('include', environmentId) }) }) }) From 78af366a4fc06c1d3091413a542fab3ba01152b6 Mon Sep 17 00:00:00 2001 From: John Whiles Date: Wed, 12 May 2021 17:42:36 +0200 Subject: [PATCH 4/9] Revert "feat: try to make it fail" This reverts commit 8a0539fab8c588b9b5e4f15e58f8c95b87368f12. --- test/cypress/integration/entry-editor-aliased.spec.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/cypress/integration/entry-editor-aliased.spec.ts b/test/cypress/integration/entry-editor-aliased.spec.ts index dbf45a9d11..2c5f89c9f1 100644 --- a/test/cypress/integration/entry-editor-aliased.spec.ts +++ b/test/cypress/integration/entry-editor-aliased.spec.ts @@ -25,7 +25,7 @@ context(`Aliased Entry editor extension (${role})`, () => { }) it('verifies that onValueChanged is called with the initial value and updates', () => { - const environmentId = Cypress.env('activeEnvironmentId') + const aliasId = Cypress.env('activeAliasId') const spaceId = Cypress.env('activeSpaceId') cy.intercept({ method: 'GET', @@ -34,7 +34,7 @@ context(`Aliased Entry editor extension (${role})`, () => { cy.getSdk(iframeSelector).then(async (sdk) => { sdk.space.getContentTypes() - cy.wait('@contentTypesRequest').its('request.url').should('include', environmentId) + cy.wait('@contentTypesRequest').its('request.url').should('include', aliasId) }) }) }) From 9d6f2de2c4bd3b195f5461ac9f9d99d24409a3b2 Mon Sep 17 00:00:00 2001 From: John Whiles Date: Fri, 14 May 2021 10:33:49 +0200 Subject: [PATCH 5/9] feat: wait till env is ready to make alias --- test/integration/tasks/create-new-environment.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/test/integration/tasks/create-new-environment.ts b/test/integration/tasks/create-new-environment.ts index 1b8c59aba4..d1539d7720 100644 --- a/test/integration/tasks/create-new-environment.ts +++ b/test/integration/tasks/create-new-environment.ts @@ -23,9 +23,6 @@ export default async () => { 'test-base' )) as any - const aliasId = nanoid() - const alias = (await space.createEnvironmentAliasWithId(aliasId, { environment })) as any - let status = environment.sys.status.sys.id while (status !== 'ready') { @@ -36,5 +33,10 @@ export default async () => { console.log(`New "${environmentId}" environment is created`) + const aliasId = nanoid() + const alias = (await space.createEnvironmentAliasWithId(aliasId, { environment })) as any + + console.log(`New "${aliasId}" alias is created`) + return { environmentId, aliasId: alias.sys.id } } From 1a7639c3764fa7894a0f72f0fc496a4ae367d2a7 Mon Sep 17 00:00:00 2001 From: John Whiles Date: Fri, 14 May 2021 10:45:58 +0200 Subject: [PATCH 6/9] Revert "Revert "feat: try to make it fail"" This reverts commit f2e13e004e74ad56f0f2383c2388d19afbe3cc35. --- test/cypress/integration/entry-editor-aliased.spec.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/cypress/integration/entry-editor-aliased.spec.ts b/test/cypress/integration/entry-editor-aliased.spec.ts index 2c5f89c9f1..dbf45a9d11 100644 --- a/test/cypress/integration/entry-editor-aliased.spec.ts +++ b/test/cypress/integration/entry-editor-aliased.spec.ts @@ -25,7 +25,7 @@ context(`Aliased Entry editor extension (${role})`, () => { }) it('verifies that onValueChanged is called with the initial value and updates', () => { - const aliasId = Cypress.env('activeAliasId') + const environmentId = Cypress.env('activeEnvironmentId') const spaceId = Cypress.env('activeSpaceId') cy.intercept({ method: 'GET', @@ -34,7 +34,7 @@ context(`Aliased Entry editor extension (${role})`, () => { cy.getSdk(iframeSelector).then(async (sdk) => { sdk.space.getContentTypes() - cy.wait('@contentTypesRequest').its('request.url').should('include', aliasId) + cy.wait('@contentTypesRequest').its('request.url').should('include', environmentId) }) }) }) From d098e27748d5b9527d2c12c26d27abca4719b93a Mon Sep 17 00:00:00 2001 From: John Whiles Date: Fri, 14 May 2021 10:57:38 +0200 Subject: [PATCH 7/9] Revert "Revert "Revert "feat: try to make it fail""" This reverts commit 6de184dd6f7b8b5680f39f5964f80c9d530834f5. --- test/cypress/integration/entry-editor-aliased.spec.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/cypress/integration/entry-editor-aliased.spec.ts b/test/cypress/integration/entry-editor-aliased.spec.ts index dbf45a9d11..2c5f89c9f1 100644 --- a/test/cypress/integration/entry-editor-aliased.spec.ts +++ b/test/cypress/integration/entry-editor-aliased.spec.ts @@ -25,7 +25,7 @@ context(`Aliased Entry editor extension (${role})`, () => { }) it('verifies that onValueChanged is called with the initial value and updates', () => { - const environmentId = Cypress.env('activeEnvironmentId') + const aliasId = Cypress.env('activeAliasId') const spaceId = Cypress.env('activeSpaceId') cy.intercept({ method: 'GET', @@ -34,7 +34,7 @@ context(`Aliased Entry editor extension (${role})`, () => { cy.getSdk(iframeSelector).then(async (sdk) => { sdk.space.getContentTypes() - cy.wait('@contentTypesRequest').its('request.url').should('include', environmentId) + cy.wait('@contentTypesRequest').its('request.url').should('include', aliasId) }) }) }) From 1daa26778e4ba3cbc529b358e9efebbdfe262845 Mon Sep 17 00:00:00 2001 From: John Whiles Date: Fri, 14 May 2021 11:26:57 +0200 Subject: [PATCH 8/9] feat: add extra assertion --- test/cypress/integration/entry-editor-aliased.spec.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/test/cypress/integration/entry-editor-aliased.spec.ts b/test/cypress/integration/entry-editor-aliased.spec.ts index 2c5f89c9f1..b24c6ce045 100644 --- a/test/cypress/integration/entry-editor-aliased.spec.ts +++ b/test/cypress/integration/entry-editor-aliased.spec.ts @@ -24,17 +24,23 @@ context(`Aliased Entry editor extension (${role})`, () => { }) }) - it('verifies that onValueChanged is called with the initial value and updates', () => { + it('verifies that API calls use the active Alias', () => { const aliasId = Cypress.env('activeAliasId') const spaceId = Cypress.env('activeSpaceId') cy.intercept({ method: 'GET', url: `/spaces/${spaceId}/environments/*/content_types`, }).as('contentTypesRequest') + cy.intercept({ + method: 'GET', + url: `spaces/${spaceId}/environments/*/entries/${post.id}/tasks`, + }).as('tasksRequest') cy.getSdk(iframeSelector).then(async (sdk) => { sdk.space.getContentTypes() cy.wait('@contentTypesRequest').its('request.url').should('include', aliasId) + sdk.entry.getTasks() + cy.wait('@tasksRequest').its('request.url').should('include', aliasId) }) }) }) From 7d7c2b13b20e0778b378a25d94e644e23b0f59c7 Mon Sep 17 00:00:00 2001 From: John Whiles Date: Fri, 14 May 2021 14:16:26 +0200 Subject: [PATCH 9/9] chore: pass alias id --- test/integration/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/integration/index.ts b/test/integration/index.ts index 9e65768f67..7917763d55 100644 --- a/test/integration/index.ts +++ b/test/integration/index.ts @@ -141,7 +141,7 @@ const run = async () => { environmentId: 'master-test', role: 'editorMasterOnly', entries: newEntryIds, - aliasId: '', + aliasId: tempAliasId, }) await runCypress('editorMasterOnly', true) }