admin 管理员组文章数量: 1086019
I wrote a test which creates a Venue with attachments property which is of Graphql Upload type. But when I try to run the test, it fails with error "message": "Variable \"$attachments\" got invalid value { fieldName: \"1\", filename: \"valid-image.png\", mimetype: \"image/png\", encoding: \"7bit\" } at \"attachments[0]\"; Upload value invalid.
" basically Upload value invalid
.
In backend the attachments is structure like that
{
fieldName: '1',
filename: 'Screenshot 2023-09-05 193500.png',
mimetype: 'image/png',
encoding: '7bit',
createReadStream: [Function: createReadStream]
}
Unit test
it("should create a venue with valid attachments", async () => {
const imagePath = join(__dirname, "test-files", "valid-image.png");
const variables = {
anizationId: Id,
name: `Test Venue ${faker.string.alphanumeric(5)}`,
description: "Test venue with valid attachments",
capacity: 50,
attachments: [
{
fieldName: "1",
filename: "valid-image.png",
mimetype: "image/png",
encoding: "7bit",
createReadStream: () => createReadStream(imagePath),
},
],
};
const result = await mercuriusClient.mutate(Mutation_createVenue, {
headers: { authorization: `bearer ${authToken}` },
variables,
});
console.log('result is ', result);
})
I have never tested FileUpload
so I'm not sure whether I'm correctly testing it or not.
Any help would be appreciated.
本文标签: javascriptHow can I unit test Graphql Upload in api using VitestStack Overflow
版权声明:本文标题:javascript - How can I unit test Graphql Upload in api using Vitest - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://roclinux.cn/p/1744090243a2531895.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论