Skip to content

Commit d36917b

Browse files
authored
Fixed frontend tests - dependencies mismatch and out-of-date Zod usage (#2344)
- fixed dependencies mismatch, - fixed out-of-date Zod usage
1 parent dfd061c commit d36917b

File tree

2 files changed

+33
-27
lines changed

2 files changed

+33
-27
lines changed

ui/src/pages/Profile/components/PasswordDetails.tsx

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,31 @@ import { Input } from '@/components/ui/input';
1717
import { Button } from '@/components/ui/button';
1818
import { ErrorMessage } from '@/components/ErrorMessage';
1919

20-
const schema = z
21-
.object({
22-
currentPassword: z
23-
.string()
24-
.min(5, { message: 'Current password must be at least 5 characters' }),
25-
newPassword: z
26-
.string()
27-
.min(5, { message: 'New password must be at least 5 characters' }),
28-
repeatedPassword: z
29-
.string()
30-
.min(5, { message: 'Repeat password must be at least 5 characters' }),
31-
})
32-
.refine((data) => data.newPassword === data.repeatedPassword, {
20+
const baseSchema = z.object({
21+
currentPassword: z
22+
.string()
23+
.min(5, { message: 'Current password must be at least 5 characters' }),
24+
newPassword: z
25+
.string()
26+
.min(5, { message: 'New password must be at least 5 characters' }),
27+
repeatedPassword: z
28+
.string()
29+
.min(5, { message: 'Repeat password must be at least 5 characters' }),
30+
});
31+
32+
const schema = baseSchema.refine(
33+
(data) => data.newPassword === data.repeatedPassword,
34+
{
3335
message: 'Passwords do not match',
3436
path: ['repeatedPassword'],
3537

3638
when(payload) {
37-
return schema
39+
return baseSchema
3840
.pick({ newPassword: true, repeatedPassword: true })
3941
.safeParse(payload.value).success;
4042
},
41-
});
43+
}
44+
);
4245

4346
export const PasswordDetails: FC = () => {
4447
const [storageApiKeyState, setStorageApiKeyState] = useApiKeyState();

ui/src/pages/Register/index.tsx

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,28 @@ import { Button } from '@/components/ui/button';
2828
import { toast } from 'sonner';
2929
import { ErrorMessage } from '@/components/ErrorMessage';
3030

31-
const schema = z
32-
.object({
33-
login: z
34-
.string('Login is required')
35-
.min(3, 'Login must be at least 3 characters long'),
36-
email: z.email('Email is required'),
37-
password: z.string('Password is required').min(5),
38-
repeatedPassword: z.string('Please repeat your password'),
39-
})
40-
.refine((data) => data.password === data.repeatedPassword, {
31+
const baseSchema = z.object({
32+
login: z
33+
.string('Login is required')
34+
.min(3, 'Login must be at least 3 characters long'),
35+
email: z.email('Email is required'),
36+
password: z.string('Password is required').min(5),
37+
repeatedPassword: z.string('Please repeat your password'),
38+
});
39+
40+
const schema = baseSchema.refine(
41+
(data) => data.password === data.repeatedPassword,
42+
{
4143
message: 'Passwords do not match',
4244
path: ['repeatedPassword'],
4345

4446
when(payload) {
45-
return schema
47+
return baseSchema
4648
.pick({ password: true, repeatedPassword: true })
4749
.safeParse(payload.value).success;
4850
},
49-
});
51+
}
52+
);
5053

5154
const FORM_ID = 'registration-form';
5255

0 commit comments

Comments
 (0)