Skip to content

Commit 615e92a

Browse files
committed
Remove all undefined/null values
Fixes #40
1 parent 9564b3b commit 615e92a

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

src/oauth.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ export function oauth (axios, { url, ...credentials }) {
55
...moreCredentials
66
}
77

8-
// remove blank scope
9-
if ('scope' in body && !body.scope) {
10-
delete body.scope
8+
// remove all blank values
9+
for (const key of Object.keys(body)) {
10+
if (!body[key])
11+
delete body[key]
1112
}
1213

1314
return axios({

src/oauth.test.js

+20
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,26 @@ describe('oauth()', function () {
7070
})
7171
})
7272

73+
test('should omit any null or undefined value', async function () {
74+
const params = {
75+
url: 'https://oauth.com/2.0/token',
76+
grant_type: 'client_credentials',
77+
client_id: undefined,
78+
client_secret: undefined,
79+
scope: null
80+
}
81+
82+
const actualConfig = {}
83+
const auth = oauth(fakeAxios(actualConfig), params)
84+
await auth()
85+
86+
assert.deepStrictEqual(actualConfig, {
87+
url: 'https://oauth.com/2.0/token',
88+
method: 'post',
89+
data: 'grant_type=client_credentials'
90+
})
91+
})
92+
7393
test('should resolve to the OAuth token response', async function () {
7494
const expectedData = { access_token: 'FAKE_TOKEN', expires_in: 5 }
7595
const auth = oauth(fakeAxios({}, expectedData), {})

0 commit comments

Comments
 (0)