Merge pull request #13246 from Budibase/fix/deleting-attachment-column-with-empty-values
Fix - Allow deleting attachment column with empty values
This commit is contained in:
commit
563eada394
|
@ -43,7 +43,7 @@ export class AttachmentCleanup {
|
||||||
if ((columnRemoved && !renaming) || opts.deleting) {
|
if ((columnRemoved && !renaming) || opts.deleting) {
|
||||||
rows.forEach(row => {
|
rows.forEach(row => {
|
||||||
files = files.concat(
|
files = files.concat(
|
||||||
row[key].map((attachment: any) => attachment.key)
|
(row[key] || []).map((attachment: any) => attachment.key)
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -115,4 +115,31 @@ describe("attachment cleanup", () => {
|
||||||
await AttachmentCleanup.rowUpdate(table(), { row: row(), oldRow: row() })
|
await AttachmentCleanup.rowUpdate(table(), { row: row(), oldRow: row() })
|
||||||
expect(mockedDeleteFiles).not.toBeCalled()
|
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()
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue