-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d6c13a5
commit ebf6428
Showing
2 changed files
with
64 additions
and
6 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
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,64 @@ | ||
const util = require('./util.js'); | ||
const axios = require('axios'); | ||
const networkAdapter = require('../../../adapters/network'); | ||
const { handleHttpRequest } = networkAdapter; | ||
|
||
// Mock the handleHttpRequest function | ||
jest.mock('../../../adapters/network'); | ||
|
||
const successfulResponse = { | ||
status: 200, | ||
response: { | ||
access_token: '<dummy-access-token>', | ||
token_type: 'bearer', | ||
expires_in: 3600, | ||
scope: '[email protected]', | ||
success: true, | ||
}, | ||
}; | ||
|
||
const unsuccessfulResponse = { | ||
status: 400, | ||
response: '[ENOTFOUND] :: DNS lookup failed', | ||
}; | ||
|
||
const emptyResponse = { | ||
response: '', | ||
}; | ||
|
||
const invalidClientErrorResponse = { | ||
status: 401, | ||
response: { | ||
error: 'invalid_client', | ||
error_description: 'Bad client credentials', | ||
}, | ||
}; | ||
describe('util.getAccessToken', () => { | ||
beforeEach(() => { | ||
handleHttpRequest.mockClear(); | ||
}); | ||
|
||
it('should retrieve and return access token on successful response', async () => { | ||
const url = | ||
'https://dummyMunchkinId.mktorest.com/identity/oauth/token?client_id=dummyClientId&client_secret=dummyClientSecret&grant_type=client_credentials'; | ||
|
||
handleHttpRequest.mockResolvedValueOnce({ | ||
processedResponse: successfulResponse, | ||
}); | ||
|
||
const config = { | ||
clientId: 'dummyClientId', | ||
clientSecret: 'dummyClientSecret', | ||
munchkinId: 'dummyMunchkinId', | ||
}; | ||
|
||
const result = await util.getAccessToken(config); | ||
expect(result).toBe('<dummy-access-token>'); | ||
expect(handleHttpRequest).toHaveBeenCalledTimes(1); | ||
// Ensure your mock response structure is consistent with the actual behavior | ||
expect(handleHttpRequest).toHaveBeenCalledWith('get', url, { | ||
destType: 'marketo_bulk_upload', | ||
feature: 'transformation', | ||
}); | ||
}); | ||
}); |