Skip to content

Commit

Permalink
BE #4 functional test for POST method
Browse files Browse the repository at this point in the history
  • Loading branch information
tito433 committed May 17, 2020
1 parent 4656366 commit 7cb8e8f
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions test/routes/article.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const request = require("supertest");
const app = require("../../app");

describe("Test route /article", () => {
describe("Test GET /article", () => {
test("It should response 200 on GET method", done => {
request(app)
.get("/article")
Expand All @@ -10,4 +10,25 @@ describe("Test route /article", () => {
done();
});
});
});
});


const article = {
title: "Test: how to test express API POST request?",
body: ["<h2>Article body sub heading</h2>","<p>Article body paragraph</p>"]
};

/* POST /article */
describe("Test POST /article", () => {
test("It should response 200 on POST method", done => {
request(app)
.post("/article")
.send(article)
.then(response => {
const respArticle=JSON.parse(response.text);
expect(response.statusCode).toBe(200);
expect(respArticle.title).toBe(article.title);
done();
});
});
});

0 comments on commit 7cb8e8f

Please sign in to comment.