Created
September 17, 2019 20:10
-
-
Save stoneboyindc/b328f63e9d0b42335acfecf9314535aa to your computer and use it in GitHub Desktop.
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
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