Created
August 20, 2018 08:29
-
-
Save dulgeoion/56f90024ddc416abd3496d4d52dfb030 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
process.env.NODE_ENV = "test"; | |
const moment = require("moment"); | |
const chai = require("chai"); | |
const should = chai.should(); | |
const chaiHttp = require("chai-http"); | |
chai.use(chaiHttp); | |
const jwt = require("../../middlewares/jwt"); | |
const server = require("../../../server"); | |
const knex = require("../../db/connection.js"); | |
const body = { | |
email: "kerrattnew0@vkontakte.ru", | |
password: "12345678", | |
firstname: "lololo", | |
surname: "Cowpe", | |
refLink: null, | |
payment: 1, | |
birthdate: "6/22/1990", | |
gender: "Male", | |
phone: "(332) 5680417", | |
job: "Payment Adjustment Coordinator", | |
company: "Lindgren-Erdman", | |
industry: "Topicblab", | |
salary: 1, | |
subscription: false, | |
addressId: 1 | |
}; | |
const token = jwt.sign({ data: body }); | |
describe("POST /auth/register", () => { | |
beforeEach(() => { | |
return knex.migrate | |
.rollback() | |
.then(() => { | |
return knex.migrate.latest(); | |
}) | |
.then(() => { | |
return knex.seed.run(); | |
}); | |
}); | |
afterEach(() => { | |
return knex.migrate.rollback(); | |
}); | |
it("throws error without email", done => { | |
body.email = ""; | |
chai | |
.request(server) | |
.post("/auth/register") | |
.send(body) | |
.end((err, res) => { | |
// there should be no errors | |
should.not.exist(err); | |
// there should be a 200 status code | |
res.status.should.equal(400); | |
done(); | |
}); | |
}); | |
it("throws error without passwrod", done => { | |
body.password = ""; | |
chai | |
.request(server) | |
.post("/auth/register") | |
.send(body) | |
.end((err, res) => { | |
// there should be no errors | |
should.not.exist(err); | |
// there should be a 200 status code | |
res.status.should.equal(400); | |
done(); | |
}); | |
}); | |
it("should return user object", done => { | |
var user = {}; | |
body.email = "kerrattnew012@vkontakte.ru"; | |
body.password = "123123123"; | |
chai | |
.request(server) | |
.post("/auth/register") | |
.send(body) | |
.end((err, res) => { | |
// there should be no errors | |
should.not.exist(err); | |
// console.log(res) | |
// there should be a 200 status code | |
res.status.should.equal(200); | |
// the response should be JSON | |
res.type.should.equal("application/json"); | |
// the JSON response body should have a | |
// key-value pair of {"status": "success"} | |
res.body.message.should.eql("success"); | |
// the JSON response body should have a | |
// key-value pair of {"data": [3 movie objects]} | |
res.body.user.should.include.keys( | |
"id", | |
"firstname", | |
"gender", | |
"surname", | |
"subscription", | |
"industry", | |
"job", | |
"password", | |
"payment", | |
"phone", | |
"addressId", | |
"birthdate", | |
"company", | |
"email" | |
); | |
done(); | |
}); | |
}); | |
it("throws error that email is already taken", done => { | |
body.email = "osmewing1@mapquest.com"; | |
body.password = "13232332332"; | |
chai | |
.request(server) | |
.post("/auth/register") | |
.send(body) | |
.end((err, res) => { | |
// there should be no errors | |
should.not.exist(err); | |
// there should be a 406 status code | |
res.status.should.equal(406); | |
done(); | |
}); | |
}); | |
it("should throw error if required fields are not sent", done => { | |
var user = {}; | |
body.email = "kerrattnew012@vkontakte.ru"; | |
body.password = "123123123"; | |
body.firstname = ""; | |
chai | |
.request(server) | |
.post("/auth/register") | |
.send(body) | |
.end((err, res) => { | |
// there should be no errors | |
should.not.exist(err); | |
// console.log(res) | |
// there should be a 200 status code | |
res.status.should.equal(200); | |
// the response should be JSON | |
done(); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment