diff --git a/test/cds.ql.test.js b/test/cds.ql.test.js index 5b6e0a73..c9f3f6dc 100644 --- a/test/cds.ql.test.js +++ b/test/cds.ql.test.js @@ -1,20 +1,18 @@ -const cds = require('@sap/cds/lib') -const { expect } = cds.test -const { cdr } = cds.ql -const Foo = { name: 'Foo' } -const Books = { name: 'capire.bookshop.Books' } - - -const STAR = cdr ? '*' : { ref: ['*'] } -const skip = {to:{eql:()=>skip}} -const srv = new cds.Service -let cqn - -expect.plain = (cqn) => !cqn.SELECT.one && !cqn.SELECT.distinct ? expect(cqn) : skip -expect.one = (cqn) => !cqn.SELECT.distinct ? expect(cqn) : skip - describe('cds.ql → cqn', () => { - // + + const cds = require('@sap/cds/lib') + const { expect } = cds.test + const { cdr } = cds.ql + const Foo = { name: 'Foo' } + const Books = { name: 'capire.bookshop.Books' } + + const STAR = cdr ? '*' : { ref: ['*'] } + const skip = {to:{eql:()=>skip}} + const srv = new cds.Service + let cqn + + expect.plain = (cqn) => !cqn.SELECT.one && !cqn.SELECT.distinct ? expect(cqn) : skip + expect.one = (cqn) => !cqn.SELECT.distinct ? expect(cqn) : skip describe.each(['SELECT', 'SELECT one', 'SELECT distinct'])(`%s...`, (each) => { diff --git a/test/consuming-services.test.js b/test/consuming-services.test.js index 71c0b19e..deb0e18d 100644 --- a/test/consuming-services.test.js +++ b/test/consuming-services.test.js @@ -1,8 +1,9 @@ const cds = require('@sap/cds/lib') -const { expect } = cds.test ('@capire/bookshop') describe('cap/samples - Consuming Services locally', () => { - // + + const { expect } = cds.test ('@capire/bookshop') + it('bootstrapped the database successfully', ()=>{ const { AdminService } = cds.services const { Authors } = AdminService.entities diff --git a/test/custom-handlers.test.js b/test/custom-handlers.test.js index a5cd43c9..ae2184d3 100644 --- a/test/custom-handlers.test.js +++ b/test/custom-handlers.test.js @@ -1,10 +1,11 @@ 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('cap/samples - Custom Handlers', () => { + 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 + it('should reject out-of-stock orders', async () => { await POST `/browse/submitOrder ${{ book: 201, quantity: 5 }}` await POST `/browse/submitOrder ${{ book: 201, quantity: 5 }}` diff --git a/test/fiori.test.js b/test/fiori.test.js index 42d6f0ff..9da8eb5e 100644 --- a/test/fiori.test.js +++ b/test/fiori.test.js @@ -1,9 +1,10 @@ const cds = require('@sap/cds/lib') -const { GET, expect, axios } = cds.test ('@capire/fiori', '--with-mocks') -axios.defaults.auth = { username: 'alice', password: 'admin' } describe('cap/samples - Fiori APIs - v2', () => { + const { GET, expect, axios } = cds.test ('@capire/fiori', '--with-mocks') + axios.defaults.auth = { username: 'alice', password: 'admin' } + it('serves $metadata documents in v2', async () => { const { headers, data } = await GET `/v2/browse/$metadata` expect(headers).to.contain({ diff --git a/test/hello-world.test.js b/test/hello-world.test.js index 5fd85f49..30f3c5d8 100644 --- a/test/hello-world.test.js +++ b/test/hello-world.test.js @@ -1,8 +1,9 @@ const cds = require('@sap/cds/lib') -const { GET, expect } = cds.test (__dirname+'/../hello') describe('cap/samples - Hello world!', () => { + const { GET, expect } = cds.test (__dirname+'/../hello') + it('should say hello with class impl', async () => { const {data} = await GET `/say/hello(to='world')` expect(data.value).to.eql('Hello world!') diff --git a/test/hierarchical-data.test.js b/test/hierarchical-data.test.js index 62f41830..3f12ff57 100644 --- a/test/hierarchical-data.test.js +++ b/test/hierarchical-data.test.js @@ -1,20 +1,18 @@ const cds = require('@sap/cds/lib') -const {expect} = cds.test - -// should become cds.compile(...) when cds5 is released -const model = cds.compile.to.csn (` - entity Categories { - key ID : Integer; - name : String; - children : Composition of many Categories on children.parent = $self; - parent : Association to Categories; - } -`) -const {Categories:Cats} = model.definitions - describe('cap/samples - Hierarchical Data', ()=>{ + const model = CDL` + entity Categories { + key ID : Integer; + name : String; + children : Composition of many Categories on children.parent = $self; + parent : Association to Categories; + } + ` + const {Categories:Cats} = model.definitions + const {expect} = cds.test + before ('bootstrap sqlite in-memory db...', async()=>{ await cds.deploy (model) .to ('sqlite::memory:') expect (cds.db) .to.exist diff --git a/test/localized-data/services.test.js b/test/localized-data/services.test.js index baed3321..4781148e 100644 --- a/test/localized-data/services.test.js +++ b/test/localized-data/services.test.js @@ -1,9 +1,9 @@ -const { GET, expect, cds } = require('@sap/cds/lib').test (__dirname) -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('cap/samples - Localized Data', () => { + const { GET, expect, cds } = require('@sap/cds/lib').test (__dirname) + 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 + it('serves localized $metadata documents', async () => { const { data } = await GET`/browse/$metadata?sap-language=de` expect(data).to.contain('') diff --git a/test/messaging.test.js b/test/messaging.test.js index 2df0afcd..f31f715a 100644 --- a/test/messaging.test.js +++ b/test/messaging.test.js @@ -1,14 +1,14 @@ const cds = require('@sap/cds/lib') const {resolve} = require('path') -const { expect } = cds.test -const _model = '@capire/reviews' -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 - -const Reviews = 'sap.capire.reviews.Reviews' describe('cap/samples - Messaging', ()=>{ + const { expect } = cds.test + const _model = '@capire/reviews' + const Reviews = 'sap.capire.reviews.Reviews' + 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 + beforeAll(() => { cds.root = resolve(__dirname, '..') }) afterAll(() => { cds.root = process.cwd() }) diff --git a/test/odata.test.js b/test/odata.test.js index 741fe413..f5eba97e 100644 --- a/test/odata.test.js +++ b/test/odata.test.js @@ -1,8 +1,8 @@ const cds = require('@sap/cds/lib') -const { GET, expect, axios } = cds.test ('@capire/bookshop') -axios.defaults.auth = { username: 'alice', password: 'admin' } describe('cap/samples - Bookshop APIs', () => { + const { GET, expect, axios } = cds.test ('@capire/bookshop') + axios.defaults.auth = { username: 'alice', password: 'admin' } // Genres const Drama = { diff --git a/test/registry.test.js b/test/registry.test.js index 267821ad..e42a94ca 100644 --- a/test/registry.test.js +++ b/test/registry.test.js @@ -1,12 +1,14 @@ const cds = require('@sap/cds/lib') -const { expect } = cds.test const { fork } = require('child_process') const { resolve } = require('path') const verbose = process.env.CDS_TEST_VERBOSE -// ||true describe('cap/samples - Local NPM registry', () => { + + const { expect } = cds.test + // ||true + let registry let axios const cwd = resolve(__dirname, '..')