Skip to Content
1
May 29, 2020 at 04:27 AM

The option --with-mocks doesn't work anymore once credentials config is provided

411 Views

Original post is here:

https://open.sap.com/courses/cp7/question/7ec44a77-d378-4462-a129-137332f7bc53

Working with SCP Destination Service, and configuring credentials.destination property in package.json file, forces the application to always use the destination configuration even though --with-mocks option is present using the command cds watch.

Is this a bug in the framework? I need to be able to control the behaviour of the service in order to successfully execute unit tests. I know you can manually remove the configuration but this approach defeats the purpose of setting up automated unit tests. Please advise. Thanks!

Terminal:

jhodel: demo > cds watch

[cds] - running nodemon... 
--ext cds,csn,csv,ts,mjs,cjs,js,json,properties,edmx,xml 
--exec cds serve all --with-mocks --in-memory? 

Configuration:

"cds": {
    "requires": {
        "NorthWind": {
            "kind": "odata",
            "model": "srv/external/NorthWind",
            "credentials": {
                "destination": "NorthWind"
            }
        }
    }
}

I tried using the configuration profile from the documentation below:

https://cap.cloud.sap/docs/advanced/config#profiles

But still wit no luck.

Here's the latest configuration after using config profile:

    "cds": {
        "requires": {
            "NorthWind": {
                "kind": "odata",
                "model": "srv/external/NorthWind"
            }
        },
        "[development]": {
            "requires": {
                "NorthWind": {
                    "kind": "odata",
                    "model": "srv/external/NorthWind",
                    "credentials": {
                        "destination": "NorthWind"
                    }
                }
            }
        }
    }

Note that I tried the config profile below for HANA DB case, and it works. The question now is if the external service config supports config profiles?

    "cds": {
        "requires": {
            "db": {
                "kind": "sqlite",
                "credentials": {
                    "database": "bookshop.db"
                }
            }
        },
        "[production]": {
            "requires": {
                "db": {
                    "kind": "hana"
                }
            }
        }
    }