From 1c1d1a67ea87b3b5c06803d6bd673d9c84b8cbe0 Mon Sep 17 00:00:00 2001 From: Matt Rider Date: Thu, 23 May 2019 15:31:05 -0300 Subject: [PATCH] Merge in master --- backend/src/graphql-schema.js | 4 +-- .../notifications/extractIds/index.js | 2 +- backend/src/resolvers/fileUpload/index.js | 4 +-- backend/src/resolvers/fileUpload/spec.js | 27 ++++++++++++------- backend/src/resolvers/users.js | 4 +-- backend/src/resolvers/users.spec.js | 2 +- 6 files changed, 26 insertions(+), 17 deletions(-) diff --git a/backend/src/graphql-schema.js b/backend/src/graphql-schema.js index afceec029..a846541e7 100644 --- a/backend/src/graphql-schema.js +++ b/backend/src/graphql-schema.js @@ -36,6 +36,6 @@ export const resolvers = { ...socialMedia.Mutation, ...notifications.Mutation, ...comments.Mutation, - ...users.Mutation - } + ...users.Mutation, + }, } diff --git a/backend/src/middleware/notifications/extractIds/index.js b/backend/src/middleware/notifications/extractIds/index.js index f642484b8..c2fcf169c 100644 --- a/backend/src/middleware/notifications/extractIds/index.js +++ b/backend/src/middleware/notifications/extractIds/index.js @@ -1,7 +1,7 @@ import cheerio from 'cheerio' const ID_REGEX = /\/profile\/([\w\-.!~*'"(),]+)/g -export default function (content) { +export default function(content) { if (!content) return [] const $ = cheerio.load(content) const urls = $('.mention') diff --git a/backend/src/resolvers/fileUpload/index.js b/backend/src/resolvers/fileUpload/index.js index 85bdf920b..c37d87e39 100644 --- a/backend/src/resolvers/fileUpload/index.js +++ b/backend/src/resolvers/fileUpload/index.js @@ -7,10 +7,10 @@ const storeUpload = ({ createReadStream, fileLocation }) => createReadStream() .pipe(createWriteStream(`public${fileLocation}`)) .on('finish', resolve) - .on('error', reject) + .on('error', reject), ) -export default async function fileUpload (params, { file, url }, uploadCallback = storeUpload) { +export default async function fileUpload(params, { file, url }, uploadCallback = storeUpload) { const upload = params[file] if (upload) { diff --git a/backend/src/resolvers/fileUpload/spec.js b/backend/src/resolvers/fileUpload/spec.js index 798e4f9c5..5767d6457 100644 --- a/backend/src/resolvers/fileUpload/spec.js +++ b/backend/src/resolvers/fileUpload/spec.js @@ -10,8 +10,8 @@ describe('fileUpload', () => { filename: 'avatar.jpg', mimetype: 'image/jpeg', encoding: '7bit', - createReadStream: jest.fn() - } + createReadStream: jest.fn(), + }, } uploadCallback = jest.fn() }) @@ -34,21 +34,30 @@ describe('fileUpload', () => { }) it('creates a url safe name', async () => { - params.uploadAttribute.filename = '/path/to/awkward?/ file-location/?foo- bar-avatar.jpg?foo- bar' + params.uploadAttribute.filename = + '/path/to/awkward?/ file-location/?foo- bar-avatar.jpg?foo- bar' await fileUpload(params, { file: 'uploadAttribute', url: 'attribute' }, uploadCallback) expect(params.attribute).toMatch(/^\/uploads\/\d+-foo-bar-avatar$/) }) describe('in case of duplicates', () => { it('creates unique names to avoid overwriting existing files', async () => { - const { attribute: first } = await fileUpload({ - ...params - }, { file: 'uploadAttribute', url: 'attribute' }, uploadCallback) + const { attribute: first } = await fileUpload( + { + ...params, + }, + { file: 'uploadAttribute', url: 'attribute' }, + uploadCallback, + ) await new Promise(resolve => setTimeout(resolve, 1000)) - const { attribute: second } = await fileUpload({ - ...params - }, { file: 'uploadAttribute', url: 'attribute' }, uploadCallback) + const { attribute: second } = await fileUpload( + { + ...params, + }, + { file: 'uploadAttribute', url: 'attribute' }, + uploadCallback, + ) expect(first).not.toEqual(second) }) }) diff --git a/backend/src/resolvers/users.js b/backend/src/resolvers/users.js index 01beae522..53bf0967e 100644 --- a/backend/src/resolvers/users.js +++ b/backend/src/resolvers/users.js @@ -10,6 +10,6 @@ export default { CreateUser: async (object, params, context, resolveInfo) => { params = await fileUpload(params, { file: 'avatarUpload', url: 'avatar' }) return neo4jgraphql(object, params, context, resolveInfo, false) - } - } + }, + }, } diff --git a/backend/src/resolvers/users.spec.js b/backend/src/resolvers/users.spec.js index e81b555c5..22096b6c8 100644 --- a/backend/src/resolvers/users.spec.js +++ b/backend/src/resolvers/users.spec.js @@ -67,7 +67,7 @@ describe('users', () => { it('with no name', async () => { const variables = { id: 'u47', - name: null + name: null, } const expected = 'Username must be at least 3 characters long!' await expect(client.request(mutation, variables)).rejects.toThrow(expected)