diff --git a/src/v0/destinations/marketo_bulk_upload/util.js b/src/v0/destinations/marketo_bulk_upload/util.js index c4d7ce22fa..b3714e982d 100644 --- a/src/v0/destinations/marketo_bulk_upload/util.js +++ b/src/v0/destinations/marketo_bulk_upload/util.js @@ -36,11 +36,6 @@ const hydrateStatusForServer = (statusCode, context) => { return status; }; -// const getAccessTokenCacheKey = (config = {}) => { -// const { munchkinId, clientId, clientSecret } = config; -// return `${munchkinId}-${clientId}-${clientSecret}`; -// }; - /** * Handles common error responses returned from API calls. * Checks the error code and throws the appropriate error object based on the code. @@ -74,7 +69,6 @@ const handleCommonErrorResponse = (apiCallResult, OpErrorMessage, OpActivity) => // checking for invalid/expired token errors and evicting cache in that case // rudderJobMetadata contains some destination info which is being used to evict the cache if ( - // authCache && apiCallResult.response?.errors && apiCallResult.response?.errors?.length > 0 && apiCallResult.response?.errors.some( diff --git a/src/v0/destinations/marketo_bulk_upload/util.test.js b/src/v0/destinations/marketo_bulk_upload/util.test.js new file mode 100644 index 0000000000..dba1dfdd38 --- /dev/null +++ b/src/v0/destinations/marketo_bulk_upload/util.test.js @@ -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: '', + token_type: 'bearer', + expires_in: 3600, + scope: 'dummy@scope.com', + 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(''); + 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', + }); + }); +});