diff --git a/packages/react/src/authentication/hooks/__tests__/useSocialLogin.test.tsx b/packages/react/src/authentication/hooks/__tests__/useSocialLogin.test.tsx index ac2ec52b3..1bdc4a79a 100644 --- a/packages/react/src/authentication/hooks/__tests__/useSocialLogin.test.tsx +++ b/packages/react/src/authentication/hooks/__tests__/useSocialLogin.test.tsx @@ -1,5 +1,8 @@ import { cleanup, renderHook } from '@testing-library/react'; -import { mockInitialState } from 'tests/__fixtures__/authentication/index.mjs'; +import { + mockInitialState, + mockResponse, +} from 'tests/__fixtures__/authentication/index.mjs'; import { mockStore } from '../../../../tests/helpers/index.js'; import { postAccountLink, postSocialLogin } from '@farfetch/blackout-client'; import { Provider } from 'react-redux'; @@ -24,15 +27,15 @@ jest.mock('@farfetch/blackout-client', () => { return { ...original, - postSocialLogin: jest.fn(() => Promise.resolve()), - postAccountLink: jest.fn(() => Promise.resolve()), + postSocialLogin: jest.fn(() => Promise.resolve(mockResponse)), + postAccountLink: jest.fn(() => Promise.resolve(mockResponse)), }; }); const genericMock = { actions: { createAccountLink: expect.any(Function), - login: expect.any(Function), + socialLogin: expect.any(Function), }, }; @@ -61,19 +64,19 @@ describe('useSocialLogin', () => { }); describe('actions', () => { - describe('login', () => { - it('should call `useSocialLogin` login action with config', async () => { + describe('socialLogin', () => { + it('should call `useSocialLogin` socialLogin action with config', async () => { const current = getRenderedHook(mockInitialState); - await current.actions.login(mockLoginData, mockConfig); + await current.actions.socialLogin(mockLoginData, mockConfig); expect(postSocialLogin).toHaveBeenCalledWith(mockLoginData, mockConfig); }); - it('should call `useSocialLogin` login action without config', async () => { + it('should call `useSocialLogin` socialLogin action without config', async () => { const current = getRenderedHook(mockInitialState); - await current.actions.login(mockLoginData); + await current.actions.socialLogin(mockLoginData); expect(postSocialLogin).toHaveBeenCalledWith(mockLoginData, undefined); }); diff --git a/packages/react/src/authentication/hooks/useSocialLogin.ts b/packages/react/src/authentication/hooks/useSocialLogin.ts index 8b5be968a..7ebc5d8d1 100644 --- a/packages/react/src/authentication/hooks/useSocialLogin.ts +++ b/packages/react/src/authentication/hooks/useSocialLogin.ts @@ -5,23 +5,23 @@ import { } from '@farfetch/blackout-client'; import { createAccountLink as createAccountLinkAction, - socialLogin as socialLoginAction, + socialLogin as socialLoginReduxAction, } from '@farfetch/blackout-redux'; import { useCallback } from 'react'; import useAction from '../../helpers/useAction.js'; function useSocialLogin() { - const socialLogin = useAction(socialLoginAction); + const socialLoginAction = useAction(socialLoginReduxAction); const accountLink = useAction(createAccountLinkAction); - const login = useCallback( + const socialLogin = useCallback( async (data: PostSocialLoginData, config?: Config) => { if (!data) { return Promise.reject(new Error('No data was specified.')); } - return await socialLogin(data, config); + return await socialLoginAction(data, config); }, - [socialLogin], + [socialLoginAction], ); const createAccountLink = useCallback( @@ -37,7 +37,7 @@ function useSocialLogin() { return { actions: { - login, + socialLogin, createAccountLink, }, }; diff --git a/packages/redux/src/users/authentication/actions/__tests__/__snapshots__/createAccountLink.test.ts.snap b/packages/redux/src/users/authentication/actions/__tests__/__snapshots__/createAccountLink.test.ts.snap index d5c71cc85..3351e8cc3 100644 --- a/packages/redux/src/users/authentication/actions/__tests__/__snapshots__/createAccountLink.test.ts.snap +++ b/packages/redux/src/users/authentication/actions/__tests__/__snapshots__/createAccountLink.test.ts.snap @@ -6,6 +6,7 @@ Object { "entities": Object { "user": Object {}, }, + "result": undefined, }, "type": "@farfetch/blackout-redux/CREATE_ACCOUNT_LINK_SUCCESS", } diff --git a/packages/redux/src/users/authentication/actions/__tests__/__snapshots__/socialLogin.test.ts.snap b/packages/redux/src/users/authentication/actions/__tests__/__snapshots__/socialLogin.test.ts.snap index 98d5d17f4..48ef8f26a 100644 --- a/packages/redux/src/users/authentication/actions/__tests__/__snapshots__/socialLogin.test.ts.snap +++ b/packages/redux/src/users/authentication/actions/__tests__/__snapshots__/socialLogin.test.ts.snap @@ -29,6 +29,7 @@ Object { "wishlistId": "1e5232f8-7af0-4fba-b6b1-b87e2cb3a88f", }, }, + "result": 29556478, }, "type": "@farfetch/blackout-redux/SOCIAL_LOGIN_SUCCESS", } diff --git a/packages/redux/src/users/authentication/actions/__tests__/socialLogin.test.ts b/packages/redux/src/users/authentication/actions/__tests__/socialLogin.test.ts index bffc0d9af..98b559b83 100644 --- a/packages/redux/src/users/authentication/actions/__tests__/socialLogin.test.ts +++ b/packages/redux/src/users/authentication/actions/__tests__/socialLogin.test.ts @@ -1,6 +1,6 @@ import * as actionTypes from '../../actionTypes.js'; import { - expectedNormalizedSocialLoginPayload, + expectedNormalizedPayload, mockResponse, } from 'tests/__fixtures__/authentication/index.mjs'; import { find } from 'lodash-es'; @@ -71,7 +71,7 @@ describe('socialLogin() action creator', () => { { type: actionTypes.SOCIAL_LOGIN_REQUEST }, { type: actionTypes.SOCIAL_LOGIN_SUCCESS, - payload: expectedNormalizedSocialLoginPayload, + payload: expectedNormalizedPayload, }, ]); expect( diff --git a/packages/redux/src/users/authentication/actions/factories/createAccountLinkFactory.ts b/packages/redux/src/users/authentication/actions/factories/createAccountLinkFactory.ts index 1db7e420f..03c0f49c1 100644 --- a/packages/redux/src/users/authentication/actions/factories/createAccountLinkFactory.ts +++ b/packages/redux/src/users/authentication/actions/factories/createAccountLinkFactory.ts @@ -27,6 +27,7 @@ const createAccountLinkFactory = const user = result; const userEntity = { entities: { user }, + result: result.id, }; dispatch({ diff --git a/packages/redux/src/users/authentication/actions/factories/socialLoginFactory.ts b/packages/redux/src/users/authentication/actions/factories/socialLoginFactory.ts index 79a3146bd..98b084264 100644 --- a/packages/redux/src/users/authentication/actions/factories/socialLoginFactory.ts +++ b/packages/redux/src/users/authentication/actions/factories/socialLoginFactory.ts @@ -30,6 +30,7 @@ const socialLoginFactory = const userEntity = { entities: { user }, + result: result.id, }; await dispatch({