From 7b3aed4728910cd74c7db28ac85cad681367e4cb Mon Sep 17 00:00:00 2001 From: Tyler Nullmeier Date: Mon, 24 Jun 2024 10:47:23 -0500 Subject: [PATCH] Add tests for new validation; fix existing tests --- server/src/model/book.spec.ts | 15 +++++++++++++-- server/src/model/bundle.spec.ts | 8 +++++++- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/server/src/model/book.spec.ts b/server/src/model/book.spec.ts index 65ead91f..792973d7 100644 --- a/server/src/model/book.spec.ts +++ b/server/src/model/book.spec.ts @@ -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, () => { @@ -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', () => { diff --git a/server/src/model/bundle.spec.ts b/server/src/model/bundle.spec.ts index 191b43a4..8537b7b7 100644 --- a/server/src/model/bundle.spec.ts +++ b/server/src/model/bundle.spec.ts @@ -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, () => { @@ -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', () => {