Giter Club home page Giter Club logo

Comments (3)

vobu avatar vobu commented on June 3, 2024

hi, thanks for the detailed issue report!
and given that CAP encourages domain-driven modelling (just like what you did with

notifications: array of { 
  description: String; 
  frequency: Integer enum { 
    daily = 1; 
    weekly = 2; 
    monthly = 3; 
  }
}

instead of putting this in a relation e.g. via association of),
i think it's not just a rare case, but a pending issue we need to address.

could you bake a test case into code?

i would see the cds-runtime/-ql related test in https://github.com/sapmentors/cds-pg/blob/main/__tests__/lib/pg/ql.test.js
where you could load a dedicated model à la (watch out, pidgeon code)

  test('load array model prop', async () => {
       await deploy(yourModel, {}).to(this._dbProperties)
      
     const { Setting } = cds.entities('your.name.space')

      const setting = await cds.run(INSERT.into(...).entries([{ 
        "id": 2,
        "tempThreshold": "10.1",
         "notifications": [{
             "description": "New settings",
             "frequency": 1,
              "message": "String"
          }] 
      }]

      expect(setting.affectedRows).toStrictEqual(1)

      const singleSetting = await cds.run(SELECT.one(Setting).where({ id: '2 }))
      expect(singleSetting).toHaveProperty('notifications', ...)
    })

and the related OData-related test (POST with payload) in https://github.com/sapmentors/cds-pg/blob/main/__tests__/lib/pg/service.test.js

this would make it way easier to both locate the origin of the bug and be closer to the domain-modelling idea of CAP also with PostgreSQL!

from cds-pg.

Regloom avatar Regloom commented on June 3, 2024

Ok looks like I've managed the first part.

test('load array model prop', async () => {
      await deploy('./arraymodel.cds', {}).to(this._dbProperties)
      const { Settings } = cds.entities('arraymodel')
 
      const setting = await cds.run(INSERT.into(Settings).entries([{ 
         "id": 2,
         "tempThreshold": "10.1",
         "notifications": [{
              "description": "New settings",
              "frequency": 1,
               "message": "String"
         }] 
       }]))
 
       expect(setting.affectedRows).toStrictEqual(1)
 
       const singleSetting = await cds.run(SELECT.one(Settings).where({ id: 2 }))
       expect(singleSetting).toHaveProperty('notifications', '[{"description": "New settings","frequency": 1,"message": "String"}]')
     })

here is a content of arraymodel.cds file:

namespace arraymodel;

service settingsService {
    entity Settings {
        key id: Integer;
        tempThreshold: Decimal(3,1) not null;
        Notifications: Array of {
            description: String;
            frequency: Integer enum {
                daily = 1;
                weekly = 2;
                monthly = 3;
            };
            message: String;
        }
    }
}

I'm new to the JS testing frameworks, so I might misunderstand the process (

from cds-pg.

vobu avatar vobu commented on June 3, 2024

cool, things start coming together!
the test looks fine!
hint 1: use test.only to ... well ... only run that one test when you issue npm run test -- <testfilename>
hint 2: please find much more detail about the test- and dev-env setup in https://github.com/sapmentors/cds-pg/blob/main/docs/CONTRIBUTING.md#runnable-queries-and-runtime-debug-capabilites

looking fwd to the odata-level test, then we have something to work in the array of feature in postgres!

from cds-pg.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.