2021-03-13 14:24:05 +07:00
|
|
|
import { PrismaClient } from "@prisma/client";
|
2021-03-13 11:27:14 +07:00
|
|
|
import {
|
|
|
|
createUser,
|
|
|
|
findOneByEmail,
|
|
|
|
createProfile,
|
|
|
|
findOneProfileByEmail,
|
|
|
|
} from "../src/User/UserService";
|
|
|
|
|
2021-03-13 14:24:05 +07:00
|
|
|
const prisma = new PrismaClient();
|
|
|
|
|
2021-03-13 11:27:14 +07:00
|
|
|
// all tests about user
|
|
|
|
describe("user", function () {
|
|
|
|
const email = "sombochea@cubetiqs.com";
|
|
|
|
const name = "Sambo Chea";
|
|
|
|
const bio = "Software Developer";
|
|
|
|
|
|
|
|
// create user test
|
|
|
|
it("createUser", async (done) => {
|
|
|
|
// create user
|
|
|
|
await createUser({
|
|
|
|
email: email,
|
|
|
|
name: name,
|
|
|
|
})
|
2021-03-13 14:24:05 +07:00
|
|
|
.then(async (user) => {
|
2021-03-13 11:27:14 +07:00
|
|
|
if (user == null) {
|
|
|
|
throw Error("user is null");
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(user).not.toBeNull();
|
|
|
|
expect(email).toBe(user.email);
|
|
|
|
expect(name).toBe(user.name);
|
|
|
|
|
|
|
|
// create profile
|
2021-03-13 14:24:05 +07:00
|
|
|
await createProfile(user, {
|
2021-03-13 11:27:14 +07:00
|
|
|
bio: "Software Developer",
|
|
|
|
})
|
|
|
|
.then((profile) => {
|
|
|
|
if (profile == null) {
|
|
|
|
throw Error("profile is null");
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(profile).not.toBeNull();
|
|
|
|
expect(bio).toBe(profile.bio);
|
|
|
|
})
|
2021-03-13 14:24:05 +07:00
|
|
|
.catch((e) => console.error(e))
|
|
|
|
.finally(() => done());
|
2021-03-13 11:27:14 +07:00
|
|
|
})
|
2021-03-13 14:24:05 +07:00
|
|
|
.catch((e) => console.error(e))
|
|
|
|
.finally(() => done());
|
2021-03-13 11:27:14 +07:00
|
|
|
});
|
|
|
|
|
|
|
|
// check user test
|
|
|
|
it("checkUser", async (done) => {
|
|
|
|
await findOneByEmail(email)
|
|
|
|
.then((user) => {
|
|
|
|
if (user == null) {
|
|
|
|
throw Error("user is null");
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(user).not.toBeNull();
|
|
|
|
expect(email).toBe(user.email);
|
|
|
|
expect(name).toBe(user.name);
|
|
|
|
})
|
2021-03-13 14:24:05 +07:00
|
|
|
.catch((e) => console.error(e))
|
|
|
|
.finally(() => done());
|
2021-03-13 11:27:14 +07:00
|
|
|
});
|
|
|
|
|
|
|
|
// check profile included user test
|
|
|
|
it("checkProfileUser", async (done) => {
|
|
|
|
await findOneProfileByEmail(email)
|
|
|
|
.then((profile) => {
|
|
|
|
if (profile == null) {
|
|
|
|
throw Error("profile is null");
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(profile).not.toBeNull();
|
|
|
|
expect(bio).toBe(profile.bio);
|
|
|
|
expect(email).toBe(profile.user.email);
|
|
|
|
expect(name).toBe(profile.user.name);
|
|
|
|
})
|
2021-03-13 14:24:05 +07:00
|
|
|
.catch((e) => console.error(e))
|
|
|
|
.finally(() => done());
|
|
|
|
});
|
|
|
|
|
|
|
|
// try to finish
|
|
|
|
afterAll(async (done) => {
|
|
|
|
await prisma.$disconnect();
|
2021-03-13 11:27:14 +07:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
2021-03-13 14:24:05 +07:00
|
|
|
|
|
|
|
// after all
|
2021-03-13 11:27:14 +07:00
|
|
|
});
|