From 432b1a903e9b052e0c99d35f46e7855b79122dab Mon Sep 17 00:00:00 2001 From: Stefan Rudi Date: Mon, 3 Aug 2026 14:42:47 +0200 Subject: [PATCH 1/5] test: remove withUser helper and patch cds-test to accept Buffer bodies --- package.json | 8 ++-- patches/@cap-js+cds-test+1.0.1.patch | 25 ++++++++++++ tests/integration/attachments-draft.test.js | 4 +- .../integration/attachments-features.test.js | 4 +- .../integration/attachments-non-draft.test.js | 6 +-- tests/integration/attachments-rename.test.js | 4 +- tests/integration/attachments-single.test.js | 16 ++++---- tests/unit/validateAttachmentMimeType.test.js | 5 ++- tests/unit/validateAttachmentSize.test.js | 5 ++- tests/utils/testUtils.js | 39 ------------------- 10 files changed, 53 insertions(+), 63 deletions(-) create mode 100644 patches/@cap-js+cds-test+1.0.1.patch diff --git a/package.json b/package.json index 6a9dbc15..5396f60a 100644 --- a/package.json +++ b/package.json @@ -19,16 +19,18 @@ "test": "npx jest --silent=true", "test:postgres": "CDS_ENV=pg npx jest --silent=true", "deploy:postgres": "cd ./tests/incidents-app && cds deploy --profile pg", - "prepare": "git config core.hooksPath .husky" + "prepare": "git config core.hooksPath .husky", + "postinstall": "patch-package" }, "devDependencies": { "@aws-sdk/client-s3": "^3.993.0", "@aws-sdk/lib-storage": "^3.993.0", "@azure/storage-blob": "^12.31.0", - "@google-cloud/storage": "^7.19.0", "@cap-js/cds-test": "^1", "@cap-js/hana": ">=2.7", - "@cap-js/sqlite": ">=2" + "@cap-js/sqlite": ">=2", + "@google-cloud/storage": "^7.19.0", + "patch-package": "^8.0.1" }, "peerDependencies": { "@aws-sdk/client-s3": "^3", diff --git a/patches/@cap-js+cds-test+1.0.1.patch b/patches/@cap-js+cds-test+1.0.1.patch new file mode 100644 index 00000000..1b0c23aa --- /dev/null +++ b/patches/@cap-js+cds-test+1.0.1.patch @@ -0,0 +1,25 @@ +diff --git a/node_modules/@cap-js/cds-test/lib/naxios.js b/node_modules/@cap-js/cds-test/lib/naxios.js +index f08dc96..7f358fe 100644 +--- a/node_modules/@cap-js/cds-test/lib/naxios.js ++++ b/node_modules/@cap-js/cds-test/lib/naxios.js +@@ -55,8 +55,10 @@ class Naxios { + if (data) o.body = + typeof data === 'string' ? data : + data instanceof Readable ? data : ++ Buffer.isBuffer(data) ? data : + JSON.stringify(data) +- if (typeof data === 'object' && !o.headers.has('Content-Type')) o.headers.set('Content-Type', 'application/json') ++ if (typeof data === 'object' && !Buffer.isBuffer(data) && !(data instanceof Readable) && !o.headers.has('Content-Type')) ++ o.headers.set('Content-Type', 'application/json') + if (!url.startsWith('http')) url = (o.baseURL||'') + (o.path||'') + (url[0]==='/'?'':'/') + url + if (params) url += '?' + new URLSearchParams (params) + o.url = url +@@ -77,7 +79,7 @@ class Naxios { + case 'arraybuffer': return res.arrayBuffer().then(Buffer.from) + } + let ct = res.headers.get('content-type') +- if (/stream|image|pdf|tar/.test(ct)) return res.body ++ if (/stream|image|pdf|tar|octet-stream/.test(ct)) return res.arrayBuffer().then(Buffer.from) + if (/xml/.test(ct)) return res.text() + else return res.text().then(x => { + try { return JSON.parse(x) } diff --git a/tests/integration/attachments-draft.test.js b/tests/integration/attachments-draft.test.js index 73dc2775..1996ea09 100644 --- a/tests/integration/attachments-draft.test.js +++ b/tests/integration/attachments-draft.test.js @@ -6,14 +6,14 @@ const { waitForMalwareDeletion, waitForDeletion, runWithUser, - withUser, uploadDraftAttachment, } = require("../utils/testUtils") const path = require("path") const { Readable } = require("stream") const app = path.resolve(__dirname, "../incidents-app") -const { GET, POST, DELETE, PATCH, PUT } = withUser("alice", cds.test(app)) +const { GET, POST, DELETE, PATCH, PUT, defaults } = cds.test(app) +defaults.auth = { username: "alice" } const alice = new cds.User({ id: "alice", roles: { admin: 1, support: 1 } }) const { createReadStream, readFileSync } = cds.utils.fs const { join, basename } = cds.utils.path diff --git a/tests/integration/attachments-features.test.js b/tests/integration/attachments-features.test.js index 05d645d9..b4fbaabc 100644 --- a/tests/integration/attachments-features.test.js +++ b/tests/integration/attachments-features.test.js @@ -3,12 +3,12 @@ const { RequestSend } = require("../utils/api") const { waitForScanStatus, newIncident, - withUser, } = require("../utils/testUtils") const path = require("path") const app = path.resolve(__dirname, "../incidents-app") -const { GET, POST, DELETE, PATCH, PUT } = withUser("alice", cds.test(app)) +const { GET, POST, DELETE, PATCH, PUT, defaults } = cds.test(app) +defaults.auth = { username: "alice" } const { createReadStream, readFileSync } = cds.utils.fs const { join } = cds.utils.path diff --git a/tests/integration/attachments-non-draft.test.js b/tests/integration/attachments-non-draft.test.js index 478df2f2..8634bd70 100644 --- a/tests/integration/attachments-non-draft.test.js +++ b/tests/integration/attachments-non-draft.test.js @@ -4,12 +4,12 @@ const { newIncident, waitForDeletion, delay, - withUser, } = require("../utils/testUtils") const path = require("path") const app = path.resolve(__dirname, "../incidents-app") -const { GET, POST, PATCH, DELETE, PUT } = withUser("alice", cds.test(app)) +const { GET, POST, DELETE, PATCH, PUT, defaults } = cds.test(app) +defaults.auth = { username: "alice" } const { join } = cds.utils.path const { createReadStream, readFileSync, statSync } = cds.utils.fs @@ -1265,7 +1265,7 @@ describe("Tests for inline single attachment in non-draft mode", () => { `/odata/v4/admin/SingleAttachment(ID=${entity.ID})/myAttachment_content`, ) expect(getRes.status).toEqual(200) - expect(getRes.data).toEqual(fileContent) + expect(getRes.data).toEqual(Buffer.from(fileContent)) }) it("Should delete a SingleAttachment and clear all inline fields", async () => { diff --git a/tests/integration/attachments-rename.test.js b/tests/integration/attachments-rename.test.js index f6d45add..efbb5c92 100644 --- a/tests/integration/attachments-rename.test.js +++ b/tests/integration/attachments-rename.test.js @@ -5,12 +5,12 @@ const { newIncident, runWithUser, uploadDraftAttachment, - withUser, } = require("../utils/testUtils") const path = require("path") const app = path.resolve(__dirname, "../incidents-app") -const { GET, POST, DELETE, PUT } = withUser("alice", cds.test(app)) +const { GET, POST, DELETE, PUT, defaults } = cds.test(app) +defaults.auth = { username: "alice" } const alice = new cds.User({ id: "alice", roles: { admin: 1, support: 1 } }) const { readFileSync } = cds.utils.fs const { join, basename } = cds.utils.path diff --git a/tests/integration/attachments-single.test.js b/tests/integration/attachments-single.test.js index f5139a51..5ee1a38c 100644 --- a/tests/integration/attachments-single.test.js +++ b/tests/integration/attachments-single.test.js @@ -5,12 +5,12 @@ const { waitForMalwareDeletion, waitForDeletion, runWithUser, - withUser, } = require("../utils/testUtils") const path = require("path") const app = path.resolve(__dirname, "../incidents-app") -const { GET, POST, DELETE, PATCH, PUT } = withUser("alice", cds.test(app)) +const { GET, POST, DELETE, PATCH, PUT, defaults } = cds.test(app) +defaults.auth = { username: "alice" } const alice = new cds.User({ id: "alice", roles: { admin: 1, support: 1 } }) const { readFileSync } = cds.utils.fs const { join } = cds.utils.path @@ -79,7 +79,7 @@ describe("Tests for single attachment entity", () => { `/odata/v4/processor/SingleAttachment(ID=${singleAttachment.ID},IsActiveEntity=true)/myAttachment_content`, ) expect(getRes.status).toEqual(200) - expect(getRes.data).toEqual(fileContent.toString()) + expect(getRes.data).toEqual(fileContent) }) it("Should delete a SingleAttachment and its attachment", async () => { @@ -168,7 +168,7 @@ describe("Tests for single attachment entity", () => { `/odata/v4/processor/SingleAttachment(ID=${singleAttachment.ID},IsActiveEntity=true)/myAttachment_content`, ) expect(getContentRes.status).toEqual(200) - expect(getContentRes.data).toEqual(fileContent) + expect(getContentRes.data).toEqual(Buffer.from(fileContent)) }) it("Should fail to upload content that exceeds the size limit", async () => { @@ -446,7 +446,7 @@ describe("Tests for single attachment entity", () => { `/odata/v4/processor/SingleAttachment(ID=${singleAttachment.ID},IsActiveEntity=true)/myAttachment_content`, ) expect(getV1.status).toEqual(200) - expect(getV1.data).toEqual(v1Content) + expect(getV1.data).toEqual(Buffer.from(v1Content)) // Re-edit: create a new draft from the active entity await POST( @@ -473,7 +473,7 @@ describe("Tests for single attachment entity", () => { `/odata/v4/processor/SingleAttachment(ID=${singleAttachment.ID},IsActiveEntity=true)/myAttachment_content`, ) expect(getV2.status).toEqual(200) - expect(getV2.data).toEqual(v2Content) + expect(getV2.data).toEqual(Buffer.from(v2Content)) }) it("Should populate myAttachment_url on the active entity after draft activation", async () => { @@ -604,7 +604,7 @@ describe("Tests for single attachment entity", () => { `/odata/v4/processor/SingleAttachment(ID=${singleAttachment.ID},IsActiveEntity=true)/myAttachment_content`, ) expect(getRes.status).toEqual(200) - expect(getRes.data).toEqual(fileContent) + expect(getRes.data).toEqual(Buffer.from(fileContent)) }) it("Should not delete blob when discarding a re-edit with no new upload", async () => { @@ -774,7 +774,7 @@ describe("Tests for single attachment entity", () => { `/odata/v4/processor/SingleAttachment(ID=${singleAttachment.ID},IsActiveEntity=false)/myAttachment_content`, ) expect(getRes.status).toEqual(200) - expect(getRes.data).toEqual(fileContent) + expect(getRes.data).toEqual(Buffer.from(fileContent)) }) it("Should clear inline attachment fields when DeleteInfectedAttachment is triggered with the correct hash", async () => { diff --git a/tests/unit/validateAttachmentMimeType.test.js b/tests/unit/validateAttachmentMimeType.test.js index 1c7661e3..7c97752c 100644 --- a/tests/unit/validateAttachmentMimeType.test.js +++ b/tests/unit/validateAttachmentMimeType.test.js @@ -4,8 +4,9 @@ const path = require("path") const app = path.resolve(__dirname, "../incidents-app") const { validateAttachmentMimeType } = require("../../lib/generic-handlers") -const { withUser, newIncident } = require("../utils/testUtils") -const { GET, POST, PUT } = withUser("alice", cds.test(app)) +const { newIncident } = require("../utils/testUtils") +const { GET, POST, PUT, defaults } = cds.test(app) +defaults.auth = { username: "alice" } const { readFileSync } = cds.utils.fs const { join } = cds.utils.path diff --git a/tests/unit/validateAttachmentSize.test.js b/tests/unit/validateAttachmentSize.test.js index 94b905cb..7a5e344e 100644 --- a/tests/unit/validateAttachmentSize.test.js +++ b/tests/unit/validateAttachmentSize.test.js @@ -3,8 +3,9 @@ const cds = require("@sap/cds") const path = require("path") const app = path.resolve(__dirname, "../incidents-app") const { validateAttachmentSize } = require("../../lib/generic-handlers") -const { newIncident, withUser } = require("../utils/testUtils") -const { POST, PUT } = withUser("alice", cds.test(app)) +const { newIncident } = require("../utils/testUtils") +const { POST, PUT, defaults } = cds.test(app) +defaults.auth = { username: "alice" } const { readFileSync } = cds.utils.fs const { join } = cds.utils.path diff --git a/tests/utils/testUtils.js b/tests/utils/testUtils.js index 4d928b01..c3c84381 100644 --- a/tests/utils/testUtils.js +++ b/tests/utils/testUtils.js @@ -183,44 +183,6 @@ async function waitUntil(predicate, timeout = 180000) { throw new Error(`Timeout: condition not met within ${timeout}ms`) } -const { Readable } = require("stream") - -async function unwrapStream(res) { - if (res.data && typeof res.data.getReader === "function") { - const reader = res.data.getReader() - const chunks = [] - while (true) { - const { done, value } = await reader.read() - if (done) break - chunks.push(value) - } - res.data = Buffer.concat(chunks).toString() - } - return res -} - -function withUser(username, test) { - const auth = { auth: { username } } - const wrap = (body) => (Buffer.isBuffer(body) ? Readable.from(body) : body) - const req = - (fn) => - (...args) => - fn(...args).then(unwrapStream) - return { - GET: req((url, opts) => test.GET(url, { ...auth, ...opts })), - POST: req((url, body, opts) => - test.POST(url, wrap(body), { ...auth, ...opts }), - ), - PUT: req((url, body, opts) => - test.PUT(url, wrap(body), { ...auth, ...opts }), - ), - DELETE: req((url, opts) => test.DELETE(url, { ...auth, ...opts })), - PATCH: req((url, body, opts) => - test.PATCH(url, wrap(body), { ...auth, ...opts }), - ), - } -} - /** * Uploads attachment in draft mode using CDS test utilities * @param {Object} utils - RequestSend utility instance @@ -296,6 +258,5 @@ module.exports = { waitForDeletion, waitForMalwareDeletion, runWithUser, - withUser, uploadDraftAttachment, } From c10e348dd0e4407bfb33e03dcde08672d1e3c475 Mon Sep 17 00:00:00 2001 From: Stefan Rudi Date: Tue, 4 Aug 2026 13:44:30 +0200 Subject: [PATCH 2/5] test: remove manual createdAt / createdBy --- tests/integration/attachments-draft.test.js | 61 -------------- .../integration/attachments-features.test.js | 80 ------------------- .../integration/attachments-non-draft.test.js | 72 ----------------- tests/integration/attachments-rename.test.js | 30 ------- 4 files changed, 243 deletions(-) diff --git a/tests/integration/attachments-draft.test.js b/tests/integration/attachments-draft.test.js index 1996ea09..a42cc8e5 100644 --- a/tests/integration/attachments-draft.test.js +++ b/tests/integration/attachments-draft.test.js @@ -95,10 +95,6 @@ describe("Tests for uploading/deleting attachments through API calls", () => { up__ID: incidentID, filename: "sample.pdf", mimeType: "application/pdf", - createdAt: new Date( - Date.now() - Math.random() * 30 * 24 * 60 * 60 * 1000, - ), - createdBy: "alice", }, ) @@ -134,11 +130,7 @@ describe("Tests for uploading/deleting attachments through API calls", () => { up__ID: incidentID, filename: "sample.pdf", mimeType: "application/pdf", - createdAt: new Date( - Date.now() - Math.random() * 30 * 24 * 60 * 60 * 1000, - ), content: fakeFileBuffer, - createdBy: "alice", }, ).catch((e) => { expectedError = e @@ -161,10 +153,6 @@ describe("Tests for uploading/deleting attachments through API calls", () => { up__ID: incidentID, filename: "large-stream.pdf", mimeType: "application/pdf", - createdAt: new Date( - Date.now() - Math.random() * 30 * 24 * 60 * 60 * 1000, - ), - createdBy: "alice", }, ) @@ -296,10 +284,6 @@ describe("Tests for uploading/deleting attachments through API calls", () => { filename: "test.pdf", mimeType: "application/pdf", content: createReadStream(join(__dirname, "content/test.pdf")), - createdAt: new Date( - Date.now() - Math.random() * 30 * 24 * 60 * 60 * 1000, - ), - createdBy: "alice", }, ) await utils.draftModeSave( @@ -467,7 +451,6 @@ describe("Tests for uploading/deleting attachments through API calls", () => { up__ID: incidentID, filename: "draft-only.pdf", mimeType: "application/pdf", - createdBy: "alice", }, ) expect(secondAttachRes.data.ID).toBeTruthy() @@ -522,10 +505,6 @@ describe("Tests for uploading/deleting attachments through API calls", () => { content: createReadStream( join(__dirname, "..", "integration", "content/sample.pdf"), ), - createdAt: new Date( - Date.now() - Math.random() * 30 * 24 * 60 * 60 * 1000, - ), - createdBy: "alice", }, ) expect(doc.data.ID).toBeTruthy() @@ -550,10 +529,6 @@ describe("Tests for uploading/deleting attachments through API calls", () => { up__sampleID: sampleID, up__gjahr: gjahr, filename: "myfancyfile.pdf", - createdAt: new Date( - Date.now() - Math.random() * 30 * 24 * 60 * 60 * 1000, - ), - createdBy: "alice", }, ) expect(doc.data.ID).toBeTruthy() @@ -789,8 +764,6 @@ describe("Tests for uploading/deleting attachments through API calls", () => { up__ID: testID, filename: "testfile.pdf", mimeType: "application/pdf", - createdAt: new Date(), - createdBy: "alice", }, ) expect(res.data.ID).not.toBeNull() @@ -833,8 +806,6 @@ describe("Tests for uploading/deleting attachments through API calls", () => { up__ID: testID, filename: "testfile.pdf", mimeType: "application/pdf", - createdAt: new Date(), - createdBy: "alice", }, ], }) @@ -882,8 +853,6 @@ describe("Tests for uploading/deleting attachments through API calls", () => { up__ID: testID, filename: "testfile.pdf", mimeType: "application/pdf", - createdAt: new Date(), - createdBy: "alice", }, ], details: [ @@ -895,8 +864,6 @@ describe("Tests for uploading/deleting attachments through API calls", () => { up__ID: detailsID, filename: "detailsfile.pdf", mimeType: "application/pdf", - createdAt: new Date(), - createdBy: "alice", }, ], }, @@ -991,8 +958,6 @@ describe("Tests for uploading/deleting attachments through API calls", () => { up__ID: detailsID, filename: "detailsfile.pdf", mimeType: "application/pdf", - createdAt: new Date(), - createdBy: "alice", }, ) expect(res.data.ID).not.toBeNull() @@ -1046,8 +1011,6 @@ describe("Tests for uploading/deleting attachments through API calls", () => { up__ID: detailsID, filename: "nested-draft.pdf", mimeType: "application/pdf", - createdAt: new Date(), - createdBy: "alice", }, ) expect(attachRes.data.ID).toBeTruthy() @@ -1177,8 +1140,6 @@ describe("Tests for uploading/deleting attachments through API calls", () => { up__ID: level2ID, filename: "depth3.pdf", mimeType: "application/pdf", - createdAt: new Date(), - createdBy: "alice", }, ) expect(attachRes.data.ID).toBeTruthy() @@ -1257,8 +1218,6 @@ describe("Tests for uploading/deleting attachments through API calls", () => { up__ID: level3ID, filename: "depth4.pdf", mimeType: "application/pdf", - createdAt: new Date(), - createdBy: "alice", }, ) expect(attachRes.data.ID).toBeTruthy() @@ -1331,8 +1290,6 @@ describe("Tests for uploading/deleting attachments through API calls", () => { up__ID: testID, filename: "testfile.pdf", mimeType: "application/pdf", - createdAt: new Date(), - createdBy: "alice", }, ) expect(attachRes.data.ID).not.toBeNull() @@ -1371,8 +1328,6 @@ describe("Tests for uploading/deleting attachments through API calls", () => { up__ID: detailsID, filename: "detailsfile.pdf", mimeType: "application/pdf", - createdAt: new Date(), - createdBy: "alice", }, ) expect(attachRes.data.ID).not.toBeNull() @@ -1408,8 +1363,6 @@ describe("Tests for uploading/deleting attachments through API calls", () => { up__ID: testID, filename: "testfile.pdf", mimeType: "application/pdf", - createdAt: new Date(), - createdBy: "alice", }, ) expect(attachResTest.data.ID).not.toBeNull() @@ -1440,8 +1393,6 @@ describe("Tests for uploading/deleting attachments through API calls", () => { up__ID: detailsID, filename: "detailsfile.pdf", mimeType: "application/pdf", - createdAt: new Date(), - createdBy: "alice", }, ) expect(attachResDetails.data.ID).not.toBeNull() @@ -1491,8 +1442,6 @@ describe("Tests for uploading/deleting attachments through API calls", () => { up__ID: testID, filename: "parentfile.pdf", mimeType: "application/pdf", - createdAt: new Date(), - createdBy: "alice", }, ) expect(attachResParent.data.ID).toBeTruthy() @@ -1509,8 +1458,6 @@ describe("Tests for uploading/deleting attachments through API calls", () => { up__ID: detailsID, filename: "childfile.pdf", mimeType: "application/pdf", - createdAt: new Date(), - createdBy: "alice", }, ) expect(attachResChild.data.ID).toBeTruthy() @@ -1566,8 +1513,6 @@ describe("Tests for uploading/deleting attachments through API calls", () => { up__ID: testID, filename: "parentfile.pdf", mimeType: "application/pdf", - createdAt: new Date(), - createdBy: "alice", }, ) expect(attachResParent.data.ID).toBeTruthy() @@ -1578,8 +1523,6 @@ describe("Tests for uploading/deleting attachments through API calls", () => { up__ID: detailsID, filename: "childfile.pdf", mimeType: "application/pdf", - createdAt: new Date(), - createdBy: "alice", }, ) expect(attachResChild.data.ID).toBeTruthy() @@ -1634,8 +1577,6 @@ describe("Tests for uploading/deleting attachments through API calls", () => { filename: "testfile.pdf", mimeType: "application/pdf", url: maliciousUrl, - createdAt: new Date(), - createdBy: "alice", }, ) expect(res.data.ID).toBeTruthy() @@ -1684,8 +1625,6 @@ describe("Tests for uploading/deleting attachments through API calls", () => { up__ID: incidentID, filename: "testmal.png", mimeType: "image/png", - createdAt: new Date(), - createdBy: "alice", }, ) expect(res.data.ID).toBeTruthy() diff --git a/tests/integration/attachments-features.test.js b/tests/integration/attachments-features.test.js index b4fbaabc..53103ac0 100644 --- a/tests/integration/attachments-features.test.js +++ b/tests/integration/attachments-features.test.js @@ -159,10 +159,6 @@ describe("Tests for acceptable media types", () => { filename: "sample.pdf", mimeType: "application/pdf", content: createReadStream(join(__dirname, "content/sample.pdf")), - createdAt: new Date( - Date.now() - Math.random() * 30 * 24 * 60 * 60 * 1000, - ), - createdBy: "alice", }, ).catch((e) => { expectedError = e @@ -189,11 +185,7 @@ describe("Tests for acceptable media types", () => { up__ID: incidentID, filename: "sample.pdf", mimeType: "application/pdf boundary=something", - createdAt: new Date( - Date.now() - Math.random() * 30 * 24 * 60 * 60 * 1000, - ), content: createReadStream(join(__dirname, "content/sample.pdf")), - createdBy: "alice", }, ).catch((e) => { expectedError = e @@ -220,11 +212,7 @@ describe("Tests for acceptable media types", () => { up__ID: incidentID, filename: "sample.pdf", mimeType: "application/pdf charset=UTF-8", - createdAt: new Date( - Date.now() - Math.random() * 30 * 24 * 60 * 60 * 1000, - ), content: createReadStream(join(__dirname, "content/sample.pdf")), - createdBy: "alice", }, ).catch((e) => { expect(e.status).toEqual(400) @@ -250,10 +238,6 @@ describe("Testing max and min amounts of attachments", () => { filename: "sample.pdf", mimeType: "application/jpeg; charset=UTF-8", content: createReadStream(join(__dirname, "content/sample-1.jpg")), - createdAt: new Date( - Date.now() - Math.random() * 30 * 24 * 60 * 60 * 1000, - ), - createdBy: "alice", }, ) await POST( @@ -263,10 +247,6 @@ describe("Testing max and min amounts of attachments", () => { filename: "sample.pdf", mimeType: "application/jpeg; charset=UTF-8", content: createReadStream(join(__dirname, "content/sample-1.jpg")), - createdAt: new Date( - Date.now() - Math.random() * 30 * 24 * 60 * 60 * 1000, - ), - createdBy: "alice", }, ) const { status: postStatus } = await POST( @@ -276,10 +256,6 @@ describe("Testing max and min amounts of attachments", () => { filename: "sample.pdf", mimeType: "application/jpeg; charset=UTF-8", content: createReadStream(join(__dirname, "content/sample-1.jpg")), - createdAt: new Date( - Date.now() - Math.random() * 30 * 24 * 60 * 60 * 1000, - ), - createdBy: "alice", }, ) expect(postStatus).toEqual(201) @@ -304,10 +280,6 @@ describe("Testing max and min amounts of attachments", () => { up__ID: incidentID, filename: "sample.pdf", mimeType: "application/jpeg; charset=UTF-8", - createdAt: new Date( - Date.now() - Math.random() * 30 * 24 * 60 * 60 * 1000, - ), - createdBy: "alice", }, ) const { status: deleteStatus } = await DELETE( @@ -340,10 +312,6 @@ describe("Testing max and min amounts of attachments", () => { { filename: "sample.pdf", mimeType: "application/jpeg; charset=UTF-8", - createdAt: new Date( - Date.now() - Math.random() * 30 * 24 * 60 * 60 * 1000, - ), - createdBy: "alice", }, ], }, @@ -385,26 +353,14 @@ describe("Testing max and min amounts of attachments", () => { { filename: "sample.pdf", mimeType: "application/jpeg; charset=UTF-8", - createdAt: new Date( - Date.now() - Math.random() * 30 * 24 * 60 * 60 * 1000, - ), - createdBy: "alice", }, { filename: "sample.pdf", mimeType: "application/jpeg; charset=UTF-8", - createdAt: new Date( - Date.now() - Math.random() * 30 * 24 * 60 * 60 * 1000, - ), - createdBy: "alice", }, { filename: "sample.pdf", mimeType: "application/jpeg; charset=UTF-8", - createdAt: new Date( - Date.now() - Math.random() * 30 * 24 * 60 * 60 * 1000, - ), - createdBy: "alice", }, ], }, @@ -446,10 +402,6 @@ describe("Testing max and min amounts of attachments", () => { { filename: "sample.pdf", mimeType: "application/jpeg; charset=UTF-8", - createdAt: new Date( - Date.now() - Math.random() * 30 * 24 * 60 * 60 * 1000, - ), - createdBy: "alice", DraftAdministrativeData_DraftUUID: "12345", }, ], @@ -478,28 +430,16 @@ describe("Testing max and min amounts of attachments", () => { { filename: "sample.pdf", mimeType: "application/jpeg; charset=UTF-8", - createdAt: new Date( - Date.now() - Math.random() * 30 * 24 * 60 * 60 * 1000, - ), - createdBy: "alice", DraftAdministrativeData_DraftUUID: "12345", }, { filename: "sample.pdf", mimeType: "application/jpeg; charset=UTF-8", - createdAt: new Date( - Date.now() - Math.random() * 30 * 24 * 60 * 60 * 1000, - ), - createdBy: "alice", DraftAdministrativeData_DraftUUID: "12345", }, { filename: "sample.pdf", mimeType: "application/jpeg; charset=UTF-8", - createdAt: new Date( - Date.now() - Math.random() * 30 * 24 * 60 * 60 * 1000, - ), - createdBy: "alice", DraftAdministrativeData_DraftUUID: "12345", }, ], @@ -542,10 +482,6 @@ describe("Testing max and min amounts of attachments", () => { filename: "sample.pdf", mimeType: "application/jpeg; charset=UTF-8", content: createReadStream(join(__dirname, "content/sample-1.jpg")), - createdAt: new Date( - Date.now() - Math.random() * 30 * 24 * 60 * 60 * 1000, - ), - createdBy: "alice", DraftAdministrativeData_DraftUUID: "12345", }, ], @@ -558,10 +494,6 @@ describe("Testing max and min amounts of attachments", () => { filename: "sample.pdf", mimeType: "application/jpeg; charset=UTF-8", content: createReadStream(join(__dirname, "content/sample-1.jpg")), - createdAt: new Date( - Date.now() - Math.random() * 30 * 24 * 60 * 60 * 1000, - ), - createdBy: "alice", }, ) await POST( @@ -571,10 +503,6 @@ describe("Testing max and min amounts of attachments", () => { filename: "sample.pdf", mimeType: "application/jpeg; charset=UTF-8", content: createReadStream(join(__dirname, "content/sample-1.jpg")), - createdAt: new Date( - Date.now() - Math.random() * 30 * 24 * 60 * 60 * 1000, - ), - createdBy: "alice", }, ) await INSERT.into( @@ -598,10 +526,6 @@ describe("Testing max and min amounts of attachments", () => { filename: "sample.pdf", mimeType: "application/jpeg; charset=UTF-8", content: createReadStream(join(__dirname, "content/sample-1.jpg")), - createdAt: new Date( - Date.now() - Math.random() * 30 * 24 * 60 * 60 * 1000, - ), - createdBy: "alice", }, ) @@ -769,10 +693,6 @@ describe("Testing max and min amounts of attachments", () => { filename: "sample.pdf", mimeType: "application/jpeg; charset=UTF-8", content: createReadStream(join(__dirname, "content/sample-1.jpg")), - createdAt: new Date( - Date.now() - Math.random() * 30 * 24 * 60 * 60 * 1000, - ), - createdBy: "alice", }, ) diff --git a/tests/integration/attachments-non-draft.test.js b/tests/integration/attachments-non-draft.test.js index 8634bd70..28635d02 100644 --- a/tests/integration/attachments-non-draft.test.js +++ b/tests/integration/attachments-non-draft.test.js @@ -299,8 +299,6 @@ describe("Tests for uploading/deleting and fetching attachments through API call up__ID: testID, filename: "parentfile.pdf", mimeType: "application/pdf", - createdAt: new Date(), - createdBy: "alice", }, { headers: { "Content-Type": "application/json" } }, ) @@ -312,8 +310,6 @@ describe("Tests for uploading/deleting and fetching attachments through API call up__ID: detailsID, filename: "childfile.pdf", mimeType: "application/pdf", - createdAt: new Date(), - createdBy: "alice", }, ) expect(attachResDetails.data.ID).toBeTruthy() @@ -349,8 +345,6 @@ describe("Tests for uploading/deleting and fetching attachments through API call up__ID: testID, filename: "parentfile.pdf", mimeType: "application/pdf", - createdAt: new Date(), - createdBy: "alice", }, { headers: { "Content-Type": "application/json" } }, ) @@ -362,8 +356,6 @@ describe("Tests for uploading/deleting and fetching attachments through API call up__ID: detailsID, filename: "childfile.pdf", mimeType: "application/pdf", - createdAt: new Date(), - createdBy: "alice", }, ) expect(attachResDetails.data.ID).toBeTruthy() @@ -415,8 +407,6 @@ describe("Tests for uploading/deleting and fetching attachments through API call up__ID: testID, filename: "parentfile.pdf", mimeType: "application/pdf", - createdAt: new Date(), - createdBy: "alice", }, ) expect(attachResTest.data.url).toBeTruthy() @@ -460,8 +450,6 @@ describe("Tests for uploading/deleting and fetching attachments through API call up__ID: testID, filename: "parentfile.pdf", mimeType: "application/pdf", - createdAt: new Date(), - createdBy: "alice", }, ) expect(attachRes.data.url).toBeTruthy() @@ -503,8 +491,6 @@ describe("Tests for uploading/deleting and fetching attachments through API call up__ID: firstID, filename: "file1.pdf", mimeType: "application/pdf", - createdAt: new Date(), - createdBy: "alice", }, ) expect(attachRes1.data.ID).toBeTruthy() @@ -515,8 +501,6 @@ describe("Tests for uploading/deleting and fetching attachments through API call up__ID: secondID, filename: "file2.pdf", mimeType: "application/pdf", - createdAt: new Date(), - createdBy: "alice", }, ) expect(attachRes2.data.ID).toBeTruthy() @@ -550,8 +534,6 @@ describe("Tests for uploading/deleting and fetching attachments through API call up__ID: testID, filename: "parentfile.pdf", mimeType: "application/pdf", - createdAt: new Date(), - createdBy: "alice", }, { headers: { "Content-Type": "application/json" } }, ) @@ -563,8 +545,6 @@ describe("Tests for uploading/deleting and fetching attachments through API call up__ID: detailsID, filename: "childfile.pdf", mimeType: "application/pdf", - createdAt: new Date(), - createdBy: "alice", }, ) expect(attachResDetails.data.ID).toBeTruthy() @@ -810,28 +790,16 @@ describe("Testing max and min amounts of attachments", () => { { filename: "sample.pdf", mimeType: "application/jpeg; charset=UTF-8", - createdAt: new Date( - Date.now() - Math.random() * 30 * 24 * 60 * 60 * 1000, - ), - createdBy: "alice", }, { filename: "sample.pdf", mimeType: "application/jpeg; charset=UTF-8", - createdAt: new Date( - Date.now() - Math.random() * 30 * 24 * 60 * 60 * 1000, - ), - createdBy: "alice", }, ], hiddenAttachments2: [ { filename: "sample.pdf", mimeType: "application/jpeg; charset=UTF-8", - createdAt: new Date( - Date.now() - Math.random() * 30 * 24 * 60 * 60 * 1000, - ), - createdBy: "alice", }, ], }) @@ -841,10 +809,6 @@ describe("Testing max and min amounts of attachments", () => { up__ID: incidentID, filename: "sample.pdf", mimeType: "application/jpeg; charset=UTF-8", - createdAt: new Date( - Date.now() - Math.random() * 30 * 24 * 60 * 60 * 1000, - ), - createdBy: "alice", }, ).catch((e) => { expect(e.status).toEqual(400) @@ -868,10 +832,6 @@ describe("Testing max and min amounts of attachments", () => { up__ID: incidentID, filename: "sample.pdf", mimeType: "application/jpeg; charset=UTF-8", - createdAt: new Date( - Date.now() - Math.random() * 30 * 24 * 60 * 60 * 1000, - ), - createdBy: "alice", }, ) await DELETE( @@ -902,10 +862,6 @@ describe("Testing max and min amounts of attachments", () => { { filename: "sample.pdf", mimeType: "application/jpeg; charset=UTF-8", - createdAt: new Date( - Date.now() - Math.random() * 30 * 24 * 60 * 60 * 1000, - ), - createdBy: "alice", }, ], }, @@ -937,26 +893,14 @@ describe("Testing max and min amounts of attachments", () => { { filename: "sample.pdf", mimeType: "application/jpeg; charset=UTF-8", - createdAt: new Date( - Date.now() - Math.random() * 30 * 24 * 60 * 60 * 1000, - ), - createdBy: "alice", }, { filename: "sample.pdf", mimeType: "application/jpeg; charset=UTF-8", - createdAt: new Date( - Date.now() - Math.random() * 30 * 24 * 60 * 60 * 1000, - ), - createdBy: "alice", }, { filename: "sample.pdf", mimeType: "application/jpeg; charset=UTF-8", - createdAt: new Date( - Date.now() - Math.random() * 30 * 24 * 60 * 60 * 1000, - ), - createdBy: "alice", }, ], }, @@ -995,10 +939,6 @@ describe("Testing max and min amounts of attachments", () => { { filename: "sample.pdf", mimeType: "application/jpeg; charset=UTF-8", - createdAt: new Date( - Date.now() - Math.random() * 30 * 24 * 60 * 60 * 1000, - ), - createdBy: "alice", }, ], }, @@ -1026,26 +966,14 @@ describe("Testing max and min amounts of attachments", () => { { filename: "sample.pdf", mimeType: "application/jpeg; charset=UTF-8", - createdAt: new Date( - Date.now() - Math.random() * 30 * 24 * 60 * 60 * 1000, - ), - createdBy: "alice", }, { filename: "sample.pdf", mimeType: "application/jpeg; charset=UTF-8", - createdAt: new Date( - Date.now() - Math.random() * 30 * 24 * 60 * 60 * 1000, - ), - createdBy: "alice", }, { filename: "sample.pdf", mimeType: "application/jpeg; charset=UTF-8", - createdAt: new Date( - Date.now() - Math.random() * 30 * 24 * 60 * 60 * 1000, - ), - createdBy: "alice", }, ], }, diff --git a/tests/integration/attachments-rename.test.js b/tests/integration/attachments-rename.test.js index efbb5c92..b45e04e7 100644 --- a/tests/integration/attachments-rename.test.js +++ b/tests/integration/attachments-rename.test.js @@ -50,8 +50,6 @@ describe("Tests for renaming duplicate attachments", () => { up__ID: incidentID, filename: basename(filepath), mimeType: "application/pdf", - createdAt: new Date(), - createdBy: "alice", }, ) @@ -62,8 +60,6 @@ describe("Tests for renaming duplicate attachments", () => { up__ID: incidentID, filename: basename(filepath), mimeType: "application/pdf", - createdAt: new Date(), - createdBy: "alice", }, ) @@ -74,8 +70,6 @@ describe("Tests for renaming duplicate attachments", () => { up__ID: incidentID, filename: basename(filepath), mimeType: "application/pdf", - createdAt: new Date(), - createdBy: "alice", }, ) @@ -134,8 +128,6 @@ describe("Tests for renaming duplicate attachments", () => { up__ID: incidentID, filename: basename(filepath), mimeType: "application/pdf", - createdAt: new Date(), - createdBy: "alice", }, ) @@ -187,8 +179,6 @@ describe("Tests for renaming duplicate attachments", () => { up__ID: incidentID, filename: initialFilename, mimeType: "application/pdf", - createdAt: new Date(), - createdBy: "alice", }, ) @@ -199,8 +189,6 @@ describe("Tests for renaming duplicate attachments", () => { up__ID: incidentID, filename: initialFilename, mimeType: "application/pdf", - createdAt: new Date(), - createdBy: "alice", }, ) @@ -211,8 +199,6 @@ describe("Tests for renaming duplicate attachments", () => { up__ID: incidentID, filename: initialFilename, mimeType: "application/pdf", - createdAt: new Date(), - createdBy: "alice", }, ) @@ -401,8 +387,6 @@ describe("Tests for renaming duplicate attachments", () => { up__ID: incidentID, filename: basename(filepath), mimeType: "application/pdf", - createdAt: new Date(), - createdBy: "alice", }, ) await POST( @@ -411,8 +395,6 @@ describe("Tests for renaming duplicate attachments", () => { up__ID: incidentID, filename: basename(filepath), mimeType: "application/pdf", - createdAt: new Date(), - createdBy: "alice", }, ) @@ -442,8 +424,6 @@ describe("Tests for renaming duplicate attachments", () => { up__ID: incidentID, filename: basename(filepath), mimeType: "application/pdf", - createdAt: new Date(), - createdBy: "alice", }, ) await POST( @@ -452,8 +432,6 @@ describe("Tests for renaming duplicate attachments", () => { up__ID: incidentID, filename: basename(filepath), mimeType: "application/pdf", - createdAt: new Date(), - createdBy: "alice", }, ) await POST( @@ -462,8 +440,6 @@ describe("Tests for renaming duplicate attachments", () => { up__ID: incidentID, filename: basename(filepath), mimeType: "application/pdf", - createdAt: new Date(), - createdBy: "alice", }, ) await POST( @@ -472,8 +448,6 @@ describe("Tests for renaming duplicate attachments", () => { up__ID: incidentID, filename: basename(filepath), mimeType: "application/pdf", - createdAt: new Date(), - createdBy: "alice", }, ) @@ -519,8 +493,6 @@ describe("Tests for renaming duplicate attachments", () => { up__ID: incidentID, filename: basename(filepath), mimeType: "application/pdf", - createdAt: new Date(), - createdBy: "alice", }, ) @@ -531,8 +503,6 @@ describe("Tests for renaming duplicate attachments", () => { up__ID: incidentID, filename: basename(filepath), mimeType: "application/pdf", - createdAt: new Date(), - createdBy: "alice", }, ) From 22306a4fad13f2d68dda32b0eea75088fe8a59ba Mon Sep 17 00:00:00 2001 From: Stefan Rudi Date: Tue, 4 Aug 2026 13:45:16 +0200 Subject: [PATCH 3/5] . --- tests/integration/attachments-features.test.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/tests/integration/attachments-features.test.js b/tests/integration/attachments-features.test.js index 53103ac0..59b60285 100644 --- a/tests/integration/attachments-features.test.js +++ b/tests/integration/attachments-features.test.js @@ -1,9 +1,6 @@ const cds = require("@sap/cds") const { RequestSend } = require("../utils/api") -const { - waitForScanStatus, - newIncident, -} = require("../utils/testUtils") +const { waitForScanStatus, newIncident } = require("../utils/testUtils") const path = require("path") const app = path.resolve(__dirname, "../incidents-app") From 94fd4be225d1373fea3da78a3cf90f32fdb4aeed Mon Sep 17 00:00:00 2001 From: Stefan Rudi Date: Tue, 4 Aug 2026 16:31:51 +0200 Subject: [PATCH 4/5] remove patch --- package.json | 8 +++----- patches/@cap-js+cds-test+1.0.1.patch | 25 ------------------------- 2 files changed, 3 insertions(+), 30 deletions(-) delete mode 100644 patches/@cap-js+cds-test+1.0.1.patch diff --git a/package.json b/package.json index 5396f60a..6a9dbc15 100644 --- a/package.json +++ b/package.json @@ -19,18 +19,16 @@ "test": "npx jest --silent=true", "test:postgres": "CDS_ENV=pg npx jest --silent=true", "deploy:postgres": "cd ./tests/incidents-app && cds deploy --profile pg", - "prepare": "git config core.hooksPath .husky", - "postinstall": "patch-package" + "prepare": "git config core.hooksPath .husky" }, "devDependencies": { "@aws-sdk/client-s3": "^3.993.0", "@aws-sdk/lib-storage": "^3.993.0", "@azure/storage-blob": "^12.31.0", + "@google-cloud/storage": "^7.19.0", "@cap-js/cds-test": "^1", "@cap-js/hana": ">=2.7", - "@cap-js/sqlite": ">=2", - "@google-cloud/storage": "^7.19.0", - "patch-package": "^8.0.1" + "@cap-js/sqlite": ">=2" }, "peerDependencies": { "@aws-sdk/client-s3": "^3", diff --git a/patches/@cap-js+cds-test+1.0.1.patch b/patches/@cap-js+cds-test+1.0.1.patch deleted file mode 100644 index 1b0c23aa..00000000 --- a/patches/@cap-js+cds-test+1.0.1.patch +++ /dev/null @@ -1,25 +0,0 @@ -diff --git a/node_modules/@cap-js/cds-test/lib/naxios.js b/node_modules/@cap-js/cds-test/lib/naxios.js -index f08dc96..7f358fe 100644 ---- a/node_modules/@cap-js/cds-test/lib/naxios.js -+++ b/node_modules/@cap-js/cds-test/lib/naxios.js -@@ -55,8 +55,10 @@ class Naxios { - if (data) o.body = - typeof data === 'string' ? data : - data instanceof Readable ? data : -+ Buffer.isBuffer(data) ? data : - JSON.stringify(data) -- if (typeof data === 'object' && !o.headers.has('Content-Type')) o.headers.set('Content-Type', 'application/json') -+ if (typeof data === 'object' && !Buffer.isBuffer(data) && !(data instanceof Readable) && !o.headers.has('Content-Type')) -+ o.headers.set('Content-Type', 'application/json') - if (!url.startsWith('http')) url = (o.baseURL||'') + (o.path||'') + (url[0]==='/'?'':'/') + url - if (params) url += '?' + new URLSearchParams (params) - o.url = url -@@ -77,7 +79,7 @@ class Naxios { - case 'arraybuffer': return res.arrayBuffer().then(Buffer.from) - } - let ct = res.headers.get('content-type') -- if (/stream|image|pdf|tar/.test(ct)) return res.body -+ if (/stream|image|pdf|tar|octet-stream/.test(ct)) return res.arrayBuffer().then(Buffer.from) - if (/xml/.test(ct)) return res.text() - else return res.text().then(x => { - try { return JSON.parse(x) } From ab96b15418ef72c5e0ecd7dac0f9bfa204798e39 Mon Sep 17 00:00:00 2001 From: Stefan Rudi Date: Tue, 4 Aug 2026 18:16:53 +0200 Subject: [PATCH 5/5] test: set response type to arraybuffer --- tests/integration/attachments-non-draft.test.js | 1 + tests/integration/attachments-single.test.js | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/tests/integration/attachments-non-draft.test.js b/tests/integration/attachments-non-draft.test.js index 28635d02..e69b18fb 100644 --- a/tests/integration/attachments-non-draft.test.js +++ b/tests/integration/attachments-non-draft.test.js @@ -1191,6 +1191,7 @@ describe("Tests for inline single attachment in non-draft mode", () => { const getRes = await GET( `/odata/v4/admin/SingleAttachment(ID=${entity.ID})/myAttachment_content`, + { responseType: "arraybuffer" }, ) expect(getRes.status).toEqual(200) expect(getRes.data).toEqual(Buffer.from(fileContent)) diff --git a/tests/integration/attachments-single.test.js b/tests/integration/attachments-single.test.js index 5ee1a38c..16589776 100644 --- a/tests/integration/attachments-single.test.js +++ b/tests/integration/attachments-single.test.js @@ -77,6 +77,7 @@ describe("Tests for single attachment entity", () => { const getRes = await GET( `/odata/v4/processor/SingleAttachment(ID=${singleAttachment.ID},IsActiveEntity=true)/myAttachment_content`, + { responseType: "arraybuffer" }, ) expect(getRes.status).toEqual(200) expect(getRes.data).toEqual(fileContent) @@ -166,6 +167,7 @@ describe("Tests for single attachment entity", () => { const getContentRes = await GET( `/odata/v4/processor/SingleAttachment(ID=${singleAttachment.ID},IsActiveEntity=true)/myAttachment_content`, + { responseType: "arraybuffer" }, ) expect(getContentRes.status).toEqual(200) expect(getContentRes.data).toEqual(Buffer.from(fileContent)) @@ -444,6 +446,7 @@ describe("Tests for single attachment entity", () => { // Verify v1 content is readable const getV1 = await GET( `/odata/v4/processor/SingleAttachment(ID=${singleAttachment.ID},IsActiveEntity=true)/myAttachment_content`, + { responseType: "arraybuffer" }, ) expect(getV1.status).toEqual(200) expect(getV1.data).toEqual(Buffer.from(v1Content)) @@ -471,6 +474,7 @@ describe("Tests for single attachment entity", () => { // Verify v2 content is now returned const getV2 = await GET( `/odata/v4/processor/SingleAttachment(ID=${singleAttachment.ID},IsActiveEntity=true)/myAttachment_content`, + { responseType: "arraybuffer" }, ) expect(getV2.status).toEqual(200) expect(getV2.data).toEqual(Buffer.from(v2Content)) @@ -602,6 +606,7 @@ describe("Tests for single attachment entity", () => { const getRes = await GET( `/odata/v4/processor/SingleAttachment(ID=${singleAttachment.ID},IsActiveEntity=true)/myAttachment_content`, + { responseType: "arraybuffer" }, ) expect(getRes.status).toEqual(200) expect(getRes.data).toEqual(Buffer.from(fileContent)) @@ -772,6 +777,7 @@ describe("Tests for single attachment entity", () => { const getRes = await GET( `/odata/v4/processor/SingleAttachment(ID=${singleAttachment.ID},IsActiveEntity=false)/myAttachment_content`, + { responseType: "arraybuffer" }, ) expect(getRes.status).toEqual(200) expect(getRes.data).toEqual(Buffer.from(fileContent))