-
Notifications
You must be signed in to change notification settings - Fork 214
@W-19990736 render salesforce payments paypal #3415
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
File renamed without changes
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
21 changes: 0 additions & 21 deletions
21
packages/template-retail-react-app/app/hooks/use-salesforce-payments.js
This file was deleted.
Oops, something went wrong.
21 changes: 21 additions & 0 deletions
21
packages/template-retail-react-app/app/hooks/use-shopper-configuration.js
This file contains hidden or 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,21 @@ | ||
| /* | ||
| * Copyright (c) 2025, salesforce.com, inc. | ||
| * All rights reserved. | ||
| * 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 {useConfigurations} from '@salesforce/commerce-sdk-react' | ||
|
|
||
| /** | ||
| * Hook to get a shopper configuration value. | ||
| * @param {string} configurationId - The ID of the configuration to retrieve | ||
| * @returns {*} The configuration value, or undefined if not found | ||
| */ | ||
| export const useShopperConfiguration = (configurationId) => { | ||
| const {data: configurations} = useConfigurations() | ||
| const config = configurations?.configurations?.find( | ||
| (configuration) => configuration.id === configurationId | ||
| ) | ||
| return config?.value | ||
| } |
229 changes: 229 additions & 0 deletions
229
packages/template-retail-react-app/app/hooks/use-shopper-configuration.test.js
This file contains hidden or 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,229 @@ | ||
| /* | ||
| * Copyright (c) 2025, salesforce.com, inc. | ||
| * All rights reserved. | ||
| * 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 {renderHook} from '@testing-library/react' | ||
| import {useShopperConfiguration} from '@salesforce/retail-react-app/app/hooks/use-shopper-configuration' | ||
| import {useConfigurations} from '@salesforce/commerce-sdk-react' | ||
|
|
||
| // Mock the commerce-sdk-react hook | ||
| jest.mock('@salesforce/commerce-sdk-react', () => ({ | ||
| useConfigurations: jest.fn() | ||
| })) | ||
|
|
||
| describe('useShopperConfiguration', () => { | ||
| afterEach(() => { | ||
| jest.clearAllMocks() | ||
| }) | ||
|
|
||
| test('returns the configuration value when configuration exists with boolean true', () => { | ||
| useConfigurations.mockReturnValue({ | ||
| data: { | ||
| configurations: [ | ||
| {id: 'SalesforcePaymentsAllowed', value: true}, | ||
| {id: 'AnotherConfig', value: false} | ||
| ] | ||
| } | ||
| }) | ||
|
|
||
| const {result} = renderHook(() => useShopperConfiguration('SalesforcePaymentsAllowed')) | ||
|
|
||
| expect(result.current).toBe(true) | ||
| }) | ||
|
|
||
| test('returns the configuration value when configuration exists with boolean false', () => { | ||
| useConfigurations.mockReturnValue({ | ||
| data: { | ||
| configurations: [{id: 'SomeConfig', value: false}] | ||
| } | ||
| }) | ||
|
|
||
| const {result} = renderHook(() => useShopperConfiguration('SomeConfig')) | ||
|
|
||
| expect(result.current).toBe(false) | ||
| }) | ||
|
|
||
| test('returns the configuration value when configuration exists with string value', () => { | ||
| useConfigurations.mockReturnValue({ | ||
| data: { | ||
| configurations: [{id: 'StringConfig', value: 'some-string-value'}] | ||
| } | ||
| }) | ||
|
|
||
| const {result} = renderHook(() => useShopperConfiguration('StringConfig')) | ||
|
|
||
| expect(result.current).toBe('some-string-value') | ||
| }) | ||
|
|
||
| test('returns the configuration value when configuration exists with numeric value', () => { | ||
| useConfigurations.mockReturnValue({ | ||
| data: { | ||
| configurations: [{id: 'NumericConfig', value: 42}] | ||
| } | ||
| }) | ||
|
|
||
| const {result} = renderHook(() => useShopperConfiguration('NumericConfig')) | ||
|
|
||
| expect(result.current).toBe(42) | ||
| }) | ||
|
|
||
| test('returns the configuration value when configuration exists with object value', () => { | ||
| const objectValue = {key: 'value', nested: {prop: 'test'}} | ||
| useConfigurations.mockReturnValue({ | ||
| data: { | ||
| configurations: [{id: 'ObjectConfig', value: objectValue}] | ||
| } | ||
| }) | ||
|
|
||
| const {result} = renderHook(() => useShopperConfiguration('ObjectConfig')) | ||
|
|
||
| expect(result.current).toEqual(objectValue) | ||
| }) | ||
|
|
||
| test('returns undefined when configuration does not exist', () => { | ||
| useConfigurations.mockReturnValue({ | ||
| data: { | ||
| configurations: [ | ||
| {id: 'Config1', value: true}, | ||
| {id: 'Config2', value: false} | ||
| ] | ||
| } | ||
| }) | ||
|
|
||
| const {result} = renderHook(() => useShopperConfiguration('NonExistentConfig')) | ||
|
|
||
| expect(result.current).toBeUndefined() | ||
| }) | ||
|
|
||
| test('returns undefined when configurations data is undefined', () => { | ||
| useConfigurations.mockReturnValue({ | ||
| data: undefined | ||
| }) | ||
|
|
||
| const {result} = renderHook(() => useShopperConfiguration('SomeConfig')) | ||
|
|
||
| expect(result.current).toBeUndefined() | ||
| }) | ||
|
|
||
| test('returns undefined when configurations data is null', () => { | ||
| useConfigurations.mockReturnValue({ | ||
| data: null | ||
| }) | ||
|
|
||
| const {result} = renderHook(() => useShopperConfiguration('SomeConfig')) | ||
|
|
||
| expect(result.current).toBeUndefined() | ||
| }) | ||
|
|
||
| test('returns undefined when configurations array is undefined', () => { | ||
| useConfigurations.mockReturnValue({ | ||
| data: { | ||
| configurations: undefined | ||
| } | ||
| }) | ||
|
|
||
| const {result} = renderHook(() => useShopperConfiguration('SomeConfig')) | ||
|
|
||
| expect(result.current).toBeUndefined() | ||
| }) | ||
|
|
||
| test('returns undefined when configurations array is empty', () => { | ||
| useConfigurations.mockReturnValue({ | ||
| data: { | ||
| configurations: [] | ||
| } | ||
| }) | ||
|
|
||
| const {result} = renderHook(() => useShopperConfiguration('SomeConfig')) | ||
|
|
||
| expect(result.current).toBeUndefined() | ||
| }) | ||
|
|
||
| test('returns the correct configuration when multiple configurations exist', () => { | ||
| useConfigurations.mockReturnValue({ | ||
| data: { | ||
| configurations: [ | ||
| {id: 'Config1', value: 'value1'}, | ||
| {id: 'Config2', value: 'value2'}, | ||
| {id: 'Config3', value: 'value3'} | ||
| ] | ||
| } | ||
| }) | ||
|
|
||
| const {result} = renderHook(() => useShopperConfiguration('Config2')) | ||
|
|
||
| expect(result.current).toBe('value2') | ||
| }) | ||
|
|
||
| test('returns undefined when configuration exists but has no value property', () => { | ||
| useConfigurations.mockReturnValue({ | ||
| data: { | ||
| configurations: [{id: 'ConfigWithoutValue'}] | ||
| } | ||
| }) | ||
|
|
||
| const {result} = renderHook(() => useShopperConfiguration('ConfigWithoutValue')) | ||
|
|
||
| expect(result.current).toBeUndefined() | ||
| }) | ||
|
|
||
| test('returns null when configuration value is explicitly null', () => { | ||
| useConfigurations.mockReturnValue({ | ||
| data: { | ||
| configurations: [{id: 'NullConfig', value: null}] | ||
| } | ||
| }) | ||
|
|
||
| const {result} = renderHook(() => useShopperConfiguration('NullConfig')) | ||
|
|
||
| expect(result.current).toBeNull() | ||
| }) | ||
|
|
||
| test('returns 0 when configuration value is 0', () => { | ||
| useConfigurations.mockReturnValue({ | ||
| data: { | ||
| configurations: [{id: 'ZeroConfig', value: 0}] | ||
| } | ||
| }) | ||
|
|
||
| const {result} = renderHook(() => useShopperConfiguration('ZeroConfig')) | ||
|
|
||
| expect(result.current).toBe(0) | ||
| }) | ||
|
|
||
| test('returns empty string when configuration value is empty string', () => { | ||
| useConfigurations.mockReturnValue({ | ||
| data: { | ||
| configurations: [{id: 'EmptyStringConfig', value: ''}] | ||
| } | ||
| }) | ||
|
|
||
| const {result} = renderHook(() => useShopperConfiguration('EmptyStringConfig')) | ||
|
|
||
| expect(result.current).toBe('') | ||
| }) | ||
|
|
||
| test('is case-sensitive when matching configuration IDs', () => { | ||
| useConfigurations.mockReturnValue({ | ||
| data: { | ||
| configurations: [ | ||
| {id: 'SalesforcePaymentsAllowed', value: true}, | ||
| {id: 'salesforcepaymentsallowed', value: false} | ||
| ] | ||
| } | ||
| }) | ||
|
|
||
| const {result: result1} = renderHook(() => | ||
| useShopperConfiguration('SalesforcePaymentsAllowed') | ||
| ) | ||
| const {result: result2} = renderHook(() => | ||
| useShopperConfiguration('salesforcepaymentsallowed') | ||
| ) | ||
|
|
||
| expect(result1.current).toBe(true) | ||
| expect(result2.current).toBe(false) | ||
| }) | ||
| }) |
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we put this
useShopperConfiguration('SalesforcePaymentsAllowed') === truecheck in a place where it doesn't have to be duplicated? For example if a thing is already importinguseSalesforcePaymentscould that hook result include anenabledproperty?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
took a note to address this in my next iteration