refactor(auth): add workspaces selection (#12098)
This commit is contained in:
@ -2,6 +2,7 @@ import { useAuth } from '@/auth/hooks/useAuth';
|
||||
import { billingState } from '@/client-config/states/billingState';
|
||||
import { isDeveloperDefaultSignInPrefilledState } from '@/client-config/states/isDeveloperDefaultSignInPrefilledState';
|
||||
import { supportChatState } from '@/client-config/states/supportChatState';
|
||||
import { SnackBarProviderScope } from '@/ui/feedback/snack-bar-manager/scopes/SnackBarProviderScope';
|
||||
import { workspaceAuthProvidersState } from '@/workspace/states/workspaceAuthProvidersState';
|
||||
import { useApolloClient } from '@apollo/client';
|
||||
import { MockedProvider } from '@apollo/client/testing';
|
||||
@ -30,9 +31,13 @@ jest.mock('@/object-metadata/hooks/useRefreshObjectMetadataItem', () => ({
|
||||
}));
|
||||
|
||||
const Wrapper = ({ children }: { children: ReactNode }) => (
|
||||
<MockedProvider mocks={mocks} addTypename={false}>
|
||||
<MockedProvider mocks={Object.values(mocks)} addTypename={false}>
|
||||
<RecoilRoot>
|
||||
<MemoryRouter>{children}</MemoryRouter>
|
||||
<MemoryRouter>
|
||||
<SnackBarProviderScope snackBarManagerScopeId="test-scope-id">
|
||||
{children}
|
||||
</SnackBarProviderScope>
|
||||
</MemoryRouter>
|
||||
</RecoilRoot>
|
||||
</MockedProvider>
|
||||
);
|
||||
@ -63,7 +68,7 @@ describe('useAuth', () => {
|
||||
).toStrictEqual(results.getLoginTokenFromCredentials);
|
||||
});
|
||||
|
||||
expect(mocks[0].result).toHaveBeenCalled();
|
||||
expect(mocks.getLoginTokenFromCredentials.result).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should verify user', async () => {
|
||||
@ -73,19 +78,19 @@ describe('useAuth', () => {
|
||||
await result.current.getAuthTokensFromLoginToken(token);
|
||||
});
|
||||
|
||||
expect(mocks[1].result).toHaveBeenCalled();
|
||||
expect(mocks[3].result).toHaveBeenCalled();
|
||||
expect(mocks.getAuthTokensFromLoginToken.result).toHaveBeenCalled();
|
||||
expect(mocks.getCurrentUser.result).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should handle credential sign-in', async () => {
|
||||
const { result } = renderHooks();
|
||||
|
||||
await act(async () => {
|
||||
await result.current.signInWithCredentials(email, password);
|
||||
await result.current.signInWithCredentialsInWorkspace(email, password);
|
||||
});
|
||||
|
||||
expect(mocks[0].result).toHaveBeenCalled();
|
||||
expect(mocks[1].result).toHaveBeenCalled();
|
||||
expect(mocks.getLoginTokenFromCredentials.result).toHaveBeenCalled();
|
||||
expect(mocks.getAuthTokensFromLoginToken.result).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should handle google sign-in', async () => {
|
||||
@ -94,6 +99,7 @@ describe('useAuth', () => {
|
||||
await act(async () => {
|
||||
await result.current.signInWithGoogle({
|
||||
workspaceInviteHash: 'workspaceInviteHash',
|
||||
action: 'join-workspace',
|
||||
});
|
||||
});
|
||||
|
||||
@ -163,9 +169,12 @@ describe('useAuth', () => {
|
||||
const { result } = renderHooks();
|
||||
|
||||
await act(async () => {
|
||||
await result.current.signUpWithCredentials({ email, password });
|
||||
await result.current.signUpWithCredentialsInWorkspace({
|
||||
email,
|
||||
password,
|
||||
});
|
||||
});
|
||||
|
||||
expect(mocks[2].result).toHaveBeenCalled();
|
||||
expect(mocks.signUpInWorkspace.result).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user