Skip to content

Commit 8ec4e58

Browse files
committed
updates
1 parent 81e9184 commit 8ec4e58

File tree

8 files changed

+112
-21
lines changed

8 files changed

+112
-21
lines changed

src/api/boards.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
import type { Client, Request } from '@/interfaces';
2-
import { boardSchema, BoardSchema, CreateBoard } from '@/schemas/api/boards';
2+
import { boardSchema, Board, CreateBoard } from '@/schemas/api/boards';
33

44
export class Boards {
55
constructor(private client: Client) {}
66

77
/** Create a new board. */
8-
async createBoard<T = BoardSchema>(board: CreateBoard): Promise<T> {
8+
async create<T = Board>(board: CreateBoard): Promise<T> {
99
const request: Request = {
1010
url: '/boards',
1111
method: 'POST',
1212
query: board,
1313
};
1414

15-
return this.client.sendRequest(request, boardSchema);
15+
return this.client.sendRequest<T, never>(request, boardSchema);
1616
}
17+
18+
async delete(boardId) {}
1719
}

src/baseClient.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export class BaseClient implements Client {
2929
});
3030

3131
if (!response.ok) {
32+
const text = await response.text();
3233
throw new Error('Request Error'); // todo handle error
3334
}
3435

src/schemas/api/boards/boardSchema.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
import { z } from 'zod';
2+
import { prefsSchema } from '@/schemas/common/prefsSchema';
3+
import { colorSchema } from '@/schemas/common';
24

35
export const boardSchema = z.object({
4-
id: z.unknown(),
5-
name: z.unknown(),
6-
desc: z.unknown(),
7-
descData: z.unknown(),
8-
closed: z.unknown(),
6+
id: z.string(),
7+
name: z.string(),
8+
desc: z.string(),
9+
descData: z.string().nullable(),
10+
closed: z.boolean(),
911
idOrganization: z.unknown(),
1012
idEnterprise: z.unknown(),
11-
pinned: z.unknown(),
12-
url: z.unknown(),
13-
shortUrl: z.unknown(),
14-
prefs: z.unknown(),
15-
labelNames: z.unknown(),
16-
limits: z.unknown()
13+
pinned: z.boolean(),
14+
url: z.string().url(),
15+
shortUrl: z.string().url(),
16+
prefs: prefsSchema,
17+
labelNames: z.record(colorSchema, z.string()),
18+
limits: z.object({}).strict(),
1719
}).strict();
1820

19-
export type BoardSchema = z.infer<typeof boardSchema>;
21+
export type Board = z.infer<typeof boardSchema>;

src/schemas/common/colorSchema.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { z } from 'zod';
2+
3+
export const colorSchema = z.enum([
4+
'green',
5+
'yellow',
6+
'orange',
7+
'red',
8+
'purple',
9+
'blue',
10+
'sky',
11+
'lime',
12+
'pink',
13+
'black',
14+
'green_dark',
15+
'yellow_dark',
16+
'orange_dark',
17+
'red_dark',
18+
'purple_dark',
19+
'blue_dark',
20+
'sky_dark',
21+
'lime_dark',
22+
'pink_dark',
23+
'black_dark',
24+
'green_light',
25+
'yellow_light',
26+
'orange_light',
27+
'red_light',
28+
'purple_light',
29+
'blue_light',
30+
'sky_light',
31+
'lime_light',
32+
'pink_light',
33+
'black_light'
34+
]);

src/schemas/common/hexColorSchema.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { z } from 'zod';
2+
3+
export const hexColorSchema = z.string().regex(/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/, {
4+
message: 'Invalid hex color code',
5+
});

src/schemas/common/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export * from './colorSchema';
2+
export * from './hexColorSchema';
3+
export * from './prefsSchema';

src/schemas/common/prefsSchema.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { z } from 'zod';
2+
import { colorSchema } from './colorSchema';
3+
import { hexColorSchema } from './hexColorSchema';
4+
5+
export const prefsSchema = z.object({
6+
permissionLevel: z.enum(['private']),
7+
hideVotes: z.boolean(),
8+
voting: z.enum(['disabled']),
9+
comments: z.enum(['members']),
10+
invitations: z.enum(['members']),
11+
selfJoin: z.boolean(),
12+
cardCovers: z.boolean(),
13+
showCompleteStatus: z.boolean(),
14+
cardCounts: z.boolean(),
15+
isTemplate: z.boolean(),
16+
cardAging: z.enum(['regular']),
17+
calendarFeedEnabled: z.boolean(),
18+
hiddenPluginBoardButtons: z.array(z.unknown()),
19+
switcherViews: z.array(z.object({
20+
viewType: z.enum(['Board', 'Table', 'Calendar', 'Dashboard', 'Timeline', 'Map']),
21+
enabled: z.boolean(),
22+
}).strict()),
23+
background: colorSchema,
24+
backgroundColor: hexColorSchema,
25+
backgroundDarkColor: hexColorSchema.nullable(),
26+
backgroundImage: z.unknown().nullable(),
27+
backgroundDarkImage: z.unknown().nullable(),
28+
backgroundImageScaled: z.unknown().nullable(),
29+
backgroundTile: z.boolean(),
30+
backgroundBrightness: z.enum(['dark']),
31+
sharedSourceUrl: z.string().url().nullable(),
32+
backgroundBottomColor: hexColorSchema,
33+
backgroundTopColor: hexColorSchema,
34+
canBePublic: z.boolean(),
35+
canBeEnterprise: z.boolean(),
36+
canBeOrg: z.boolean(),
37+
canBePrivate: z.boolean(),
38+
canInvite: z.boolean(),
39+
}).strict();
40+
41+
export type Prefs = z.infer<typeof prefsSchema>;

tests/integration/api/boards.test.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { describe, it, expect } from 'vitest';
2-
import { type BoardSchema, CreateBoard } from '@/schemas/api/boards';
2+
import { Board, CreateBoard } from '@/schemas/api/boards';
33
import { TrelloClient } from '@';
44
import { config } from '@tests/integration/config';
55

@@ -9,14 +9,17 @@ const mockBoardInput: CreateBoard = {
99
};
1010

1111
describe('Boards Service Integration Tests', () => {
12+
let board: Board | undefined;
1213
const trelloClient = new TrelloClient(config);
1314

1415
it('should successfully create a board with valid input', async () => {
15-
const result = await trelloClient.boards.createBoard(mockBoardInput);
16+
board = await trelloClient.boards.createBoard<Board>(mockBoardInput); // todo remove generic use
1617

17-
// Verify the response matches our mock data
18-
expect(result).toBeDefined();
19-
20-
// expect(result.id).toBe('board-123');
18+
expect(board).toBeDefined();
19+
expect(board.name).toBe(mockBoardInput.name);
2120
});
21+
22+
it('should successfully delete a board', async () => {
23+
24+
})
2225
});

0 commit comments

Comments
 (0)