Skip to content

Commit

Permalink
Add tests for new validation; fix existing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
TylerZeroMaster committed Jul 1, 2024
1 parent e37144f commit 7b3aed4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
15 changes: 13 additions & 2 deletions server/src/model/book.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('Book validations', () => {
{ title: chapterTitle, children: [] },
{ title: chapterTitle, children: [] }
]
book.load(bookMaker({ toc }))
book.load(bookMaker({ toc, slug: 'test' }))
expectErrors(book, [BookValidationKind.DUPLICATE_CHAPTER_TITLE, BookValidationKind.DUPLICATE_CHAPTER_TITLE])
})
it(BookValidationKind.MISSING_PAGE.title, () => {
Expand All @@ -28,11 +28,22 @@ describe('Book validations', () => {
{ title: 'Chapter 1', children: ['m00001'] },
{ title: 'Chapter 2', children: ['m00001'] }
]
book.load(bookMaker({ toc }))
book.load(bookMaker({ toc, slug: 'test' }))
const page = first(book.pages)
page.load(pageMaker({}))
expectErrors(book, [BookValidationKind.DUPLICATE_PAGE, BookValidationKind.DUPLICATE_PAGE])
})
it(BookValidationKind.INVALID_BOOK_NAME.title, () => {
const bundle = makeBundle()
const book = first(loadSuccess(bundle).books)
const toc: BookMakerTocNode[] = [
{ title: 'Chapter 1', children: ['m00001'] }
]
book.load(bookMaker({ toc, slug: 'not-test' }))
const page = first(book.pages)
page.load(pageMaker({}))
expectErrors(book, [BookValidationKind.INVALID_BOOK_NAME])
})
})

describe('Book computed properties', () => {
Expand Down
8 changes: 7 additions & 1 deletion server/src/model/bundle.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect } from '@jest/globals'
import { type Bundle, BundleValidationKind } from './bundle'
import { bundleMaker, expectErrors, first, loadSuccess, makeBundle, read } from './spec-helpers.spec'
import { bookMaker, bundleMaker, expectErrors, first, loadSuccess, makeBundle, read } from './spec-helpers.spec'

describe('Bundle validations', () => {
it(BundleValidationKind.NO_BOOKS.title, () => {
Expand All @@ -14,6 +14,12 @@ describe('Bundle validations', () => {
book.load(undefined)
expectErrors(bundle, [BundleValidationKind.MISSING_BOOK])
})
it(BundleValidationKind.MISMATCHED_SLUG.title, () => {
const bundle = loadSuccess(makeBundle())
const book = first(bundle.books)
book.load(bookMaker({ slug: 'something' }))
expectErrors(bundle, [BundleValidationKind.MISMATCHED_SLUG])
})
})

describe('Happy path', () => {
Expand Down

0 comments on commit 7b3aed4

Please sign in to comment.