Skip to content

Commit

Permalink
fix(btp-utils): return oauth destination
Browse files Browse the repository at this point in the history
  • Loading branch information
longieirl committed Jan 9, 2025
1 parent 9c8bd0b commit d976179
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
7 changes: 6 additions & 1 deletion packages/btp-utils/src/app-studio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,13 +238,18 @@ async function generateOAuthTokenExchangeDestination(
*
* @param destination destination info
* @param logger Logger
* @returns Newly generated OAuth destination
*/
export async function createBTPOAuthExchangeDestination(destination: Destination, logger?: Logger): Promise<void> {
export async function createBTPOAuthExchangeDestination(
destination: Destination,
logger?: Logger
): Promise<OAuth2Destination> {
if (!isAppStudio()) {
throw new Error(`Creating SAP BTP destinations is only supported on SAP Business Application Studio.`);
}
const btpDestination = await generateOAuthTokenExchangeDestination(destination, logger);
await createBTPDestination(btpDestination);
return btpDestination;
}

/**
Expand Down
21 changes: 11 additions & 10 deletions packages/btp-utils/test/app-studio.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,15 +238,7 @@ describe('App Studio', () => {

test('generate new SAP BTP destination', async () => {
process.env[ENV.H2O_URL] = server;
let bodyParam;
nock(server)
.post('/api/createDestination', (body) => {
bodyParam = body;
return true;
})
.reply(200);
await expect(createBTPOAuthExchangeDestination(destination)).resolves.toBeUndefined();
expect(bodyParam).toMatchInlineSnapshot(`
const result = `
Object {
"Authentication": "OAuth2UserTokenExchange",
"Description": "Destination generated by App Studio for 'my-abap-env', Do not remove.",
Expand All @@ -263,7 +255,16 @@ describe('App Studio', () => {
"tokenServiceURL": "http://my-server/oauth/token",
"tokenServiceURLType": "Dedicated",
}
`);
`;
let bodyParam;
nock(server)
.post('/api/createDestination', (body) => {
bodyParam = body;
return true;
})
.reply(200);
await expect(createBTPOAuthExchangeDestination(destination)).resolves.toMatchInlineSnapshot(result);
expect(bodyParam).toMatchInlineSnapshot(result);
});

test('throw exception if no UAA credentials found', async () => {
Expand Down

0 comments on commit d976179

Please sign in to comment.