-
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
4 changed files
with
35 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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import Post from '../../src/models/post.model' | ||
|
||
describe('Post model', () => { | ||
describe('validation', () => { | ||
test('should validate a post', async function () { | ||
await expect(new Post({ | ||
title: 'Lorem ipsum', | ||
content: 'Lorem ipsum' | ||
}).validate()).resolves.toBeUndefined() | ||
}) | ||
test('should have a title', async () => { | ||
await expect(new Post({ title: undefined, content: '' }).validate()).rejects.toThrow() | ||
}) | ||
test('should have content', async () => { | ||
await expect(new Post({ title: '', content: undefined }).validate()).rejects.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
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,16 @@ | ||
import mongoose from 'mongoose' | ||
|
||
const schema = new mongoose.Schema({ | ||
title: { | ||
type: String, | ||
required: true | ||
}, | ||
content: { | ||
type: String, | ||
required: true | ||
} | ||
}) | ||
|
||
const model = mongoose.model('Post', schema) | ||
|
||
export default model |
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