Skip to content

Commit

Permalink
Add extra error message to validation page, fixed: can enter create o…
Browse files Browse the repository at this point in the history
…ffer page with admin account
  • Loading branch information
FranciscoCardoso913 committed Sep 16, 2023
1 parent 4198681 commit 055fe5a
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
8 changes: 6 additions & 2 deletions src/components/Apply/Company/CompanyApplicationUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,12 @@ const ValidationMessages = Object.freeze({
" You will need to create a new application.",
},
"application-already-validated": {
title: "Application is already validated!",
text: "This application is already validated. ",
title: "Application was already validated!",
text: "This application was already validated. ",
},
"account-already-using-email":{
title: "Error! Duplicated Email",
text: "There is already an account with this email, please create an application with another email. "
},
});

Expand Down
3 changes: 2 additions & 1 deletion src/components/Offers/Form/form-components/OfferForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ const OfferForm = ({ context, title }) => {
const session = useSession();

useEffect(() => {
if(session.data?.isAdmin) return;
if (!session.isValidating && session.isLoggedIn) {
fetchCompanyApplication(session.data?.company?._id)
.then((application) => {
Expand All @@ -113,7 +114,7 @@ const OfferForm = ({ context, title }) => {
});
});
}
}, [session.isValidating, session.isLoggedIn, session.data.company._id]);
}, [session.isValidating, session.isLoggedIn, session.data?.company?._id]);

const showOwnerComponent = isAdmin && showCompanyField;

Expand Down
2 changes: 1 addition & 1 deletion src/pages/CompanyOffersManagementPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const CompanyOffersManagementPage = () => {
});
});
}
}, [session.data.company._id, session.isLoggedIn, session.isValidating]);
}, [session.data?.company?._id, session.isLoggedIn, session.isValidating]);

return (
<CardContent className={classes.content}>
Expand Down
15 changes: 15 additions & 0 deletions src/pages/ValidationPage.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,19 @@ describe("Validation Page", () => {
const { title } = getValidationMessage("application-already-validated");
expect(page.queryByText(title)).toBeInTheDocument();
});

it("Should show error message if there is an account with the same email of the application", async () => {
validateApplication.mockImplementation(() => {
throw [{ msg: "account-already-using-email" }];
});
const page = await render(
<BrowserRouter>
<ThemeProvider theme={AppTheme}>
<ValidationPage />
</ThemeProvider>
</BrowserRouter>,
);
const { title } = getValidationMessage("account-already-using-email");
expect(page.queryByText(title)).toBeInTheDocument();
});
});

0 comments on commit 055fe5a

Please sign in to comment.