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

MPDX-7893 - Allowing users to add offline organizations to their accounts #936

Merged
merged 2 commits into from
May 1, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@ const GetOrganizationsMock: Pick<
giftAidPercentage: 60,
disableNewUsers: true,
},
{
id: 'disableNewUserAsNull',
name: 'Org With DisableNewUsers As NULL',
apiClass: 'OfflineOrg',
oauth: false,
giftAidPercentage: 60,
disableNewUsers: null,
},
];

const standardMocks = {
Expand Down Expand Up @@ -178,6 +186,46 @@ describe('OrganizationAddAccountModal', () => {
});
});

it('allows offline Organization to be added if disableNewUsers is null', async () => {
const mutationSpy = jest.fn();
const { getByText, getByRole, findByRole } = render(
<Components>
<GqlMockedProvider<{
GetOrganizations: GetOrganizationsQuery;
}>
mocks={{
getOrganizations: {
organizations: GetOrganizationsMock,
},
}}
onCall={mutationSpy}
>
<OrganizationAddAccountModal
handleClose={handleClose}
refetchOrganizations={refetchOrganizations}
accountListId={accountListId}
/>
</GqlMockedProvider>
</Components>,
);

userEvent.click(getByRole('combobox'));
userEvent.click(
await findByRole('option', { name: 'Org With DisableNewUsers As NULL' }),
);

await waitFor(() => {
expect(getByText('Add Account')).not.toBeDisabled();
userEvent.click(getByText('Add Account'));
});
await waitFor(() => {
expect(mockEnqueue).toHaveBeenCalledWith(
'{{appName}} added your organization account',
{ variant: 'success' },
);
});
});

it('should select Ministry Organization and be unable to add it.', async () => {
const mutationSpy = jest.fn();
const { getByText, getByRole } = render(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,41 @@ export type OrganizationFormikSchema = {
password: string | undefined;
};

const OrganizationSchema: yup.SchemaOf<OrganizationFormikSchema> = yup.object({
selectedOrganization: yup
.object({
id: yup.string().required(),
apiClass: yup.string().required(),
name: yup.string().required(),
oauth: yup.boolean().required(),
giftAidPercentage: yup.number().nullable(),
disableNewUsers: yup.boolean().nullable(),
})
.required(),
username: yup
.string()
.when('selectedOrganization', (organization, schema) => {
if (
getOrganizationType(organization?.apiClass, organization?.oauth) ===
OrganizationTypesEnum.LOGIN
) {
return schema.required('Must enter username');
}
return schema;
}),
password: yup
.string()
.when('selectedOrganization', (organization, schema) => {
if (
getOrganizationType(organization?.apiClass, organization?.oauth) ===
OrganizationTypesEnum.LOGIN
) {
return schema.required('Must enter password');
}
return schema;
}),
});

const StyledBox = styled(Box)(() => ({
padding: '0 10px',
}));
Expand Down Expand Up @@ -144,43 +179,6 @@ export const OrganizationAddAccountModal: React.FC<
showArticle('HS_SETUP_FIND_ORGANIZATION');
};

const OrganizationSchema: yup.SchemaOf<OrganizationFormikSchema> = yup.object(
{
selectedOrganization: yup
.object({
id: yup.string().required(),
apiClass: yup.string().required(),
name: yup.string().required(),
oauth: yup.boolean().required(),
giftAidPercentage: yup.number().nullable(),
disableNewUsers: yup.boolean(),
})
.required(),
username: yup
.string()
.when('selectedOrganization', (organization, schema) => {
if (
getOrganizationType(organization?.apiClass, organization?.oauth) ===
OrganizationTypesEnum.LOGIN
) {
return schema.required('Must enter username');
}
return schema;
}),
password: yup
.string()
.when('selectedOrganization', (organization, schema) => {
if (
getOrganizationType(organization?.apiClass, organization?.oauth) ===
OrganizationTypesEnum.LOGIN
) {
return schema.required('Must enter password');
}
return schema;
}),
},
);

return (
<Modal
isOpen={true}
Expand Down Expand Up @@ -239,13 +237,11 @@ export const OrganizationAddAccountModal: React.FC<
)}
/>
</StyledBox>

{!selectedOrganization && !!articles.HS_SETUP_FIND_ORGANIZATION && (
<Button onClick={showOrganizationHelp}>
{t("Can't find your organization?")}
</Button>
)}

{organizationType === OrganizationTypesEnum.MINISTRY && (
<WarningBox>
<Typography
Expand Down Expand Up @@ -288,7 +284,9 @@ export const OrganizationAddAccountModal: React.FC<
});
}}
>
{t('click here to log out of {{appName}}', { appName })}
{t('click here to log out of {{appName}}', {
appName,
})}
</Link>
{t(
' so you can log back in with your official key account.',
Expand All @@ -307,7 +305,6 @@ export const OrganizationAddAccountModal: React.FC<
</StyledTypography>
</WarningBox>
)}

{organizationType === OrganizationTypesEnum.OAUTH && (
<WarningBox>
<Typography color={theme.palette.mpdxYellow.contrastText}>
Expand All @@ -318,7 +315,6 @@ export const OrganizationAddAccountModal: React.FC<
</Typography>
</WarningBox>
)}

{organizationType === OrganizationTypesEnum.LOGIN && (
<>
<StyledBox marginTop={4}>
Expand Down Expand Up @@ -353,7 +349,6 @@ export const OrganizationAddAccountModal: React.FC<
</StyledBox>
</>
)}

<DialogActions>
<CancelButton onClick={handleClose} disabled={isSubmitting} />

Expand Down
Loading