chore: adding user creation tests

This commit is contained in:
canove
2020-10-23 13:12:00 -03:00
parent 3302cd643a
commit 4d01cc3379
54 changed files with 459 additions and 366 deletions

View File

@@ -1,3 +0,0 @@
test("sum two number", () => {
expect(1 + 2).toBe(3);
});

View File

@@ -0,0 +1,41 @@
import { disconnect, truncate } from "../utils/database";
// import User from "../../models/User";
// import app from "../../app";
import CreateUserService from "../../services/UserServices/CreateUserService";
import AppError from "../../errors/AppError";
describe("User", () => {
beforeEach(async () => {
await truncate();
});
afterAll(async () => {
await disconnect();
});
it("should be able to create a new user", async () => {
const user = await CreateUserService({
name: "dasdas",
email: "tesssst@test.com",
password: "passwo22221131rd"
});
expect(user).toHaveProperty("id");
});
it("should not be able to create a user with duplicated email", async () => {
await CreateUserService({
name: "dasdas",
email: "tesssst@test.com",
password: "passwo22221131rd"
});
expect(
CreateUserService({
name: "dasdas",
email: "tesssst@test.com",
password: "passwo22221131rd"
})
).rejects.toBeInstanceOf(AppError);
});
});

View File

@@ -0,0 +1,11 @@
import database from "../../database";
const truncate = async (): Promise<void> => {
await database.sync({ force: true });
};
const disconnect = async (): Promise<void> => {
return database.connectionManager.close();
};
export { truncate, disconnect };