Fix issue with duplicate images (#30073)
* ensure export file paths are unique * add unit test for filepath uniqueness. fix createMessagesRequest mock. * add return types
This commit is contained in:
@@ -104,8 +104,8 @@ describe("HTMLExport", () => {
|
||||
const chunk = events.slice(from, limit);
|
||||
return Promise.resolve({
|
||||
chunk,
|
||||
from: from.toString(),
|
||||
to: (from + limit).toString(),
|
||||
start: from.toString(),
|
||||
end: (from + limit).toString(),
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -419,6 +419,36 @@ describe("HTMLExport", () => {
|
||||
expect(text).toBe(attachmentBody);
|
||||
});
|
||||
|
||||
it("should handle attachments with identical names and dates", async () => {
|
||||
mockMessages(EVENT_MESSAGE, EVENT_ATTACHMENT, EVENT_ATTACHMENT);
|
||||
|
||||
const exporter = new HTMLExporter(
|
||||
room,
|
||||
ExportType.LastNMessages,
|
||||
{
|
||||
attachmentsIncluded: true,
|
||||
maxSize: 1_024 * 1_024,
|
||||
numberOfMessages: 40,
|
||||
},
|
||||
() => {},
|
||||
);
|
||||
|
||||
await exporter.export();
|
||||
|
||||
const files = getFiles(exporter);
|
||||
|
||||
// There should be 5 files: 2 attachments, 1 html file, 1 css file and 1 js file
|
||||
expect(Object.keys(files)).toHaveLength(5);
|
||||
|
||||
// Ensure that the attachment is present
|
||||
const file = files[Object.keys(files).find((k) => k.endsWith(".txt"))!];
|
||||
expect(file).not.toBeUndefined();
|
||||
|
||||
// Ensure that the duplicate attachment has been uniquely named
|
||||
const duplicateFile = files[Object.keys(files).find((k) => k.endsWith("(1).txt"))!];
|
||||
expect(duplicateFile).not.toBeUndefined();
|
||||
});
|
||||
|
||||
it("should handle when attachment cannot be fetched", async () => {
|
||||
mockMessages(EVENT_MESSAGE, EVENT_ATTACHMENT_MALFORMED, EVENT_ATTACHMENT);
|
||||
const attachmentBody = "Lorem ipsum dolor sit amet";
|
||||
|
||||
Reference in New Issue
Block a user