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,19 +99,6 @@ describe('mergeImage', () => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('on existing resource', () => {
|
|
||||||
beforeEach(async () => {
|
|
||||||
post = await Factory.build(
|
|
||||||
'post',
|
|
||||||
{ id: 'p99' },
|
|
||||||
{
|
|
||||||
author: Factory.build('user', {}, { avatar: null }),
|
|
||||||
image: null,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
post = await post.toJson()
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('given image.upload', () => {
|
describe('given image.upload', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
imageInput = {
|
imageInput = {
|
||||||
@ -129,6 +116,19 @@ describe('mergeImage', () => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe('on existing resource', () => {
|
||||||
|
beforeEach(async () => {
|
||||||
|
post = await Factory.build(
|
||||||
|
'post',
|
||||||
|
{ id: 'p99' },
|
||||||
|
{
|
||||||
|
author: Factory.build('user', {}, { avatar: null }),
|
||||||
|
image: null,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
post = await post.toJson()
|
||||||
|
})
|
||||||
|
|
||||||
it('returns new image', async () => {
|
it('returns new image', async () => {
|
||||||
await expect(
|
await expect(
|
||||||
mergeImage(post, 'HERO_IMAGE', imageInput, { uploadCallback, deleteCallback }),
|
mergeImage(post, 'HERO_IMAGE', imageInput, { uploadCallback, deleteCallback }),
|
||||||
@ -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