-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixup! ✨(frontend) add crisp chatbot
- Loading branch information
Showing
2 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
src/frontend/apps/impress/src/core/auth/__tests__/useAuthStore.test.tsx
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,56 @@ | ||
import { waitFor } from '@testing-library/react'; | ||
import { Crisp } from 'crisp-sdk-web'; | ||
import fetchMock from 'fetch-mock'; | ||
|
||
import { useAuthStore } from '../useAuthStore'; | ||
|
||
jest.mock('crisp-sdk-web', () => ({ | ||
...jest.requireActual('crisp-sdk-web'), | ||
Crisp: { | ||
setTokenId: jest.fn(), | ||
user: { | ||
setEmail: jest.fn(), | ||
}, | ||
session: { | ||
reset: jest.fn(), | ||
}, | ||
}, | ||
})); | ||
|
||
describe('useAuthStore', () => { | ||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
fetchMock.restore(); | ||
}); | ||
|
||
it('checks initialize support session when initAuth', async () => { | ||
window.$crisp = true; | ||
fetchMock.mock('end:users/me/', { | ||
id: '123456', | ||
email: '[email protected]', | ||
}); | ||
|
||
useAuthStore.getState().initAuth(); | ||
|
||
await waitFor(() => { | ||
expect(Crisp.setTokenId).toHaveBeenCalledWith('123456'); | ||
}); | ||
|
||
expect(Crisp.user.setEmail).toHaveBeenCalledWith('[email protected]'); | ||
}); | ||
|
||
it('checks support session is terminated when logout', () => { | ||
window.$crisp = true; | ||
Object.defineProperty(window, 'location', { | ||
value: { | ||
...window.location, | ||
replace: jest.fn(), | ||
}, | ||
writable: true, | ||
}); | ||
|
||
useAuthStore.getState().logout(); | ||
|
||
expect(Crisp.session.reset).toHaveBeenCalled(); | ||
}); | ||
}); |
30 changes: 30 additions & 0 deletions
30
src/frontend/apps/impress/src/hook/__tests__/useSupport.test.tsx
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,30 @@ | ||
import { renderHook } from '@testing-library/react'; | ||
import { Crisp } from 'crisp-sdk-web'; | ||
|
||
import { useSupport } from '../useSupport'; | ||
|
||
jest.mock('crisp-sdk-web', () => ({ | ||
...jest.requireActual('crisp-sdk-web'), | ||
Crisp: { | ||
configure: jest.fn(), | ||
}, | ||
})); | ||
|
||
describe('useSupport', () => { | ||
afterEach(() => jest.clearAllMocks()); | ||
|
||
it('checks that env NEXT_PUBLIC_CRISP_WEBSITE_ID not set give a warning', () => { | ||
process.env.NEXT_PUBLIC_CRISP_WEBSITE_ID = ''; | ||
jest.spyOn(console, 'warn').mockImplementation(() => {}); | ||
|
||
renderHook(() => useSupport()); | ||
expect(console.warn).toHaveBeenCalledWith('Crisp Website ID is not set'); | ||
}); | ||
|
||
it('checks Crisp is configured', () => { | ||
process.env.NEXT_PUBLIC_CRISP_WEBSITE_ID = '123456'; | ||
renderHook(() => useSupport()); | ||
|
||
expect(Crisp.configure).toHaveBeenCalledWith('123456'); | ||
}); | ||
}); |