using cds.test

This commit is contained in:
Daniel
2021-08-30 16:04:54 +02:00
committed by Daniel Hutzel
parent 2be3d50389
commit 2f5d159428
9 changed files with 16 additions and 17 deletions

View File

@@ -1,14 +1,14 @@
const { GET, POST, expect } = require('../test') .run ('bookshop')
const cds = require('@sap/cds/lib')
const { GET, POST, expect } = cds.test(__dirname+'/../bookshop')
if (cds.User.default) cds.User.default = cds.User.Privileged // hard core monkey patch
else cds.User = cds.User.Privileged // hard core monkey patch for older cds releases
describe('Custom Handlers', () => {
it('should reject out-of-stock orders', async () => {
await POST('/browse/submitOrder', { book: 201, amount: 5 })
await POST('/browse/submitOrder', { book: 201, amount: 5 })
await expect(POST('/browse/submitOrder', { book: 201, amount: 5 })).to.be.rejectedWith(/409 - 5 exceeds stock for book #201/)
await POST `/browse/submitOrder ${{ book: 201, amount: 5 }}`
await POST `/browse/submitOrder ${{ book: 201, amount: 5 }}`
await expect(POST `/browse/submitOrder ${{ book: 201, amount: 5 }}`).to.be.rejectedWith(/409 - 5 exceeds stock for book #201/)
const { data } = await GET`/admin/Books/201/stock/$value`
expect(data).to.equal(2)
})