You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
demo-graphql-oauth/src/modules/User/UserResolver.spec.ts

59 lines
1.4 KiB

import faker from "faker";
import { createConnection, getConnection } from "typeorm";
import { callSchema } from "../../utils/callSchema";
import { User } from "../User";
const usersQuery = `
query {
users {
email
}
}`
beforeEach(() => {
return createConnection({
type: "sqlite",
database: ":memory:",
dropSchema: true,
entities: [User],
synchronize: true,
logging: false
});
});
afterEach(() => {
let conn = getConnection();
return conn.close();
});
describe("resolver of", () => {
describe("users query", () => {
it("should return an empty array when no users are created", async () => {
const response = await callSchema({
source: usersQuery,
})
expect(response).toMatchObject({
data: {
users: [],
},
})
})
it("should return a populated array when an user is created", async () => {
const user = await User.create({
email: faker.internet.email(),
}).save()
const response = await callSchema({
source: usersQuery,
})
expect(response).toMatchObject({
data: {
users: [{ email: user.email }],
},
})
})
})
})