fix: #1656 remove size data

This commit is contained in:
Dan Ribbens
2022-12-19 14:51:49 -05:00
parent 2e765a1e05
commit 389ee261d4
4 changed files with 41 additions and 21 deletions

View File

@@ -7,6 +7,7 @@ import { RESTClient } from '../helpers/rest';
import config, { mediaSlug, relationSlug } from './config';
import payload from '../../src';
import getFileByPath from '../../src/uploads/getFileByPath';
import type { Media } from './payload-types';
const stat = promisify(fs.stat);
@@ -76,7 +77,7 @@ describe('Collections - Uploads', () => {
expect(await fileExists(path.join(__dirname, './media', doc.sizes.icon.filename))).toBe(true);
// Check api response
expect(doc.sizes.tablet.filename).toBeUndefined();
expect(doc.sizes.tablet.filename).toBeNull();
expect(doc.sizes.icon.filename).toBeDefined();
});
@@ -159,6 +160,28 @@ describe('Collections - Uploads', () => {
expect(await fileExists(path.join(__dirname, './media', mediaDoc.sizes.icon.filename))).toBe(true);
});
it('should remove extra sizes on update', async () => {
const filePath = path.resolve(__dirname, './image.png');
const file = await getFileByPath(filePath);
const small = await getFileByPath(path.resolve(__dirname, './small.png'));
const { id } = await payload.create<Media>({
collection: mediaSlug,
data: {},
file,
});
const doc = await payload.update<Media>({
collection: mediaSlug,
id,
data: {},
file: small,
});
expect(doc.sizes.icon).toBeDefined();
expect(doc.sizes.tablet.width).toBeNull();
});
it('should allow update removing a relationship', async () => {
const filePath = path.resolve(__dirname, './image.png');
const file = await getFileByPath(filePath);