cancel
Showing results for 
Search instead for 
Did you mean: 

Using hybrid profile with cds.test

sreehari_vpillai
Active Contributor
139

I have a CAPM application and that has an action which uses an external API call via destination. In local , I do 'hybrid" test that resolves the "cds bound" service , including destinations . 
I am now intending to writer a test suite for these services. So , I do this. (Followed this blog

let service = cds.test("serve",'--profile' ,'hybrid','--resolve-bindings' ).verbose();

 But , its not resolving the destination services and throws an error 
Error during request to remote service: Failed to load destination.

Any luck ? dependency versions are 

"@sap/cds-dk": "8.4.0",
"@sap/cds": "8.4.0"
 
Note - I am able to do a cds watch or cds serve from console and get the cloud foundry services resolved. 
Screenshot 2024-11-04 at 11.19.50 AM.png

 @Dinu am I doing any obvious mistakes here ? 

 

Accepted Solutions (0)

Answers (1)

Answers (1)

sreehari_vpillai
Active Contributor
0 Kudos

@catano Thanks for checking this. And equally I am glad that it works with your code base ( sighs with relief ) . Below is my code ( cleaned ) 

const cds = require("@sap/cds");

const chai = require("chai");
const chaiHttp = require("chai-http");
chai.use(chaiHttp);
chai.should();


let service = cds.test("serve",'--profile' ,'hybrid','--resolve-bindings' );
const { GET, POST } = service; 


//using basic authentication ( mock )
const auth = {
    auth: {
        username: 'sreeharip',
        password: 'password'
    }
};

describe("Starting service", async () => {

    it("Metadata retrieval", async () => {
        let metadata = await GET("/dealmgmt-srv/$metadata", auth);
        chai.expect(metadata).status(200);
    }).timeout(60 * 1000);

    it("Destination call", async () => {
        // test is a function , that consumes a destination service - this call works fine in 
        // "cds watch --profile hybrd" or "cds serve --profile hybrid"
        // and "cds serve --profile hybrid --resolve-bindings"
        let testOutcome = await GET("/dealmgmt-srv/test()", auth);
        chai.expect(testOutcome).status(200);
    }).timeout(60 * 1000);


});

in the logs , I dont see the cloud foundry bindings being resolved  - 
( could this be the mocked authentication ) - destination is password credentials type, that doesn't expect the jwt .

sreehari_vpillai
Active Contributor

I put the code in a public repo - I have kept the .cdsrc-private.json

https://github.com/sreehari-pillai-atom/capm-unit-testing-hybrid