Skip to content

Commit 33b1351

Browse files
committed
Multi-level deleting tests
1 parent 5d6e5b6 commit 33b1351

File tree

1 file changed

+142
-0
lines changed

1 file changed

+142
-0
lines changed

tests/integration/attachments.test.js

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,148 @@ describe("Tests for uploading/deleting attachments through API calls", () => {
322322
expect(getRes.data.value.length).to.equal(1)
323323
expect(getRes.data.value[0].status).to.be.oneOf(["Scanning", "Clean", "Unscanned"])
324324
})
325+
326+
it("Deleting Test deletes Test attachment", async () => {
327+
// Create Test entity and add attachment
328+
const testID = cds.utils.uuid()
329+
await POST(`odata/v4/processor/Test`, { ID: testID, name: "Test Entity" })
330+
await utils.draftModeEdit("processor", "Test", testID, "ProcessorService")
331+
const attachRes = await POST(
332+
`odata/v4/processor/Test(ID=${testID},IsActiveEntity=false)/attachments`,
333+
{
334+
up__ID: testID,
335+
filename: "testfile.pdf",
336+
mimeType: "application/pdf",
337+
createdAt: new Date(),
338+
createdBy: "alice",
339+
}
340+
)
341+
expect(attachRes.data.ID).to.not.be.null
342+
await utils.draftModeSave("processor", "Test", testID, () => {}, "ProcessorService")
343+
344+
// Delete the parent Test entity
345+
const delRes = await DELETE(
346+
`odata/v4/processor/Test(ID=${testID},IsActiveEntity=true)`
347+
)
348+
expect(delRes.status).to.equal(204)
349+
350+
// Check that the attachment is deleted
351+
let error
352+
try {
353+
await GET(
354+
`odata/v4/processor/Test_attachments(up__ID=${testID},ID=${attachRes.data.ID},IsActiveEntity=true)`
355+
)
356+
} catch (e) {
357+
error = e
358+
}
359+
expect(error?.response?.status || error?.status).to.equal(404)
360+
})
361+
362+
it("Deleting TestDetails deletes TestDetails attachment", async () => {
363+
// Create Test and TestDetails entities
364+
const testID = cds.utils.uuid()
365+
await POST(`odata/v4/processor/Test`, { ID: testID, name: "Test Entity" })
366+
await utils.draftModeEdit("processor", "Test", testID, "ProcessorService")
367+
const detailsID = cds.utils.uuid()
368+
await POST(
369+
`odata/v4/processor/Test(ID=${testID},IsActiveEntity=false)/details`,
370+
{ ID: detailsID, description: "Test Details Entity" }
371+
)
372+
// Add attachment to TestDetails
373+
const attachRes = await POST(
374+
`odata/v4/processor/Test(ID=${testID},IsActiveEntity=false)/details(ID=${detailsID},IsActiveEntity=false)/attachments`,
375+
{
376+
up__ID: detailsID,
377+
filename: "detailsfile.pdf",
378+
mimeType: "application/pdf",
379+
createdAt: new Date(),
380+
createdBy: "alice",
381+
}
382+
)
383+
expect(attachRes.data.ID).to.not.be.null
384+
await utils.draftModeSave("processor", "Test", testID, () => {}, "ProcessorService")
385+
386+
// Delete the child TestDetails entity
387+
const delRes = await DELETE(
388+
`odata/v4/processor/TestDetails(ID=${detailsID},IsActiveEntity=true)`
389+
)
390+
expect(delRes.status).to.equal(204)
391+
392+
// Check that the attachment is deleted
393+
let error
394+
try {
395+
await GET(
396+
`odata/v4/processor/TestDetails_attachments(up__ID=${detailsID},ID=${attachRes.data.ID},IsActiveEntity=true)`
397+
)
398+
} catch (e) {
399+
error = e
400+
}
401+
expect(error?.response?.status || error?.status).to.equal(404)
402+
})
403+
404+
it("Deleting Test deletes both Test and TestDetails attachments", async () => {
405+
// Create Test and TestDetails entities
406+
const testID = cds.utils.uuid()
407+
await POST(`odata/v4/processor/Test`, { ID: testID, name: "Test Entity" })
408+
await utils.draftModeEdit("processor", "Test", testID, "ProcessorService")
409+
const attachResTest = await POST(
410+
`odata/v4/processor/Test(ID=${testID},IsActiveEntity=false)/attachments`,
411+
{
412+
up__ID: testID,
413+
filename: "testfile.pdf",
414+
mimeType: "application/pdf",
415+
createdAt: new Date(),
416+
createdBy: "alice",
417+
}
418+
)
419+
expect(attachResTest.data.ID).to.not.be.null
420+
421+
const detailsID = cds.utils.uuid()
422+
await POST(
423+
`odata/v4/processor/Test(ID=${testID},IsActiveEntity=false)/details`,
424+
{ ID: detailsID, description: "Test Details Entity" }
425+
)
426+
// Add attachment to TestDetails
427+
const attachResDetails = await POST(
428+
`odata/v4/processor/Test(ID=${testID},IsActiveEntity=false)/details(ID=${detailsID},IsActiveEntity=false)/attachments`,
429+
{
430+
up__ID: detailsID,
431+
filename: "detailsfile.pdf",
432+
mimeType: "application/pdf",
433+
createdAt: new Date(),
434+
createdBy: "alice",
435+
}
436+
)
437+
expect(attachResDetails.data.ID).to.not.be.null
438+
await utils.draftModeSave("processor", "Test", testID, () => {}, "ProcessorService")
439+
440+
// Delete the child TestDetails entity
441+
const delRes = await DELETE(
442+
`odata/v4/processor/Test(ID=${testID},IsActiveEntity=true)`
443+
)
444+
expect(delRes.status).to.equal(204)
445+
446+
// Check that the attachment is deleted
447+
let error
448+
try {
449+
await GET(
450+
`odata/v4/processor/Test_attachments(up__ID=${testID},ID=${attachResTest.data.ID},IsActiveEntity=true)`
451+
)
452+
} catch (e) {
453+
error = e
454+
}
455+
expect(error?.response?.status || error?.status).to.equal(404)
456+
error = null
457+
458+
try {
459+
await GET(
460+
`odata/v4/processor/TestDetails_attachments(up__ID=${detailsID},ID=${attachResDetails.data.ID},IsActiveEntity=true)`
461+
)
462+
} catch (e) {
463+
error = e
464+
}
465+
expect(error?.response?.status || error?.status).to.equal(404)
466+
})
325467
})
326468

327469
describe("Tests for attachments facet disable", () => {

0 commit comments

Comments
 (0)