Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions sqlite/test/general/managed.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,21 @@ describe('Managed thingies', () => {
expect(result[0].createdBy).to.equal(result[1].createdBy)
}
})

// Regression: since @cap-js/db-service@2.9.0, managed fields excluded from a
// service projection are silently dropped from the generated INSERT.
// See https://github.tools.sap/cap/issues/issues/20583
test('managed fields excluded from the projection still reach the INSERT', async () => {
const resPost = await POST('/test/fooManagedRestricted', { ID: 99, value: 'test' })
expect(resPost.status).to.equal(201)

// Read the underlying DB entity directly: the managed columns are not
// exposed through the restricted projection, so we must query db.fooManaged.
const db = await cds.connect.to('db')
const row = await db.run(SELECT.one.from('db.fooManaged').where({ ID: 99 }))
// On the buggy version the managed columns are NULL because they were
// dropped from the INSERT; assert on the whole row for a readable diff.
expect(row).to.containSubset({ ID: 99, value: 'test', createdBy: 'anonymous' })
expect(typeof row.createdAt).to.eq('string')
})
})
12 changes: 12 additions & 0 deletions sqlite/test/general/model.cds
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ entity db.fooTemporal : managed, temporal {
key ID : Integer;
}

entity db.fooManaged : managed {
key ID : Integer;
value : String;
}

@path: '/test'
service test {
entity foo : managed {
Expand Down Expand Up @@ -35,6 +40,13 @@ service test {

entity fooTemporal as projection on db.fooTemporal;

// Projection that intentionally excludes the managed fields
// (createdBy/createdAt/modifiedBy/modifiedAt) — see issue 20583.
entity fooManagedRestricted as projection on db.fooManaged {
ID,
value
};

entity Images {
key ID : Integer;
data : LargeBinary @Core.MediaType: 'image/jpeg';
Expand Down
Loading