mirror of
https://github.com/strapi/strapi.git
synced 2025-12-24 21:54:24 +00:00
Fix: Registration - Make lastname field nullable
Co-authored-by: Fouad Balhawan <fbalhawan@users.noreply.github.com>
This commit is contained in:
parent
72d546eb53
commit
cac604c9a8
@ -98,6 +98,10 @@ const Register = ({ authType, fieldsToDisable, noSignin, onSubmit, schema }) =>
|
||||
|
||||
if (!['password', 'confirmPassword'].includes(key) && typeof value === 'string') {
|
||||
normalizedvalue = normalizedvalue.trim();
|
||||
|
||||
if (key === 'lastname') {
|
||||
normalizedvalue = normalizedvalue || null;
|
||||
}
|
||||
}
|
||||
|
||||
acc[key] = normalizedvalue;
|
||||
|
||||
@ -136,6 +136,61 @@ describe('ADMIN | PAGES | AUTH | Register', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('Validates optional Lastname value to be null', async () => {
|
||||
const spy = jest.fn();
|
||||
const { getByRole, getByLabelText, user } = setup({ onSubmit: spy });
|
||||
|
||||
await user.type(getByLabelText(/Firstname/i), 'First name');
|
||||
await user.type(getByLabelText(/Email/i), 'test@strapi.io');
|
||||
await user.type(getByLabelText(/^Password/i), 'secret');
|
||||
await user.type(getByLabelText(/Confirm Password/i), 'secret');
|
||||
|
||||
fireEvent.click(getByRole('button', { name: /let's start/i }));
|
||||
|
||||
await waitFor(() =>
|
||||
expect(spy).toHaveBeenCalledWith(
|
||||
{
|
||||
firstname: 'First name',
|
||||
lastname: null,
|
||||
email: 'test@strapi.io',
|
||||
news: false,
|
||||
registrationToken: undefined,
|
||||
confirmPassword: 'secret',
|
||||
password: 'secret',
|
||||
},
|
||||
expect.any(Object)
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
it('Validates optional Lastname value to be empty space', async () => {
|
||||
const spy = jest.fn();
|
||||
const { getByRole, getByLabelText, user } = setup({ onSubmit: spy });
|
||||
|
||||
await user.type(getByLabelText(/Firstname/i), 'First name');
|
||||
await user.type(getByLabelText(/Lastname/i), ' ');
|
||||
await user.type(getByLabelText(/Email/i), 'test@strapi.io');
|
||||
await user.type(getByLabelText(/^Password/i), 'secret');
|
||||
await user.type(getByLabelText(/Confirm Password/i), 'secret');
|
||||
|
||||
fireEvent.click(getByRole('button', { name: /let's start/i }));
|
||||
|
||||
await waitFor(() =>
|
||||
expect(spy).toHaveBeenCalledWith(
|
||||
{
|
||||
firstname: 'First name',
|
||||
lastname: null,
|
||||
email: 'test@strapi.io',
|
||||
news: false,
|
||||
registrationToken: undefined,
|
||||
confirmPassword: 'secret',
|
||||
password: 'secret',
|
||||
},
|
||||
expect.any(Object)
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
it('Disable fields', () => {
|
||||
const { getByLabelText } = setup({
|
||||
fieldsToDisable: ['email', 'firstname'],
|
||||
|
||||
@ -55,7 +55,7 @@ export const FORMS = {
|
||||
fieldsToOmit: ['userInfo.confirmPassword', 'userInfo.news', 'userInfo.email'],
|
||||
schema: yup.object().shape({
|
||||
firstname: yup.string().trim().required(translatedErrors.required),
|
||||
lastname: yup.string(),
|
||||
lastname: yup.string().nullable(),
|
||||
password: yup
|
||||
.string()
|
||||
.min(8, translatedErrors.minLength)
|
||||
@ -79,7 +79,7 @@ export const FORMS = {
|
||||
fieldsToOmit: ['confirmPassword', 'news'],
|
||||
schema: yup.object().shape({
|
||||
firstname: yup.string().trim().required(translatedErrors.required),
|
||||
lastname: yup.string(),
|
||||
lastname: yup.string().nullable(),
|
||||
password: yup
|
||||
.string()
|
||||
.min(8, translatedErrors.minLength)
|
||||
|
||||
@ -11,7 +11,7 @@ const registrationSchema = yup
|
||||
.object()
|
||||
.shape({
|
||||
firstname: validators.firstname.required(),
|
||||
lastname: validators.lastname,
|
||||
lastname: validators.lastname.nullable(),
|
||||
password: validators.password.required(),
|
||||
})
|
||||
.required()
|
||||
@ -32,7 +32,7 @@ const adminRegistrationSchema = yup
|
||||
.shape({
|
||||
email: validators.email.required(),
|
||||
firstname: validators.firstname.required(),
|
||||
lastname: validators.lastname,
|
||||
lastname: validators.lastname.nullable(),
|
||||
password: validators.password.required(),
|
||||
})
|
||||
.required()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user