1
0
Fork 0
mirror of synced 2024-10-02 10:08:09 +13:00

Merge branch 'master' into budi-8067-sql-testing-more-datasource-types

This commit is contained in:
Sam Rose 2024-03-14 09:21:46 +00:00 committed by GitHub
commit 64ea77237f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 28 additions and 1 deletions

View file

@ -43,7 +43,7 @@ export class AttachmentCleanup {
if ((columnRemoved && !renaming) || opts.deleting) {
rows.forEach(row => {
files = files.concat(
row[key].map((attachment: any) => attachment.key)
(row[key] || []).map((attachment: any) => attachment.key)
)
})
}

View file

@ -115,4 +115,31 @@ describe("attachment cleanup", () => {
await AttachmentCleanup.rowUpdate(table(), { row: row(), oldRow: row() })
expect(mockedDeleteFiles).not.toBeCalled()
})
it("should be able to cleanup a column and not throw when attachments are undefined", async () => {
const originalTable = table()
delete originalTable.schema["attach"]
await AttachmentCleanup.tableUpdate(
originalTable,
[row("file 1"), { attach: undefined }, row("file 2")],
{
oldTable: table(),
}
)
expect(mockedDeleteFiles).toBeCalledTimes(1)
expect(mockedDeleteFiles).toBeCalledWith(BUCKET, ["file 1", "file 2"])
})
it("should be able to cleanup a column and not throw when ALL attachments are undefined", async () => {
const originalTable = table()
delete originalTable.schema["attach"]
await AttachmentCleanup.tableUpdate(
originalTable,
[{}, { attach: undefined }],
{
oldTable: table(),
}
)
expect(mockedDeleteFiles).not.toBeCalled()
})
})