-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #59 from vtex-apps/hotfix/B2BTEAM-1244-get-payment…
…s-terms-from-cost-center hotfix: get payments terms from cost center
- Loading branch information
Showing
16 changed files
with
2,673 additions
and
127 deletions.
There are no files selected for viewing
This file contains 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,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) |
This file contains 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 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 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 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 |
---|---|---|
|
@@ -11,3 +11,5 @@ src/ | |
.gitignore | ||
gulpfile.js | ||
tsconfig.json | ||
**/*.test.* | ||
**/*.mock.* |
This file contains 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 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,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', | ||
}, | ||
}, | ||
], | ||
} |
This file contains 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 |
---|---|---|
|
@@ -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", | ||
|
@@ -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", | ||
|
@@ -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" | ||
} | ||
} |
This file contains 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,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() | ||
}) | ||
}) | ||
}) |
This file contains 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 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.