Skip to content

Commit 0b3be6e

Browse files
authored
Merge pull request #5 from hiddenboox/feature/grant-type
Feature/grant type
2 parents b6118c1 + 55cd066 commit 0b3be6e

File tree

3 files changed

+37
-16
lines changed

3 files changed

+37
-16
lines changed

src/consts.js

+12-9
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,27 @@
11
export const ContentType = {
2-
JSON: 'application/json'
2+
JSON: 'application/json'
33
}
44

55
export const HEADERS = {
6-
Authorization: 'Authorization',
7-
'Content-Type': 'Content-Type'
6+
Authorization: 'Authorization',
7+
'Content-Type': 'Content-Type'
88
}
99

1010
export const HttpVerb = {
11-
POST: 'POST',
12-
GET: 'GET',
11+
POST: 'POST',
12+
GET: 'GET'
1313
}
1414

1515
export const EnvironmentName = {
16-
SANDBOX: 'SANDBOX',
17-
PRODUCTION: 'PRODUCTION',
16+
SANDBOX: 'SANDBOX',
17+
PRODUCTION: 'PRODUCTION'
1818
}
1919

2020
export const Environment = {
21-
[EnvironmentName.SANDBOX]: 'https://secure.snd.payu.com',
22-
[EnvironmentName.PRODUCTION]: 'https://secure.payu.com',
21+
[EnvironmentName.SANDBOX]: 'https://secure.snd.payu.com',
22+
[EnvironmentName.PRODUCTION]: 'https://secure.payu.com'
2323
}
2424

25+
export const GrantType = {
26+
ClientCredentials: 'client_credentials'
27+
}

src/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export { default as authorize } from './authorize'
22
export { default as order } from './order'
3+
export { GrantType } from './consts'

test/authorize.test.js test/unit/authorize.test.js

+24-7
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@ import nock from 'nock'
22
import assert from 'assert'
33
import { expect } from 'chai'
44

5-
import { mockAuthorize } from './server'
6-
7-
import { authorize } from '../src'
5+
import { mockAuthorize } from '../server'
6+
import { authorize, GrantType } from '../../src'
87

98
const { PAYU_CLIENT_ID, PAYU_CLIENT_SECRET } = process.env
109

@@ -19,7 +18,7 @@ describe('authorize function', () => {
1918
const response = await authorize({
2019
clientSecret: PAYU_CLIENT_SECRET,
2120
clientId: PAYU_CLIENT_ID,
22-
grantType: 'client_credentials',
21+
grantType: GrantType.ClientCredentials
2322
})
2423

2524
response.should.have.property('accessToken')
@@ -32,23 +31,41 @@ describe('authorize function', () => {
3231
try {
3332
await authorize()
3433
} catch (err) {
35-
should.throw(() => { throw err }, assert.AssertionError, 'PAYU_CLIENT_ID should not be empty')
34+
should.throw(
35+
() => {
36+
throw err
37+
},
38+
assert.AssertionError,
39+
'PAYU_CLIENT_ID should not be empty'
40+
)
3641
}
3742
})
3843

3944
it('should return validation error on PAYU_CLIENT_SECRET when field is not provided', async () => {
4045
try {
4146
await authorize({ clientId: 2 })
4247
} catch (err) {
43-
should.throw(() => { throw err }, assert.AssertionError, 'PAYU_CLIENT_SECRET should not be empty')
48+
should.throw(
49+
() => {
50+
throw err
51+
},
52+
assert.AssertionError,
53+
'PAYU_CLIENT_SECRET should not be empty'
54+
)
4455
}
4556
})
4657

4758
it('should return validation error on grantType when field is not provided', async () => {
4859
try {
4960
await authorize({ clientId: 2, clientSecret: 2 })
5061
} catch (err) {
51-
should.throw(() => { throw err }, assert.AssertionError, 'grantType should not be empty')
62+
should.throw(
63+
() => {
64+
throw err
65+
},
66+
assert.AssertionError,
67+
'grantType should not be empty'
68+
)
5269
}
5370
})
5471
})

0 commit comments

Comments
 (0)