Skip to content

Commit

Permalink
Remove all undefined/null values
Browse files Browse the repository at this point in the history
  • Loading branch information
orgads committed Nov 10, 2024
1 parent 9564b3b commit 615e92a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/oauth.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ export function oauth (axios, { url, ...credentials }) {
...moreCredentials
}

// remove blank scope
if ('scope' in body && !body.scope) {
delete body.scope
// remove all blank values
for (const key of Object.keys(body)) {
if (!body[key])
delete body[key]
}

return axios({
Expand Down
20 changes: 20 additions & 0 deletions src/oauth.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,26 @@ describe('oauth()', function () {
})
})

test('should omit any null or undefined value', async function () {
const params = {
url: 'https://oauth.com/2.0/token',
grant_type: 'client_credentials',
client_id: undefined,
client_secret: undefined,
scope: null
}

const actualConfig = {}
const auth = oauth(fakeAxios(actualConfig), params)
await auth()

assert.deepStrictEqual(actualConfig, {
url: 'https://oauth.com/2.0/token',
method: 'post',
data: 'grant_type=client_credentials'
})
})

test('should resolve to the OAuth token response', async function () {
const expectedData = { access_token: 'FAKE_TOKEN', expires_in: 5 }
const auth = oauth(fakeAxios({}, expectedData), {})
Expand Down

0 comments on commit 615e92a

Please sign in to comment.