Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Weekly release: dev-main-05-09-23 #859

Merged
merged 4 commits into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions packages/client/src/contents/types/contents.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,7 @@ export type ComponentType = {
};

export type ContentMetadata = {
custom?: {
id: string;
gender: string;
brand: string;
priceType: string;
category: string;
eventDate?: string;
};
custom?: Record<string, string>;
};

export type ContentEntry<T = ComponentType[]> = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ describe('putUserDefaultBillingAddress', () => {

expect(spy).toHaveBeenCalledWith(
`/account/v1/users/${userId}/addresses/billing/${id}`,
undefined,
expectedConfig,
);
});
Expand All @@ -32,6 +33,7 @@ describe('putUserDefaultBillingAddress', () => {
).rejects.toMatchSnapshot();
expect(spy).toHaveBeenCalledWith(
`/account/v1/users/${userId}/addresses/billing/${id}`,
undefined,
expectedConfig,
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('putUserDefaultContactAddress', () => {
mswServer.use(fixtures.success());

await expect(putUserDefaultContactAddress(userId, id)).resolves.toBe(204);
expect(spy).toHaveBeenCalledWith(expectedUrl, expectedConfig);
expect(spy).toHaveBeenCalledWith(expectedUrl, undefined, expectedConfig);
});

it('should receive a client request error', async () => {
Expand All @@ -27,6 +27,6 @@ describe('putUserDefaultContactAddress', () => {
await expect(
putUserDefaultContactAddress(userId, id),
).rejects.toMatchSnapshot();
expect(spy).toHaveBeenCalledWith(expectedUrl, expectedConfig);
expect(spy).toHaveBeenCalledWith(expectedUrl, undefined, expectedConfig);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ describe('putUserDefaultShippingAddress', () => {

expect(spy).toHaveBeenCalledWith(
`/account/v1/users/${userId}/addresses/shipping/${id}`,
undefined,
expectedConfig,
);
});
Expand All @@ -35,6 +36,7 @@ describe('putUserDefaultShippingAddress', () => {
).rejects.toMatchSnapshot();
expect(spy).toHaveBeenCalledWith(
`/account/v1/users/${userId}/addresses/shipping/${id}`,
undefined,
expectedConfig,
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const putUserDefaultBillingAddress: PutUserDefaultBillingAddress = (
client
.put(
join('/account/v1/users', userId, 'addresses/billing', addressId),
undefined,
config,
)
.then(response => response.status)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const putUserDefaultContactAddress: PutUserDefaultContactAddress = (
client
.put(
join('/account/v1/users', userId, 'addresses/preferred', addressId),
undefined,
config,
)
.then(response => response.status)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const putUserDefaultShippingAddress: PutUserDefaultShippingAddress = (
client
.put(
join('/account/v1/users', userId, 'addresses/shipping', addressId),
undefined,
config,
)
.then(response => response.status)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ Object {
"useSearchIntents": [Function],
"useSearchSuggestions": [Function],
"useSeoMetadata": [Function],
"useSocialLogin": [Function],
"useSubscriptionPackages": [Function],
"useTopCategories": [Function],
"useUser": [Function],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import { cleanup, renderHook } from '@testing-library/react';
import { mockInitialState } 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';
import { useSocialLogin } from '../index.js';

const mockConfig = {};

const mockLoginData = {
provider: 'Google',
socialAccessToken: 'xxx-xxx-xxx-xxx',
rememberMe: true,
countryCode: 'PT',
};

const mockAccountLinkData = {
username: 'xxxxxxxx',
password: 'xxxxxxxx',
};

jest.mock('@farfetch/blackout-client', () => {
const original = jest.requireActual('@farfetch/blackout-client');

return {
...original,
postSocialLogin: jest.fn(() => Promise.resolve()),
postAccountLink: jest.fn(() => Promise.resolve()),
};
});

const genericMock = {
actions: {
createAccountLink: expect.any(Function),
login: expect.any(Function),
},
};

const getRenderedHook = (state = mockInitialState) => {
const {
result: { current },
} = renderHook(() => useSocialLogin(), {
wrapper: props => <Provider store={mockStore(state)} {...props} />,
});

return current;
};

describe('useSocialLogin', () => {
beforeEach(jest.clearAllMocks);

afterEach(cleanup);

it('should return correctly with initial state', () => {
const current = getRenderedHook(mockInitialState);

expect(current).toStrictEqual(genericMock);

expect(postSocialLogin).not.toHaveBeenCalled();
expect(postAccountLink).not.toHaveBeenCalled();
});

describe('actions', () => {
describe('login', () => {
it('should call `useSocialLogin` login action with config', async () => {
const current = getRenderedHook(mockInitialState);

await current.actions.login(mockLoginData, mockConfig);

expect(postSocialLogin).toHaveBeenCalledWith(mockLoginData, mockConfig);
});

it('should call `useSocialLogin` login action without config', async () => {
const current = getRenderedHook(mockInitialState);

await current.actions.login(mockLoginData);

expect(postSocialLogin).toHaveBeenCalledWith(mockLoginData, undefined);
});
});

describe('createAccountLink', () => {
it('should call `useSocialLogin` accountLink action', async () => {
const current = getRenderedHook(mockInitialState);

await current.actions.createAccountLink(
mockAccountLinkData,
mockConfig,
);

expect(postAccountLink).toHaveBeenCalledWith(
mockAccountLinkData,
mockConfig,
);
});

it('should call `useSocialLogin` accountLink action without config', async () => {
const current = getRenderedHook(mockInitialState);

await current.actions.createAccountLink(mockAccountLinkData);

expect(postAccountLink).toHaveBeenCalledWith(
mockAccountLinkData,
undefined,
);
});
});
});
});
1 change: 1 addition & 0 deletions packages/react/src/authentication/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export { default as useAuthentication } from './useAuthentication.js';
export { default as useUserProfile } from './useUserProfile.js';
export { default as useSocialLogin } from './useSocialLogin.js';
46 changes: 46 additions & 0 deletions packages/react/src/authentication/hooks/useSocialLogin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import {
type Config,
type PostAccountLinkData,
type PostSocialLoginData,
} from '@farfetch/blackout-client';
import {
createAccountLink as createAccountLinkAction,
socialLogin as socialLoginAction,
} from '@farfetch/blackout-redux';
import { useCallback } from 'react';
import useAction from '../../helpers/useAction.js';

function useSocialLogin() {
const socialLogin = useAction(socialLoginAction);
const accountLink = useAction(createAccountLinkAction);
const login = useCallback(
async (data: PostSocialLoginData, config?: Config) => {
if (!data) {
return Promise.reject(new Error('No data was specified.'));
}

return await socialLogin(data, config);
},
[socialLogin],
);

const createAccountLink = useCallback(
async (data: PostAccountLinkData, config?: Config) => {
if (!data) {
return Promise.reject(new Error('No data was specified.'));
}

return await accountLink(data, config);
},
[accountLink],
);

return {
actions: {
login,
createAccountLink,
},
};
}

export default useSocialLogin;
19 changes: 19 additions & 0 deletions packages/redux/src/__tests__/__snapshots__/index.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ Object {
"areWishlistSetsLoading": [Function],
"areWishlistSetsWithAnyError": [Function],
"authenticationActionTypes": Object {
"CREATE_ACCOUNT_LINK_FAILURE": "@farfetch/blackout-redux/CREATE_ACCOUNT_LINK_FAILURE",
"CREATE_ACCOUNT_LINK_REQUEST": "@farfetch/blackout-redux/CREATE_ACCOUNT_LINK_REQUEST",
"CREATE_ACCOUNT_LINK_SUCCESS": "@farfetch/blackout-redux/CREATE_ACCOUNT_LINK_SUCCESS",
"CREATE_CLIENT_CREDENTIALS_TOKEN_FAILURE": "@farfetch/blackout-redux/CREATE_CLIENT_CREDENTIALS_TOKEN_FAILURE",
"CREATE_CLIENT_CREDENTIALS_TOKEN_REQUEST": "@farfetch/blackout-redux/CREATE_CLIENT_CREDENTIALS_TOKEN_REQUEST",
"CREATE_CLIENT_CREDENTIALS_TOKEN_SUCCESS": "@farfetch/blackout-redux/CREATE_CLIENT_CREDENTIALS_TOKEN_SUCCESS",
Expand Down Expand Up @@ -216,6 +219,9 @@ Object {
"RESET_USER_ENTITIES": "@farfetch/blackout-redux/RESET_USER_ENTITIES",
"RESET_USER_STATE": "@farfetch/blackout-redux/RESET_USER_STATE",
"RESET_VALIDATE_EMAIL": "@farfetch/blackout-redux/RESET_VALIDATE_EMAIL",
"SOCIAL_LOGIN_FAILURE": "@farfetch/blackout-redux/SOCIAL_LOGIN_FAILURE",
"SOCIAL_LOGIN_REQUEST": "@farfetch/blackout-redux/SOCIAL_LOGIN_REQUEST",
"SOCIAL_LOGIN_SUCCESS": "@farfetch/blackout-redux/SOCIAL_LOGIN_SUCCESS",
"UPDATE_USER_FAILURE": "@farfetch/blackout-redux/UPDATE_USER_FAILURE",
"UPDATE_USER_REQUEST": "@farfetch/blackout-redux/UPDATE_USER_REQUEST",
"UPDATE_USER_SUCCESS": "@farfetch/blackout-redux/UPDATE_USER_SUCCESS",
Expand Down Expand Up @@ -426,6 +432,8 @@ Object {
},
"contentsReducer": [Function],
"contentsServerInitialState": [Function],
"createAccountLink": [Function],
"createAccountLinkFactory": [Function],
"createCheckoutOrder": [Function],
"createCheckoutOrderCharge": [Function],
"createCheckoutOrderChargeFactory": [Function],
Expand Down Expand Up @@ -574,6 +582,7 @@ Object {
"@farfetch/blackout-redux/SET_USER_DEFAULT_BILLING_ADDRESS_SUCCESS": [Function],
"@farfetch/blackout-redux/SET_USER_DEFAULT_CONTACT_ADDRESS_SUCCESS": [Function],
"@farfetch/blackout-redux/SET_USER_DEFAULT_SHIPPING_ADDRESS_SUCCESS": [Function],
"@farfetch/blackout-redux/SOCIAL_LOGIN_SUCCESS": [Function],
"@farfetch/blackout-redux/UPDATE_USER_ADDRESS_SUCCESS": [Function],
"@farfetch/blackout-redux/UPDATE_USER_PREFERENCES_SUCCESS": [Function],
},
Expand Down Expand Up @@ -639,6 +648,7 @@ Object {
"fetchCheckoutOrderDetails": [Function],
"fetchCheckoutOrderDetailsFactory": [Function],
"fetchCheckoutOrderFactory": [Function],
"fetchCheckoutOrderOperation": [Function],
"fetchCheckoutOrderOperationFactory": [Function],
"fetchCheckoutOrderOperations": [Function],
"fetchCheckoutOrderOperationsFactory": [Function],
Expand Down Expand Up @@ -1781,6 +1791,8 @@ Object {
"RESET_SIZE_SCALES_STATE": "@farfetch/blackout-redux/RESET_SIZE_SCALES_STATE",
},
"sizeScalesReducer": [Function],
"socialLogin": [Function],
"socialLoginFactory": [Function],
"staffMembersActionTypes": Object {
"FETCH_STAFF_MEMBER_FAILURE": "@farfetch/blackout-redux/FETCH_STAFF_MEMBER_FAILURE",
"FETCH_STAFF_MEMBER_REQUEST": "@farfetch/blackout-redux/FETCH_STAFF_MEMBER_REQUEST",
Expand Down Expand Up @@ -1855,6 +1867,9 @@ Object {
"updateWishlistSet": [Function],
"updateWishlistSetFactory": [Function],
"usersActionTypes": Object {
"CREATE_ACCOUNT_LINK_FAILURE": "@farfetch/blackout-redux/CREATE_ACCOUNT_LINK_FAILURE",
"CREATE_ACCOUNT_LINK_REQUEST": "@farfetch/blackout-redux/CREATE_ACCOUNT_LINK_REQUEST",
"CREATE_ACCOUNT_LINK_SUCCESS": "@farfetch/blackout-redux/CREATE_ACCOUNT_LINK_SUCCESS",
"CREATE_CLIENT_CREDENTIALS_TOKEN_FAILURE": "@farfetch/blackout-redux/CREATE_CLIENT_CREDENTIALS_TOKEN_FAILURE",
"CREATE_CLIENT_CREDENTIALS_TOKEN_REQUEST": "@farfetch/blackout-redux/CREATE_CLIENT_CREDENTIALS_TOKEN_REQUEST",
"CREATE_CLIENT_CREDENTIALS_TOKEN_SUCCESS": "@farfetch/blackout-redux/CREATE_CLIENT_CREDENTIALS_TOKEN_SUCCESS",
Expand Down Expand Up @@ -2015,6 +2030,9 @@ Object {
"SET_USER_DEFAULT_SHIPPING_ADDRESS_FAILURE": "@farfetch/blackout-redux/SET_USER_DEFAULT_SHIPPING_ADDRESS_FAILURE",
"SET_USER_DEFAULT_SHIPPING_ADDRESS_REQUEST": "@farfetch/blackout-redux/SET_USER_DEFAULT_SHIPPING_ADDRESS_REQUEST",
"SET_USER_DEFAULT_SHIPPING_ADDRESS_SUCCESS": "@farfetch/blackout-redux/SET_USER_DEFAULT_SHIPPING_ADDRESS_SUCCESS",
"SOCIAL_LOGIN_FAILURE": "@farfetch/blackout-redux/SOCIAL_LOGIN_FAILURE",
"SOCIAL_LOGIN_REQUEST": "@farfetch/blackout-redux/SOCIAL_LOGIN_REQUEST",
"SOCIAL_LOGIN_SUCCESS": "@farfetch/blackout-redux/SOCIAL_LOGIN_SUCCESS",
"UPDATE_USER_ADDRESS_FAILURE": "@farfetch/blackout-redux/UPDATE_USER_ADDRESS_FAILURE",
"UPDATE_USER_ADDRESS_REQUEST": "@farfetch/blackout-redux/UPDATE_USER_ADDRESS_REQUEST",
"UPDATE_USER_ADDRESS_SUCCESS": "@farfetch/blackout-redux/UPDATE_USER_ADDRESS_SUCCESS",
Expand Down Expand Up @@ -2054,6 +2072,7 @@ Object {
"@farfetch/blackout-redux/SET_USER_DEFAULT_BILLING_ADDRESS_SUCCESS": [Function],
"@farfetch/blackout-redux/SET_USER_DEFAULT_CONTACT_ADDRESS_SUCCESS": [Function],
"@farfetch/blackout-redux/SET_USER_DEFAULT_SHIPPING_ADDRESS_SUCCESS": [Function],
"@farfetch/blackout-redux/SOCIAL_LOGIN_SUCCESS": [Function],
"@farfetch/blackout-redux/UPDATE_USER_ADDRESS_SUCCESS": [Function],
"@farfetch/blackout-redux/UPDATE_USER_PREFERENCES_SUCCESS": [Function],
},
Expand Down
1 change: 1 addition & 0 deletions packages/redux/src/checkout/actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export { default as fetchCheckoutOrderContext } from './fetchCheckoutOrderContex
export { default as fetchCheckoutOrderContexts } from './fetchCheckoutOrderContexts.js';
export { default as fetchCheckoutOrderDetails } from './fetchCheckoutOrderDetails.js';
export { default as fetchCheckoutOrderCharge } from './fetchCheckoutOrderCharge.js';
export { default as fetchCheckoutOrderOperation } from './fetchCheckoutOrderOperation.js';
export { default as fetchCheckoutOrderOperations } from './fetchCheckoutOrderOperations.js';
export { default as fetchCollectPoints } from './fetchCollectPoints.js';
export { default as fetchCheckoutOrderDeliveryBundleUpgrades } from './fetchCheckoutOrderDeliveryBundleUpgrades.js';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ Object {
"@farfetch/blackout-redux/SET_USER_DEFAULT_BILLING_ADDRESS_SUCCESS": [Function],
"@farfetch/blackout-redux/SET_USER_DEFAULT_CONTACT_ADDRESS_SUCCESS": [Function],
"@farfetch/blackout-redux/SET_USER_DEFAULT_SHIPPING_ADDRESS_SUCCESS": [Function],
"@farfetch/blackout-redux/SOCIAL_LOGIN_SUCCESS": [Function],
"@farfetch/blackout-redux/UPDATE_USER_ADDRESS_SUCCESS": [Function],
"@farfetch/blackout-redux/UPDATE_USER_PREFERENCES_SUCCESS": [Function],
},
Expand Down
6 changes: 3 additions & 3 deletions packages/redux/src/entities/types/contents.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import type {
ContentMetadata,
} from '@farfetch/blackout-client';

export type CustomMetadataNormalized = Omit<
NonNullable<ContentMetadata['custom']>,
'eventDate'
export type CustomMetadataNormalized = Record<
string,
string | number | null
> & {
eventDate: number | null;
};
Expand Down
Loading
Loading