From d976179f57a171762e1d2ecf0fb828519003d982 Mon Sep 17 00:00:00 2001 From: John Long Date: Thu, 9 Jan 2025 20:06:14 +0000 Subject: [PATCH] fix(btp-utils): return oauth destination --- packages/btp-utils/src/app-studio.ts | 7 ++++++- packages/btp-utils/test/app-studio.test.ts | 21 +++++++++++---------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/packages/btp-utils/src/app-studio.ts b/packages/btp-utils/src/app-studio.ts index c68a1b514e..3a844fcd98 100644 --- a/packages/btp-utils/src/app-studio.ts +++ b/packages/btp-utils/src/app-studio.ts @@ -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 { +export async function createBTPOAuthExchangeDestination( + destination: Destination, + logger?: Logger +): Promise { 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; } /** diff --git a/packages/btp-utils/test/app-studio.test.ts b/packages/btp-utils/test/app-studio.test.ts index e2ab830e57..1a55143326 100644 --- a/packages/btp-utils/test/app-studio.test.ts +++ b/packages/btp-utils/test/app-studio.test.ts @@ -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.", @@ -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 () => {