-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c5b2677
commit 571e067
Showing
7 changed files
with
78 additions
and
30 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
47 changes: 47 additions & 0 deletions
47
.../src/modules/settings/developers/webhook/hooks/__tests__/useAnalyticsTinybirdJwt.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,47 @@ | ||
import { renderHook } from '@testing-library/react'; | ||
|
||
import { CurrentUser, currentUserState } from '@/auth/states/currentUserState'; | ||
import { useAnalyticsTinybirdJwt } from '@/settings/developers/webhook/hooks/useAnalyticsTinybirdJwt'; | ||
import { act } from 'react'; | ||
import { useSetRecoilState } from 'recoil'; | ||
import { getJestMetadataAndApolloMocksWrapper } from '~/testing/jest/getJestMetadataAndApolloMocksWrapper'; | ||
|
||
const Wrapper = getJestMetadataAndApolloMocksWrapper({ | ||
apolloMocks: [], | ||
}); | ||
|
||
describe('useAnalyticsTinybirdJwt', () => { | ||
it('should return the analytics jwt token', async () => { | ||
const { result } = renderHook( | ||
() => { | ||
const setCurrentUserState = useSetRecoilState(currentUserState); | ||
|
||
return { | ||
useAnalyticsTinybirdJwt: useAnalyticsTinybirdJwt(), | ||
setCurrentUserState, | ||
}; | ||
}, | ||
{ wrapper: Wrapper }, | ||
); | ||
|
||
act(() => { | ||
result.current.setCurrentUserState({ | ||
analyticsTinybirdJwt: 'jwt', | ||
} as CurrentUser); | ||
}); | ||
|
||
expect(result.current.useAnalyticsTinybirdJwt).toBe('jwt'); | ||
|
||
act(() => { | ||
result.current.setCurrentUserState(null); | ||
}); | ||
|
||
expect(result.current.useAnalyticsTinybirdJwt).toBeUndefined(); | ||
|
||
act(() => { | ||
result.current.setCurrentUserState({} as CurrentUser); | ||
}); | ||
|
||
expect(result.current.useAnalyticsTinybirdJwt).toBeUndefined(); | ||
}); | ||
}); |
14 changes: 12 additions & 2 deletions
14
...ges/twenty-front/src/modules/settings/developers/webhook/hooks/useAnalyticsTinybirdJwt.ts
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 |
---|---|---|
@@ -1,8 +1,18 @@ | ||
import { useRecoilValue } from 'recoil'; | ||
|
||
import { currentUserState } from '@/auth/states/currentUserState'; | ||
import { isNull } from '@sniptt/guards'; | ||
|
||
export const useAnalyticsTinybirdJwt = (): string | null | undefined => { | ||
export const useAnalyticsTinybirdJwt = (): string | undefined => { | ||
const currentUser = useRecoilValue(currentUserState); | ||
return currentUser?.analyticsTinybirdJwt; | ||
|
||
if (!currentUser) { | ||
return undefined; | ||
} | ||
|
||
if (isNull(currentUser.analyticsTinybirdJwt)) { | ||
return undefined; | ||
} | ||
|
||
return currentUser.analyticsTinybirdJwt; | ||
}; |
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
17 changes: 2 additions & 15 deletions
17
packages/twenty-server/src/engine/core-modules/analytics/analytics.module.ts
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
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