submitOrder: set IsActiveEntity to true - #48
Conversation
| Items: [{ product:{ID:`${book}`}, title, price, quantity }], | ||
| buyer, createdBy: buyer, currency | ||
| buyer, createdBy: buyer, currency, | ||
| IsActiveEntity: true |
There was a problem hiding this comment.
@johannes-vogel @sjvans is this the recommended pattern?
There was a problem hiding this comment.
https://cap.cloud.sap/docs/guides/uis/fiori#requests-to-active-data
Add IsActiveEntity=true as a key parameter to your requests to address active data directly
, for POST(CREATE) too
https://cap.cloud.sap/docs/guides/uis/fiori#draft-agnostic-requests
Taking this further, through cds.fiori.draft_new_action: true IsActiveEntity=true is assumed by default, so clients that are unaware of drafts or don't need to handle them can ignore all draft-specific requests and parameters
The cds.fiori.draft_new_action feature is currently not enabled in the orders module.
There was a problem hiding this comment.
it should be active by default, as you're creating a Orders and not a Orders.drafts
how can i reproduce?
There was a problem hiding this comment.
In order to reproduce it follow the steps:
- prepare the repository
For more details on @capire modules, see Using @capire modules from GitHub Packages.
git clone https://github.com/capire/orders.git
cd orders
npm login --scope @capire --registry=https://npm.pkg.github.com/
npm i
npm i -D @cap-js/sqlite
npm i -D @cap-js/cds-test
- create a new file named odata.create.order.active.by.default.test.js with content:
const cds = require('@sap/cds')
const { POST, expect, defaults } = cds.test(".", '--with-mocks')
describe ('OrdersService', () => {
beforeAll (()=> {
cds.requires.queue = { timeout: '1h' }
defaults.auth = { username: 'alice' }
defaults.path = '/odata/v4/orders'
})
it('create active order by default', async () => {
const { data: data1 } = await POST(`/Orders`, {
'OrderNo': 'active',
//IsActiveEntity: true // uncomment to fix
})
expect (data1.OrderNo) .to.equal ('active')
expect (data1.IsActiveEntity) .to.equal (true)
})
})
- run the test to get error
npx jest odata.create.order.active.by.default.test.js
- uncomment line 15 to fix the test
....
IsActiveEntity: true // uncomment to fix
...
Uh oh!
There was an error while loading. Please reload this page.