Skip to content
This repository has been archived by the owner on Mar 3, 2023. It is now read-only.

Commit

Permalink
fix: testcafe running with correct api with setup
Browse files Browse the repository at this point in the history
  • Loading branch information
estherthetesteramido committed Jul 21, 2020
1 parent d9fb33f commit c8e3e6a
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions packages/scaffolding-cli/templates/test/testcafe/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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=""
```

Expand All @@ -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
Expand Down
24 changes: 24 additions & 0 deletions packages/scaffolding-cli/templates/test/testcafe/api/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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']")
Expand All @@ -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)
Expand Down

0 comments on commit c8e3e6a

Please sign in to comment.