Skip to content

Commit 6f8a0e7

Browse files
committed
Merge branch 'singleAttachment' of https://github.com/cap-js/attachments into singleAttachment
2 parents f33c67d + f00bb12 commit 6f8a0e7

3 files changed

Lines changed: 27 additions & 18 deletions

File tree

db/index.cds

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ using {
1212
context sap.attachments {
1313

1414
type SingleMediaData @(_is_media_data) {
15-
url : String @UI.Hidden;
16-
content : LargeBinary @title: '{i18n>Attachment}'; // only for db-based services
17-
mimeType : String default 'application/octet-stream' @title: '{i18n>MediaType}';
18-
filename : String @title: '{i18n>FileName}';
19-
hash : String @UI.Hidden @Core.Computed;
20-
status : Association to one ScanStates default 'Unscanned' @title: '{i18n>ScanStatus}' @Common.Text: status.name @Common.TextArrangement: #TextOnly;
21-
lastScan : Timestamp @title: '{i18n>LastScan}' @Core.Computed;
15+
url : String @UI.Hidden;
16+
content : LargeBinary @title: '{i18n>Attachment}'; // only for db-based services
17+
mimeType : String default 'application/octet-stream' @title: '{i18n>MediaType}';
18+
filename : String @title: '{i18n>FileName}';
19+
hash : String @UI.Hidden @Core.Computed;
20+
status : Association to one ScanStates default 'Unscanned' @title: '{i18n>ScanStatus}' @Common.Text: status.name @Common.TextArrangement: #TextOnly;
21+
lastScan : Timestamp @title: '{i18n>LastScan}' @Core.Computed;
2222
}
2323

2424
aspect MediaData @(_is_media_data) {
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
ID,name
2+
a1b2c3d4-e5f6-4a7b-8c9d-0e1f2a3b4c5d,My single attachment
3+
b2c3d4e5-f6a7-4b8c-9d0e-1f2a3b4c5d6e,My other attachment

tests/integration/attachments.test.js

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1304,24 +1304,25 @@ describe("Tests for single attachment entity", () => {
13041304
const filepath = join(__dirname, "content/sample.pdf")
13051305
const fileContent = readFileSync(filepath)
13061306

1307-
const postRes = await POST(
1307+
const putRes = await PUT(
13081308
`/odata/v4/processor/SingleAttachment(ID=${singleAttachment.ID},IsActiveEntity=false)/myAttachment`,
13091309
{
1310-
filename: basename(filepath),
1311-
mimeType: "application/pdf",
1310+
filename: basename(filepath),
1311+
mimeType: "application/pdf",
13121312
},
13131313
)
1314+
expect(putRes.status).toEqual(200)
13141315

1315-
const putRes = await PUT(
1316-
`/odata/v4/processor/SingleAttachment_myAttachment(up__ID=${singleAttachment.ID},ID=${postRes.data.ID},IsActiveEntity=false)/content`,
1316+
const putContentRes = await PUT(
1317+
`/odata/v4/processor/SingleAttachment(ID=${singleAttachment.ID},IsActiveEntity=false)/myAttachment/content`,
13171318
fileContent,
13181319
{
13191320
headers: {
13201321
"Content-Type": "application/pdf",
13211322
},
13221323
},
13231324
)
1324-
expect(putRes.status).toEqual(204)
1325+
expect(putContentRes.status).toEqual(204)
13251326

13261327
// Activate the draft
13271328
await POST(
@@ -1332,7 +1333,7 @@ describe("Tests for single attachment entity", () => {
13321333
const getRes = await GET(
13331334
`/odata/v4/processor/SingleAttachment(ID=${singleAttachment.ID},IsActiveEntity=true)/myAttachment`,
13341335
)
1335-
expect(getRes.data.ID).toBeDefined()
1336+
expect(getRes.data.filename).toBe(basename(filepath))
13361337
})
13371338

13381339
it("should delete a SingleAttachment and its attachment", async () => {
@@ -1345,15 +1346,21 @@ describe("Tests for single attachment entity", () => {
13451346
)
13461347
const filepath = join(__dirname, "content/sample.pdf")
13471348
const fileContent = readFileSync(filepath)
1348-
const postRes = await POST(
1349+
1350+
await PUT(
13491351
`/odata/v4/processor/SingleAttachment(ID=${singleAttachment.ID},IsActiveEntity=false)/myAttachment`,
1350-
{ filename: basename(filepath) },
1352+
{
1353+
filename: basename(filepath),
1354+
mimeType: "application/pdf",
1355+
},
13511356
)
1357+
13521358
await PUT(
1353-
`/odata/v4/processor/SingleAttachment_myAttachment(up__ID=${singleAttachment.ID},ID=${postRes.data.ID},IsActiveEntity=false)/content`,
1359+
`/odata/v4/processor/SingleAttachment(ID=${singleAttachment.ID},IsActiveEntity=false)/myAttachment/content`,
13541360
fileContent,
13551361
{ headers: { "Content-Type": "application/pdf" } },
13561362
)
1363+
13571364
await POST(
13581365
`/odata/v4/processor/SingleAttachment(ID=${singleAttachment.ID},IsActiveEntity=false)/ProcessorService.draftActivate`,
13591366
)
@@ -1376,7 +1383,6 @@ describe("Tests for single attachment entity", () => {
13761383
SELECT.one
13771384
.from("sap.attachments.Attachments")
13781385
.where({ url: attachmentUrl })
1379-
.columns("content"),
13801386
)
13811387
expect(content.content).toBeNull()
13821388
})

0 commit comments

Comments
 (0)