-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ce4d078
commit bc0fde2
Showing
5 changed files
with
74 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
import { chapterSchema, lessonSchema, partSchema, tutorialSchema } from '@tutorialkit/types'; | ||
import { contentSchema } from '@tutorialkit/types'; | ||
import { defineCollection } from 'astro:content'; | ||
|
||
const tutorial = defineCollection({ | ||
type: 'content', | ||
schema: tutorialSchema.strict().or(partSchema.strict()).or(chapterSchema.strict()).or(lessonSchema.strict()), | ||
schema: contentSchema, | ||
}); | ||
|
||
export const collections = { tutorial }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
import { chapterSchema, lessonSchema, partSchema, tutorialSchema } from '@tutorialkit/types'; | ||
import { contentSchema } from '@tutorialkit/types'; | ||
import { defineCollection } from 'astro:content'; | ||
|
||
const tutorial = defineCollection({ | ||
type: 'content', | ||
schema: tutorialSchema.strict().or(partSchema.strict()).or(chapterSchema.strict()).or(lessonSchema.strict()), | ||
schema: contentSchema, | ||
}); | ||
|
||
export const collections = { tutorial }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { describe, it, expect } from 'vitest'; | ||
import { contentSchema } from './content.js'; | ||
|
||
describe('contentSchema', () => { | ||
it('should validate a valid part', () => { | ||
expect(() => | ||
contentSchema.parse({ | ||
title: 'Part 1', | ||
type: 'part', | ||
slug: 'part-one', | ||
}), | ||
).not.toThrow(); | ||
}); | ||
|
||
it('should validate an invalid part', () => { | ||
expect(() => | ||
contentSchema.parse({ | ||
type: 'part', | ||
}), | ||
).toThrow(); | ||
}); | ||
|
||
it('should validate a valid chapter', () => { | ||
expect(() => | ||
contentSchema.parse({ | ||
type: 'chapter', | ||
title: 'Chapter 1', | ||
}), | ||
).not.toThrow(); | ||
}); | ||
|
||
it('should validate an invalid chapter', () => { | ||
expect(() => | ||
contentSchema.parse({ | ||
type: 'chapter', | ||
}), | ||
).toThrow(); | ||
}); | ||
|
||
it('should validate a valid lesson', () => { | ||
expect(() => | ||
contentSchema.parse({ | ||
type: 'lesson', | ||
title: 'Lesson 1', | ||
}), | ||
).not.toThrow(); | ||
}); | ||
|
||
it('should validate an invalid lesson', () => { | ||
expect(() => | ||
contentSchema.parse({ | ||
type: 'lesson', | ||
}), | ||
).toThrow(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import type { z } from 'zod'; | ||
import { chapterSchema } from './chapter.js'; | ||
import { lessonSchema } from './lesson.js'; | ||
import { partSchema } from './part.js'; | ||
import { tutorialSchema } from './tutorial.js'; | ||
|
||
export const contentSchema = tutorialSchema | ||
.strict() | ||
.or(partSchema.strict()) | ||
.or(chapterSchema.strict()) | ||
.or(lessonSchema.strict()); | ||
|
||
export type ContentSchema = z.infer<typeof contentSchema>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
export * from './chapter.js'; | ||
export * from './common.js'; | ||
export * from './content.js'; | ||
export * from './lesson.js'; | ||
export * from './part.js'; | ||
export * from './tutorial.js'; |