mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2025-12-13 07:45:56 +00:00
Fix lint
This commit is contained in:
parent
51d25c1c9a
commit
39d4771ce1
@ -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)
|
||||
|
||||
@ -18,10 +18,10 @@ import gql from 'graphql-tag'
|
||||
|
||||
export default {
|
||||
components: {
|
||||
vueDropzone
|
||||
vueDropzone,
|
||||
},
|
||||
props: {
|
||||
user: { type: Object, default: null }
|
||||
user: { type: Object, default: null },
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
@ -29,20 +29,18 @@ export default {
|
||||
url: this.vddrop,
|
||||
maxFilesize: 0.5,
|
||||
previewTemplate: this.template(),
|
||||
dictDefaultMessage: ''
|
||||
}
|
||||
dictDefaultMessage: '',
|
||||
},
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
backgroundImage() {
|
||||
const { avatar } = this.user || {}
|
||||
const userAvatar = avatar.startsWith('/')
|
||||
? avatar.replace('/', '/api/')
|
||||
: avatar
|
||||
const userAvatar = avatar.startsWith('/') ? avatar.replace('/', '/api/') : avatar
|
||||
return {
|
||||
backgroundImage: `url(${userAvatar})`
|
||||
backgroundImage: `url(${userAvatar})`,
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
template() {
|
||||
@ -88,15 +86,15 @@ export default {
|
||||
`,
|
||||
variables: {
|
||||
avatarUpload,
|
||||
id: this.user.id
|
||||
}
|
||||
id: this.user.id,
|
||||
},
|
||||
})
|
||||
.then(() => {
|
||||
this.$toast.success(this.$t('user.avatar.submitted'))
|
||||
})
|
||||
.catch(error => this.$toast.error(error.message))
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
</script>
|
||||
<style>
|
||||
|
||||
@ -16,22 +16,22 @@ describe('Upload', () => {
|
||||
mutate: jest
|
||||
.fn()
|
||||
.mockResolvedValueOnce({
|
||||
data: { UpdateUser: { id: 'upload1', avatar: '/upload/avatar.jpg' } }
|
||||
data: { UpdateUser: { id: 'upload1', avatar: '/upload/avatar.jpg' } },
|
||||
})
|
||||
.mockRejectedValue({
|
||||
message: 'File upload unsuccessful! Whatcha gonna do?'
|
||||
})
|
||||
message: 'File upload unsuccessful! Whatcha gonna do?',
|
||||
}),
|
||||
},
|
||||
$toast: {
|
||||
success: jest.fn(),
|
||||
error: jest.fn()
|
||||
}
|
||||
error: jest.fn(),
|
||||
},
|
||||
}
|
||||
|
||||
const propsData = {
|
||||
user: {
|
||||
avatar: '/api/generic.jpg'
|
||||
}
|
||||
avatar: '/api/generic.jpg',
|
||||
},
|
||||
}
|
||||
|
||||
const file = {
|
||||
@ -39,17 +39,17 @@ describe('Upload', () => {
|
||||
previewElement: {
|
||||
classList: {
|
||||
remove: jest.fn(),
|
||||
add: jest.fn()
|
||||
add: jest.fn(),
|
||||
},
|
||||
querySelectorAll: jest.fn().mockReturnValue([
|
||||
{
|
||||
alt: '',
|
||||
style: {
|
||||
'background-image': '/api/generic.jpg'
|
||||
}
|
||||
}
|
||||
])
|
||||
}
|
||||
'background-image': '/api/generic.jpg',
|
||||
},
|
||||
},
|
||||
]),
|
||||
},
|
||||
}
|
||||
|
||||
const dataUrl = 'avatar.jpg'
|
||||
|
||||
@ -344,7 +344,7 @@ export default {
|
||||
HcLoadMore,
|
||||
HcEmpty,
|
||||
ContentMenu,
|
||||
HcUpload
|
||||
HcUpload,
|
||||
},
|
||||
transition: {
|
||||
name: 'slide-up',
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user