Skip to content

Commit 6f1c464

Browse files
committed
fix: 🐛 split description into many entities
1 parent ec22810 commit 6f1c464

9 files changed

+38
-244
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
node_modules
2-
.env
2+
.env
3+
dist

dist/index.esm.js

-106
This file was deleted.

dist/index.js

-113
This file was deleted.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"scripts": {
99
"start": "./node_modules/.bin/nodemon --exec babel-node ./src/index.js",
1010
"test": "./node_modules/.bin/mocha --require dotenv/config --require @babel/register",
11-
"test-watch": "./node_modules/.bin/mocha --require dotenv/config --require @babel/register --watch --watch-extensions js \"test/**/*.js\"",
11+
"test:watch": "./node_modules/.bin/mocha --require dotenv/config --require @babel/register --watch --watch-extensions js \"test/**/*.js\"",
1212
"build": "./node_modules/.bin/rollup -c",
1313
"serve": "node ./dist/index.js",
1414
"debug": "babel-node --inspect-brk ./src/index.js",

src/env.js

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
import { Environment } from "./consts"
22

33
export const environment = Environment[(process.env.PAYU_ENVIRONMENT ? process.env.PAYU_ENVIRONMENT : 'sandbox').toUpperCase()]
4-
5-
console.log('test')

src/order.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,23 @@ import { environment } from './env'
66

77
const { PAYU_CLIENT_NOTIFY_SITE_URL, PAYU_CLIENT_ID } = process.env
88

9-
export default async ({ accessToken, description }) => {
9+
export default async ({ accessToken, payment, cart, buyer, products }) => {
1010
assert.ok(accessToken, 'accessToken should not be empty')
11-
assert.ok(description, 'description should not be empty')
11+
assert.ok(payment, 'payment should not be empty')
12+
assert.ok(cart, 'cart should not be empty')
13+
assert.ok(buyer, 'buyer should not be empty')
14+
assert.ok(products, 'products should not be empty')
1215

1316
try {
1417
return await post(
1518
`${environment}/api/v2_1/orders`,
1619
{
1720
notifyUrl: PAYU_CLIENT_NOTIFY_SITE_URL,
1821
merchantPosId: PAYU_CLIENT_ID,
19-
...description,
22+
...payment,
23+
...cart,
24+
...buyer,
25+
...products
2026
},
2127
{
2228
json: true,

test/authorize.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { mockAuthorize } from './server'
55

66
import { authorize } from '../src'
77

8-
const { PAYU_CLIENT_ID, PAYU_CLIENT_SECRET, PAYU_CLIENT_NOTIFY_SITE_URL } = process.env
8+
const { PAYU_CLIENT_ID, PAYU_CLIENT_SECRET } = process.env
99

1010
describe('authorize function', () => {
1111
afterEach(() => {

test/order.test.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ describe('order function', () => {
1515

1616
const response = await order({
1717
accessToken: '123131=',
18-
description: {}
18+
payment: {},
19+
cart: {},
20+
buyer: {},
21+
products: [],
1922
})
2023

2124
response.should.have.property('redirectUri')

test/orderFlow.test.js

+21-16
Original file line numberDiff line numberDiff line change
@@ -15,32 +15,37 @@ describe('order flow', () => {
1515
mockAuthorize()
1616
mockOrder()
1717

18-
const description = {
18+
const products = [
19+
{
20+
name: 'Wireless Mouse for Laptop',
21+
unitPrice: '15000',
22+
quantity: '1'
23+
}
24+
]
25+
26+
const buyer = {
27+
email: 'john.doe@example.com',
28+
phone: '654111654',
29+
firstName: 'John',
30+
lastName: 'Doe',
1931
customerIp: '127.0.0.1',
20-
description: 'RTV market',
32+
}
33+
34+
const payment = {
2135
currencyCode: 'PLN',
2236
totalAmount: '15000',
23-
buyer: {
24-
email: 'john.doe@example.com',
25-
phone: '654111654',
26-
firstName: 'John',
27-
lastName: 'Doe'
28-
},
29-
products: [
30-
{
31-
name: 'Wireless Mouse for Laptop',
32-
unitPrice: '15000',
33-
quantity: '1'
34-
}
35-
]
37+
}
38+
39+
const cart = {
40+
description: 'RTV market',
3641
}
3742

3843
const { accessToken } = await authorize({
3944
clientSecret: PAYU_CLIENT_SECRET,
4045
clientId: PAYU_CLIENT_ID,
4146
grantType: 'client_credentials'
4247
})
43-
const response = await order({ accessToken, description })
48+
const response = await order({ accessToken, payment, cart, buyer, products })
4449

4550
response.should.have.property('redirectUri')
4651
response.should.have.property('orderId')

0 commit comments

Comments
 (0)