Skip to content

Commit

Permalink
Merge pull request #59 from vtex-apps/hotfix/B2BTEAM-1244-get-payment…
Browse files Browse the repository at this point in the history
…s-terms-from-cost-center

hotfix: get payments terms from cost center
  • Loading branch information
Rudge authored Jul 12, 2023
2 parents 7645c2c + f46071d commit 40b15d5
Show file tree
Hide file tree
Showing 16 changed files with 2,673 additions and 127 deletions.
27 changes: 27 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#### What problem is this solving?

<!--- What is the motivation and context for this change? -->

#### How to test it?

<!--- Don't forget to add a link to a Workspace where this branch is linked -->

[Workspace](Link goes here!)

#### Screenshots or example usage:

<!--- Add some images or gifs to showcase changes in behaviour or layout. Example: before and after images -->

#### Describe alternatives you've considered, if any.

<!--- Optional -->

#### Related to / Depends on

<!--- Optional -->

#### How does this PR make you feel? [:link:](http://giphy.com/)

<!-- Go to http://giphy.com/ and pick a gif that represents how this PR makes you feel -->

![](put .gif link here - can be found under "advanced" on giphy)
2 changes: 1 addition & 1 deletion .github/workflows/qe-pull-request-target.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
danger: true
dangerRequireChangelog: false
nodeLint: true
nodeTest: false
nodeTest: true
reactTest: false
nodeSonar: true
nodeSonarProjectKey: vtex-apps_b2b-checkout-settings
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/qe-pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
danger: true
dangerRequireChangelog: false
nodeLint: true
nodeTest: false
nodeTest: true
reactTest: false
nodeSonar: true
nodeSonarProjectKey: vtex-apps_b2b-checkout-settings
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/qe-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
uses: vtex-apps/usqa/.github/workflows/quality-engineering.yml@v2
with:
nodeLint: true
nodeTest: false
nodeTest: true
nodeSonar: true
nodeSonarProjectKey: vtex-apps_b2b-checkout-settings
nodeSonarOrganization: vtex-apps
Expand Down
2 changes: 2 additions & 0 deletions .vtexignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ src/
.gitignore
gulpfile.js
tsconfig.json
**/*.test.*
**/*.mock.*
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Fixed
- Use payment terms from the cost center when it is configured instead of the organization

## [1.9.5] - 2023-06-30
### Fixed
Expand Down
21 changes: 21 additions & 0 deletions node/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/** @type {import("jest").Config} */

module.exports = {
projects: [
{
globals: {
'ts-jest': {
tsConfig: '<rootDir>/tsconfig.json',
},
},
moduleFileExtensions: ['ts', 'tsx', 'js'],
preset: 'ts-jest',
testEnvironment: 'node',
testEnvironmentOptions: {},
testMatch: ['<rootDir>/**/?(*.)+(spec|test).(js|ts)?(x)'],
transform: {
'^.+\\.tsx?$': 'ts-jest',
},
},
],
}
15 changes: 10 additions & 5 deletions 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.9.5",
"dependencies": {
"@vtex/api": "6.45.15",
"@vtex/api": "6.45.18",
"atob": "^2.1.2",
"co-body": "^6.0.0",
"graphql": "^14.5.0",
Expand All @@ -12,17 +12,21 @@
"ramda": "^0.25.0"
},
"devDependencies": {
"@ngneat/falso": "^6.4.0",
"@types/atob": "^2.1.2",
"@types/bluebird": "^3.5.25",
"@types/co-body": "0.0.3",
"@types/graphql": "^14.5.0",
"@types/jest": "^27.0.2",
"@types/jest": "27.4.1",
"@types/jsonwebtoken": "^8.5.0",
"@types/node": "^12.0.0",
"@types/node": "^12.12.21",
"@types/ramda": "types/npm-ramda#dist",
"@vtex/api": "6.45.15",
"@vtex/api": "6.45.18",
"@vtex/prettier-config": "^0.3.1",
"@vtex/tsconfig": "^0.6.0",
"jest": "27.5.1",
"ts-jest": "^27.1.4",
"ts-node": "^10.9.1",
"tslint": "^5.12.0",
"tslint-config-prettier": "^1.18.0",
"tslint-config-vtex": "^2.1.0",
Expand All @@ -32,6 +36,7 @@
"vtex.styleguide": "http://vtex.vtexassets.com/_v/public/typings/v1/[email protected]/public/@types/vtex.styleguide"
},
"scripts": {
"lint": "tsc --noEmit && tslint -c tslint.json './**/*.ts'"
"lint": "tsc --noEmit && tslint -c tslint.json './**/*.ts'",
"test": "jest"
}
}
139 changes: 139 additions & 0 deletions node/resolvers/Routes/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
import { randUuid } from '@ngneat/falso'
import type { PaymentTerm } from 'vtex.b2b-organizations-graphql'

import index from './index'

const costCenterPaymentTerms = 'costCenterPaymentTerms'
const organizationPaymentTerms = 'organizationPaymentTerms'

const graphQLQuery = jest.fn()

interface ResponseBody {
paymentTerms: PaymentTerm[]
}

const mockContext = () => {
return {
clients: {
graphQLServer: {
query: graphQLQuery
.mockResolvedValueOnce({ data: {} })
.mockResolvedValueOnce({
data: {
getCostCenterById: {
addresses: {},
customFields: {},
paymentTerms: [{ id: costCenterPaymentTerms }],
},
},
})
.mockResolvedValueOnce({
data: {
getOrganizationById: {
addresses: {},
customFields: {},
paymentTerms: [{ id: organizationPaymentTerms }],
},
},
}),
},
session: {
getSession: jest.fn().mockResolvedValueOnce({
sessionData: {
namespaces: {
'storefront-permissions': {
costcenter: {
value: randUuid(),
},
organization: {
value: randUuid(),
},
},
},
},
}),
},
vbase: {
getJSON: jest.fn().mockResolvedValueOnce({}),
},
},
response: {} as Response,
set: jest.fn(),
vtex: {
logger: jest.fn(),
sessionToken: jest.fn().mockResolvedValueOnce({}),
storeUserAuthToken: jest.fn().mockResolvedValueOnce({ data: {} }),
},
} as unknown as Context
}

describe('given Routes to call b2b checkout settings', () => {
describe('when have the cost center and organization with payment terms', () => {
let context: Context

beforeEach(async () => {
context = mockContext()
await index.settings(context)
})
it('should return payments terms from cost center', () => {
const { response } = context

expect(response.status).toEqual(200)
expect(
(response.body as ResponseBody)?.paymentTerms.some(
(item: PaymentTerm) => item.id === costCenterPaymentTerms
)
).toBeTruthy()

expect(
(response.body as ResponseBody)?.paymentTerms.some(
(item: PaymentTerm) => item.id === organizationPaymentTerms
)
).toBeFalsy()
})
})
describe('when have just the organization with payment terms', () => {
let context: Context

beforeEach(async () => {
graphQLQuery
.mockResolvedValueOnce({ data: {} })
.mockResolvedValueOnce({
data: {
getCostCenterById: {
addresses: {},
customFields: {},
paymentTerms: [],
},
},
})
.mockResolvedValueOnce({
data: {
getOrganizationById: {
addresses: {},
customFields: {},
paymentTerms: [{ id: organizationPaymentTerms }],
},
},
})
context = mockContext()
await index.settings(context)
})
it('should return payments terms from organization', () => {
const { response } = context

expect(response.status).toEqual(200)
expect(
(response.body as ResponseBody)?.paymentTerms.some(
(item: PaymentTerm) => item.id === costCenterPaymentTerms
)
).toBeFalsy()

expect(
(response.body as ResponseBody)?.paymentTerms.some(
(item: PaymentTerm) => item.id === organizationPaymentTerms
)
).toBeTruthy()
})
})
})
14 changes: 9 additions & 5 deletions node/resolvers/Routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default {
} else {
const accountSettings: any = await vbase

Check warning on line 26 in node/resolvers/Routes/index.ts

View workflow job for this annotation

GitHub Actions / QE / Lint Node.js

Unexpected any. Specify a different type
.getJSON(VBASE_BUCKET, VBASE_SETTINGS_FILE, true)
.catch(error => {
.catch((error) => {
logger.error({
message: 'settings-getJSON-error',
error,
Expand All @@ -35,7 +35,7 @@ export default {
if (accountSettings?.showPONumber && !accountSettings?.hasPONumber) {
const checkoutConfig: any = await checkout

Check warning on line 36 in node/resolvers/Routes/index.ts

View workflow job for this annotation

GitHub Actions / QE / Lint Node.js

Unexpected any. Specify a different type
.getOrderFormConfiguration()
.catch(error => {
.catch((error) => {
logger.error({
message: 'settings-getOrderformConfiguration-error',
error,
Expand All @@ -59,7 +59,7 @@ export default {
const setCheckoutConfig: any = await checkout

Check warning on line 59 in node/resolvers/Routes/index.ts

View workflow job for this annotation

GitHub Actions / QE / Lint Node.js

Unexpected any. Specify a different type
.setOrderFormConfiguration(checkoutConfig, ctx.vtex.authToken)
.then(() => true)
.catch(error => {
.catch((error) => {
accountSettings.hasPONumber = false

logger.error({
Expand All @@ -73,7 +73,7 @@ export default {
if (setCheckoutConfig) {
await vbase
.saveJSON(VBASE_BUCKET, VBASE_SETTINGS_FILE, accountSettings)
.catch(error => {
.catch((error) => {
logger.error({
message: 'settings-saveJSON-error',
error,
Expand Down Expand Up @@ -119,7 +119,7 @@ export default {
.then((currentSession: any) => {

Check warning on line 119 in node/resolvers/Routes/index.ts

View workflow job for this annotation

GitHub Actions / QE / Lint Node.js

Unexpected any. Specify a different type
return currentSession.sessionData
})
.catch(error => {
.catch((error) => {
logger.error({
message: 'getSession-error',
error,
Expand Down Expand Up @@ -194,6 +194,10 @@ export default {
if (getCostCenterById?.customFields) {
settings.costCenterCustomFields = getCostCenterById.customFields
}

if (getCostCenterById?.paymentTerms.length > 0) {
settings.paymentTerms = getCostCenterById.paymentTerms
}
}

if (
Expand Down
8 changes: 7 additions & 1 deletion node/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
"extends": "@vtex/tsconfig",
"include": ["./typings/*.d.ts", "./**/*.tsx", "./**/*.ts"],
"compilerOptions": {
"types": ["node", "jest"]
"noEmitOnError": false,
"lib": ["dom"],
"module": "commonjs",
"moduleResolution": "node",
"target": "es2019",
"esModuleInterop": true,
"skipLibCheck": true
}
}
Loading

0 comments on commit 40b15d5

Please sign in to comment.