Skip to content
Open
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

This file was deleted.

48 changes: 0 additions & 48 deletions pages/api/Schema/ContactPrimaryAddress/datahandler.ts

This file was deleted.

15 changes: 0 additions & 15 deletions pages/api/Schema/ContactPrimaryAddress/resolvers.ts

This file was deleted.

6 changes: 0 additions & 6 deletions pages/api/Schema/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import AccountListDonorAccountsTypeDefs from './AccountListDonorAccounts/account
import { AccountListDonorAccountsResolvers } from './AccountListDonorAccounts/resolvers';
import CoachingAnswerSetsTypeDefs from './CoachingAnswerSets/coachingAnswerSets.graphql';
import { CoachingAnswerSetsResolvers } from './CoachingAnswerSets/resolvers';
import ContactPrimaryAddressTypeDefs from './ContactPrimaryAddress/contactPrimaryAddress.graphql';
import { ContactPrimaryAddressResolvers } from './ContactPrimaryAddress/resolvers';
import DestroyDonorAccountTypeDefs from './Contacts/DonorAccounts/Destroy/destroyDonorAccount.graphql';
import { DestroyDonorAccountResolvers } from './Contacts/DonorAccounts/Destroy/resolvers';
import ExportContactsTypeDefs from './ExportContacts/exportContacts.graphql';
Expand Down Expand Up @@ -72,10 +70,6 @@ const schema = buildSubgraphSchema([
typeDefs: AppointmentResultsTypeDefs,
resolvers: AppointmentResultsResolvers,
},
{
typeDefs: ContactPrimaryAddressTypeDefs,
resolvers: ContactPrimaryAddressResolvers,
},
{ typeDefs: ExportContactsTypeDefs, resolvers: ExportContactsResolvers },
{ typeDefs: MergeContactsTypeDefs, resolvers: MergeContactsResolvers },
{ typeDefs: MergePeopleBulkTypeDefs, resolvers: MergePeopleBulkResolvers },
Expand Down
48 changes: 0 additions & 48 deletions pages/api/graphql-rest.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {
getCoachingAnswerSet,
getCoachingAnswerSets,
} from './Schema/CoachingAnswerSets/dataHandler';
import { readExistingAddresses } from './Schema/ContactPrimaryAddress/datahandler';
import {
DestroyDonorAccount,
DestroyDonorAccountResponse,
Expand Down Expand Up @@ -416,53 +415,6 @@ class MpdxRestApi extends RESTDataSource {
return getCoachingAnswer(res);
}

// TODO: This should be merged with the updateContact mutation by adding the ability to update
// the primaryMailingAddress field when we have API resources again
async setContactPrimaryAddress(
contactId: string,
primaryAddressId: string | null | undefined,
) {
// Setting primary_mailing_address to true on one address doesn't set it to false on all the
// others, so we have to load all the existing addresses and update all of their
// primary_mailing_address attributes
const getAddressesResponse = await this.get(
`contacts/${contactId}?include=addresses`,
);
const addresses = readExistingAddresses(getAddressesResponse).map(
(address) => ({
...address,
primaryMailingAddress: address.id === primaryAddressId,
}),
);
await this.put(`contacts/${contactId}`, {
body: {
included: addresses.map(({ id, primaryMailingAddress }) => ({
type: 'addresses',
id,
attributes: {
primary_mailing_address: primaryMailingAddress,
},
})),
data: {
type: 'contacts',
id: contactId,
attributes: { overwrite: true },
relationships: {
addresses: {
data: addresses.map(({ id }) => ({
type: 'addresses',
id,
})),
},
},
},
},
});
return {
addresses,
};
}

async getExpectedMonthlyTotalReport(
accountListId: string,
designationAccountId: string[] | null | undefined,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';

Check notice on line 1 in src/components/Contacts/ContactDetails/ContactDetailsTab/Mailing/AddAddressModal/AddAddressModal.test.tsx

View check run for this annotation

CodeScene Delta Analysis / CodeScene Code Health Review (main)

✅ No longer an issue: Code Duplication

The module no longer contains too many functions with similar structure
import { ThemeProvider } from '@mui/material/styles';
import { act, render, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
Expand All @@ -6,9 +6,10 @@
import { placePromise, setupMocks } from '__tests__/util/googlePlacesMock';
import { GqlMockedProvider } from '__tests__/util/graphqlMocking';
import theme from '../../../../../../theme';
import { SetContactPrimaryAddressMutation } from '../SetPrimaryAddress.generated';
import { AddAddressModal } from './AddAddressModal';
import { CreateContactAddressMutation } from './CreateContactAddress.generated';

const handleClose = jest.fn();
const accountListId = 'abc';
const contactId = '123';

Expand All @@ -27,83 +28,57 @@

jest.mock('@react-google-maps/api');

const mutationSpy = jest.fn();
const handleClose = jest.fn();

const TestComponent: React.FC = () => (
<SnackbarProvider>
<ThemeProvider theme={theme}>
<GqlMockedProvider<{
CreateContactAddress: CreateContactAddressMutation;
SetContactPrimaryAddress: SetContactPrimaryAddressMutation;
}>
onCall={mutationSpy}
>
<AddAddressModal
accountListId={accountListId}
contactId={contactId}
handleClose={handleClose}
/>
</GqlMockedProvider>
</ThemeProvider>
</SnackbarProvider>
);

describe('AddAddressModal', () => {
beforeEach(() => {
setupMocks();
});

it('should render edit contact address modal', async () => {
const { getByText } = render(
<SnackbarProvider>
<ThemeProvider theme={theme}>
<GqlMockedProvider>
<AddAddressModal
accountListId={accountListId}
contactId={contactId}
handleClose={handleClose}
/>
</GqlMockedProvider>
</ThemeProvider>
</SnackbarProvider>,
);
const { getByText } = render(<TestComponent />);

expect(getByText('Add Address')).toBeInTheDocument();
});

it('should close edit contact other modal', () => {
const { getByText, getByLabelText } = render(
<SnackbarProvider>
<ThemeProvider theme={theme}>
<GqlMockedProvider>
<AddAddressModal
accountListId={accountListId}
contactId={contactId}
handleClose={handleClose}
/>
</GqlMockedProvider>
</ThemeProvider>
</SnackbarProvider>,
);
const { getByText, getByLabelText } = render(<TestComponent />);

expect(getByText('Add Address')).toBeInTheDocument();
userEvent.click(getByLabelText('Close'));
expect(handleClose).toHaveBeenCalled();
});

it('should handle cancel click', () => {
const { getByText } = render(
<SnackbarProvider>
<ThemeProvider theme={theme}>
<GqlMockedProvider>
<AddAddressModal
accountListId={accountListId}
contactId={contactId}
handleClose={handleClose}
/>
</GqlMockedProvider>
</ThemeProvider>
</SnackbarProvider>,
);
const { getByText } = render(<TestComponent />);

expect(getByText('Add Address')).toBeInTheDocument();
userEvent.click(getByText('Cancel'));
expect(handleClose).toHaveBeenCalled();
});

it('requires at least one field to be filled', async () => {
const { getByRole } = render(
<SnackbarProvider>
<ThemeProvider theme={theme}>
<GqlMockedProvider>
<AddAddressModal
accountListId={accountListId}
contactId={contactId}
handleClose={handleClose}
/>
</GqlMockedProvider>
</ThemeProvider>
</SnackbarProvider>,
);
const { getByRole } = render(<TestComponent />);

const saveButton = getByRole('button', { name: 'Save' });
await waitFor(() => expect(saveButton).toBeDisabled());
Expand All @@ -113,27 +88,14 @@
});

it('should create contact address', async () => {
const mutationSpy = jest.fn();
const newStreet = '4321 Neat Street';
const newCity = 'Orlando';
const newState = 'FL';
const newPostalCode = '55555';
const newCountry = 'United States';
const newRegion = 'New Region';
const newMetroArea = 'New Metro';
const { getByRole, getByText, getByLabelText } = render(
<SnackbarProvider>
<ThemeProvider theme={theme}>
<GqlMockedProvider onCall={mutationSpy}>
<AddAddressModal
accountListId={accountListId}
contactId={contactId}
handleClose={handleClose}
/>
</GqlMockedProvider>
</ThemeProvider>
</SnackbarProvider>,
);
const { getByRole, getByText, getByLabelText } = render(<TestComponent />);

userEvent.clear(getByRole('combobox', { name: 'Street' }));
userEvent.clear(getByLabelText('City'));
Expand Down Expand Up @@ -176,19 +138,7 @@
it('handles chosen address predictions', async () => {
jest.useFakeTimers();

const { getByRole } = render(
<SnackbarProvider>
<ThemeProvider theme={theme}>
<GqlMockedProvider>
<AddAddressModal
accountListId={accountListId}
contactId={contactId}
handleClose={handleClose}
/>
</GqlMockedProvider>
</ThemeProvider>
</SnackbarProvider>,
);
const { getByRole } = render(<TestComponent />);

// Let Google Maps initialize
jest.runOnlyPendingTimers();
Expand Down Expand Up @@ -218,21 +168,8 @@
}, 20000);

it('should set new address as primary', async () => {
const mutationSpy = jest.fn();
const newStreet = '4321 Neat Street';
const { getByText, getByRole } = render(
<SnackbarProvider>
<ThemeProvider theme={theme}>
<GqlMockedProvider onCall={mutationSpy}>
<AddAddressModal
accountListId={accountListId}
contactId={contactId}
handleClose={handleClose}
/>
</GqlMockedProvider>
</ThemeProvider>
</SnackbarProvider>,
);
const { getByText, getByRole } = render(<TestComponent />);

const street = getByRole('combobox', { name: 'Street' });
userEvent.clear(street);
Expand All @@ -249,25 +186,13 @@
expect(operation.variables.attributes.street).toEqual(newStreet);

const { operation: operation2 } = mutationSpy.mock.calls[1][0];
expect(operation2.variables.accountListId).toEqual(accountListId);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Suggestion] Optional: assert `contactId` alongside `accountListId` to tighten the contract — `expect(operation2.variables.contactId).toEqual(contactId);`. The existing `primaryAddressId` check transitively covers contact identity, but pinning `contactId` directly makes a future regression more obvious. Low priority; current coverage is sufficient.

expect(operation2.variables.primaryAddressId).not.toBeNull();
}, 30000);

it('should not set new address as primary if it is unchecked', async () => {
const mutationSpy = jest.fn();
const newStreet = '4321 Neat Street';
const { getByText, getByLabelText, getByRole } = render(
<SnackbarProvider>
<ThemeProvider theme={theme}>
<GqlMockedProvider onCall={mutationSpy}>
<AddAddressModal
accountListId={accountListId}
contactId={contactId}
handleClose={handleClose}
/>
</GqlMockedProvider>
</ThemeProvider>
</SnackbarProvider>,
);
const { getByText, getByLabelText, getByRole } = render(<TestComponent />);

userEvent.type(getByRole('combobox', { name: 'Street' }), newStreet);
userEvent.click(getByLabelText('Primary'));
Expand Down
Loading
Loading