Last active
November 24, 2018 15:00
-
-
Save ekpangmichael/817e37661bca744500707402bc8c81d7 to your computer and use it in GitHub Desktop.
userTest.js
This file contains hidden or 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
import request from "supertest"; | |
import chaiHttp from "chai-http"; | |
import chai, { expect } from "chai"; | |
chai.use(chaiHttp); | |
const newUser = { | |
userName: "Ekpang Michael", | |
userEmail: "[email protected]", | |
userAddress: "Lagos", | |
userPassword: "test123" | |
}; | |
describe("### Testing Users Routes", () => { | |
it("should create a new user and get back a response", done => { | |
request(app) | |
.post("/api/v1/users") | |
.send(newUser) | |
.end((err, res) => { | |
const data = JSON.parse(res.text); | |
const name = data[1].users.userName; | |
expect(err).to.be.a("null"); | |
expect(name).to.equal(newUser.userName); | |
expect(data[0].message).to.equal("Registration successful"); | |
done(); | |
}); | |
}); | |
it("Signin should return user sigin successful", done => { | |
request(app) | |
.post("/api/v1/users/signin") | |
.send({ | |
userEmail: newUser.userEmail, | |
userPassword: newUser.userPassword | |
}) | |
.end((err, res) => { | |
const data = JSON.parse(res.text); | |
const name = data[1].users.userName; | |
expect(err).to.be.a("null"); | |
expect(name).to.equal(newUser.userName); | |
expect(data[0].message).to.equal("User login successfully"); | |
done(); | |
}); | |
}); | |
it("Get one particular user - should return User found successfully", done => { | |
request(app) | |
.get(`/api/v1/users/${id}`) | |
.send() | |
.end((err, res) => { | |
expect(res).to.have.status(200); | |
const data = JSON.parse(res.text); | |
expect(data[0].message).to.equal("User found successfully"); | |
done(); | |
}); | |
}); | |
it("create new user with the same email should return Email already Taken", done => { | |
request(app) | |
.post("/api/v1/users/") | |
.send(newUser) | |
.end((err, res) => { | |
expect(res).to.have.status(400); | |
const data = JSON.parse(res.text); | |
expect(data.message).to.equal("Email already Taken!"); | |
done(); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Looks good to me