From 5bf6f7e35f0069ac3bab0f3fe134ffc76b9d6293 Mon Sep 17 00:00:00 2001 From: Icaro Oliveira Date: Thu, 4 Jul 2024 12:10:49 -0300 Subject: [PATCH 1/4] fix: adjust payment terms on cost center --- CHANGELOG.md | 4 +++ node/package.json | 2 +- node/resolvers/Routes/index.test.ts | 53 +++++++++++++++++++++++------ node/resolvers/Routes/index.ts | 16 +++++++++ node/yarn.lock | 10 +++--- 5 files changed, 69 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 14d22f1..b020341 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Fixed +- Adjust payment terms on cost center + +### Fixed + - Add catalog-info.yaml ## [1.11.1] - 2023-12-15 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: From a2a6b4f37301288f783648f6d4ef807a107a4cf4 Mon Sep 17 00:00:00 2001 From: Icaro Oliveira Date: Thu, 11 Jul 2024 13:59:46 -0300 Subject: [PATCH 2/4] fix: updates changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b020341..8974127 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Fixed +- Adjust payment terms on cost center + +### Fixed + - Provide correct tokens to clients ### Fixed From ca4eb02dc30553dc0cb0ff2186d2026d92ccfe6c Mon Sep 17 00:00:00 2001 From: Icaro Oliveira Date: Thu, 11 Jul 2024 14:02:09 -0300 Subject: [PATCH 3/4] fix: updates changelog --- CHANGELOG.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8974127..c9014e2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,10 +19,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Fixed -- Adjust payment terms on cost center - -### Fixed - - Add catalog-info.yaml ## [1.11.1] - 2023-12-15 From 92095c63f366bcd461d9525f3aa02306a2fd0bfe Mon Sep 17 00:00:00 2001 From: Icaro Oliveira Date: Thu, 11 Jul 2024 18:30:37 -0300 Subject: [PATCH 4/4] fix: updates changelog --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c9014e2..066f4bc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,12 +7,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] -## [1.11.2] - 2024-06-12 - ### Fixed - Adjust payment terms on cost center +## [1.11.2] - 2024-06-12 + ### Fixed - Provide correct tokens to clients