Skip to content

Commit

Permalink
fix: removing console logs
Browse files Browse the repository at this point in the history
  • Loading branch information
shrouti1507 committed Jan 25, 2024
1 parent d6c13a5 commit ebf6428
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 6 deletions.
6 changes: 0 additions & 6 deletions src/v0/destinations/marketo_bulk_upload/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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(
Expand Down
64 changes: 64 additions & 0 deletions src/v0/destinations/marketo_bulk_upload/util.test.js
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',
});
});
});

0 comments on commit ebf6428

Please sign in to comment.