-
Notifications
You must be signed in to change notification settings - Fork 362
Expand file tree
/
Copy pathjson-schema-file-upload.test.ts
More file actions
70 lines (69 loc) · 1.76 KB
/
json-schema-file-upload.test.ts
File metadata and controls
70 lines (69 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import { join } from 'path';
import { findAndParseConfig } from '@graphql-mesh/cli';
import { getMesh, MeshInstance } from '@graphql-mesh/runtime';
import { File } from '@whatwg-node/fetch';
import { router } from '../src/router';
describe('JSON Schema File Uploads', () => {
let mesh: MeshInstance;
beforeAll(async () => {
const config = await findAndParseConfig({
dir: join(__dirname, '..'),
});
mesh = await getMesh({
...config,
fetchFn: router.fetch,
});
});
afterAll(() => {
mesh.destroy();
});
it('should upload files correctly', async () => {
const uploadResult = await mesh.execute(
/* GraphQL */ `
mutation UploadFile($file: File!, $description: String!) {
uploadFile(input: { file: $file, description: $description }) {
message
}
}
`,
{
file: new File(['This is a test file'], 'test.txt', {
type: 'text/plain',
}),
description: 'This is a test file description',
},
);
expect(uploadResult).toMatchObject({
data: {
uploadFile: {
message: 'File uploaded',
},
},
});
});
it('should read files correctly', async () => {
const readResult = await mesh.execute(
/* GraphQL */ `
query ReadFile($fileName: String!) {
readFileAsText(fileName: $fileName) {
name
description
content
}
}
`,
{
fileName: 'example.txt',
},
);
expect(readResult).toMatchObject({
data: {
readFileAsText: {
name: 'example.txt',
description: 'This is an example file description',
content: 'This is an example file\n',
},
},
});
});
});