I want to test some graphql mutations. but I am not sure what to give as context while writing test. for example, I want to call createPost mutation:
it('admin should create a post', async () => {
await createPost(
null,
{
title: 'How to write a blog post',
body: 'lorem ipsum dollar emmet',
published: true,
},
dummyContext
).should.be.fulfilled;
});
here as a dummyContext I am using this:
const dummyContext = {
request: { get: () => token },
};
but, it is not working. Inside createPost
mutation logincheker
method is called:
export async function loginChecker({ request }) {
const Authorization = request.get('Authorization');
if (Authorization) {
const token = Authorization.replace('Bearer ', '');
const userInJwt = jwtValidator(token);
const user = await prisma.user.findOne({ where: { id: userInJwt.id } });
if (!user) {
throw new Error('Not Authorized');
}
return user;
}
}
and I am getting this error while running the test cases
AssertionError: expected promise to be fulfilled but it was rejected with 'TypeError: Authorization.replace is not a function