Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(schema): Add workspace invitation schema #612

Merged
merged 4 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions packages/schema/src/workspace/index.ts
rajdip-b marked this conversation as resolved.
Show resolved Hide resolved
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'])
})
})
})
Loading