Skip to content

Commit

Permalink
Fix few cypress tests
Browse files Browse the repository at this point in the history
  • Loading branch information
louptheron committed Oct 17, 2024
1 parent 3971f30 commit 78af39f
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion frontend/cypress/e2e/nav_monitorfish.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ context('Light MonitorFish', () => {
cy.get('*[data-cy="missions-menu-box"]').should('not.exist')

// Given
cy.loadPath('/ext#@-188008.06,6245230.27,8.70')
cy.loadPath('/#@-188008.06,6245230.27,8.70')

// Then
// No missions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ context('Side Window > Mission Form > Main Form', () => {
).as('getMissionStubbed')
editSideWindowMissionListMissionWithId(6, SeafrontGroup.MED)
cy.wait(200)
cy.get('@getMissionStubbed.all').should('have.length', 3)
cy.get('@getMissionStubbed.all').should('have.length', 2)
cy.get('*[data-cy="mission-form-error"]').contains("Nous n'avons pas pu récupérer la mission")
})

Expand Down
1 change: 0 additions & 1 deletion frontend/cypress/e2e/side_window/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export const openSideWindowAsUser = () => {
if (document.querySelector('[data-cy="first-loader"]')) {
cy.getDataCy('first-loader').should('not.be.visible')
}
cy.clickButton(SideWindowMenuLabel.PRIOR_NOTIFICATION_LIST)
}

export const openSideWindowAsSuperUser = () => {
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ export const monitorenvApi = createApi({
// =============================================================================
// Monitorfish API

const AUTHORIZATION_HEADER = 'authorization'
const CORRELATION_HEADER = 'X-Correlation-Id'
export const AUTHORIZATION_HEADER = 'authorization'
export const CORRELATION_HEADER = 'X-Correlation-Id'
const { IS_OIDC_ENABLED } = getOIDCConfig()

const setAuthorizationHeader = async headers => {
Expand Down
10 changes: 7 additions & 3 deletions frontend/src/auth/hooks/useAuthRequestHeaders.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { AUTHORIZATION_HEADER, CORRELATION_HEADER } from '@api/api'
import { isCypress } from '@utils/isCypress'
import { sha256 } from '@utils/sha256'
import { getOIDCConfig } from 'auth/getOIDCConfig'
import { getOIDCUser } from 'auth/getOIDCUser'
import { useCallback, useEffect, useState } from 'react'

const { IS_OIDC_ENABLED } = getOIDCConfig()

const IS_CYPRESS = isCypress()

/**
* Hook to get API request headers required for OIDC authentication.
*
Expand All @@ -19,7 +23,7 @@ export function useAuthRequestHeaders(): Record<string, string> | undefined {
const token = user?.access_token

const updateHeaders = useCallback(async (nextToken: string | undefined) => {
if (!IS_OIDC_ENABLED) {
if (!IS_OIDC_ENABLED || IS_CYPRESS) {
setHeaders({})

return
Expand All @@ -31,8 +35,8 @@ export function useAuthRequestHeaders(): Record<string, string> | undefined {
}

const nextHeaders = {
authorization: `Bearer ${nextToken}`,
...(crypto?.subtle ? { 'x-correlation-id': await sha256(nextToken) } : {})
[AUTHORIZATION_HEADER]: `Bearer ${nextToken}`,
...(crypto?.subtle ? { [CORRELATION_HEADER]: await sha256(nextToken) } : {})
}

setHeaders(nextHeaders)
Expand Down

0 comments on commit 78af39f

Please sign in to comment.