Skip to content

Commit

Permalink
Change order of login test (#268)
Browse files Browse the repository at this point in the history
* ENGINEERS-1199 change order of login test

* ENGINEERS-1199 reduce code complexity
  • Loading branch information
thyarles authored Mar 12, 2023
1 parent 6242428 commit b5ff6c5
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 23 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
## [Unreleased]

### Changed

- [ENGINEERS-119] Changed the order of login test to be after app link

### Added

- Added CI in cypress vtex environment variables


### Changed

- Increasse delay for address type
Expand Down
49 changes: 27 additions & 22 deletions node/workspace.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,10 @@ exports.init = async (config) => {
logger.msgPad(NAME)

// Create namespace
let check = await toolbelt.changeWorkspace(NAME)
const check = await toolbelt.changeWorkspace(NAME)

if (!check) system.crash('Failed to change workspace')

// Test HTTPS access
let thisTry = 1
const LOGIN_PATH = '/_v/segment/admin-login/v1/login'
const AXIOS_CFG = {
url: `https://${NAME}--productusqa.myvtex.com${LOGIN_PATH}`,
method: 'get',
}

check = false
while (thisTry <= MAX_RETRIES && !check) {
logger.msgOk(`[try ${thisTry}/${MAX_RETRIES}] Access login page`)
thisTry++

// eslint-disable-next-line no-await-in-loop
const response = await http.request(AXIOS_CFG)

if (/2../.test(response?.status)) check = true
}

if (!check) system.crash('Access the workspace over HTTPS failed')

return system.tack(START)
}

Expand Down Expand Up @@ -155,12 +134,38 @@ exports.linkApp = async (config) => {

if (link.pid) storage.write(link.pid.toString(), APP_PID)

// Test login page after app link
this.checkLoginPage(config.workspace.name)

return { success: check, time: system.tack(START), subprocess: link }
}

return { success: true, time: system.tack(START), subprocess: null }
}

exports.checkLoginPage = async (workspace) => {
const LOGIN_PATH = '/_v/segment/admin-login/v1/login'
const AXIOS_CFG = {
url: `https://${workspace}--productusqa.myvtex.com${LOGIN_PATH}`,
method: 'get',
}

let thisTry = 1
let check = false

while (thisTry <= MAX_RETRIES && !check) {
logger.msgOk(`[try ${thisTry}/${MAX_RETRIES}] Checking login page`)

// eslint-disable-next-line no-await-in-loop
const response = await http.request(AXIOS_CFG)

if (/2../.test(response?.status)) check = true
thisTry++
}

if (!check) system.crash('Access to login page failed')
}

exports.teardown = async (config, linkSucceed = true) => {
const START = system.tick()
const { workspace } = config
Expand Down

0 comments on commit b5ff6c5

Please sign in to comment.