Skip to content

Commit

Permalink
feat(schema): Add workspace invitation schema (keyshade-xyz#612)
Browse files Browse the repository at this point in the history
  • Loading branch information
Souvik9205 authored Jan 9, 2025
1 parent 2ed31c0 commit 1a5721b
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 2 deletions.
22 changes: 22 additions & 0 deletions packages/schema/src/workspace/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,25 @@ export const GlobalSearchResponseSchema = z.object({
})
)
})

export const GetWorkspaceInvitationsRequest = PageRequestSchema

export const GetWorkspaceInvitationsResponse = PageResponseSchema(
z.object({
workspace: z.object({
id: z.string(),
name: z.string(),
slug: z.string(),
icon: z.string().nullable()
}),
roles: z.array(
z.object({
role: z.object({
name: z.string(),
colorCode: z.string().nullable()
})
})
),
invitedOn: z.string().datetime()
})
)
12 changes: 11 additions & 1 deletion packages/schema/src/workspace/index.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ import {
ExportDataRequestSchema,
ExportDataResponseSchema,
GlobalSearchRequestSchema,
GlobalSearchResponseSchema
GlobalSearchResponseSchema,
GetWorkspaceInvitationsRequest,
GetWorkspaceInvitationsResponse
} from '.'
import { PageRequestSchema } from '..'

Expand Down Expand Up @@ -66,3 +68,11 @@ export type ExportDataResponse = z.infer<typeof ExportDataResponseSchema>
export type GlobalSearchRequest = z.infer<typeof GlobalSearchRequestSchema>

export type GlobalSearchResponse = z.infer<typeof GlobalSearchResponseSchema>

export type GetWorkspaceInvitationsRequest = z.infer<
typeof GetWorkspaceInvitationsRequest
>

export type GetWorkspaceInvitationsResponse = z.infer<
typeof GetWorkspaceInvitationsResponse
>
69 changes: 68 additions & 1 deletion packages/schema/tests/workspace.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ import {
ExportDataResponseSchema,
GetAllWorkspacesOfUserResponseSchema,
GlobalSearchResponseSchema,
GetAllWorkspacesOfUserRequestSchema
GetAllWorkspacesOfUserRequestSchema,
GetWorkspaceInvitationsRequest,
GetWorkspaceInvitationsResponse
} from '@/workspace'

describe('Workspace Schema Tests', () => {
Expand Down Expand Up @@ -511,4 +513,69 @@ describe('Workspace Schema Tests', () => {
])
})
})

describe('GetInvitationRequestSchema Tests', () => {
it('should validate when correct page and limit are provided for GetInvitationRequestSchema', () => {
const result = GetWorkspaceInvitationsRequest.safeParse({
page: 1,
limit: 10
})

expect(result.success).toBe(true)
})
})

describe('GetInvitationResponseSchema Tests', () => {
it('should validate with proper input for GetInvitationResponseSchema', () => {
const result = GetWorkspaceInvitationsResponse.safeParse({
items: [
{
workspace: {
id: 'workspace-id',
name: 'Workspace Name',
slug: 'workspace-slug',
icon: null
},
roles: [
{
role: {
name: 'Admin',
colorCode: '#FFFFFF'
}
}
],
invitedOn: '2023-12-01T12:00:00Z'
}
],
metadata: {
page: 1,
perPage: 10,
pageCount: 1,
totalCount: 1,
links: {
self: 'https://example.com/self',
first: 'https://example.com/first',
previous: null,
next: null,
last: 'https://example.com/last'
}
}
})

expect(result.success).toBe(true)
})

it('should not validate if items are not an array in GetInvitationResponseSchema', () => {
const result = GetWorkspaceInvitationsResponse.safeParse({
items: 'not-an-array',
metadata: {
page: 1,
perPage: 10
}
})

expect(result.success).toBe(false)
expect(result.error?.issues[0].path).toEqual(['items'])
})
})
})

0 comments on commit 1a5721b

Please sign in to comment.