diff --git a/cypress/component/SignIn/sign_in_button.spec.js b/cypress/component/SignIn/sign_in_button.spec.js index d492b334d..d24c7193d 100644 --- a/cypress/component/SignIn/sign_in_button.spec.js +++ b/cypress/component/SignIn/sign_in_button.spec.js @@ -10,12 +10,18 @@ import {Metrics} from '../../../src/libs/ajax/Metrics'; import {StackdriverReporter} from '../../../src/libs/stackdriverReporter'; import {ToS} from '../../../src/libs/ajax/ToS'; import {mockOidcUser} from '../Auth/mockOidcUser'; - const signInText = 'Sign In'; const duosUser = { displayName: 'display name', email: 'test@user.com', + isAdmin: true, + isAlumni: false, + isChairPerson: false, + isDataSubmitter: false, + isMember: false, + isResearcher: false, + isSigningOfficial: false, roles: [{ name: 'Admin' }] @@ -33,6 +39,11 @@ const notAcceptedUserStatus = Object.assign({}, userStatus, {'tosAccepted': fals describe('Sign In: Component Loads', function () { + // Intercept configuration calls + beforeEach(() => { + cy.initApplicationConfig(); + }); + it('Sign In Button Loads', function () { cy.viewport(600, 300); mount(); @@ -42,14 +53,15 @@ describe('Sign In: Component Loads', function () { it('Sign In: On Success', function () { cy.viewport(600, 300); cy.stub(Auth, 'signIn').returns(Promise.resolve(mockOidcUser)); - cy.stub(User, 'getMe').returns(duosUser); + cy.intercept({method: 'GET', url: '**/api/user/me'}, {statusCode: 200, body: duosUser}).as('getMe'); cy.stub(StackdriverReporter, 'report'); cy.stub(Metrics, 'identify'); cy.stub(Metrics, 'syncProfile'); cy.stub(Metrics, 'captureEvent'); cy.stub(ToS, 'getStatus').returns(userStatus); mount(); - cy.get('button').click().then(() => { + cy.get('button').click(); + cy.wait('@getMe').then(() => { expect(Storage.getCurrentUser()).to.deep.equal(duosUser); expect(Storage.getAnonymousId()).to.not.be.null; expect(StackdriverReporter.report).to.not.be.called; @@ -63,14 +75,15 @@ describe('Sign In: Component Loads', function () { const bareUser = {email: 'test@user.com'}; cy.viewport(600, 300); cy.stub(Auth, 'signIn').returns(Promise.resolve(mockOidcUser)); - cy.stub(User, 'getMe').returns(bareUser); + cy.intercept({method: 'GET', url: '**/api/user/me'}, {statusCode: 200, body: bareUser}).as('getMe'); cy.stub(StackdriverReporter, 'report'); cy.stub(Metrics, 'identify'); cy.stub(Metrics, 'syncProfile'); cy.stub(Metrics, 'captureEvent'); cy.stub(ToS, 'getStatus').returns(userStatus); mount(); - cy.get('button').click().then(() => { + cy.get('button').click(); + cy.wait('@getMe').then(() => { expect(StackdriverReporter.report).to.be.called; }); }); @@ -78,14 +91,15 @@ describe('Sign In: Component Loads', function () { it('Sign In: Redirects to ToS if not accepted', function () { cy.viewport(600, 300); cy.stub(Auth, 'signIn').returns(Promise.resolve(mockOidcUser)); - cy.stub(User, 'getMe').returns(duosUser); + cy.intercept({method: 'GET', url: '**/api/user/me'}, {statusCode: 200, body: duosUser}).as('getMe'); cy.stub(ToS, 'getStatus').returns(notAcceptedUserStatus); cy.stub(Metrics, 'identify'); cy.stub(Metrics, 'syncProfile'); cy.stub(Metrics, 'captureEvent'); let history = []; mount(); - cy.get('button').click().then(() => { + cy.get('button').click(); + cy.wait('@getMe').then(() => { expect(history).to.not.be.empty; expect(history[0].includes('tos_acceptance')).to.be.true; }); @@ -96,15 +110,15 @@ describe('Sign In: Component Loads', function () { cy.stub(Auth, 'signIn').returns(Promise.resolve(mockOidcUser)); // Simulate user not found cy.stub(User, 'getMe').throws(); - cy.stub(User, 'registerUser').returns(duosUser); + cy.intercept({method: 'POST', url: '**/api/user'}, {statusCode: 200, body: duosUser}).as('registerUser'); cy.stub(ToS, 'getStatus').returns(notAcceptedUserStatus); cy.stub(Metrics, 'identify'); cy.stub(Metrics, 'syncProfile'); cy.stub(Metrics, 'captureEvent'); let history = []; mount(); - cy.get('button').click().then(() => { - expect(User.registerUser).to.be.called; + cy.get('button').click(); + cy.wait('@registerUser').then(() => { expect(history).to.not.be.empty; expect(history[0].includes('tos_acceptance')).to.be.true; }); diff --git a/cypress/support/commands.js b/cypress/support/commands.js index d19d7fefc..c256a0e7a 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -34,4 +34,26 @@ Cypress.Commands.add('auth', async (roleName) => { const url = Cypress.env('baseUrl'); await client.request({ url }); return client.credentials; -}); \ No newline at end of file +}); + +Cypress.Commands.add('initApplicationConfig', () => { + cy.intercept({ + method: 'GET', + url: '/config.json', + hostname: 'localhost', + }, { + 'env': 'ci', + 'hash': '', + 'tag': '', + 'bardApiUrl': '', + 'apiUrl': '', + 'ontologyApiUrl': '', + 'terraUrl': '', + 'tdrApiUrl': '', + 'errorApiKey': '', + 'profileUrl': '', + 'nihUrl': '', + 'gaId': '', + 'features': {} + }); +}); diff --git a/src/components/SignInButton.tsx b/src/components/SignInButton.tsx index 8e762a8a8..6de3cd37f 100644 --- a/src/components/SignInButton.tsx +++ b/src/components/SignInButton.tsx @@ -109,9 +109,12 @@ export const SignInButton = (props: SignInButtonProps) => { const syncSignInOrRegistrationEvent = async (event: String) => { Storage.setAnonymousId(); - await Metrics.identify(Storage.getAnonymousId()); - await Metrics.syncProfile(); - await Metrics.captureEvent(event); + // noinspection ES6MissingAwait + Metrics.identify(Storage.getAnonymousId()); + // noinspection ES6MissingAwait + Metrics.syncProfile(); + // noinspection ES6MissingAwait + Metrics.captureEvent(event); }; const errorStreamToString = async (error: HttpError) => { diff --git a/src/libs/ajax/DAR.js b/src/libs/ajax/DAR.js index 274257bdb..4c65c0cf6 100644 --- a/src/libs/ajax/DAR.js +++ b/src/libs/ajax/DAR.js @@ -19,7 +19,8 @@ export const DAR = { //v2, v3 Draft DAR Update updateDarDraft: async (dar, referenceId) => { - await Metrics.captureEvent(eventList.dar, {'action': 'update'}); + // noinspection ES6MissingAwait + Metrics.captureEvent(eventList.dar, {'action': 'update'}); const url = DAAUtils.isEnabled() ? `${await getApiUrl()}/api/dar/v3/draft/${referenceId}` : `${await getApiUrl()}/api/dar/v2/draft/${referenceId}`; @@ -29,7 +30,8 @@ export const DAR = { //v2, v3 Draft DAR Creation postDarDraft: async (dar) => { - await Metrics.captureEvent(eventList.dar, {'action': 'draft'}); + // noinspection ES6MissingAwait + Metrics.captureEvent(eventList.dar, {'action': 'draft'}); const url = DAAUtils.isEnabled() ? `${await getApiUrl()}/api/dar/v3/draft` : `${await getApiUrl()}/api/dar/v2/draft`; @@ -46,7 +48,8 @@ export const DAR = { //v2, v3 DAR Creation postDar: async (dar) => { - await Metrics.captureEvent(eventList.dar, {'action': 'submit'}); + // noinspection ES6MissingAwait + Metrics.captureEvent(eventList.dar, {'action': 'submit'}); const filteredDar = fp.omit(['createDate', 'sortDate', 'data_access_request_id'])(dar); const url = DAAUtils.isEnabled() ? `${await getApiUrl()}/api/dar/v3` : diff --git a/src/pages/DatasetSearch.jsx b/src/pages/DatasetSearch.jsx index df86eeee6..f5cd1073a 100644 --- a/src/pages/DatasetSearch.jsx +++ b/src/pages/DatasetSearch.jsx @@ -275,9 +275,10 @@ export const DatasetSearch = (props) => { useEffect(() => { const init = async () => { + // noinspection ES6MissingAwait key === '/datalibrary' ? - await Metrics.captureEvent(eventList.dataLibrary) : - await Metrics.captureEvent(eventList.dataLibrary, {'brand': key.replaceAll('/', '').toLowerCase()}); + Metrics.captureEvent(eventList.dataLibrary) : + Metrics.captureEvent(eventList.dataLibrary, {'brand': key.replaceAll('/', '').toLowerCase()}); }; init(); }, [key]); diff --git a/src/pages/dar_application/DataAccessRequestApplication.jsx b/src/pages/dar_application/DataAccessRequestApplication.jsx index 1ac2d01e3..f88f360dd 100644 --- a/src/pages/dar_application/DataAccessRequestApplication.jsx +++ b/src/pages/dar_application/DataAccessRequestApplication.jsx @@ -375,7 +375,8 @@ const DataAccessRequestApplication = (props) => { if (isInvalidForm) { scrollToFormErrors(validation, eraCommonsIdValid, hasLibraryCard); } else { - await Metrics.captureEvent(eventList.dar, {'action': 'attest'}); + // noinspection ES6MissingAwait + Metrics.captureEvent(eventList.dar, {'action': 'attest'}); setIsAttested(true); addDucAddendumTab(); await goToDucAddendum();