import { describe, beforeEach, afterEach, it, expect } from 'vitest'; import { Express } from 'express'; import path from 'path'; import request from 'supertest'; import { init } from '../app'; import { Config } from '../app'; import { remoteApplication1 } from '../test/remote-graphql-1'; import { remoteApplication2 } from '../test/remote-graphql-2'; describe('upload', () => { let remote1: any; let remote2: any; let app: { app: Express, stop: () => void }; beforeEach(async () => { const config: Config = { reloadInterval: 5000, list: [ { name: "Movies!", url: "http://localhost:8008/graphql", prefix: "movies_" }, { name: "Books!", url: "http://localhost:8009/graphql", prefix: "books_" } ], allowedQueriesAndMutations: ['uploadCover'], }; remote1 = await remoteApplication1(); remote2 = await remoteApplication2(); app = await init({ config }); }); afterEach(async () => { app.stop(); remote1.server.close(); remote2.server.close(); }); it('should be to execute a mutation with a file upload', async () => { const payload = JSON.stringify({ query: ` mutation ($file: Upload!) { uploadCover(id: 1, file: $file) { cover } } `, variables: { file: null }, }, null, 4); const result = await request(app.app) .post('/graphql') .type('form') .set('Content-Type', 'multipart/form-data') .field('operations', payload) .field('map', JSON.stringify({ '0': ['variables.file'] })) .attach('0', path.join(__dirname, '../test/upload-test.txt')); const { body, status } = result; expect(status).toEqual(200); expect(body.data.uploadCover.cover).toEqual('hello\n'); }); });