Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: removed previous logs and added new relic logs #786

Merged
merged 2 commits into from
Aug 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions src/subscription/data/status/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,17 @@ export const subscriptionStatusReducer = (state = subscriptionStatusInitialState
case SUBSCRIPTION_STATUS_RECEIVED: return {
...state,
...action.payload,
// Checking if 3DS leads to neither `succeeded` nor `requires_payment_method`
// then setting status to `requires_payment_method`
// eslint-disable-next-line no-nested-ternary
status: CONFIRMATION_STATUS[action.payload.status]
? CONFIRMATION_STATUS[action.payload.status] : (
// if 3DS was active, and empty status received setting it to `requires_payment_method`
state.status === CONFIRMATION_STATUS.requires_action
? CONFIRMATION_STATUS.requires_payment_method
: null
),
// TODO: remove this commented code
// // Checking if 3DS leads to neither `succeeded` nor `requires_payment_method`
// // then setting status to `requires_payment_method`
// // eslint-disable-next-line no-nested-ternary
// status: CONFIRMATION_STATUS[action.payload.status]
// ? CONFIRMATION_STATUS[action.payload.status] : (
// // if 3DS was active, and empty status received setting it to `requires_payment_method`
// state.status === CONFIRMATION_STATUS.requires_action
// ? CONFIRMATION_STATUS.requires_payment_method
// : null
// ),
};
default:
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import '../../__factories__/subscription.factory';
import '../../__factories__/subscriptionStatus.factory';

import {
screen, render, act, store, // fireEvent
render, act, store, // fireEvent
} from '../../test-utils';
import { Secure3DModal } from './Secure3dModal';
import { fetchSubscriptionDetails, subscriptionDetailsReceived } from '../../data/details/actions';
Expand All @@ -17,6 +17,7 @@ import { camelCaseObject } from '../../../payment/data/utils';

// Mock the logError function
jest.mock('@edx/frontend-platform/logging', () => ({
logInfo: jest.fn(),
logError: jest.fn(),
}));

Expand Down Expand Up @@ -115,7 +116,7 @@ describe('<Secure3DModal />', () => {
await act(() => paymentIntentPromise);

// Expect the modal to be rendered
screen.debug();
// screen.debug();
const iframe = container.querySelector('#secure-3d-iframe');
expect(iframe).toBeDefined();
expect(container.querySelector('#secure-3d-iframe')).toBeDefined();
Expand Down
32 changes: 16 additions & 16 deletions src/subscription/secure-3d/secure-3d-modal/Secure3dModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React, {
} from 'react';
import PropTypes from 'prop-types';
import { useDispatch, useSelector } from 'react-redux';
import { logError } from '@edx/frontend-platform/logging';
import { logError, logInfo } from '@edx/frontend-platform/logging';

import {
ModalDialog,
Expand Down Expand Up @@ -47,7 +47,6 @@ export const Secure3DModal = ({ stripe, elements }) => {
iframe.width = '100%';
iframe.height = '100%';
container.appendChild(iframe);
console.log('Testing 3ds - 6 loading iframe details');
});
};

Expand Down Expand Up @@ -77,15 +76,11 @@ export const Secure3DModal = ({ stripe, elements }) => {
*/
const on3DSComplete = async () => {
// Hide the 3DS UI
// TODO: remove this after testing
console.log('Testing 3ds - 7 on3DSComplete initial');
if (modalRef.current === 'active') {
// completed 3DS, set to inactive so multiple state updates doesn't trigger the 3DS update
modalRef.current = 'inactive';
dispatch(onSuccessful3DS({}));
window.removeEventListener('message', null);
// TODO: remove this after testing
console.log('Testing 3ds - 8 on3DSComplete end');
}
};

Expand All @@ -97,15 +92,15 @@ export const Secure3DModal = ({ stripe, elements }) => {
try {
const fetchPaymentDetails = isTrialEligible ? retrieveSetupIntent : retrievePaymentIntent;
// TODO: remove this after testing
console.log('Testing 3ds - 2 -- fetchingPaymentDetails');
logInfo('3DS - fetchingPaymentDetails');
const paymentDetails = await fetchPaymentDetails();
// TODO: remove this after testing
console.log(`Testing 3ds - 3 -- paymentDetailsLoaded: ${!paymentDetails.next_action.redirect_to_url.url}`);
logInfo('3DS - successfully fetched the paymentDetails', {
hasUrl: !!paymentDetails.next_action.redirect_to_url.url,
});
loadSecureDetails(paymentDetails.next_action.redirect_to_url.url);
setOpen(() => {
// attempting 3ds, because state changes doesn't work with window listeners
// TODO: remove this after testing
console.log('Testing 3ds - 4 -- openingModal');
modalRef.current = 'active';
return true;
});
Expand All @@ -115,16 +110,20 @@ export const Secure3DModal = ({ stripe, elements }) => {
}
}, false);
} catch (e) {
// TODO: remove this after testing
console.log(`Testing 3ds - 5 --Error Message: ${e.message}, Error: ${JSON.stringify(e)}`);
logError(`Error loading 3D secure details): ${e.message}`);
logError(`Error loading 3DS details): ${e.message}`);
}
};

useEffect(() => {
// TODO: remove this after testing
logInfo('3DS - status change effect', {
status,
});
if (status === 'requires_action') {
// TODO: remove this after testing
console.log(`Testing 3ds - 1 -- fetchSecureDetails -- status: ${status}`);
logInfo('3DS - fetchingSecureDetails', {
status,
});
fetchSecureDetails();
} else if (status === 'requires_payment_method') {
// clear the stripe elements and ask user to submit new details
Expand All @@ -136,13 +135,14 @@ export const Secure3DModal = ({ stripe, elements }) => {

if (status !== 'requires_action' && isOpen) {
// hide the modal for all other states
// TODO: remove this after testing
console.log('Testing 3ds - 9 -- hideModal');
setOpen(false);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [status]);

// TODO: remove this after testing
logInfo('3DS - Component before render', { status });

if (!isOpen || !stripe || !elements) { return null; }

return (
Expand Down
6 changes: 6 additions & 0 deletions src/subscription/test-utils.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ import createRootReducer from '../data/reducers';
const config = getConfig();
const locale = 'en';

// Mock the logError function
jest.mock('@edx/frontend-platform/logging', () => ({
logInfo: jest.fn(),
logError: jest.fn(),
}));

configureI18n({
config: {
ENVIRONMENT: process.env.ENVIRONMENT,
Expand Down