diff --git a/react/src/components/Checkout.jsx b/react/src/components/Checkout.jsx index fdd552a45..2cf1fe2df 100644 --- a/react/src/components/Checkout.jsx +++ b/react/src/components/Checkout.jsx @@ -55,10 +55,14 @@ async function checkout(cart, checkout_span) { return; } + if(getTag('backendType') === 'flask') { + Sentry.setTag('seerDemo', true); + } + checkout_span.setAttribute("checkout.click", 1); checkout_span.setAttribute("items_at_checkout", itemsInCart); - let tags = { 'backendType': getTag('backendType'), 'cexp': getTag('cexp'), 'items_at_checkout': itemsInCart, 'checkout.click': 1 }; + let tags = { 'backendType': getTag('backendType'), 'cexp': getTag('cexp'), 'items_at_checkout': itemsInCart, 'checkout.click': 1, }; checkout_span.setAttributes(tags); const stopMeasurement = measureRequestDuration('/checkout'); diff --git a/react/src/tests/Checkout.test.js b/react/src/tests/Checkout.test.js index d1d0f5899..4c5a45b10 100644 --- a/react/src/tests/Checkout.test.js +++ b/react/src/tests/Checkout.test.js @@ -10,6 +10,10 @@ jest.mock('react-loader-spinner', () => () =>
); jest.mock('@sentry/react', () => ({ ...jest.requireActual('@sentry/react'), captureException: jest.fn(), + setTag: jest.fn(), + getCurrentScope: jest.fn(() => ({ + _tags: {} + })), metrics: { increment: jest.fn(), distribution: jest.fn(), @@ -44,6 +48,72 @@ describe('Checkout Component', () => { // expect(screen.getByPlaceholderText(/123 Main Street/i)).toBeInTheDocument(); }); + // test('sets seerDemo tag when backendType is flask', async () => { + // const mockGetCurrentScope = jest.fn(() => ({ + // _tags: { backendType: 'flask' } + // })); + // Sentry.getCurrentScope.mockImplementation(mockGetCurrentScope); + + // render( + // + // + // + // + // + // ); + + // // Trigger checkout by submitting the form + // fireEvent.submit(screen.getByRole('button', { name: /Complete order/i })); + + // await waitFor(() => { + // expect(Sentry.setTag).toHaveBeenCalledWith('seerDemo', true); + // }); + // }); + + // test('does not set seerDemo tag when backendType is not flask', async () => { + // const mockGetCurrentScope = jest.fn(() => ({ + // _tags: { backendType: 'express' } + // })); + // Sentry.getCurrentScope.mockImplementation(mockGetCurrentScope); + + // render( + // + // + // + // + // + // ); + + // // Trigger checkout by submitting the form + // fireEvent.submit(screen.getByRole('button', { name: /Complete order/i })); + + // await waitFor(() => { + // expect(Sentry.setTag).not.toHaveBeenCalledWith('seerDemo', true); + // }); + // }); + + // test('does not set seerDemo tag when backendType is undefined', async () => { + // const mockGetCurrentScope = jest.fn(() => ({ + // _tags: {} + // })); + // Sentry.getCurrentScope.mockImplementation(mockGetCurrentScope); + + // render( + // + // + // + // + // + // ); + + // // Trigger checkout by submitting the form + // fireEvent.submit(screen.getByRole('button', { name: /Complete order/i })); + + // await waitFor(() => { + // expect(Sentry.setTag).not.toHaveBeenCalledWith('seerDemo', true); + // }); + // }); + // test('handles input change', () => { // render( //