Skip to content
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

fix: Payment Terms changes not applied in the B2B Checkout Settings #69

Merged
merged 4 commits into from
Jul 15, 2024
Merged
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
53 changes: 43 additions & 10 deletions node/resolvers/Routes/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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({
Expand Down Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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

Expand Down
16 changes: 16 additions & 0 deletions node/resolvers/Routes/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { PaymentTerm } from 'vtex.b2b-organizations-graphql'

import { DEFAULTS, VBASE_BUCKET, VBASE_SETTINGS_FILE } from '../constants'

const CACHE = 180
Expand Down Expand Up @@ -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
}
Expand Down
10 changes: 5 additions & 5 deletions node/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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:
Expand Down