-
Notifications
You must be signed in to change notification settings - Fork 81
feat(core): B2B contract switcher in the account drawer #3390
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
Open
rodrigo-tavares
wants to merge
20
commits into
dev
Choose a base branch
from
feat/suma-contracts-switcher
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 6 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
6a13c8c
chore: lern force-publish release
lemagnetic e9b2105
fix: fix vtex message
lemagnetic 516e784
[no ci] Release: 4.2.1
lemagnetic da907bc
chore: revert accidental 4.2.1 release (#3375) [skip ci]
lemagnetic a0c982a
feat: add B2B contract switcher to the FastStore account drawer
rodrigo-tavares 2fa360f
feat(core): wire contract switcher to real SDK hooks and remove UI mocks
rodrigo-tavares 54bd372
fix: address contract switcher PR review feedback
rodrigo-tavares ba36ccd
chore: merge dev and add contract switcher SDD spec
rodrigo-tavares 18dfa15
fix(core): resolve Sonar issues in contract switcher
rodrigo-tavares 1dbcbdd
refactor(api): load availableContracts via buyer-portal store-front BFF
rodrigo-tavares 04c5060
feat(core): wire contract switch to session and switch-properties
rodrigo-tavares 8c75f56
chore: merge dev and resolve contract switcher conflicts
rodrigo-tavares 95c634d
fix: correct availableContracts cacheControl and local-only dev config
rodrigo-tavares c3b4a20
style(api): format availableContracts cacheControl directive
rodrigo-tavares beb90a7
fix(core): add switchError to ContractSwitcherContentProps
rodrigo-tavares 17aaa9d
fix(core): resolve Sonar issues and raise new-code test coverage
rodrigo-tavares d9f0430
style(core): compare globalThis.window with undefined directly
rodrigo-tavares 4a9c204
test: raise contract switcher new-code coverage for Sonar gate
rodrigo-tavares bc6d1f5
fix(core): apply auth cookie from contract switch response
rodrigo-tavares 6072feb
fix(core): address CodeRabbit review for contract switcher
rodrigo-tavares 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
147 changes: 147 additions & 0 deletions
147
packages/api/test/unit/platforms/vtex/resolvers/availableContracts.test.ts
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,147 @@ | ||
| import { beforeEach, describe, expect, it, vi } from 'vitest' | ||
|
|
||
| import { Query } from '../../../../../src/platforms/vtex/resolvers/query' | ||
|
|
||
| const getScopesByOrgUnit = vi.fn() | ||
| const getContractById = vi.fn() | ||
| const session = vi.fn() | ||
|
|
||
| const makeCtx = () => | ||
| ({ | ||
| clients: { | ||
| commerce: { | ||
| units: { getScopesByOrgUnit }, | ||
| masterData: { getContractById }, | ||
| session, | ||
| }, | ||
| }, | ||
| }) as any | ||
|
|
||
| const availableContracts = (Query as any).availableContracts | ||
|
|
||
| beforeEach(() => { | ||
| vi.clearAllMocks() | ||
| // Default: active contract id resolves to "b" via the session profile id. | ||
| session.mockResolvedValue({ | ||
| namespaces: { profile: { id: { value: 'b' } } }, | ||
| }) | ||
| }) | ||
|
|
||
| describe('Query.availableContracts', () => { | ||
| it('throws when orgUnitId is missing', async () => { | ||
| await expect( | ||
| availableContracts(null, { orgUnitId: '' }, makeCtx()) | ||
| ).rejects.toThrow(/orgUnitId/i) | ||
| expect(getScopesByOrgUnit).not.toHaveBeenCalled() | ||
| }) | ||
|
|
||
| it('lists the Org Unit contracts by corporate name and flags the active one', async () => { | ||
| getScopesByOrgUnit.mockResolvedValue({ | ||
| organizationUnitId: 'unit-1', | ||
| scopes: [{ scope: 'contract', ids: ['a', 'b', 'c'] }], | ||
| }) | ||
| getContractById.mockImplementation( | ||
| ({ contractId }: { contractId: string }) => | ||
| Promise.resolve({ corporateName: `Corp ${contractId.toUpperCase()}` }) | ||
| ) | ||
|
|
||
| const result = await availableContracts( | ||
| null, | ||
| { orgUnitId: 'unit-1' }, | ||
| makeCtx() | ||
| ) | ||
|
|
||
| expect(getScopesByOrgUnit).toHaveBeenCalledWith({ orgUnitId: 'unit-1' }) | ||
| // Governance + name resolution: corporate names, never raw IDs. | ||
| expect(result).toEqual([ | ||
| { id: 'a', corporateName: 'Corp A', isActive: false }, | ||
| { id: 'b', corporateName: 'Corp B', isActive: true }, | ||
| { id: 'c', corporateName: 'Corp C', isActive: false }, | ||
| ]) | ||
| }) | ||
|
|
||
| it('returns an empty list when the Org Unit has no contracts', async () => { | ||
| getScopesByOrgUnit.mockResolvedValue({ | ||
| organizationUnitId: 'unit-1', | ||
| scopes: [], | ||
| }) | ||
|
|
||
| const result = await availableContracts( | ||
| null, | ||
| { orgUnitId: 'unit-1' }, | ||
| makeCtx() | ||
| ) | ||
|
|
||
| expect(result).toEqual([]) | ||
| expect(getContractById).not.toHaveBeenCalled() | ||
| }) | ||
|
|
||
| it('isolates per-contract resolution failures', async () => { | ||
| getScopesByOrgUnit.mockResolvedValue({ | ||
| organizationUnitId: 'unit-1', | ||
| scopes: [{ scope: 'contract', ids: ['a', 'b'] }], | ||
| }) | ||
| getContractById.mockImplementation( | ||
| ({ contractId }: { contractId: string }) => | ||
| contractId === 'a' | ||
| ? Promise.reject(new Error('MasterData down')) | ||
| : Promise.resolve({ corporateName: 'Corp B' }) | ||
| ) | ||
|
|
||
| const result = await availableContracts( | ||
| null, | ||
| { orgUnitId: 'unit-1' }, | ||
| makeCtx() | ||
| ) | ||
|
|
||
| expect(result).toEqual([ | ||
| { id: 'b', corporateName: 'Corp B', isActive: true }, | ||
| ]) | ||
| }) | ||
|
|
||
| it('skips contracts that have no corporate name', async () => { | ||
| getScopesByOrgUnit.mockResolvedValue({ | ||
| organizationUnitId: 'unit-1', | ||
| scopes: [{ scope: 'contract', ids: ['a', 'b'] }], | ||
| }) | ||
| getContractById.mockImplementation( | ||
| ({ contractId }: { contractId: string }) => | ||
| contractId === 'a' | ||
| ? Promise.resolve({ corporateName: '' }) | ||
| : Promise.resolve({ corporateName: 'Corp B' }) | ||
| ) | ||
|
|
||
| const result = await availableContracts( | ||
| null, | ||
| { orgUnitId: 'unit-1' }, | ||
| makeCtx() | ||
| ) | ||
|
|
||
| expect(result).toEqual([ | ||
| { id: 'b', corporateName: 'Corp B', isActive: true }, | ||
| ]) | ||
| }) | ||
|
|
||
| it('deduplicates contract ids across scopes', async () => { | ||
| getScopesByOrgUnit.mockResolvedValue({ | ||
| organizationUnitId: 'unit-1', | ||
| scopes: [ | ||
| { scope: 'contract', ids: ['a', 'b'] }, | ||
| { scope: 'price', ids: ['b'] }, | ||
| ], | ||
| }) | ||
| getContractById.mockImplementation( | ||
| ({ contractId }: { contractId: string }) => | ||
| Promise.resolve({ corporateName: `Corp ${contractId.toUpperCase()}` }) | ||
| ) | ||
|
|
||
| const result = await availableContracts( | ||
| null, | ||
| { orgUnitId: 'unit-1' }, | ||
| makeCtx() | ||
| ) | ||
|
|
||
| expect(result).toHaveLength(2) | ||
| expect(getContractById).toHaveBeenCalledTimes(2) | ||
| }) | ||
| }) |
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.
Uh oh!
There was an error while loading. Please reload this page.