Fix backend tests

This commit is contained in:
roschaefer 2020-03-23 15:52:38 +01:00 committed by mattwr18
parent 79808fe692
commit 8a90bf1642
2 changed files with 27 additions and 26 deletions

View File

@ -92,6 +92,7 @@ const deleteImageFile = (image, deleteCallback) => {
}
const uploadImageFile = async (upload, uploadCallback) => {
if (!upload) return undefined
if (!uploadCallback) {
uploadCallback = S3_CONFIGURED ? s3Upload : localFileUpload
}

View File

@ -11,7 +11,7 @@ let deleteCallback
beforeEach(async () => {
await cleanDatabase()
uploadCallback = jest.fn(({ destination }) => destination)
uploadCallback = jest.fn(({ uniqueFilename }) => `/uploads/${uniqueFilename}`)
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', () => {
beforeEach(() => {
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 () => {
await expect(
mergeImage(post, 'HERO_IMAGE', imageInput, { uploadCallback, deleteCallback }),
@ -330,7 +330,7 @@ describe('mergeImage', () => {
})
it('updates metadata', async () => {
await mergeImage(post, 'HERO_IMAGE', imageInput)
await mergeImage(post, 'HERO_IMAGE', imageInput, { uploadCallback, deleteCallback })
const images = await neode.all('Image')
expect(images).toHaveLength(1)
await expect(images.first().toJson()).resolves.toMatchObject({