diff --git a/CHANGELOG.md b/CHANGELOG.md index 14d22f1..066f4bc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] +### Fixed + +- Adjust payment terms on cost center + ## [1.11.2] - 2024-06-12 ### Fixed diff --git a/node/package.json b/node/package.json index 1d6f9c5..e38aea2 100644 --- a/node/package.json +++ b/node/package.json @@ -2,7 +2,7 @@ "name": "vtex.b2b-organizations", "version": "1.11.2", "dependencies": { - "@vtex/api": "6.46.0", + "@vtex/api": "6.47.0", "atob": "^2.1.2", "co-body": "^6.0.0", "graphql": "^14.5.0", diff --git a/node/resolvers/Routes/index.test.ts b/node/resolvers/Routes/index.test.ts index c92accc..006447b 100644 --- a/node/resolvers/Routes/index.test.ts +++ b/node/resolvers/Routes/index.test.ts @@ -15,11 +15,48 @@ const getAddressMocked = jest.fn().mockResolvedValueOnce({ getCostCenterById: { addresses: {}, customFields: {}, - paymentTerms: [{ id: costCenterPaymentTerms }], + paymentTerms: [ + { id: costCenterPaymentTerms, name: costCenterPaymentTerms }, + ], }, }, }) +const getOrganizationMocked = jest + .fn() + .mockImplementationOnce(() => + Promise.resolve({ + data: { + getOrganizationById: { + addresses: {}, + customFields: {}, + paymentTerms: [ + { + id: costCenterPaymentTerms, + name: costCenterPaymentTerms, + }, + ], + }, + }, + }) + ) + .mockImplementationOnce(() => + Promise.resolve({ + data: { + getOrganizationById: { + addresses: {}, + customFields: {}, + paymentTerms: [ + { + id: organizationPaymentTerms, + name: organizationPaymentTerms, + }, + ], + }, + }, + }) + ) + const mockContext = () => { return { clients: { @@ -28,15 +65,7 @@ const mockContext = () => { }, organizations: { getAddresses: getAddressMocked, - getOrganization: jest.fn().mockResolvedValueOnce({ - data: { - getOrganizationById: { - addresses: {}, - customFields: {}, - paymentTerms: [{ id: organizationPaymentTerms }], - }, - }, - }), + getOrganization: getOrganizationMocked, }, session: { getSession: jest.fn().mockResolvedValueOnce({ @@ -80,6 +109,7 @@ describe('given Routes to call b2b checkout settings', () => { context = mockContext() await index.settings(context) }) + it('should return payments terms from cost center', () => { const { response } = context @@ -97,6 +127,7 @@ describe('given Routes to call b2b checkout settings', () => { ).toBeFalsy() }) }) + describe('when have just the organization with payment terms', () => { let context: Context @@ -110,9 +141,11 @@ describe('given Routes to call b2b checkout settings', () => { }, }, }) + context = mockContext() await index.settings(context) }) + it('should return payments terms from organization', () => { const { response } = context diff --git a/node/resolvers/Routes/index.ts b/node/resolvers/Routes/index.ts index 95445a1..b330e67 100644 --- a/node/resolvers/Routes/index.ts +++ b/node/resolvers/Routes/index.ts @@ -1,3 +1,5 @@ +import type { PaymentTerm } from 'vtex.b2b-organizations-graphql' + import { DEFAULTS, VBASE_BUCKET, VBASE_SETTINGS_FILE } from '../constants' const CACHE = 180 @@ -224,6 +226,20 @@ export default { } }) + // fix to only show the payment terms that are in common between the organization and the cost center + if (settings.paymentTerms && getOrganizationById?.paymentTerms) { + const intersection = settings.paymentTerms.filter( + (ccPaymentTerms: PaymentTerm) => + getOrganizationById.paymentTerms.some( + (orgPaymentTerms: PaymentTerm) => + ccPaymentTerms.id === orgPaymentTerms.id && + ccPaymentTerms.name === orgPaymentTerms.name + ) + ) + + settings.paymentTerms = intersection + } + if (!settings.paymentTerms && getOrganizationById?.paymentTerms) { settings.paymentTerms = getOrganizationById.paymentTerms } diff --git a/node/yarn.lock b/node/yarn.lock index 67f74fa..8a6f410 100644 --- a/node/yarn.lock +++ b/node/yarn.lock @@ -857,10 +857,10 @@ dependencies: "@types/yargs-parser" "*" -"@vtex/api@6.46.0": - version "6.46.0" - resolved "https://registry.yarnpkg.com/@vtex/api/-/api-6.46.0.tgz#208d14b96cbc8fd5eb6bd18fbd0c8424886e6154" - integrity sha512-XAvJlD1FG1GynhPXiMcayunahFCL2r3ilO5MHAWKxYvB/ljyxi4+U+rVpweeaQGpxHfhKHdfPe7qNEEh2oa2lw== +"@vtex/api@6.47.0": + version "6.47.0" + resolved "https://registry.yarnpkg.com/@vtex/api/-/api-6.47.0.tgz#6910455d593d8bb76f1f4f2b7660023853fda35e" + integrity sha512-t9gt7Q89EMbSj3rLhho+49Fv+/lQgiy8EPVRgtmmXFp1J4v8hIAZF7GPjCPie111KVs4eG0gfZFpmhA5dafKNA== dependencies: "@types/koa" "^2.11.0" "@types/koa-compose" "^3.2.3" @@ -3615,7 +3615,7 @@ stack-utils@^2.0.3: dependencies: escape-string-regexp "^2.0.0" -stats-lite@vtex/node-stats-lite#dist: +"stats-lite@github:vtex/node-stats-lite#dist": version "2.2.0" resolved "https://codeload.github.com/vtex/node-stats-lite/tar.gz/1b0d39cc41ef7aaecfd541191f877887a2044797" dependencies: