diff --git a/package.json b/package.json index 26b5184c..29255da6 100644 --- a/package.json +++ b/package.json @@ -42,6 +42,7 @@ ] }, "mocha": { + "recursive": true, "parallel": true }, "license": "SAP SAMPLE CODE LICENSE", diff --git a/test/cds.ql.test.js b/test/cds.ql.test.js index 2a0535e1..9dec2ae1 100644 --- a/test/cds.ql.test.js +++ b/test/cds.ql.test.js @@ -16,13 +16,13 @@ expect.one = (cqn) => !cqn.SELECT.distinct ? expect(cqn) : skip describe('cds.ql → cqn', () => { // - for (let each of ['SELECT', 'SELECT one', 'SELECT distinct']) { + describe.each(['SELECT', 'SELECT one', 'SELECT distinct'])(`%s...`, (each) => { + let SELECT; beforeEach(()=> SELECT = ( each === 'SELECT distinct' ? cds.ql.SELECT.distinct : each === 'SELECT one' ? cds.ql.SELECT.one : cds.ql.SELECT )) - describe(`${each}...`, () => { test(`from Foo`, () => { expect(cqn = SELECT `from Foo`) @@ -333,7 +333,7 @@ describe('cds.ql → cqn', () => { }) }) - })} + }) describe ('SELECT where...', ()=>{ @@ -630,6 +630,34 @@ describe('cds.ql → cqn', () => { // }) + describe(`SELECT for update`, () => { + beforeAll(() => { + delete cds.env.sql.lock_acquire_timeout + }) + + it('no wait', () => { + const q = SELECT.from('Foo').forUpdate() + expect(q.SELECT.forUpdate).eqls({}) + }) + + it('specific wait', () => { + const q = SELECT.from('Foo').forUpdate({ wait: 1 }) + expect(q.SELECT.forUpdate).eqls({ wait: 1 }) + }) + + it('default wait', () => { + cds.env.sql.lock_acquire_timeout = 2 + const q = SELECT.from('Foo').forUpdate() + expect(q.SELECT.forUpdate).eqls({ wait: 2 }) + }) + + it('override default', () => { + cds.env.sql.lock_acquire_timeout = 1 + const q = SELECT.from('Foo').forUpdate({ wait:-1 }) + expect(q.SELECT.forUpdate).eqls({}) + }) + }) + describe(`INSERT...`, () => { test('entries ({a,b}, ...)', () => { const entries = [{ foo: 1 }, { boo: 2 }] diff --git a/test/consuming-services.test.js b/test/consuming-services.test.js index 936425fe..b4c92169 100644 --- a/test/consuming-services.test.js +++ b/test/consuming-services.test.js @@ -1,15 +1,13 @@ const cds = require('@sap/cds/lib') -const { expect } = cds.test ( - 'serve', 'AdminService', '--from', '@capire/bookshop,@capire/common', '--in-memory' -) +const { expect } = cds.test ('@capire/bookshop') describe('Consuming Services locally', () => { // it('bootstrapped the database successfully', ()=>{ const { AdminService } = cds.services const { Authors } = AdminService.entities - expect(AdminService).not.to.be.undefined - expect(Authors).not.to.be.undefined + expect(AdminService).to.exist + expect(Authors).to.exist }) it('supports targets as strings or reflected defs', async () => { @@ -39,6 +37,7 @@ describe('Consuming Services locally', () => { name: 'Emily Brontë', books: [ { + ID: 201, title: 'Wuthering Heights', currency: { name: 'British Pound', symbol: '£' }, }, @@ -47,8 +46,8 @@ describe('Consuming Services locally', () => { { name: 'Edgar Allen Poe', books: [ - { title: 'The Raven', currency: { name: 'US Dollar', symbol: '$' } }, - { title: 'Eleonora', currency: { name: 'US Dollar', symbol: '$' } }, + { ID: 251, title: 'The Raven', currency: { name: 'US Dollar', symbol: '$' } }, + { ID: 252, title: 'Eleonora', currency: { name: 'US Dollar', symbol: '$' } }, ], }, ]) diff --git a/test/hello-world.test.js b/test/hello-world.test.js index 1b22a602..bd7b24a7 100644 --- a/test/hello-world.test.js +++ b/test/hello-world.test.js @@ -9,8 +9,7 @@ describe('Hello world!', () => { }) it('should say hello with another impl', async () => { - const cds = require ('@sap/cds') - cds.serve('say').from(cds.model) + await cds.serve('say').from(cds.model) .at('/say-again').in(cds.app) .with(srv => { srv.on('hello', (req) => `Hello again ${req.data.to}!`) diff --git a/test/localized-data.cds b/test/localized-data/services.cds similarity index 100% rename from test/localized-data.cds rename to test/localized-data/services.cds diff --git a/test/localized-data.test.js b/test/localized-data/services.test.js similarity index 96% rename from test/localized-data.test.js rename to test/localized-data/services.test.js index 4d399786..7de86e84 100644 --- a/test/localized-data.test.js +++ b/test/localized-data/services.test.js @@ -1,5 +1,4 @@ -const cds = require('@sap/cds/lib') -const { GET, expect } = cds.test.run ('serve', __dirname+'/localized-data.cds', '--in-memory') +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 diff --git a/test/registry.test.js b/test/registry.test.js index beb98f87..c8a02c87 100644 --- a/test/registry.test.js +++ b/test/registry.test.js @@ -1,7 +1,8 @@ +const cds = require('@sap/cds/lib') +const { expect } = cds.test const { fork } = require('child_process') const { resolve } = require('path') -const Axios = require('axios') const verbose = process.env.CDS_TEST_VERBOSE // ||true @@ -10,28 +11,28 @@ describe('Local NPM registry', () => { let axios const cwd = resolve(__dirname, '..') - beforeAll(async ()=> { + before(async ()=> { const env = Object.assign(process.env, {PORT:'0'}) const res = await exec (resolve(cwd, '.registry/server.js'), {cwd, stdio: 'pipe', env}) registry = res.cp - axios = Axios.default.create ({ baseURL: res.url, validateStatus: (status)=>status<500 }) + axios = require('axios').default.create ({ baseURL: res.url, validateStatus: (status)=>status<500 }) }) - afterAll(() => { registry.kill() }) + after(() => { registry.kill() }) for (const mod of ['bookshop','fiori','orders','reviews']) { it(`should serve ${mod}`, async () => { const resp = await axios.get(`/@capire/${mod}`) - expect(resp.data).toMatchObject({name: `@capire/${mod}`, versions:{}}) + expect(resp.data).to.containSubset({name: `@capire/${mod}`, versions:{}}) const versions = Object.values(resp.data.versions) await axios.get(versions[0].dist.tarball) }) } it(`should return 404 for unknown packages`, async () => { let resp = await axios.get(`/@capire/foo`) - expect(resp.status).toEqual(404) + expect(resp.status).to.equal(404) resp = await axios.get(`/foo`) - expect(resp.status).toEqual(404) + expect(resp.status).to.equal(404) }) })