From 9262a6f3beb7c2c46708453ce7d667dc5b39da8e Mon Sep 17 00:00:00 2001 From: Xiao Yijun Date: Wed, 15 Jun 2022 12:16:37 +0800 Subject: [PATCH] fix(console): update terms of use (#1122) --- .../SignInExperience/components/TermsForm.tsx | 2 +- .../src/routes/sign-in-experience.guard.test.ts | 16 +++++++++++++++- packages/schemas/src/foundations/jsonb-types.ts | 2 +- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/packages/console/src/pages/SignInExperience/components/TermsForm.tsx b/packages/console/src/pages/SignInExperience/components/TermsForm.tsx index 986f5ad2f..4bfce657a 100644 --- a/packages/console/src/pages/SignInExperience/components/TermsForm.tsx +++ b/packages/console/src/pages/SignInExperience/components/TermsForm.tsx @@ -24,7 +24,7 @@ const TermsForm = () => {
{t('sign_in_exp.terms_of_use.title')}
diff --git a/packages/core/src/routes/sign-in-experience.guard.test.ts b/packages/core/src/routes/sign-in-experience.guard.test.ts index 6b3452458..325c09cff 100644 --- a/packages/core/src/routes/sign-in-experience.guard.test.ts +++ b/packages/core/src/routes/sign-in-experience.guard.test.ts @@ -67,10 +67,24 @@ describe('terms of use', () => { } ); - test.each([null, '', ' \t\n\r', 'non-url'])('%p should fail', async (contentUrl) => { + test.each([null, ' \t\n\r', 'non-url'])('%p should fail', async (contentUrl) => { const signInExperience = { termsOfUse: { ...mockTermsOfUse, enabled: false, contentUrl } }; await expectPatchResponseStatus(signInExperience, 400); }); + + test('should allow empty contentUrl if termsOfUse is disabled', async () => { + const signInExperience = { + termsOfUse: { ...mockTermsOfUse, enabled: false, contentUrl: '' }, + }; + await expectPatchResponseStatus(signInExperience, 200); + }); + + test('should not allow empty contentUrl if termsOfUse is enabled', async () => { + const signInExperience = { + termsOfUse: { ...mockTermsOfUse, enabled: true, contentUrl: '' }, + }; + await expectPatchResponseStatus(signInExperience, 400); + }); }); }); diff --git a/packages/schemas/src/foundations/jsonb-types.ts b/packages/schemas/src/foundations/jsonb-types.ts index 2dffe5263..544d097ab 100644 --- a/packages/schemas/src/foundations/jsonb-types.ts +++ b/packages/schemas/src/foundations/jsonb-types.ts @@ -91,7 +91,7 @@ export type Branding = z.infer; export const termsOfUseGuard = z.object({ enabled: z.boolean(), - contentUrl: z.string().url().optional(), + contentUrl: z.string().url().optional().or(z.literal('')), }); export type TermsOfUse = z.infer;