-
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
1 parent
39977c1
commit 32aa44a
Showing
3 changed files
with
67 additions
and
1 deletion.
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 |
---|---|---|
|
@@ -31,3 +31,5 @@ src/icons | |
.env | ||
index.js | ||
.eslintignore | ||
testing.md | ||
test/db.js |
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,62 @@ | ||
const Article = require('../models/article'); | ||
const { getArticle, createArticle, deleteArticle, updateArticle} = require('../controllers/article'); | ||
const {MongoClient} = require('mongodb'); | ||
const request = require('supertest'); | ||
const mongoose = require('mongoose') | ||
const express = require('express'); | ||
const app = express(); | ||
require('./db'); | ||
|
||
const mockArticleData = { | ||
article_id: "1", title: "Title", | ||
subtitle: "Subtitle", markdown: "Markdown", description: "Description", | ||
images: "Image", category: "Category", createdAt: Date.now(), | ||
sanitizedHtml: '<p>Markdown</p>\n', updatedAt: Date.now(), __v: 0} | ||
|
||
const mockArticleData2 = {_id: mongoose.Types.ObjectId(), | ||
article_id: "2", title: "Title", | ||
subtitle: "Subtitle", markdown: "Markdown", description: "Description", | ||
images: "Image", category: "Category"} | ||
|
||
// Initial setup and tear down | ||
beforeEach(async () => { | ||
await Article.deleteMany() | ||
await Article(mockArticleData2).save() | ||
}) | ||
|
||
// Setting up testing enviroment with test code | ||
describe('Create article to database',() => { | ||
|
||
it("should create article in database", async () => { | ||
const mockArticle = new Article(mockArticleData); | ||
console.log(mockArticle) | ||
|
||
await mockArticle.save(); | ||
// expect(mockArticle.article_id).toEqual("1") | ||
// expect(mockArticle.title).toEqual("Title") | ||
// expect(mockArticle.subtitle).toEqual("Subtitle") | ||
// expect(mockArticle.markdown).toEqual("Markdown") | ||
// expect(mockArticle.description).toEqual("Description") | ||
// expect(mockArticle.images).toEqual("Image") | ||
// expect(mockArticle.category).toEqual("Category") | ||
const insertedArticle = await Article.findOne({article_id: "1"}); | ||
console.log(insertedArticle) | ||
// expect(insertedArticle).toEqual(mockArticle); | ||
}); | ||
|
||
it("should verify create route", async () => { | ||
const response = await request(app).post('/api/articles').send({ | ||
mockArticleData | ||
}); | ||
|
||
expect(response.body).not.toBeNull(); | ||
}); | ||
|
||
it("should get article from database", async () => { | ||
const article = await Article.findById(mockArticleData2._id); | ||
|
||
console.log(article) | ||
expect(mockArticleData2.title).toBe("Title") | ||
}) | ||
}); | ||
|