Skip to content
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
66 changes: 66 additions & 0 deletions src/clients/channels-client.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { http, HttpResponse } from 'msw'
import { describe, expect, it } from 'vitest'
import { CommsApi } from '../comms-api'
import { server } from '../testUtils/msw-setup'
import {
TEST_API_BASE_URL as BASE,
TEST_API_TOKEN,
TEST_CHANNEL_ID,
} from '../testUtils/test-defaults'

const CHANNEL_RESPONSE = {
id: TEST_CHANNEL_ID,
name: 'General',
creator: 1,
public: true,
workspace_id: 1,
archived: false,
created_ts: 1_609_459_200,
version: 1,
}

describe('ChannelsClient — wire serialization', () => {
it.each([
['createChannel', true],
['createChannel', false],
['updateChannel', true],
['updateChannel', false],
] as const)(
'%s sends use_default_recipients: %s and empty default audience arrays',
async (method, useDefaultRecipients) => {
const suffix = method === 'createChannel' ? 'add' : 'update'
let body: Record<string, unknown> | undefined
server.use(
http.post(`${BASE}/channels/${suffix}`, async ({ request }) => {
body = (await request.json()) as Record<string, unknown>
return HttpResponse.json(CHANNEL_RESPONSE)
}),
)

const api = new CommsApi(TEST_API_TOKEN)
if (method === 'createChannel') {
await api.channels.createChannel({
workspaceId: 1,
name: 'General',
useDefaultRecipients,
defaultGroups: [],
defaultRecipients: [],
})
} else {
await api.channels.updateChannel({
id: TEST_CHANNEL_ID,
name: 'General',
useDefaultRecipients,
defaultGroups: [],
defaultRecipients: [],
})
}

expect(body).toMatchObject({
use_default_recipients: useDefaultRecipients,
default_groups: [],
default_recipients: [],
})
},
)
})
2 changes: 2 additions & 0 deletions src/types/requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const CreateChannelArgsSchema = z.object({
color: z.number().nullable().optional(),
public: z.boolean().nullable().optional(),
description: z.string().nullable().optional(),
useDefaultRecipients: z.boolean().nullable().optional(),
defaultGroups: z.array(z.string()).nullable().optional(),
defaultRecipients: z.array(z.number()).nullable().optional(),
isFavorited: z.boolean().nullable().optional(),
Expand All @@ -32,6 +33,7 @@ export const UpdateChannelArgsSchema = z.object({
color: z.number().nullable().optional(),
public: z.boolean().nullable().optional(),
description: z.string().nullable().optional(),
useDefaultRecipients: z.boolean().nullable().optional(),
defaultGroups: z.array(z.string()).nullable().optional(),
defaultRecipients: z.array(z.number()).nullable().optional(),
isFavorited: z.boolean().nullable().optional(),
Expand Down
Loading