Skip to content

Commit

Permalink
Merge pull request #4635 from QuantiModo/feature/getApiHost
Browse files Browse the repository at this point in the history
getApiHost
  • Loading branch information
mikepsinn authored Apr 21, 2022
2 parents 7bccb4d + d8ca33d commit 1ffb3fd
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 20 deletions.
1 change: 1 addition & 0 deletions .idea/dictionaries/m.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions cypress/integration/api_connectors_spec.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// load type definitions that come with Cypress module
/// <reference types="cypress" />
describe('Mobile Connectors', function () {
let API_HOST = Cypress.env('API_HOST')
let apiUrl = `https://${API_HOST}`
let selectors = {
fitbit: {
username: '.pa0 > #loginForm > .row > #email-input > #ember644',
Expand Down Expand Up @@ -31,7 +29,6 @@ describe('Mobile Connectors', function () {
},
}
function goToMobileConnectPage () {
cy.log(`Using apiUrl: ${apiUrl}`)
cy.visitApi(`/api/v1/connect/mobile?log=testuser&pwd=testing123`)
//cy.checkForBrokenImages() // Keeps falsely failing
}
Expand Down
2 changes: 1 addition & 1 deletion cypress/integration/embeddable_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ describe('Embeddable', function () {
'firstSearchResultCogButton': '#searchResultList > div:nth-child(1) > div > div.col-md-4.controls.text-center > span.fa.fa-cog',
'firstSearchResultPlusButton': '#searchResultList > div:nth-child(1) > div > div.col-md-4.controls.text-center > span.fa.fa-plus',
}
let API_HOST = Cypress.env('API_HOST')
let API_HOST = cy.getApiHost()
let apiUrl = `https://${API_HOST}`
let embedUrl = 'https://angularjs-embeddable.quantimo.do/?plugin=search-relationships'

Expand Down
17 changes: 9 additions & 8 deletions cypress/integration/ionic_authentication_spec.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable cypress/no-unnecessary-waiting,cypress/no-assigning-return-values */
// load type definitions that come with Cypress module
let selectors = {
usernameInput: '#username-group > input',
Expand All @@ -15,13 +16,13 @@ describe('Authentication', function () {
let appDisplayName = 'OAuth test client'
let testUserName = 'testuser'
let testUserPassword = 'testing123'
let API_HOST = Cypress.env('API_HOST')
if (!API_HOST) { API_HOST = 'local.quantimo.do' }
let authorizePath = `/api/oauth2/authorize?` +
let API_HOST = cy.getApiHost()
// noinspection SpellCheckingInspection
let authorizePath = `/api/oauth2/authorize?` +
'response_type=code&' +
'scope=readmeasurements%20writemeasurements&' +
'state=testabcd&'
function goToIntroPage (API_HOST, clientId) {
function goToIntroPage (clientId) {
let url = `/#/app/intro?clientId=${clientId}&logout=true`
cy.visitIonicAndSetApiUrl(url)
cy.url().should('contain', 'intro')
Expand All @@ -35,7 +36,7 @@ describe('Authentication', function () {
it.skip('Logs into and out of an OAuth test client app', function () {
let clientId = 'oauth_test_client'
let appDisplayName = 'OAuth test client'
goToIntroPage(API_HOST, clientId)
goToIntroPage(clientId)
cy.disableSpeechAndSkipIntro()
cy.get('#circle-page-title').should('contain', appDisplayName)
cy.get('#skipButtonIntro').click({ force: true })
Expand Down Expand Up @@ -72,7 +73,6 @@ describe('Authentication', function () {
cy.allowUncaughtException(null)
})
it.skip('Logs in and out with username and password', function () {
if (!Cypress.env('API_HOST')) { cy.log(`Cypress.env('API_HOST') is empty so falling back to ${API_HOST}`) }
cy.goToApiLoginPageAndLogin(testUserName, testUserPassword)
cy.disableSpeechAndSkipIntro()
cy.log('testuser already has reminders so skipping onboarding ang going to inbox')
Expand All @@ -86,7 +86,7 @@ describe('Authentication', function () {
let appDisplayName = 'OAuth test client'
let baseUrl = Cypress.config('baseUrl')
cy.log(`baseUrl is ${baseUrl}`)
goToIntroPage(API_HOST, clientId)
goToIntroPage(clientId)
cy.disableSpeechAndSkipIntro()
cy.get('#signUpButton').click({ force: true })
cy.enterNewUserCredentials(false)
Expand Down Expand Up @@ -122,7 +122,8 @@ describe('Authentication', function () {
cy.get('#email').type('frfdorf_putnamescu_1454115735@tfbnw.net', { force: true })
cy.get('#pass').click({ force: true })
cy.get('#pass').type(Cypress.env('FACEBOOK_TEST_PASSWORD'), { force: true })
cy.get('#loginbutton').click({ force: true })
// noinspection SpellCheckingInspection
cy.get('#loginbutton').click({ force: true })
cy.get('#skipButtonIntro').click({ force: true })
cy.log('Wont be there if user has not upgraded')
cy.get('#navBarAvatar').click({ force: true })
Expand Down
3 changes: 2 additions & 1 deletion cypress/integration/ionic_onboarding_spec.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable cypress/no-unnecessary-waiting */
// load type definitions that come with Cypress module
/// <reference types="cypress" />
describe('Onboarding', function () {
Expand Down Expand Up @@ -36,7 +37,7 @@ describe('Onboarding', function () {
.type('62025', { force: true })
cy.get('body > div.popup-container.popup-showing.active > div > div.popup-buttons > button.button.ng-binding.button-positive')
.click({ force: true })
cy.get("#circle-page-title").contains("Import");
cy.get("#circle-page-title").contains("Import")
cy.toastContains("Connecting")
skip()
cy.get('#goToInboxButton').click({ force: true })
Expand Down
21 changes: 16 additions & 5 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable cypress/no-unnecessary-waiting,cypress/no-assigning-return-values */
// ***********************************************
// This example commands.js shows you how to
// create various custom commands and overwrite
Expand Down Expand Up @@ -27,7 +28,6 @@ let logLevel = Cypress.env('LOG_LEVEL') || 'info'
const PERMANENT_TEST_USER_ACCESS_TOKEN_FOR_18535 = '42ff4170172357b7312bb127fb58d5ea464943c1'
const ACCESS_TOKEN_TO_GET_OR_CREATE_REFERRER_SPECIFIC_USER = 'test-token'
let accessToken = Cypress.env('ACCESS_TOKEN') || PERMANENT_TEST_USER_ACCESS_TOKEN_FOR_18535 || ACCESS_TOKEN_TO_GET_OR_CREATE_REFERRER_SPECIFIC_USER
let API_HOST = Cypress.env('API_HOST') // API_HOST must be a quantimo.do domain so cypress can clear cookies
let baseUrl = Cypress.config('baseUrl')
let testUserName = 'testuser'
let testUserPassword = 'testing123'
Expand All @@ -45,6 +45,18 @@ cy.getOAuthAppUrl = function (){
cy.oauthAppIsHTTPS = function (){
return cy.getOAuthAppUrl().indexOf("https://") === 0
}
cy.getApiHost = function () {
cy.log(`=== getApiHost ===`)
const host = Cypress.env('API_HOST')
const configInstructions = "cypress open --config-file cypress/config/cypress.development.json"
if(!host || host === 'undefined'){
throw 'Please set API_HOST in the cypress/configs folder and provide the config like\n\t' + configInstructions
}
if(host.indexOf('quantimo.do') === -1){
throw "API_HOST must be a quantimo.do domain so cypress can clear cookies but is " + host + ". API_HOST is defined in the cypress/configs directory"
}
return host
}
Cypress.Commands.add('goToApiLoginPageAndLogin', (email = testUserName, password = testUserPassword) => {
cy.log(`=== goToApiLoginPageAndLogin as ${email} ===`)
cy.visitApi(`/api/v2/auth/login?logout=1`)
Expand Down Expand Up @@ -90,7 +102,7 @@ Cypress.Commands.add('loginWithAccessTokenIfNecessary', (path = '/#/app/reminder
}
})
Cypress.Commands.add('visitIonicAndSetApiUrl', (path = '/#/app/reminders-inbox') => {
path = UpdateQueryString('apiUrl', API_HOST, path)
path = UpdateQueryString('apiUrl', cy.getApiHost(), path)
path = UpdateQueryString('logLevel', logLevel, path)
if(Cypress.env('LOGROCKET')){ path = UpdateQueryString('logrocket', 1, path) }
let url = path
Expand All @@ -103,16 +115,15 @@ Cypress.Commands.add('visitWithApiUrlParam', (url, options = {}) => {
if(!options.qs){
options.qs = {}
}
options.qs.apiUrl = API_HOST
options.qs.apiUrl = cy.getApiHost()
cy.visit(url, options)
})
// noinspection JSUnusedLocalSymbols
Cypress.Commands.add('visitApi', (url, options = {}) => {
cy.log(`=== visitApi at ${url} ===`)
if(!API_HOST || API_HOST === 'undefined'){ throw 'Please set API_HOST env!' }
if(!options.qs){ options.qs = {} }
options.qs.XDEBUG_SESSION_START = 'PHPSTORM'
cy.visit("https://" + API_HOST + url, options)
cy.visit("https://" + cy.getApiHost() + url, options)
})
Cypress.Commands.add('containsCaseInsensitive', (selector, content) => {
function caseInsensitive(str){
Expand Down
1 change: 1 addition & 0 deletions cypress/support/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@ declare namespace Cypress {
toastContains(str: string): Chainable<Element>
getOAuthAppUrl(): string
oauthAppIsHTTPS(): boolean
getApiHost(): string
}
}
8 changes: 6 additions & 2 deletions cypress/support/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,22 @@ Cypress.on('uncaught:exception', (err, runnable) => {
expect(err.message).to.include(expectedErrorMessage)
return false
}
// eslint-disable-next-line no-debugger
debugger
cy.log(`Uncaught exception: ${err.message}`)
})
beforeEach(function(){ // runs before each test in the block
let url = Cypress.config('baseUrl')
if(!url){
// eslint-disable-next-line no-debugger
debugger
throw Error("baseUrl not set!")
}
cy.log(`baseUrl is ${url}`)
cy.log(`API_HOST is ${Cypress.env('API_HOST')}`)
cy.log(`API_HOST is ` + cy.getApiHost())
})
import addContext from 'mochawesome/addContext'
// noinspection SpellCheckingInspection
Cypress.on('test:after:run', (test, runnable) => {
// https://medium.com/@nottyo/generate-a-beautiful-test-report-from-running-tests-on-cypress-io-371c00d7865a
if(test.state === 'failed'){
Expand Down Expand Up @@ -63,7 +67,7 @@ function truncate(str, length, ending) {
}
Cypress.on('window:before:load', (win) => {
if(allowLogging && Cypress.env('ELECTRON_ENABLE_LOGGING')) {
win.console.log = (...args) => { // Needs ELECTRON_ENABLE_LOGGING=1
win.console.log = (...args) => { // Needs ELECTRON_ENABLE_LOGGING=1
try {
let str = JSON.stringify(args)
if (str.indexOf("[bugsnag] Loaded") !== -1) {
Expand Down

0 comments on commit 1ffb3fd

Please sign in to comment.