Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@
* SPDX-License-Identifier: BSD-3-Clause
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import {
ShopperBasketsTypes,
ShopperCustomers,
ShopperCustomersTypes
} from 'commerce-sdk-isomorphic'
import {ShopperBasketsTypes, ShopperCustomers, ShopperCustomersTypes} from 'commerce-sdk-isomorphic'
import {
ApiClients,
Argument,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
* SPDX-License-Identifier: BSD-3-Clause
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import {ShopperBasketsV2Types, ShopperCustomers, ShopperCustomersTypes} from 'commerce-sdk-isomorphic'
import {
ShopperBasketsV2Types,
ShopperCustomers,
ShopperCustomersTypes
} from 'commerce-sdk-isomorphic'
import {
ApiClients,
Argument,
Expand Down
25 changes: 20 additions & 5 deletions packages/commerce-sdk-react/src/hooks/ShopperBasketsV2/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ export const useBasket = (
// Parameters can be set in `apiOptions` or `client.clientConfig`;
// we must merge them in order to generate the correct query key.
const netOptions = omitNullableParameters(mergeOptions(client, apiOptions))
const parameters = pickValidParams(netOptions.parameters, ShopperBasketsV2.paramKeys[methodName])
const parameters = pickValidParams(
netOptions.parameters,
ShopperBasketsV2.paramKeys[methodName]
)
const queryKey = queryKeyHelpers[methodName].queryKey(netOptions.parameters)
// We don't use `netOptions` here because we manipulate the options in `useQuery`.
const method = async (options: Options) => await client[methodName](options)
Expand Down Expand Up @@ -82,7 +85,10 @@ export const usePaymentMethodsForBasket = (
// Parameters can be set in `apiOptions` or `client.clientConfig`;
// we must merge them in order to generate the correct query key.
const netOptions = omitNullableParameters(mergeOptions(client, apiOptions))
const parameters = pickValidParams(netOptions.parameters, ShopperBasketsV2.paramKeys[methodName])
const parameters = pickValidParams(
netOptions.parameters,
ShopperBasketsV2.paramKeys[methodName]
)
const queryKey = queryKeyHelpers[methodName].queryKey(netOptions.parameters)
// We don't use `netOptions` here because we manipulate the options in `useQuery`.
const method = async (options: Options) => await client[methodName](options)
Expand Down Expand Up @@ -124,7 +130,10 @@ export const usePriceBooksForBasket = (
// Parameters can be set in `apiOptions` or `client.clientConfig`;
// we must merge them in order to generate the correct query key.
const netOptions = omitNullableParameters(mergeOptions(client, apiOptions))
const parameters = pickValidParams(netOptions.parameters, ShopperBasketsV2.paramKeys[methodName])
const parameters = pickValidParams(
netOptions.parameters,
ShopperBasketsV2.paramKeys[methodName]
)
const queryKey = queryKeyHelpers[methodName].queryKey(netOptions.parameters)
// We don't use `netOptions` here because we manipulate the options in `useQuery`.
const method = async (options: Options) => await client[methodName](options)
Expand Down Expand Up @@ -166,7 +175,10 @@ export const useShippingMethodsForShipment = (
// Parameters can be set in `apiOptions` or `client.clientConfig`;
// we must merge them in order to generate the correct query key.
const netOptions = omitNullableParameters(mergeOptions(client, apiOptions))
const parameters = pickValidParams(netOptions.parameters, ShopperBasketsV2.paramKeys[methodName])
const parameters = pickValidParams(
netOptions.parameters,
ShopperBasketsV2.paramKeys[methodName]
)
const queryKey = queryKeyHelpers[methodName].queryKey(netOptions.parameters)
// We don't use `netOptions` here because we manipulate the options in `useQuery`.
const method = async (options: Options) => await client[methodName](options)
Expand Down Expand Up @@ -208,7 +220,10 @@ export const useTaxesFromBasket = (
// Parameters can be set in `apiOptions` or `client.clientConfig`;
// we must merge them in order to generate the correct query key.
const netOptions = omitNullableParameters(mergeOptions(client, apiOptions))
const parameters = pickValidParams(netOptions.parameters, ShopperBasketsV2.paramKeys[methodName])
const parameters = pickValidParams(
netOptions.parameters,
ShopperBasketsV2.paramKeys[methodName]
)
const queryKey = queryKeyHelpers[methodName].queryKey(netOptions.parameters)
// We don't use `netOptions` here because we manipulate the options in `useQuery`.
const method = async (options: Options) => await client[methodName](options)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('Shopper Customers hooks', () => {
expect(unimplemented).toEqual([
'getExternalProfile', // TODO: Implement when the endpoint exits closed beta
'getPublicProductListItems', // TODO: Implement when the endpoint exits closed beta
'registerExternalProfile', // TODO: Implement when the endpoint exits closed beta
'registerExternalProfile' // TODO: Implement when the endpoint exits closed beta
])
})
test('all mutations have cache update logic', () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/commerce-sdk-react/src/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ export {
useTaxesFromBasket as useTaxesFromBasketV2,
ShopperBasketsMutations as ShopperBasketsV2Mutations,
useShopperBasketsMutation as useShopperBasketsV2Mutation,
useShopperBasketsMutationHelper as useShopperBasketsV2MutationHelper,
useShopperBasketsMutationHelper as useShopperBasketsV2MutationHelper
} from './ShopperBasketsV2'
// Only needed if consumers want to type-annotate variables with it.
export type { ShopperBasketsMutation as ShopperBasketsV2Mutation } from './ShopperBasketsV2'
export type {ShopperBasketsMutation as ShopperBasketsV2Mutation} from './ShopperBasketsV2'

export * from './ShopperContexts'
export * from './ShopperCustomers'
Expand Down
1 change: 0 additions & 1 deletion packages/commerce-sdk-react/src/hooks/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import {InvalidateQueryFilters, QueryFilters, Updater, UseQueryOptions} from '@tanstack/react-query'
import {
ShopperBaskets,
ShopperBasketsV2,
ShopperConfigurations,
ShopperContexts,
ShopperCustomers,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const PasswordlessLogin = ({
handlePasswordlessLoginClick,
isSocialEnabled = false,
idps = [],
// eslint-disable-next-line @typescript-eslint/no-unused-vars
setLoginType: _setLoginType = noop
}) => {
const [showPasswordView, setShowPasswordView] = useState(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,15 +160,15 @@ jest.mock('@salesforce/commerce-sdk-react', () => {
...actual,
useShopperBasketsMutation: mockUseShopperBasketsMutation,
useShopperBasketsV2Mutation: mockUseShopperBasketsMutation,
useShippingMethodsForShipment: (params, options) => {
useShippingMethodsForShipment: () => {
if (mockValidateTestMocks && mockValidateTestMocks.refetchShippingMethods) {
return {refetch: mockValidateTestMocks.refetchShippingMethods}
}
return {
refetch: jest.fn().mockResolvedValue({data: {applicableShippingMethods: []}})
}
},
useShippingMethodsForShipmentV2: (params, options) => {
useShippingMethodsForShipmentV2: () => {
if (mockValidateTestMocks && mockValidateTestMocks.refetchShippingMethods) {
return {refetch: mockValidateTestMocks.refetchShippingMethods}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import React, {useEffect} from 'react'
import {useLocation} from 'react-router-dom'
import useScript from '@salesforce/retail-react-app/app/hooks/use-script'
import {useUsid} from '@salesforce/commerce-sdk-react'
import PropTypes from 'prop-types'
Expand Down Expand Up @@ -157,7 +156,7 @@ const ShopperAgentWindow = ({commerceAgentConfiguration, domainUrl}) => {
const theme = useTheme()

// Multi-site hook for locale and currency information
const {locale, buildUrl} = useMultiSite()
const {locale} = useMultiSite()

// Authentication hook for refresh token
const refreshToken = useRefreshToken()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ test('Renders login modal by default', async () => {

// TODO: Skipping this test because our jest version seems to too old and is run into issues with react-hooks-form
// when trying to run jest.spyOn on useForm hook. Need to bump version for jest.
/* eslint-disable jest/no-disabled-tests */
test.skip('Renders check email modal on email mode', async () => {
// Store the original useForm function
const originalUseForm = ReactHookForm.useForm
Expand Down Expand Up @@ -171,6 +172,7 @@ test.skip('Renders check email modal on email mode', async () => {
})
mockUseForm.mockRestore()
})
/* eslint-enable jest/no-disabled-tests */

test('allows regular login via Enter key in password mode', async () => {
const {user} = renderWithProviders(<MockedComponent isPasswordlessEnabled={true} />)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

import React from 'react'
import {renderHook} from '@testing-library/react'
import useMiaw, {
normalizeLocaleToSalesforce,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ export const useVariationAttributes = (
isProductPartOfSet = false,
isProductPartOfBundle = false,
controlledVariationValues = null,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
onVariationChange = null
) => {
const {variationAttributes = []} = product
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ describe('Rendering tests', function () {
})

// TODO: Investigate failures in Orphaned Bonus Products tests and re-enable
// eslint-disable-next-line jest/no-disabled-tests
describe.skip('Orphaned Bonus Products', function () {
test('renders orphaned bonus products (missing bonusDiscountLineItemId) as regular cart items', async () => {
// Create a mock basket with an orphaned bonus product (bonusProductLineItem: true but no bonusDiscountLineItemId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ const defaultProps = {
// TODO: Fix import resolution issues causing "Element type is invalid" errors in Jest
// These tests fail due to absolute import paths not resolving correctly in the test environment
// The component imports correctly but dependencies resolve to undefined during render
// eslint-disable-next-line jest/no-disabled-tests
describe.skip('SelectBonusProductsCard', () => {
test('renders with selection counter by default', () => {
renderWithProviders(<SelectBonusProductsCard {...defaultProps} />)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ import {
import useNavigation from '@salesforce/retail-react-app/app/hooks/use-navigation'
import {useCurrentCustomer} from '@salesforce/retail-react-app/app/hooks/use-current-customer'
import {useCurrentBasket} from '@salesforce/retail-react-app/app/hooks/use-current-basket'
import {isAbsoluteURL} from '@salesforce/retail-react-app/app/page-designer/utils'
import {useAppOrigin} from '@salesforce/retail-react-app/app/hooks/use-app-origin'
import {
AuthHelpers,
useAuthHelper,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ jest.mock('@salesforce/retail-react-app/app/hooks/use-current-customer', () => {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const mockUseCustomer = require('@salesforce/commerce-sdk-react').useCustomer
return {
useCurrentCustomer: (expand) => {
useCurrentCustomer: () => {
const query = mockUseCustomer()
const data = query.data
? {...query.data, customerId: 'customer123', isRegistered: true, isGuest: false}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import React from 'react'
import {screen, waitFor, within} from '@testing-library/react'
import {screen, waitFor} from '@testing-library/react'
import {Route, Switch} from 'react-router-dom'
import {rest} from 'msw'
import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ const LOGIN_ERROR_MESSAGE = defineMessage({
const LOGIN_VIEW = 'login'
const EMAIL_VIEW = 'email'

const Login = ({initialView = LOGIN_VIEW}) => {
// eslint-disable-next-line no-empty-pattern
const Login = ({}) => {
const {formatMessage} = useIntl()
const navigate = useNavigation()
const form = useForm()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ import {
getExpressPaymentMethodType
} from '@salesforce/retail-react-app/app/utils/sf-payments-utils'

import {PAYMENT_GATEWAYS} from '@salesforce/retail-react-app/app/constants'

describe('sf-payments-utils', () => {
describe('getSFPaymentsInstrument', () => {
test('returns undefined when basketOrOrder is undefined', () => {
Expand Down
Loading