Skip to content

Commit be80b32

Browse files
committed
🚨 Add tests for workbook schema (#2020)
1 parent 83446eb commit be80b32

File tree

1 file changed

+101
-0
lines changed

1 file changed

+101
-0
lines changed

src/test/lib/zod/workbook_schema.test.ts

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,71 @@ describe('workbook schema', () => {
8080
validateWorkBookSchema(workBookSchema, workbook);
8181
});
8282

83+
test('when an url slug is given one character', () => {
84+
const workbook: WorkBook = createWorkBookBase({
85+
authorId: '1',
86+
isPublished: true,
87+
urlSlug: 'a',
88+
});
89+
validateWorkBookSchema(workBookSchema, workbook);
90+
});
91+
92+
test('when an url slug is given characters and hyphen', () => {
93+
const workbook: WorkBook = createWorkBookBase({
94+
authorId: '1',
95+
isPublished: true,
96+
urlSlug: 'union-find',
97+
workBookType: WorkBookType.SOLUTION,
98+
});
99+
validateWorkBookSchema(workBookSchema, workbook);
100+
});
101+
102+
test('when an url slug is given characters, number and hyphens', () => {
103+
const workbook: WorkBook = createWorkBookBase({
104+
authorId: '1',
105+
isPublished: true,
106+
urlSlug: '2-sat',
107+
workBookType: WorkBookType.SOLUTION,
108+
});
109+
validateWorkBookSchema(workBookSchema, workbook);
110+
});
111+
112+
test('when an url slug is given 30 characters', () => {
113+
const workbook: WorkBook = createWorkBookBase({
114+
authorId: '1',
115+
isPublished: true,
116+
urlSlug: 'a'.repeat(30),
117+
});
118+
validateWorkBookSchema(workBookSchema, workbook);
119+
});
120+
121+
test('when an url slug is given an empty string', () => {
122+
const workbook: WorkBook = createWorkBookBase({
123+
authorId: '1',
124+
isPublished: true,
125+
urlSlug: '',
126+
});
127+
validateWorkBookSchema(workBookSchema, workbook);
128+
});
129+
130+
test('when an url slug is given null', () => {
131+
const workbook: WorkBook = createWorkBookBase({
132+
authorId: '1',
133+
isPublished: true,
134+
urlSlug: null,
135+
});
136+
validateWorkBookSchema(workBookSchema, workbook);
137+
});
138+
139+
test('when an url slug is given undefined', () => {
140+
const workbook: WorkBook = createWorkBookBase({
141+
authorId: '1',
142+
isPublished: true,
143+
urlSlug: undefined,
144+
});
145+
validateWorkBookSchema(workBookSchema, workbook);
146+
});
147+
83148
test('when workbook tasks are given 200 tasks', () => {
84149
const workBookTasks = [];
85150

@@ -229,6 +294,42 @@ describe('workbook schema', () => {
229294
validateWorkBookSchema(workBookSchema, workbook);
230295
});
231296

297+
test('when an invalid url slug is given 31 characters', () => {
298+
const workbook: WorkBook = createWorkBookBase({
299+
authorId: '1',
300+
isPublished: true,
301+
urlSlug: 'a'.repeat(31),
302+
});
303+
validateWorkBookSchema(workBookSchema, workbook);
304+
});
305+
306+
test('when an invalid url slug is given characters and spaces', () => {
307+
const workbook: WorkBook = createWorkBookBase({
308+
authorId: '1',
309+
isPublished: true,
310+
urlSlug: 'directed acyclic graph',
311+
});
312+
validateWorkBookSchema(workBookSchema, workbook);
313+
});
314+
315+
test('when an invalid url slug is given hyphen', () => {
316+
const workbook: WorkBook = createWorkBookBase({
317+
authorId: '1',
318+
isPublished: true,
319+
urlSlug: '-',
320+
});
321+
validateWorkBookSchema(workBookSchema, workbook);
322+
});
323+
324+
test('when an invalid url slug is given hyphens', () => {
325+
const workbook: WorkBook = createWorkBookBase({
326+
authorId: '1',
327+
isPublished: true,
328+
urlSlug: '--',
329+
});
330+
validateWorkBookSchema(workBookSchema, workbook);
331+
});
332+
232333
test('when an empty workbook task is given', () => {
233334
const workbook: WorkBook = createWorkBookBase({
234335
workBookTasks: [],

0 commit comments

Comments
 (0)