Add user tests
Some checks reported errors
continuous-integration/drone/push Build was killed

This commit is contained in:
Sambo Chea 2021-03-13 14:24:05 +07:00
parent cbf7a66390
commit 050b759cce
2 changed files with 21 additions and 9 deletions

View File

@ -13,7 +13,7 @@
"scripts": {
"dev": "ts-node ./src/main.ts",
"migrate": "prisma migrate dev --name add-profile --preview-feature",
"test": "jest"
"test": "jest --detectOpenHandles"
},
"dependencies": {
"@prisma/client": "2.18.0"

View File

@ -1,3 +1,4 @@
import { PrismaClient } from "@prisma/client";
import {
createUser,
findOneByEmail,
@ -5,6 +6,8 @@ import {
findOneProfileByEmail,
} from "../src/User/UserService";
const prisma = new PrismaClient();
// all tests about user
describe("user", function () {
const email = "sombochea@cubetiqs.com";
@ -18,7 +21,7 @@ describe("user", function () {
email: email,
name: name,
})
.then((user) => {
.then(async (user) => {
if (user == null) {
throw Error("user is null");
}
@ -28,7 +31,7 @@ describe("user", function () {
expect(name).toBe(user.name);
// create profile
createProfile(user, {
await createProfile(user, {
bio: "Software Developer",
})
.then((profile) => {
@ -39,9 +42,11 @@ describe("user", function () {
expect(profile).not.toBeNull();
expect(bio).toBe(profile.bio);
})
.catch((e) => console.error(e));
.catch((e) => console.error(e))
.finally(() => done());
})
.catch((e) => console.error(e));
.catch((e) => console.error(e))
.finally(() => done());
});
// check user test
@ -56,9 +61,8 @@ describe("user", function () {
expect(email).toBe(user.email);
expect(name).toBe(user.name);
})
.catch((e) => console.error(e));
done();
.catch((e) => console.error(e))
.finally(() => done());
});
// check profile included user test
@ -74,8 +78,16 @@ describe("user", function () {
expect(email).toBe(profile.user.email);
expect(name).toBe(profile.user.name);
})
.catch((e) => console.error(e));
.catch((e) => console.error(e))
.finally(() => done());
});
// try to finish
afterAll(async (done) => {
await prisma.$disconnect();
done();
});
// after all
});