Skip to content
Snippets Groups Projects
Commit 3da3b430 authored by Yannis Barlas's avatar Yannis Barlas
Browse files

chore(*): remove redundant file

parent b046ca17
No related branches found
No related tags found
1 merge request!123v4
/* eslint-disable jest/no-commented-out-tests */
// const { fixtures } = require('@pubsweet/model-user/test')
// const WebSocket = require('ws')
// const {
// ApolloClient,
// createHttpLink,
// gql,
// InMemoryCache,
// split,
// } = require('@apollo/client')
// const { WebSocketLink } = require('@apollo/client/link/ws')
// const { getMainDefinition } = require('@apollo/client/utilities')
// const FormData = require('form-data')
// const fetch = require('node-fetch')
// const wait = require('waait')
// const { startServer } = require('../../src')
// const authentication = require('../../src/authentication')
// const cleanDB = require('../helpers/db_cleaner')
// function generateFetchOptions(token, fileSize) {
// // This dance needs to happen because apollo-upload-client is 'untestable':
// // https://github.com/jaydenseric/apollo-upload-client/issues/32#issuecomment-327694315
// let variables
// let size
// let query
// if (fileSize) {
// variables = {
// file: null,
// fileSize,
// }
// query =
// 'mutation uploadFile($file: Upload!, $fileSize: Int) { upload(file: $file, fileSize: $fileSize) { url, __typename }}'
// size = fileSize
// } else {
// variables = {
// file: null,
// }
// query =
// 'mutation uploadFile($file: Upload!) { upload(file: $file) { url, __typename }}'
// size = 1000000
// }
// const body = new FormData()
// body.append(
// 'operations',
// JSON.stringify({
// operationName: 'uploadFile',
// variables,
// query,
// }),
// )
// body.append('map', JSON.stringify({ 1: ['variables.file'] }))
// body.append('1', 'a'.repeat(size), { filename: 'a.txt' })
// const options = {
// method: 'POST',
// body,
// headers: {
// Authorization: `Bearer ${token}`,
// },
// }
// return options
// }
// describe('GraphQL subscriptions', () => {
// let token
// let user
// let server
// let apolloClient
// let wsLink
// beforeAll(async () => {
// server = await startServer()
// })
// beforeEach(async () => {
// await cleanDB()
// user = await new User(fixtures.user).save()
// token = authentication.token.create(user)
// wsLink = new WebSocketLink({
// uri: `ws://localhost:4000/subscriptions`,
// options: {
// connectionParams: {
// authToken: token,
// },
// },
// reconnect: false,
// webSocketImpl: WebSocket,
// })
// const httpLink = createHttpLink({ fetch })
// const link = split(
// ({ query }) => {
// const { kind, operation } = getMainDefinition(query)
// return kind === 'OperationDefinition' && operation === 'subscription'
// },
// wsLink,
// httpLink,
// )
// const config = {
// link,
// cache: new InMemoryCache(),
// }
// apolloClient = new ApolloClient(config)
// })
// afterEach(async () => {
// await wsLink.subscriptionClient.client.close()
// })
// afterAll(done => server.close(done))
// it('reports progress when fileSize is given', async () => {
// let done
// let progress = 0
// const subscriptionPromise = new Promise((resolve, reject) => {
// apolloClient
// .subscribe({
// query: gql`
// subscription onUploadProgress {
// uploadProgress
// }
// `,
// })
// .subscribe({
// next: async res => {
// expect(res.data.uploadProgress).toBeGreaterThanOrEqual(progress)
// progress = res.data.uploadProgress
// expect(progress).toBeGreaterThan(-1)
// expect(progress).toBeLessThanOrEqual(100)
// // sometimes the last notification is sent slightly before
// // fetch completes, resulting in an unresolved promise, so
// // we just wait a tiny bit.
// await wait(100)
// if (done) resolve('done')
// },
// error: reject,
// })
// })
// await fetch(
// `http://localhost:4000/graphql`,
// generateFetchOptions(token, 1000000),
// )
// done = true
// expect(await subscriptionPromise).toBe('done')
// })
// it('reports progress when fileSize is not given', async () => {
// let done
// let progress = 0
// const subscriptionPromise = new Promise((resolve, reject) => {
// apolloClient
// .subscribe({
// query: gql`
// subscription onUploadProgress {
// uploadProgress
// }
// `,
// })
// .subscribe({
// next: async res => {
// expect(res.data.uploadProgress).toBeGreaterThanOrEqual(progress)
// progress = res.data.uploadProgress
// expect(progress).toBeGreaterThan(-1)
// expect(progress).toBeLessThanOrEqual(1000000)
// // sometimes the last notification is sent slightly before
// // fetch completes, resulting in an unresolved promise, so
// // we just wait a tiny bit.
// await wait(100)
// if (done) resolve('done')
// },
// error: reject,
// })
// })
// await fetch(`http://localhost:4000/graphql`, generateFetchOptions(token))
// done = true
// expect(await subscriptionPromise).toBe('done')
// })
// })
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment