diff --git a/__test__/models/post.model.test.ts b/__test__/models/post.model.test.ts new file mode 100644 index 0000000..6e082fe --- /dev/null +++ b/__test__/models/post.model.test.ts @@ -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() + }) + }) +}) \ No newline at end of file diff --git a/package.json b/package.json index fb9dfe2..dc0ec3c 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "build": "npx tsc", "start": "node dist/index.js", "dev": "env-cmd nodemon ./src/index.ts", - "test": "docker compose -f docker-compose.test.yml up --exit-code-from app" + "test": "jest" }, "repository": { "type": "git", diff --git a/src/models/post.model.ts b/src/models/post.model.ts new file mode 100644 index 0000000..23875d9 --- /dev/null +++ b/src/models/post.model.ts @@ -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 \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index a333dc0..3353882 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -7,9 +7,6 @@ "forceConsistentCasingInFileNames": true, "strict": true, "skipLibCheck": true, - "paths": { - "@/*": ["./*"] - } }, "include": [ "./src/**/*",