Skip to content

Instantly share code, notes, and snippets.

@akhalsa
Created February 9, 2019 20:05
Show Gist options
  • Save akhalsa/19b63da3be395064ff8f85c465b7b6c6 to your computer and use it in GitHub Desktop.
Save akhalsa/19b63da3be395064ff8f85c465b7b6c6 to your computer and use it in GitHub Desktop.
var chai = require("chai");
var chaiHttp = require("chai-http");
var server = require("../server");
var db = require("../models");
// Configure chai
chai.use(chaiHttp);
chai.should();
describe("Basic Example API Test", function() {
describe("GET ALL Examples", () => {
// Test to get all students record
before(async () => {
await db.sequelize.sync({ force: true });
await db.Example.destroy({
where: {},
truncate: true
});
await db.Example.create({
text: "some text for my example",
description: "example description"
});
});
it("should get all examples", function(done) {
chai
.request(server.app)
.get("/api/examples")
.end((err, res) => {
res.should.have.status(200);
console.log("got res body: " + JSON.stringify(res.body));
res.body.should.have.length(1);
chai.assert(
res.body[0].text === "some text for my example",
"got the wrong text"
);
chai.assert(
res.body[0].description === "example description",
"got the wrong description"
);
done();
});
});
});
describe("POST Example", () => {
// Test to get all students record
before(async () => {
await db.sequelize.sync({ force: true });
await db.Example.destroy({
where: {},
truncate: true
});
await chai
.request(server.app)
.post("/api/examples")
.send({ text: "posted text", description: "posted description" });
});
it("should get the posted example", function(done) {
chai
.request(server.app)
.get("/api/examples")
.end((err, res) => {
res.should.have.status(200);
res.body.should.have.length(1);
chai.assert(res.body[0].text === "posted text", "got the wrong text");
chai.assert(
res.body[0].description === "posted description",
"got the wrong description"
);
done();
});
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment