-
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
6 changed files
with
63 additions
and
48 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 |
---|---|---|
|
@@ -38,4 +38,4 @@ docker compose -f docker-compose.dev.yml up | |
#### Supported Services | ||
|
||
- MongoDB | ||
- Redis | ||
- Redis |
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,18 +1,24 @@ | ||
import Post from '../../src/models/post.model' | ||
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() | ||
}) | ||
}) | ||
}) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,34 @@ | ||
import Joi from 'joi' | ||
import Joi from "joi"; | ||
|
||
const schema = Joi | ||
.object() | ||
const schema = Joi.object() | ||
.keys({ | ||
PORT: Joi.number().required().default(3000), | ||
MONGODB_HOST: Joi.string().required().example('localhost'), | ||
MONGODB_HOST: Joi.string().required().example("localhost"), | ||
MONGODB_PORT: Joi.number().required().example(27017), | ||
MONGODB_USER: Joi.string().required().example('root'), | ||
MONGODB_PASS: Joi.string().required().example('pass'), | ||
MONGODB_NAME: Joi.string().optional().example('db'), | ||
REDIS_QUEUE_HOST: Joi.string().optional().example('localhost'), | ||
REDIS_QUEUE_PORT: Joi.number().optional().example(6379) | ||
MONGODB_USER: Joi.string().required().example("root"), | ||
MONGODB_PASS: Joi.string().required().example("pass"), | ||
MONGODB_NAME: Joi.string().optional().example("db"), | ||
REDIS_QUEUE_HOST: Joi.string().optional().example("localhost"), | ||
REDIS_QUEUE_PORT: Joi.number().optional().example(6379), | ||
}) | ||
.unknown() | ||
.unknown(); | ||
|
||
const { value: env, error } = schema.prefs({ errors: { label: 'key' } }).validate(process.env) | ||
const { value: env, error } = schema | ||
.prefs({ errors: { label: "key" } }) | ||
.validate(process.env); | ||
|
||
if (error != null) { | ||
throw new Error(`Config validation error: ${error.message}`) | ||
throw new Error(`Config validation error: ${error.message}`); | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions | ||
const MONGODB_URL = `mongodb://${env.MONGODB_USER}:${env.MONGODB_PASS}@${env.MONGODB_HOST}:${env.MONGODB_PORT}/${env.MONGODB_NAME !== undefined ? env.MONGODB_NAME : ''}` | ||
const MONGODB_URL = `mongodb://${env.MONGODB_USER}:${env.MONGODB_PASS}@${ | ||
env.MONGODB_HOST | ||
}:${env.MONGODB_PORT}/${ | ||
env.MONGODB_NAME !== undefined ? env.MONGODB_NAME : "" | ||
}`; | ||
|
||
export default { | ||
...env, | ||
MONGODB_URL | ||
} | ||
MONGODB_URL, | ||
}; |
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 |
---|---|---|
@@ -1,16 +1,16 @@ | ||
import mongoose from 'mongoose' | ||
import mongoose from "mongoose"; | ||
|
||
const schema = new mongoose.Schema({ | ||
title: { | ||
type: String, | ||
required: true | ||
required: true, | ||
}, | ||
content: { | ||
type: String, | ||
required: true | ||
} | ||
}) | ||
required: true, | ||
}, | ||
}); | ||
|
||
const model = mongoose.model('Post', schema) | ||
const model = mongoose.model("Post", schema); | ||
|
||
export default model | ||
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