Fix tests to run with mocha (#389)

This commit is contained in:
Daniel Hutzel
2022-08-15 14:11:52 +02:00
committed by GitHub
parent 2a37ef8be1
commit 8ab66b4130
10 changed files with 53 additions and 51 deletions

View File

@@ -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) => {

View File

@@ -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

View File

@@ -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 }}`

View File

@@ -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({

View File

@@ -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!')

View File

@@ -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

View File

@@ -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('<Annotation Term="Common.Label" String="Währung"/>')

View File

@@ -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() })

View File

@@ -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 = {

View File

@@ -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, '..')