Created
November 18, 2018 21:03
-
-
Save mksglu/8c4c4a3ddcb0e56782725d6457d97a0e to your computer and use it in GitHub Desktop.
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
process.env.NODE_ENV = "test"; | |
import * as mongoose from "mongoose"; | |
import * as request from "supertest"; | |
import server from "../../app"; | |
import config from "../../config"; | |
import { INVITE_EMAIL, mockUser } from "../../utils/test.utils"; | |
describe("Users Route", () => { | |
beforeAll(done => { | |
mongoose.connect( | |
config.connectionStr.dev, | |
done | |
); | |
}); | |
let token, id, mailConfirm: string; | |
const user = { ...mockUser, email: "[email protected]" }; | |
describe("/POST users", () => { | |
it("it should add a new user", done => { | |
request(server) | |
.post("/sign-up") | |
.send(user) | |
.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: user.email, password: user.password }) | |
.end((err: any, res: any) => { | |
expect(res.status).toBe(201); | |
token = res.body.data.token; | |
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(); | |
}); | |
}); | |
}); | |
afterAll(done => { | |
mongoose.connection.dropDatabase(() => { | |
mongoose.connection.close(() => { | |
done(); | |
}); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment