diff --git a/packages/scaffolding-cli/templates/build/azDevops/azure/azure-pipeline-post-deploy-testcafe.yml b/packages/scaffolding-cli/templates/build/azDevops/azure/azure-pipeline-post-deploy-testcafe.yml index 3b0e7576c..f25eefd4d 100644 --- a/packages/scaffolding-cli/templates/build/azDevops/azure/azure-pipeline-post-deploy-testcafe.yml +++ b/packages/scaffolding-cli/templates/build/azDevops/azure/azure-pipeline-post-deploy-testcafe.yml @@ -65,7 +65,7 @@ steps: parameters: env_vars: APP_BASE_URL: $(base_url) - MENU_API_URL: 'http://dev.amidostacks.com/api/menu' + MENU_API_URL: 'https://dev-netcore-api.nonprod.amidostacks.com/api/menu' APP_BASE_PATH: $(base_path) NODE_ENV: production working_directory: $(working_directory) diff --git a/packages/scaffolding-cli/templates/test/testcafe/README.md b/packages/scaffolding-cli/templates/test/testcafe/README.md index b59d0d1d5..15e138444 100644 --- a/packages/scaffolding-cli/templates/test/testcafe/README.md +++ b/packages/scaffolding-cli/templates/test/testcafe/README.md @@ -67,7 +67,7 @@ For Linux/Mac (replacing `export` with `set` for Windows): export NODE_ENV=development \ export PORT=3000 \ export APP_BASE_URL=http://localhost \ -export MENU_API_URL=https://dev.amidostacks.com/api/menu \ +export MENU_API_URL=https://dev-netcore-api.nonprod.amidostacks.com/api/menu \ export APP_BASE_PATH="" ``` @@ -77,7 +77,7 @@ Alternately, an example of your environment variable configuration for running a export NODE_ENV=production \ export APP_BASE_URL=https://dev-app.nonprod.amidostacks.com \ export APP_BASE_PATH=/web/stacks \ -export MENU_API_URL=https://dev.amidostacks.com/api/menu +export MENU_API_URL=https://dev-netcore-api.nonprod.amidostacks.com/api/menu ``` ## Running tests in Docker diff --git a/packages/scaffolding-cli/templates/test/testcafe/api/menu.ts b/packages/scaffolding-cli/templates/test/testcafe/api/menu.ts index d765a0827..071831404 100644 --- a/packages/scaffolding-cli/templates/test/testcafe/api/menu.ts +++ b/packages/scaffolding-cli/templates/test/testcafe/api/menu.ts @@ -30,3 +30,27 @@ export const deleteMenu = (menuId: string) => { .catch(() => reject(new Error())) }) } + +export const addMenu = (menuName: string) => { + const MENU_API_ENDPOINT = `${environmentVariables.MENU_API_URL}/${API_VERSION}/menu` + return new Promise((resolve, reject) => { + axios + .post(`${MENU_API_ENDPOINT}`, { + name: menuName, + description: "Testcafe beforeHook", + enabled: true, + tenantId: "d290f1ee-6c54-4b01-90e6-d701748f0851", + }) + .then(response => { + const {data, status} = response + if (status >= 200) { + console.log(`Successfully added menuName=${menuName} with status=${response.status}`) + resolve(data.id) + } else { + console.log(`Could not add menuName=${menuName}`) + reject(data) + } + }) + .catch(() => reject(new Error())) + }) +} diff --git a/packages/scaffolding-cli/templates/test/testcafe/fixtures/get-menu.test.cf.ts b/packages/scaffolding-cli/templates/test/testcafe/fixtures/get-menu.test.cf.ts index 2ad25de3a..4a0ef198c 100644 --- a/packages/scaffolding-cli/templates/test/testcafe/fixtures/get-menu.test.cf.ts +++ b/packages/scaffolding-cli/templates/test/testcafe/fixtures/get-menu.test.cf.ts @@ -12,7 +12,7 @@ test( testName, fn(t) ): */ import {Selector} from "testcafe" -import {deleteMenu} from "../api/menu" +import {deleteMenu, addMenu} from "../api/menu" import {getAppUrl} from "../environment-variables" const url = getAppUrl().APP_URL @@ -21,9 +21,23 @@ console.log(`Current url: ${url}`) fixture`home`.page`${url}` const menuList = Selector("[data-testid=results]") -test("Returns the Latest menus component", async t => { - await t.expect(menuList.innerText).contains("Breakfast Menu") -}) + +const testMenuName = "Automated Yumido Menu" + +test + .before(async (t: any) => { + t.ctx.menuId = await addMenu(testMenuName) + console.log(`Created menuId: ${t.ctx.menuId}`) + }) + ("Returns the Latest menus component", async t => { + await t + .expect(menuList.exists) + .ok() + }) + .after(async (t: any) => { + const response = await deleteMenu(t.ctx.menuId) + console.log(`deleteMenu response: ${response}`) + }) test("Create a new Yumido menu", async t => { const createMenu = Selector("[data-testid='create_button']") @@ -33,13 +47,12 @@ test("Create a new Yumido menu", async t => { const saveMenu = Selector(":nth-child(2) > .MuiButtonBase-root") const snackBarMessage = Selector("#snackbar-message-id").innerText - const testMenuName = "Automated Yumido Menu" - await t .expect(menuList.innerText) .notContains(testMenuName) .click(createMenu) - .expect(menuName.exists).ok() + .expect(menuName.exists) + .ok() .typeText(menuName, testMenuName) .typeText(menuDesc, "A delicous array of funky FE flavours") .click(menuActive)