From 4a08ce2c00f73396463aec74cdf719939fd3fb14 Mon Sep 17 00:00:00 2001 From: muntaxir4 Date: Mon, 18 Nov 2024 16:43:21 +0530 Subject: [PATCH] refactor(schema): Rename schemas and types file for user. And enhance OTP validation --- packages/schema/src/index.ts | 4 +--- packages/schema/src/index.types.ts | 3 +-- packages/schema/src/user/{user.ts => index.ts} | 2 +- .../schema/src/user/{user.types.ts => index.types.ts} | 2 +- packages/schema/tests/user.spec.ts | 10 +++++++++- 5 files changed, 13 insertions(+), 8 deletions(-) rename packages/schema/src/user/{user.ts => index.ts} (97%) rename packages/schema/src/user/{user.types.ts => index.types.ts} (98%) diff --git a/packages/schema/src/index.ts b/packages/schema/src/index.ts index dc097cda..fe0f46c3 100644 --- a/packages/schema/src/index.ts +++ b/packages/schema/src/index.ts @@ -12,9 +12,7 @@ export * from './environment' export * from './integration' export * from './project' export * from './secret' - -export * from './user/user' - +export * from './user' export * from './variable' export * from './workspace/workspace' diff --git a/packages/schema/src/index.types.ts b/packages/schema/src/index.types.ts index da5a840b..27cc9615 100644 --- a/packages/schema/src/index.types.ts +++ b/packages/schema/src/index.types.ts @@ -36,8 +36,7 @@ export type TForkProject = z.infer export type TCreateSecret = z.infer export type TUpdateSecret = z.infer -// Export types from user.types.ts -export * from './user/user.types' +export * from './user/index.types' export type TCreateVariable = z.infer export type TUpdateVariable = z.infer diff --git a/packages/schema/src/user/user.ts b/packages/schema/src/user/index.ts similarity index 97% rename from packages/schema/src/user/user.ts rename to packages/schema/src/user/index.ts index 18c3d610..e80b6865 100644 --- a/packages/schema/src/user/user.ts +++ b/packages/schema/src/user/index.ts @@ -29,7 +29,7 @@ export const DeleteSelfRequestSchema = z.void() export const DeleteSelfResponseSchema = z.void() export const ValidateEmailChangeOTPRequestSchema = z.object({ - otp: z.string() + otp: z.string().min(6).max(6) }) export const ValidateEmailChangeOTPResponseSchema = diff --git a/packages/schema/src/user/user.types.ts b/packages/schema/src/user/index.types.ts similarity index 98% rename from packages/schema/src/user/user.types.ts rename to packages/schema/src/user/index.types.ts index 365015d0..7b0f7a7f 100644 --- a/packages/schema/src/user/user.types.ts +++ b/packages/schema/src/user/index.types.ts @@ -9,7 +9,7 @@ import { ValidateEmailChangeOTPResponseSchema, ResendEmailChangeOTPRequestSchema, ResendEmailChangeOTPResponseSchema -} from './user' +} from '.' export type GetSelfResponse = z.infer diff --git a/packages/schema/tests/user.spec.ts b/packages/schema/tests/user.spec.ts index dbc051e7..0c4c1f2c 100644 --- a/packages/schema/tests/user.spec.ts +++ b/packages/schema/tests/user.spec.ts @@ -8,7 +8,7 @@ import { ValidateEmailChangeOTPResponseSchema, ResendEmailChangeOTPRequestSchema, ResendEmailChangeOTPResponseSchema -} from '@/user/user' +} from '@/user' describe('User Schema Tests', () => { // Tests for GetSelfResponseSchema @@ -122,6 +122,14 @@ describe('User Schema Tests', () => { expect(result.success).toBe(true) }) + it('should fail validation for OTP of length other than 6 ValidateEmailChangeOTPRequestSchema', () => { + const result = ValidateEmailChangeOTPRequestSchema.safeParse({ + otp: '234' // Should be a 6 digit string + }) + expect(result.success).toBe(false) + expect(result.error?.issues.length).toBe(1) + }) + it('should fail validation for invalid ValidateEmailChangeOTPRequestSchema', () => { const result = ValidateEmailChangeOTPRequestSchema.safeParse({ otp: 123456 // Should be a string