mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2025-12-13 07:45:56 +00:00
Merge in master
This commit is contained in:
parent
758bf215ac
commit
1c1d1a67ea
@ -36,6 +36,6 @@ export const resolvers = {
|
||||
...socialMedia.Mutation,
|
||||
...notifications.Mutation,
|
||||
...comments.Mutation,
|
||||
...users.Mutation
|
||||
}
|
||||
...users.Mutation,
|
||||
},
|
||||
}
|
||||
|
||||
@ -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')
|
||||
|
||||
@ -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) {
|
||||
|
||||
@ -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)
|
||||
})
|
||||
})
|
||||
|
||||
@ -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)
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
@ -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)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user