mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
Fix backend tests
This commit is contained in:
parent
79808fe692
commit
8a90bf1642
@ -92,6 +92,7 @@ const deleteImageFile = (image, deleteCallback) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const uploadImageFile = async (upload, uploadCallback) => {
|
const uploadImageFile = async (upload, uploadCallback) => {
|
||||||
|
if (!upload) return undefined
|
||||||
if (!uploadCallback) {
|
if (!uploadCallback) {
|
||||||
uploadCallback = S3_CONFIGURED ? s3Upload : localFileUpload
|
uploadCallback = S3_CONFIGURED ? s3Upload : localFileUpload
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,7 +11,7 @@ let deleteCallback
|
|||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await cleanDatabase()
|
await cleanDatabase()
|
||||||
uploadCallback = jest.fn(({ destination }) => destination)
|
uploadCallback = jest.fn(({ uniqueFilename }) => `/uploads/${uniqueFilename}`)
|
||||||
deleteCallback = jest.fn()
|
deleteCallback = jest.fn()
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -99,34 +99,34 @@ describe('mergeImage', () => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('on existing resource', () => {
|
describe('given image.upload', () => {
|
||||||
beforeEach(async () => {
|
beforeEach(() => {
|
||||||
post = await Factory.build(
|
imageInput = {
|
||||||
'post',
|
...imageInput,
|
||||||
{ id: 'p99' },
|
upload: {
|
||||||
{
|
filename: 'image.jpg',
|
||||||
author: Factory.build('user', {}, { avatar: null }),
|
mimetype: 'image/jpeg',
|
||||||
image: null,
|
encoding: '7bit',
|
||||||
|
createReadStream: () => ({
|
||||||
|
pipe: () => ({
|
||||||
|
on: (_, callback) => callback(),
|
||||||
|
}),
|
||||||
|
}),
|
||||||
},
|
},
|
||||||
)
|
}
|
||||||
post = await post.toJson()
|
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('given image.upload', () => {
|
describe('on existing resource', () => {
|
||||||
beforeEach(() => {
|
beforeEach(async () => {
|
||||||
imageInput = {
|
post = await Factory.build(
|
||||||
...imageInput,
|
'post',
|
||||||
upload: {
|
{ id: 'p99' },
|
||||||
filename: 'image.jpg',
|
{
|
||||||
mimetype: 'image/jpeg',
|
author: Factory.build('user', {}, { avatar: null }),
|
||||||
encoding: '7bit',
|
image: null,
|
||||||
createReadStream: () => ({
|
|
||||||
pipe: () => ({
|
|
||||||
on: (_, callback) => callback(),
|
|
||||||
}),
|
|
||||||
}),
|
|
||||||
},
|
},
|
||||||
}
|
)
|
||||||
|
post = await post.toJson()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('returns new image', async () => {
|
it('returns new image', async () => {
|
||||||
@ -330,7 +330,7 @@ describe('mergeImage', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('updates metadata', async () => {
|
it('updates metadata', async () => {
|
||||||
await mergeImage(post, 'HERO_IMAGE', imageInput)
|
await mergeImage(post, 'HERO_IMAGE', imageInput, { uploadCallback, deleteCallback })
|
||||||
const images = await neode.all('Image')
|
const images = await neode.all('Image')
|
||||||
expect(images).toHaveLength(1)
|
expect(images).toHaveLength(1)
|
||||||
await expect(images.first().toJson()).resolves.toMatchObject({
|
await expect(images.first().toJson()).resolves.toMatchObject({
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user