mirror of
https://github.com/cheveguerra/whaticket-community.git
synced 2026-04-18 19:59:20 +00:00
chore: adding user creation tests
This commit is contained in:
@@ -1,3 +0,0 @@
|
||||
test("sum two number", () => {
|
||||
expect(1 + 2).toBe(3);
|
||||
});
|
||||
41
backend/src/__tests__/unit/CreateUserService.spec.ts
Normal file
41
backend/src/__tests__/unit/CreateUserService.spec.ts
Normal 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);
|
||||
});
|
||||
});
|
||||
11
backend/src/__tests__/utils/database.ts
Normal file
11
backend/src/__tests__/utils/database.ts
Normal 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 };
|
||||
Reference in New Issue
Block a user