-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IA-4620] invalidate cookies on sign out (#4494)
Co-authored-by: jdcanas <jcanas@broadinstitute.com>
- Loading branch information
Showing
5 changed files
with
74 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { cookieProvider } from 'src/components/CookieProvider'; | ||
import { Ajax } from 'src/libs/ajax'; | ||
import { RuntimesAjaxContract } from 'src/libs/ajax/leonardo/Runtimes'; | ||
import { asMockedFn } from 'src/testing/test-utils'; | ||
|
||
jest.mock('src/libs/ajax'); | ||
|
||
/** | ||
* local test utility - mocks the Ajax super-object and the subset of needed multi-contracts it | ||
* returns with as much type-safety as possible. | ||
* | ||
* @return collection of key contract sub-objects for easy | ||
* mock overrides and/or method spying/assertions | ||
*/ | ||
type AjaxContract = ReturnType<typeof Ajax>; | ||
type RuntimesNeeds = Pick<RuntimesAjaxContract, 'invalidateCookie'>; | ||
interface AjaxMockNeeds { | ||
Runtimes: RuntimesNeeds; | ||
} | ||
|
||
const mockAjaxNeeds = (): AjaxMockNeeds => { | ||
const partialRuntimes: RuntimesNeeds = { | ||
invalidateCookie: jest.fn(), | ||
}; | ||
const mockRuntimes = partialRuntimes as RuntimesAjaxContract; | ||
|
||
asMockedFn(Ajax).mockReturnValue({ Runtimes: mockRuntimes } as AjaxContract); | ||
|
||
return { | ||
Runtimes: partialRuntimes, | ||
}; | ||
}; | ||
describe('CookieProvider', () => { | ||
it('calls the leo endpoint on invalidateCookie', async () => { | ||
const ajaxMock = mockAjaxNeeds(); | ||
|
||
// Act | ||
await cookieProvider.invalidateCookies(); | ||
|
||
// Assert | ||
expect(Ajax).toBeCalledTimes(1); | ||
expect(ajaxMock.Runtimes.invalidateCookie).toBeCalledTimes(1); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Ajax } from 'src/libs/ajax'; | ||
import { AbortOption } from 'src/libs/ajax/data-provider-common'; | ||
import { azureCookieReadyStore, cookieReadyStore } from 'src/libs/state'; | ||
|
||
export interface CookieProvider { | ||
invalidateCookies: (options?: AbortOption) => Promise<void>; | ||
} | ||
|
||
export const cookieProvider: CookieProvider = { | ||
invalidateCookies: async (options: AbortOption = {}) => { | ||
const { signal } = options; | ||
// TODO: call azure invalidate cookie once endpoint exists, https://broadworkbench.atlassian.net/browse/IA-3498 | ||
await Ajax(signal).Runtimes.invalidateCookie(); | ||
|
||
cookieReadyStore.reset(); | ||
azureCookieReadyStore.reset(); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters