Skip to content

Commit 5d6e5b6

Browse files
committed
Tests for two-level entities
1 parent 9218d80 commit 5d6e5b6

File tree

1 file changed

+77
-0
lines changed

1 file changed

+77
-0
lines changed

tests/integration/attachments.test.js

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,83 @@ describe("Tests for uploading/deleting attachments through API calls", () => {
245245
)
246246
expect(deleteRes.status).to.equal(204)
247247
})
248+
249+
it("Uploading attachment to Test works and scan status is set", async () => {
250+
// Create a Test entity
251+
const testID = cds.utils.uuid()
252+
await POST(`odata/v4/processor/Test`, {
253+
ID: testID,
254+
name: "Test Entity"
255+
})
256+
257+
// Upload attachment
258+
await utils.draftModeEdit("processor", "Test", testID, "ProcessorService")
259+
const res = await POST(
260+
`odata/v4/processor/Test(ID=${testID},IsActiveEntity=false)/attachments`,
261+
{
262+
up__ID: testID,
263+
filename: "testfile.pdf",
264+
mimeType: "application/pdf",
265+
createdAt: new Date(),
266+
createdBy: "alice",
267+
}
268+
)
269+
expect(res.data.ID).to.not.be.null
270+
271+
await utils.draftModeSave("processor", "Test", testID, () => {}, "ProcessorService")
272+
273+
// Test that attachment exists and scan status
274+
const getRes = await GET(
275+
`odata/v4/processor/Test(ID=${testID},IsActiveEntity=true)/attachments`
276+
)
277+
expect(getRes.status).to.equal(200)
278+
expect(getRes.data.value.length).to.equal(1)
279+
expect(getRes.data.value[0].status).to.be.oneOf(["Scanning", "Clean", "Unscanned"])
280+
})
281+
282+
it("Uploading attachment to TestDetails works and scan status is set (expected to fail)", async () => {
283+
// Create a Test entity
284+
const testID = cds.utils.uuid()
285+
await POST(`odata/v4/processor/Test`, {
286+
ID: testID,
287+
name: "Test Entity"
288+
})
289+
290+
await utils.draftModeEdit("processor", "Test", testID, "ProcessorService")
291+
292+
// Add TestDetails entity
293+
const detailsID = cds.utils.uuid()
294+
await POST(
295+
`odata/v4/processor/Test(ID=${testID},IsActiveEntity=false)/details`,
296+
{
297+
ID: detailsID,
298+
description: "Test Details Entity"
299+
}
300+
)
301+
302+
// Upload attachment
303+
const res = await POST(
304+
`odata/v4/processor/Test(ID=${testID},IsActiveEntity=false)/details(ID=${detailsID},IsActiveEntity=false)/attachments`,
305+
{
306+
up__ID: detailsID,
307+
filename: "detailsfile.pdf",
308+
mimeType: "application/pdf",
309+
createdAt: new Date(),
310+
createdBy: "alice",
311+
}
312+
)
313+
expect(res.data.ID).to.not.be.null
314+
315+
await utils.draftModeSave("processor", "Test", testID, () => {}, "ProcessorService")
316+
317+
// Test that attachment exists and scan status
318+
const getRes = await GET(
319+
`odata/v4/processor/TestDetails(ID=${detailsID},IsActiveEntity=true)/attachments`
320+
)
321+
expect(getRes.status).to.equal(200)
322+
expect(getRes.data.value.length).to.equal(1)
323+
expect(getRes.data.value[0].status).to.be.oneOf(["Scanning", "Clean", "Unscanned"])
324+
})
248325
})
249326

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

0 commit comments

Comments
 (0)