Created
November 9, 2018 10:10
-
-
Save mksglu/4abc4f8e4f7dd242f71b5b58e183dee5 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"; | |
import * as mongoose from "mongoose"; | |
import * as request from "supertest"; | |
import server from "../../app"; | |
import { INVITE_EMAIL, mockUser } from "../../utils/test.utils"; | |
describe("Users Route", () => { | |
let token, id, mailConfirm: string; | |
describe("/POST users", () => { | |
it("it should add a new user", done => { | |
request(server) | |
.post("/sign-up") | |
.send(mockUser) | |
.end((err: any, res: any) => { | |
expect(res.status).toBe(201); | |
id = res.body.data._id; | |
mailConfirm = res.body.data.mailConfirm; | |
done(); | |
}); | |
}); | |
it("it should login with correct password ", done => { | |
request(server) | |
.post("/sign-in") | |
.send({ email: mockUser.email, password: mockUser.password }) | |
.end((err: any, res: any) => { | |
expect(res.status).toBe(201); | |
token = res.body.data.token; | |
done(); | |
}); | |
}); | |
it("should be invite user", done => { | |
request(server) | |
.post("/users") | |
.set({ Authorization: `Bearer ${token}` }) | |
.send({ inviteEmail: INVITE_EMAIL }) | |
.end((err: any, res: any) => { | |
expect(res.status).toBe(201); | |
done(); | |
}); | |
}); | |
}); | |
describe("/GET users", () => { | |
it("it should be return a user by the given id", done => { | |
request(server) | |
.get(`/users/${id}`) | |
.set({ Authorization: `Bearer ${token}` }) | |
.end((err: any, res: any) => { | |
expect(res.status).toBe(200); | |
done(); | |
}); | |
}); | |
}); | |
describe("/PUT users", () => { | |
it("it should send email to invite user", done => { | |
request(server) | |
.put(`/me/mail-confirm/${mailConfirm}`) | |
.end((err: any, res: any) => { | |
expect(res.status).toBe(201); | |
done(); | |
}); | |
}); | |
it("it should be update user by the given id", done => { | |
request(server) | |
.put(`/users/${id}`) | |
.set({ Authorization: `Bearer ${token}` }) | |
.send({ firstName: "Burak" }) | |
.end((err: any, res: any) => { | |
expect(res.status).toBe(201); | |
done(); | |
}); | |
}); | |
it("it should be update user by the token", done => { | |
request(server) | |
.put("/me/") | |
.set({ Authorization: `Bearer ${token}` }) | |
.send({ firstName: "Hakan" }) | |
.end((err: any, res: any) => { | |
expect(res.status).toBe(201); | |
done(); | |
}); | |
}); | |
}); | |
afterAll(done => { | |
mongoose.connection.dropDatabase(); | |
done(); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment