Skip to content

Commit

Permalink
refactor(schema): Rename schemas and types file for user. And enhance…
Browse files Browse the repository at this point in the history
… OTP validation
  • Loading branch information
muntaxir4 committed Nov 18, 2024
1 parent c95feaa commit 4a08ce2
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 8 deletions.
4 changes: 1 addition & 3 deletions packages/schema/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
3 changes: 1 addition & 2 deletions packages/schema/src/index.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ export type TForkProject = z.infer<typeof ForkProjectSchema>
export type TCreateSecret = z.infer<typeof CreateSecretSchema>
export type TUpdateSecret = z.infer<typeof UpdateSecretSchema>

// Export types from user.types.ts
export * from './user/user.types'
export * from './user/index.types'

export type TCreateVariable = z.infer<typeof CreateVariableSchema>
export type TUpdateVariable = z.infer<typeof UpdateVariableSchema>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
ValidateEmailChangeOTPResponseSchema,
ResendEmailChangeOTPRequestSchema,
ResendEmailChangeOTPResponseSchema
} from './user'
} from '.'

export type GetSelfResponse = z.infer<typeof GetSelfResponseSchema>

Expand Down
10 changes: 9 additions & 1 deletion packages/schema/tests/user.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
ValidateEmailChangeOTPResponseSchema,
ResendEmailChangeOTPRequestSchema,
ResendEmailChangeOTPResponseSchema
} from '@/user/user'
} from '@/user'

describe('User Schema Tests', () => {
// Tests for GetSelfResponseSchema
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 4a08ce2

Please sign in to comment.