Fix tests to use productive cds model

Also remove strange whitespace
This commit is contained in:
Christian Georgi
2020-02-07 12:06:08 +00:00
parent c3c778b2be
commit b65be0cb41
2 changed files with 51 additions and 66 deletions

View File

@@ -5,10 +5,9 @@ describe('Bookshop: OData Protocol Level Testing', () => {
const app = require('express')() const app = require('express')()
const request = require('supertest')(app) const request = require('supertest')(app)
it ('should serve BooksShop', async ()=>{ it('should serve BooksShop', async () => {
await cds.deploy (__dirname+'/cat-service') .to ('sqlite::memory:') await cds.deploy(__dirname + '/../srv/cat-service').to('sqlite::memory:')
await cds.serve('CatalogService').from(__dirname+'/cat-service') .in (app) await cds.serve('CatalogService').from(__dirname + '/../srv/cat-service').in(app)
//await cds.serve('CatalogService').from(__dirname+'/../srv') .in (app)
}) })
it('Service $metadata document', async () => { it('Service $metadata document', async () => {
@@ -38,82 +37,81 @@ describe('Bookshop: OData Protocol Level Testing', () => {
title: "Sturmhöhe", title: "Sturmhöhe",
author: "Emily Brontë", author: "Emily Brontë",
currency: { currency: {
name: "Pfund", name: "Pfund",
descr: "Britische Pfund", descr: "Britische Pfund",
code: "GBP", code: "GBP",
symbol: "£" symbol: "£"
} }
}, },
{ {
ID: 207, ID: 207,
title: "Jane Eyre", title: "Jane Eyre",
author: "Charlotte Brontë", author: "Charlotte Brontë",
currency: { currency: {
name: "Pfund", name: "Pfund",
descr: "Britische Pfund", descr: "Britische Pfund",
code: "GBP", code: "GBP",
symbol: "£" symbol: "£"
} }
}, },
{ {
ID: 251, ID: 251,
title: "The Raven", title: "The Raven",
author: "Edgar Allen Poe", author: "Edgar Allen Poe",
currency: { currency: {
name: "US-Dollar", name: "US-Dollar",
descr: "United States Dollar", descr: "United States Dollar",
code: "USD", code: "USD",
symbol: "$" symbol: "$"
} }
}, },
{ {
ID: 252, ID: 252,
title: "Eleonora", title: "Eleonora",
author: "Edgar Allen Poe", author: "Edgar Allen Poe",
currency: { currency: {
name: "US-Dollar", name: "US-Dollar",
descr: "United States Dollar", descr: "United States Dollar",
code: "USD", code: "USD",
symbol: "$" symbol: "$"
} }
}, },
{ {
ID: 271, ID: 271,
title: "Catweazle", title: "Catweazle",
author: "Richard Carpenter", author: "Richard Carpenter",
currency: { currency: {
name: "Euro", name: "Euro",
descr: "European Euro", descr: "European Euro",
code: "EUR", code: "EUR",
symbol: "€" symbol: "€"
}
} }
}
]) ])
}) })
}) })
describe('Bookshop: CDS Service Level Testing', () => { describe('Bookshop: CDS Service Level Testing', () => {
let srv, Books let srv, Books
    test('Should serve bookshop', async () => { test('Should serve bookshop', async () => {
      srv = await cds.serve('CatalogService') srv = await cds.serve('CatalogService').from(__dirname + '/../srv/cat-service')
.from(__dirname+'/cat-service')
Books = srv.entities.Books Books = srv.entities.Books
      expect(Books).toBeDefined() expect(Books).toBeDefined()
    }) })
    test('GET all books', async () => { test('GET all books', async () => {
      const books = await srv.read ( const books = await srv.read(
//Books, b=>{ b.ID, b.title } //Books, b=>{ b.ID, b.title }
Books, b=>{ b.title } Books, b => { b.title }
) )
expect (books) .toMatchObject([ expect(books).toMatchObject([
{ title: 'Wuthering Heights' }, { title: 'Wuthering Heights' },
{ title: 'Jane Eyre' }, { title: 'Jane Eyre' },
{ title: 'The Raven' }, { title: 'The Raven' },
{ title: 'Eleonora' }, { title: 'Eleonora' },
{ title: 'Catweazle' } { title: 'Catweazle' }
]) ])
    }) })
}) })

View File

@@ -1,13 +0,0 @@
using { sap.capire.bookshop as my } from '../db/schema';
@path:'/browse'
service CatalogService {
@readonly entity Books as SELECT from my.Books {*,
author.name as author
} excluding { createdBy, modifiedBy };
@requires_: 'authenticated-user'
@insertonly entity Orders as projection on my.Orders;
}