-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
2 changed files
with
69 additions
and
58 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,30 +1,38 @@ | ||
import { MovieSchema } from './data'; | ||
import { MovieSchema, type MovieSchemaType } from './data'; | ||
import { TypeCompiler } from '@sinclair/typebox/compiler'; | ||
|
||
describe('MovieSchema', () => { | ||
const validate = TypeCompiler.Compile(MovieSchema); | ||
|
||
const movieTitle = 'Yet Another Movie'; | ||
const movieType = 'movie'; | ||
// const movieCast = ['This Guy', 'That Guy', 'The Other Guy', 'Guybrush Threepwood']; | ||
// const movieGenres = ['Action', 'Adventure', 'Comedy']; | ||
const movieYear = 2022; | ||
|
||
const movieWithMandatoryFields: MovieSchemaType = { | ||
title: movieTitle, | ||
type: movieType, | ||
year: movieYear | ||
}; | ||
|
||
it('should validate a movie with at least the mandatory fields', () => { | ||
const validMovie = movieWithMandatoryFields; | ||
expect(validate.Check(validMovie)).toBe(true); | ||
}); | ||
|
||
it('should validate a valid movie', () => { | ||
const validUser = { | ||
title: movieTitle, | ||
type: movieType | ||
}; | ||
expect(validate.Check(validUser)).toBe(true); | ||
it('should not validate a movie without an empty cast', () => { | ||
const invalidMovie = { ...movieWithMandatoryFields, cast: [] }; | ||
expect(validate.Check(invalidMovie)).toBe(false); | ||
}); | ||
|
||
it('should not validate a movie without a title', () => { | ||
const invalidUser = { | ||
type: movieType | ||
}; | ||
expect(validate.Check(invalidUser)).toBe(false); | ||
const invalidMovie = { ...movieWithMandatoryFields, title: '' }; | ||
expect(validate.Check(invalidMovie)).toBe(false); | ||
}); | ||
|
||
it('should not validate a movie without a type', () => { | ||
const invalidUser = { | ||
title: movieTitle | ||
}; | ||
expect(validate.Check(invalidUser)).toBe(false); | ||
const invalidMovie = { ...movieWithMandatoryFields, type: '' }; | ||
expect(validate.Check(invalidMovie)).toBe(false); | ||
}); | ||
}); |
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