Skip to content

Instantly share code, notes, and snippets.

@stoneboyindc
Created September 17, 2019 20:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stoneboyindc/b328f63e9d0b42335acfecf9314535aa to your computer and use it in GitHub Desktop.
Save stoneboyindc/b328f63e9d0b42335acfecf9314535aa to your computer and use it in GitHub Desktop.
const request = require("request");
const server = require("../../src/server");
const base = "http://localhost:3000/advertisements/";
describe("routes : advertisements", () => {
describe("GET /advertisements", () => {
it("should return a status code 200", done => {
request.get(base, (err, res, body) => {
expect(res.statusCode).toBe(200);
done();
});
});
});
describe("GET /advertisements/new", () => {
it("should render a new advertisement form", done => {
request.get(`${base}new`, (err, res, body) => {
expect(err).toBeNull();
expect(body).toContain("New advertisement");
done();
});
});
});
describe("POST /advertisements/create", () => {
const options = {
url: `${base}create`,
form: {
title: "advertisement 1",
description: "advertisement 1 content"
}
};
it("should create a new advertisement and redirect", done => {
//#1
request.post(
options,
//#2
(err, res, body) => {
Advertisement.findOne({ where: { title: "advertisement 1" } })
.then(advertisement => {
expect(res.statusCode).toBe(303);
expect(advertisement.title).toBe("advertisement 1");
expect(advertisement.description).toBe("advertisement 1 content");
done();
})
.catch(err => {
console.log(err);
done();
});
}
);
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment