From 1539eaf8f18eae097dc8864973f550b0cb09ad51 Mon Sep 17 00:00:00 2001 From: Marika Marszalkowski Date: Tue, 24 Sep 2024 15:31:24 +0200 Subject: [PATCH] fix tests --- .../destination-accessor-failure-cases.spec.ts | 5 +---- .../src/scp-cf/destination/get-subscriber-token.spec.ts | 6 ++---- .../test/test-util/destination-service-mocks.ts | 9 +++++---- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/packages/connectivity/src/scp-cf/destination/destination-accessor-failure-cases.spec.ts b/packages/connectivity/src/scp-cf/destination/destination-accessor-failure-cases.spec.ts index 97c97e6cd3..6394405a63 100644 --- a/packages/connectivity/src/scp-cf/destination/destination-accessor-failure-cases.spec.ts +++ b/packages/connectivity/src/scp-cf/destination/destination-accessor-failure-cases.spec.ts @@ -22,7 +22,6 @@ import { destinationName, oauthMultipleResponse } from '../../../../../test-resources/test/test-util/example-destination-service-responses'; -import * as jwt from '../jwt'; import { getAllDestinationsFromDestinationService, getDestination @@ -34,9 +33,7 @@ describe('Failure cases', () => { xsuaa: [xsuaaBindingMock] }); - jest - .spyOn(jwt, 'verifyJwt') - .mockResolvedValue(jwt.decodeJwt(subscriberServiceToken)); + mockVerifyJwt(); await expect( getDestination({ diff --git a/packages/connectivity/src/scp-cf/destination/get-subscriber-token.spec.ts b/packages/connectivity/src/scp-cf/destination/get-subscriber-token.spec.ts index 18322481a0..2a5428e610 100644 --- a/packages/connectivity/src/scp-cf/destination/get-subscriber-token.spec.ts +++ b/packages/connectivity/src/scp-cf/destination/get-subscriber-token.spec.ts @@ -1,13 +1,13 @@ import { customSubscriberUserToken, mockServiceBindings, + mockVerifyJwt, onlyIssuerServiceToken, onlyIssuerXsuaaUrl, subscriberServiceToken, subscriberUserToken } from '../../../../../test-resources/test/test-util'; import * as tokenAccessor from '../token-accessor'; -import * as jwtModule from '../jwt'; import { getJwtPair } from '../jwt'; import { getSubscriberToken } from './get-subscriber-token'; @@ -15,9 +15,7 @@ describe('getSubscriberToken()', () => { let verifyJwtSpy; beforeEach(() => { mockServiceBindings(); - verifyJwtSpy = jest - .spyOn(jwtModule, 'verifyJwt') - .mockResolvedValue(undefined as any); + verifyJwtSpy = mockVerifyJwt(); }); afterEach(() => { diff --git a/test-resources/test/test-util/destination-service-mocks.ts b/test-resources/test/test-util/destination-service-mocks.ts index 17b79a2c0c..f1c9363754 100644 --- a/test-resources/test/test-util/destination-service-mocks.ts +++ b/test-resources/test/test-util/destination-service-mocks.ts @@ -1,6 +1,7 @@ import nock from 'nock'; -import * as sdkJwt from '@sap-cloud-sdk/connectivity/src/scp-cf/jwt'; -import { +import * as sdkJwtVerify from '@sap-cloud-sdk/connectivity/src/scp-cf/jwt/verify'; +import * as sdkJwtJwt from '@sap-cloud-sdk/connectivity/src/scp-cf/jwt/jwt'; +import type { DestinationConfiguration, DestinationJson } from '@sap-cloud-sdk/connectivity'; @@ -232,6 +233,6 @@ export function mockFetchDestinationCalls( export function mockVerifyJwt() { return jest - .spyOn(sdkJwt, 'verifyJwt') - .mockImplementation(token => Promise.resolve(sdkJwt.decodeJwt(token))); + .spyOn(sdkJwtVerify, 'verifyJwt') + .mockImplementation(token => Promise.resolve(sdkJwtJwt.decodeJwt(token))); }