Skip to content

Commit cdcbb13

Browse files
fix: setting updates to before and after
1 parent f632ee0 commit cdcbb13

File tree

1 file changed

+42
-21
lines changed

1 file changed

+42
-21
lines changed

apps/meteor/tests/end-to-end/api/file-upload-image-rotation.ts

Lines changed: 42 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import path from 'path';
22

33
import type { Credentials } from '@rocket.chat/api-client';
4-
import type { ImageAttachmentProps, IMessage, IRoom, IUser, SettingValue } from '@rocket.chat/core-typings';
4+
import type { ImageAttachmentProps, IRoom, IUser, SettingValue } from '@rocket.chat/core-typings';
55
import { expect } from 'chai';
66
import { after, before, describe, it } from 'mocha';
77
import sharp from 'sharp';
@@ -51,23 +51,22 @@ describe('[File Upload - Image Rotation]', () => {
5151
updateSetting('FileUpload_RotateImages', rotateImagesSetting),
5252
updateSetting('Message_Attachments_Strip_Exif', stripExifSetting),
5353
updateSetting('Message_Attachments_Thumbnails_Enabled', thumbnailsEnabledSetting),
54-
testRoom ? deleteRoom({ type: 'p', roomId: testRoom._id }) : Promise.resolve(),
55-
user ? deleteUser(user) : Promise.resolve(),
54+
deleteRoom({ type: 'p', roomId: testRoom._id }),
55+
deleteUser(user),
5656
]);
5757
});
5858

59-
it('should rotate pixels, strip EXIF orientation, and generate thumbnail from rotated image', async () => {
59+
it('should rotate pixels and strip EXIF orientation', async () => {
6060
const fixtureMetadata = await sharp(testImagePath).metadata();
6161
expect(fixtureMetadata.width).to.equal(719);
6262
expect(fixtureMetadata.height).to.equal(479);
6363
expect(fixtureMetadata.orientation).to.equal(6);
6464

6565
const requestConfig: IRequestConfig = { request, credentials: userCredentials };
6666
const { message } = await uploadFileToRC(testRoom._id, testImagePath, 'rotation-exif-test', requestConfig);
67-
const uploadMessage = message as IMessage;
6867

69-
expect(uploadMessage).to.have.property('attachments');
70-
const attachment = uploadMessage.attachments?.find((item) => item.title === testImageName);
68+
expect(message).to.have.property('attachments');
69+
const attachment = message.attachments?.find((item) => item.title === testImageName);
7170
expect(attachment).to.be.an('object');
7271

7372
const fileUrl = (attachment as { title_link?: string }).title_link;
@@ -82,31 +81,53 @@ describe('[File Upload - Image Rotation]', () => {
8281
expect(originalMetadata.width).to.equal(479);
8382
expect(originalMetadata.height).to.equal(719);
8483
expect(originalMetadata.exif).to.be.undefined;
84+
});
85+
86+
it('should generate thumbnail from rotated image', async () => {
87+
const requestConfig: IRequestConfig = { request, credentials: userCredentials };
88+
const { message } = await uploadFileToRC(testRoom._id, testImagePath, 'rotation-thumb-test', requestConfig);
89+
90+
expect(message).to.have.property('attachments');
91+
const attachment = message.attachments?.find((item) => item.title === testImageName);
92+
expect(attachment).to.be.an('object');
93+
94+
const fileUrl = (attachment as { title_link?: string }).title_link;
95+
const thumbUrl = (attachment as ImageAttachmentProps).image_url;
96+
97+
expect(fileUrl).to.be.a('string');
98+
expect(thumbUrl).to.be.a('string');
8599

86100
const thumbBuffer = await downloadBuffer(thumbUrl as string, userCredentials);
87101
const thumbMetadata = await sharp(thumbBuffer).metadata();
88102

89103
expect(thumbMetadata.width).to.be.lessThan(thumbMetadata.height as number);
90104
});
91105

92-
it('should NOT rotate pixels when FileUpload_RotateImages is disabled', async () => {
93-
await updateSetting('FileUpload_RotateImages', false);
106+
describe('when FileUpload_RotateImages is disabled', () => {
107+
before(async () => {
108+
await updateSetting('FileUpload_RotateImages', false);
109+
});
94110

95-
const requestConfig: IRequestConfig = { request, credentials: userCredentials };
96-
const { message } = await uploadFileToRC(testRoom._id, testImagePath, 'no-rotation-test', requestConfig);
97-
const uploadMessage = message as IMessage;
111+
after(async () => {
112+
await updateSetting('FileUpload_RotateImages', rotateImagesSetting);
113+
});
98114

99-
expect(uploadMessage).to.have.property('attachments');
100-
const attachment = uploadMessage.attachments?.find((item) => item.title === testImageName);
101-
expect(attachment).to.be.an('object');
115+
it('should NOT rotate pixels', async () => {
116+
const requestConfig: IRequestConfig = { request, credentials: userCredentials };
117+
const { message } = await uploadFileToRC(testRoom._id, testImagePath, 'no-rotation-test', requestConfig);
102118

103-
const fileUrl = (attachment as { title_link?: string }).title_link;
104-
expect(fileUrl).to.be.a('string');
119+
expect(message).to.have.property('attachments');
120+
const attachment = message.attachments?.find((item) => item.title === testImageName);
121+
expect(attachment).to.be.an('object');
105122

106-
const originalBuffer = await downloadBuffer(fileUrl as string, userCredentials);
107-
const originalMetadata = await sharp(originalBuffer).metadata();
123+
const fileUrl = (attachment as { title_link?: string }).title_link;
124+
expect(fileUrl).to.be.a('string');
125+
126+
const originalBuffer = await downloadBuffer(fileUrl as string, userCredentials);
127+
const originalMetadata = await sharp(originalBuffer).metadata();
108128

109-
expect(originalMetadata.width).to.equal(719);
110-
expect(originalMetadata.height).to.equal(479);
129+
expect(originalMetadata.width).to.equal(719);
130+
expect(originalMetadata.height).to.equal(479);
131+
});
111132
});
112133
});

0 commit comments

Comments
 (0)