diff --git a/packages/odata-v2/src/request-builder/batch-request-builder.spec.ts b/packages/odata-v2/src/request-builder/batch-request-builder.spec.ts index 09f486fd9c..1814753fa1 100644 --- a/packages/odata-v2/src/request-builder/batch-request-builder.spec.ts +++ b/packages/odata-v2/src/request-builder/batch-request-builder.spec.ts @@ -76,13 +76,12 @@ HTTP/1.1 200 OK const response = await batch( operations.testFunctionImportGet({} as any) ).execute({ url: baseUrl }); + expect(response[0].isReadResponse()).toBeTruthy(); if (response[0].isReadResponse()) { const casted = testFunctionImportGet({} as any).responseTransformer( response[0].body ); expect(casted).toEqual('MyText'); - } else { - throw new Error('Should be readResponse'); } }); @@ -119,13 +118,12 @@ HTTP/1.1 200 OK requestBuilder ]); const response = await batch(changeSet).execute({ url: baseUrl }); + expect(response[0].isWriteResponses()).toBeTruthy(); if (response[0].isWriteResponses()) { const casted = testFunctionImportPost({} as any).responseTransformer( response[0].responses[0].body ); expect(casted).toBe(true); - } else { - throw new Error('Should be writeResponse'); } }); @@ -138,11 +136,10 @@ HTTP/1.1 200 OK const response = await batch( testEntityApi.requestBuilder().getAll() ).execute({ url: baseUrl }); + expect(response[0].isReadResponse()).toBeTruthy(); if (response[0].isReadResponse()) { const casted = response[0].as(testEntityApi); expect(casted[0].stringProperty).toEqual('4711'); - } else { - throw new Error('Should be readResponse'); } }); }); diff --git a/packages/odata-v2/src/request-builder/create-request-builder.spec.ts b/packages/odata-v2/src/request-builder/create-request-builder.spec.ts index 24105b786a..0d026b6c7b 100644 --- a/packages/odata-v2/src/request-builder/create-request-builder.spec.ts +++ b/packages/odata-v2/src/request-builder/create-request-builder.spec.ts @@ -260,8 +260,8 @@ describe('CreateRequestBuilder', () => { it('throws an error when request execution fails', async () => { mockCreateRequest( { - body: () => true, - statusCode: 500 + statusCode: 500, + path: 'A_TestEntity' }, testEntityApi ); diff --git a/packages/odata-v2/src/request-builder/delete-request-builder.spec.ts b/packages/odata-v2/src/request-builder/delete-request-builder.spec.ts index 35afe9ea50..562727dd16 100644 --- a/packages/odata-v2/src/request-builder/delete-request-builder.spec.ts +++ b/packages/odata-v2/src/request-builder/delete-request-builder.spec.ts @@ -50,12 +50,11 @@ describe('DeleteRequestBuilder', () => { testEntityApi ); - const deleteRequest = new DeleteRequestBuilder( - testEntityApi, - entity - ).execute(defaultDestination); + const deleteRequest = new DeleteRequestBuilder(testEntityApi, entity); - await expect(deleteRequest).resolves.toBe(undefined); + await expect(deleteRequest.execute(defaultDestination)).resolves.toBe( + undefined + ); }); it('delete request with version identifier on the request should resolve', async () => { diff --git a/packages/odata-v2/src/request-builder/get-all-request-builder.spec.ts b/packages/odata-v2/src/request-builder/get-all-request-builder.spec.ts index 2df1ef04b3..bef77f3f44 100644 --- a/packages/odata-v2/src/request-builder/get-all-request-builder.spec.ts +++ b/packages/odata-v2/src/request-builder/get-all-request-builder.spec.ts @@ -210,16 +210,18 @@ describe('GetAllRequestBuilder', () => { mockGetRequest( { responseBody: { error: 'ERROR' }, - statusCode: 500 + statusCode: 500, + path: 'A_TestEntity' }, testEntityApi ); const getAllRequest = requestBuilder.execute(defaultDestination); - await expect(getAllRequest).rejects.toThrowErrorMatchingInlineSnapshot( - '"get request to http://example.com/sap/opu/odata/sap/API_TEST_SRV failed! "' - ); + await expect(getAllRequest).rejects.toThrowErrorMatchingInlineSnapshot(` +"get request to http://example.com/sap/opu/odata/sap/API_TEST_SRV failed! +"ERROR"" +`); }); it('considers custom timeout on the request', async () => { diff --git a/packages/odata-v2/src/request-builder/get-by-key-request-builder.spec.ts b/packages/odata-v2/src/request-builder/get-by-key-request-builder.spec.ts index caab61615c..f169803fd1 100644 --- a/packages/odata-v2/src/request-builder/get-by-key-request-builder.spec.ts +++ b/packages/odata-v2/src/request-builder/get-by-key-request-builder.spec.ts @@ -70,9 +70,9 @@ describe('GetByKeyRequestBuilder', () => { expect(actual.versionIdentifier).toBeUndefined(); }); - it('ETag should be pulled from __metadata', async () => { + it('eTag should be pulled from __metadata', async () => { const entityData = createOriginalTestEntityData1(); - const versionIdentifier = 'etagInMetadata'; + const versionIdentifier = 'eTagInMetadata'; entityData['__metadata'] = { etag: versionIdentifier }; const expected = createTestEntity(entityData); @@ -95,10 +95,10 @@ describe('GetByKeyRequestBuilder', () => { expect(actual).toEqual(expected); }); - it('ETag should be pulled from response header when __metadata has no ETag property', async () => { + it('eTag should be pulled from response header when __metadata has no eTag property', async () => { const entityData = createOriginalTestEntityData1(); const expected = createTestEntity(entityData); - const versionIdentifier = 'etagInHeader'; + const versionIdentifier = 'eTagInHeader'; expected.setVersionIdentifier(versionIdentifier); mockGetRequest( @@ -108,7 +108,7 @@ describe('GetByKeyRequestBuilder', () => { expected.keyPropertyString ), responseBody: { d: entityData }, - responseHeaders: { Etag: versionIdentifier } + responseHeaders: { etag: versionIdentifier } }, testEntityApi ); @@ -193,7 +193,7 @@ describe('GetByKeyRequestBuilder', () => { }); it('throws a useful error when request execution fails', async () => { - nock(/.*/).get(/.*/).reply(500); + nock(defaultDestination.url).get(/.*/).reply(500); const getByKeyRequest = new GetByKeyRequestBuilder(testEntityApi, { KeyPropertyGuid: uuid(), diff --git a/packages/odata-v2/src/request-builder/operation-request-builder.spec.ts b/packages/odata-v2/src/request-builder/operation-request-builder.spec.ts index 716818f0c4..ca68a4327c 100644 --- a/packages/odata-v2/src/request-builder/operation-request-builder.spec.ts +++ b/packages/odata-v2/src/request-builder/operation-request-builder.spec.ts @@ -58,8 +58,7 @@ describe('OperationRequestBuilder', () => { const requestBuilder = testFunctionImportPost({ simpleParam }); nock(defaultHost) - .get(`${serviceUrl}/TestFunctionImportPOST`) - .query({ SimpleParam: `'${simpleParam}'` }) + .head(`${serviceUrl}/TestFunctionImportPOST/`) .reply(200, undefined, mockedBuildHeaderResponse); nock(defaultHost) @@ -168,9 +167,9 @@ describe('OperationRequestBuilder', () => { expect(returnValue).toEqual(expected); }); - it('returns undefined or throw in failure case', async () => { + it('returns undefined', async () => { nock(defaultHost) - .get(`${serviceUrl}/TestFunctionImportNoReturnType`) + .head(`${serviceUrl}/TestFunctionImportNoReturnType/`) .reply(200, undefined, mockedBuildHeaderResponse); nock(defaultHost) @@ -181,6 +180,12 @@ describe('OperationRequestBuilder', () => { defaultDestination ); expect(response).toBe(undefined); + }); + + it('throws in failure case', async () => { + nock(defaultHost) + .head(`${serviceUrl}/TestFunctionImportNoReturnType/`) + .reply(200, undefined, mockedBuildHeaderResponse); nock(defaultHost) .post(`${serviceUrl}/TestFunctionImportNoReturnType`) @@ -213,15 +218,14 @@ describe('OperationRequestBuilder', () => { it('throws an error when shared entity type is used as return type', async () => { nock(defaultHost) - .get(`${serviceUrl}/TestFunctionImportSharedEntityReturnType()`) - .query({}) + .get(`${serviceUrl}/TestFunctionImportSharedEntityReturnType`) .reply(200, {}); const requestBuilder = testFunctionImportSharedEntityReturnType({}) as any; await expect( requestBuilder.execute(defaultDestination) ).rejects.toThrowErrorMatchingInlineSnapshot( - '"get request to http://example.com/sap/opu/odata/sap/API_TEST_SRV failed! "' + "\"Failed to build an entity from the response of the function import or action import: TestFunctionImportSharedEntityReturnType, because the entity type of the return type is shared by multiple entity sets. Please use 'executeRaw' instead of 'execute' to get the raw response. Original response body: {}.\"" ); }); }); diff --git a/packages/odata-v2/src/request-builder/update-request-builder.spec.ts b/packages/odata-v2/src/request-builder/update-request-builder.spec.ts index a1ad50d6bd..c7cc9ce6f6 100644 --- a/packages/odata-v2/src/request-builder/update-request-builder.spec.ts +++ b/packages/odata-v2/src/request-builder/update-request-builder.spec.ts @@ -476,21 +476,19 @@ describe('UpdateRequestBuilder', () => { it('returns request and raw response when sending non-key properties', async () => { const entity = createTestEntity(); entity.booleanProperty = false; - const requestBody = { + const body = { Int32Property: entity.int32Property, BooleanProperty: false, StringProperty: null }; - const response = { d: requestBody }; mockUpdateRequest( { - body: requestBody, + body, path: testEntityResourcePath( entity.keyPropertyGuid, entity.keyPropertyString - ), - responseBody: response + ) }, testEntityApi ); @@ -499,8 +497,8 @@ describe('UpdateRequestBuilder', () => { testEntityApi, entity ).executeRaw(defaultDestination); - expect(actual!.data).toEqual(response); - expect(actual!.request.method).toEqual('PATCH'); + expect(actual?.status).toEqual(204); + expect(actual?.request.method).toEqual('PATCH'); }); }); }); diff --git a/packages/odata-v4/src/request-builder/get-by-key-request-builder.spec.ts b/packages/odata-v4/src/request-builder/get-by-key-request-builder.spec.ts index 925c72323d..8c98b6973f 100644 --- a/packages/odata-v4/src/request-builder/get-by-key-request-builder.spec.ts +++ b/packages/odata-v4/src/request-builder/get-by-key-request-builder.spec.ts @@ -95,9 +95,9 @@ describe('GetByKeyRequestBuilder', () => { expect(actual[0].somethingTheSdkDoesNotSupport).toBe('SomeValue'); }); - it('ETag should be pulled from @odata.etag', async () => { + it('eTag should be pulled from @odata.etag', async () => { const entityData = createOriginalTestEntityDataV4_1(); - const versionIdentifier = 'etagInMetadata'; + const versionIdentifier = 'eTagInMetadata'; entityData['@odata.etag'] = versionIdentifier; const expected = createTestEntity(entityData); const response = { @@ -129,10 +129,10 @@ describe('GetByKeyRequestBuilder', () => { expect(actual).toEqual(expected); }); - it('ETag should be pulled from response header when json payload has no @odata.etag property', async () => { + it('eTag should be pulled from response header when json payload has no @odata.etag property', async () => { const entityData = createOriginalTestEntityDataV4_1(); const expected = createTestEntity(entityData); - const versionIdentifier = 'etagInHeader'; + const versionIdentifier = 'eTagInHeader'; expected.setVersionIdentifier(versionIdentifier); const response = { KeyPropertyGuid: entityData.KeyPropertyGuid, @@ -150,7 +150,7 @@ describe('GetByKeyRequestBuilder', () => { expected.keyDateProperty ), responseBody: response, - responseHeaders: { Etag: versionIdentifier } + responseHeaders: { etag: versionIdentifier } }, testEntityApi ); diff --git a/packages/odata-v4/src/request-builder/operation-request-builder.spec.ts b/packages/odata-v4/src/request-builder/operation-request-builder.spec.ts index 564b5fd55b..f544caf4b5 100644 --- a/packages/odata-v4/src/request-builder/operation-request-builder.spec.ts +++ b/packages/odata-v4/src/request-builder/operation-request-builder.spec.ts @@ -107,12 +107,12 @@ describe('operation request builder', () => { nock(host) .post(`${basePath}/TestActionImportNoParameterNoReturnType`) - .reply(204, {}); + .reply(204); const actual = await testActionImportNoParameterNoReturnType( {} ).executeRaw(destination); - expect(actual.data).toEqual({}); + expect(actual.status).toEqual(204); expect(actual.request.method).toBe('POST'); }); }); diff --git a/packages/openapi/src/openapi-request-builder.spec.ts b/packages/openapi/src/openapi-request-builder.spec.ts index 36011b0c3d..3c56841f4c 100644 --- a/packages/openapi/src/openapi-request-builder.spec.ts +++ b/packages/openapi/src/openapi-request-builder.spec.ts @@ -210,11 +210,7 @@ describe('openapi-request-builder', () => { .get(/.*/) .reply(200, 'iss token used on the way') ]; - const requestBuilder = new OpenApiRequestBuilder('get', '/test', { - body: { - limit: 100 - } - }); + const requestBuilder = new OpenApiRequestBuilder('get', '/test'); const response = await requestBuilder.executeRaw({ destinationName: 'ERNIE-UND-CERT', iss: onlyIssuerXsuaaUrl @@ -227,10 +223,7 @@ describe('openapi-request-builder', () => { middleware: [], url: '/test', headers: { requestConfig: {} }, - params: { requestConfig: {} }, - data: { - limit: 100 - } + params: { requestConfig: {} } }, { fetchCsrfToken: false } ); diff --git a/test-packages/integration-tests/test/odata-negative-case.spec.ts b/test-packages/integration-tests/test/odata-negative-case.spec.ts index 61af2c3f6b..17bec1edfc 100644 --- a/test-packages/integration-tests/test/odata-negative-case.spec.ts +++ b/test-packages/integration-tests/test/odata-negative-case.spec.ts @@ -18,13 +18,13 @@ describe('odata negative tests', () => { await promises.mkdir(testOutputRootDir); } if (existsSync(testDir)) { - await promises.rmdir(testDir, { recursive: true }); + await promises.rm(testDir, { recursive: true }); } await promises.mkdir(testDir); }); afterAll(async () => { - await promises.rmdir(testDir, { recursive: true }); + await promises.rm(testDir, { recursive: true }); }); it('should fail on faulty edmx', async () => { diff --git a/test-packages/integration-tests/test/openapi-negative-case.spec.ts b/test-packages/integration-tests/test/openapi-negative-case.spec.ts index c355bcb9ef..17c2867a49 100644 --- a/test-packages/integration-tests/test/openapi-negative-case.spec.ts +++ b/test-packages/integration-tests/test/openapi-negative-case.spec.ts @@ -18,13 +18,13 @@ describe('openapi negative tests', () => { await promises.mkdir(testOutputRootDir); } if (existsSync(testDir)) { - await promises.rmdir(testDir, { recursive: true }); + await promises.rm(testDir, { recursive: true }); } await promises.mkdir(testDir); }); afterAll(async () => { - await promises.rmdir(testDir, { recursive: true }); + await promises.rm(testDir, { recursive: true }); }); it('should fail on generation for faulty spec file', async () => { diff --git a/test-packages/integration-tests/test/v2/batch.spec.ts b/test-packages/integration-tests/test/v2/batch.spec.ts index 4f15e1b277..32cf6ae7b8 100644 --- a/test-packages/integration-tests/test/v2/batch.spec.ts +++ b/test-packages/integration-tests/test/v2/batch.spec.ts @@ -50,7 +50,7 @@ function mockCsrfTokenRequest(host: string, sapClient: string) { 'sap-client': sapClient } }) - .head(`${basePath}/$batch`) + .head(`${basePath}/$batch/`) .reply(200, '', { 'x-csrf-token': csrfToken, 'Set-Cookie': ['key1=val1', 'key2=val2', 'key3=val3'] diff --git a/test-packages/integration-tests/test/v2/change-detection-deep-update.spec.ts b/test-packages/integration-tests/test/v2/change-detection-deep-update.spec.ts index 8c7752fa06..5e1a2046d0 100644 --- a/test-packages/integration-tests/test/v2/change-detection-deep-update.spec.ts +++ b/test-packages/integration-tests/test/v2/change-detection-deep-update.spec.ts @@ -21,8 +21,8 @@ function mockCsrfTokenRequest( }) .head( path - ? `${TestEntity._defaultBasePath}/${path}` - : TestEntity._defaultBasePath + ? `${TestEntity._defaultBasePath}/${path}/` + : `${TestEntity._defaultBasePath}/` ) .reply(200, '', { 'x-csrf-token': csrfToken, diff --git a/test-packages/integration-tests/test/v2/custom-fields.spec.ts b/test-packages/integration-tests/test/v2/custom-fields.spec.ts index 4c5afc268b..5a659a2ee7 100644 --- a/test-packages/integration-tests/test/v2/custom-fields.spec.ts +++ b/test-packages/integration-tests/test/v2/custom-fields.spec.ts @@ -19,7 +19,7 @@ function mockCsrfTokenRequest(host: string, sapClient: string, path?: string) { 'sap-client': sapClient } }) - .head(path ? `${basePath}/${path}` : basePath) + .head(path ? `${basePath}/${path}/` : `${basePath}/`) .reply(200, '', { 'x-csrf-token': csrfToken, 'Set-Cookie': ['key1=val1', 'key2=val2', 'key3=val3'] diff --git a/test-packages/integration-tests/test/v2/function-imports.spec.ts b/test-packages/integration-tests/test/v2/function-imports.spec.ts index 16f1714170..87d1e7f228 100644 --- a/test-packages/integration-tests/test/v2/function-imports.spec.ts +++ b/test-packages/integration-tests/test/v2/function-imports.spec.ts @@ -16,7 +16,7 @@ function mockCsrfTokenRequest(url: string) { 'x-csrf-token': 'Fetch' } }) - .get(basePath) + .head(`${basePath}/`) .reply(200, '', { 'x-csrf-token': csrfToken, 'Set-Cookie': ['key1=val1', 'key2=val2', 'key3=val3'] diff --git a/test-packages/integration-tests/test/v2/request-builder.spec.ts b/test-packages/integration-tests/test/v2/request-builder.spec.ts index 44d7e2ecb9..3b8a587bfe 100644 --- a/test-packages/integration-tests/test/v2/request-builder.spec.ts +++ b/test-packages/integration-tests/test/v2/request-builder.spec.ts @@ -43,7 +43,7 @@ function mockCsrfTokenRequest(path?: string) { 'x-csrf-token': 'Fetch' } }) - .head(path ? `${basePath}/${path}` : basePath) + .head(path ? `${basePath}/${path}/` : `${basePath}/`) .reply(200, '', mockedBuildHeaderResponse); } @@ -440,15 +440,27 @@ describe('Request Builder', () => { it('sending OData request should not break when x-csrf-token or cookies are not defined in csrf fetch response', async () => { const response = singleTestEntityResponse(); + destination = { ...destination, url: 'https://example.com' }; + nock(destination.url, { reqheaders: { authorization: basicHeader(destination.username, destination.password), 'x-csrf-token': 'Fetch', - 'sap-client': destination.sapClient as string + 'sap-client': destination.sapClient } }) - .get(`${basePath}/${entityName}`) - .reply(200, undefined, undefined); + .head(`${basePath}/${entityName}/`) + .reply(200); + + nock(destination.url, { + reqheaders: { + authorization: basicHeader(destination.username, destination.password), + 'x-csrf-token': 'Fetch', + 'sap-client': destination.sapClient + } + }) + .head(`${basePath}/${entityName}`) + .reply(200); nock(destination.url, { reqheaders: { @@ -473,10 +485,14 @@ describe('Request Builder', () => { .int16Property(145) .booleanProperty(true) .build() - ) - .execute(destination); - - await expect(request).resolves.not.toThrow(); + ); + + // try { + // await request.execute(destination); + // } catch (err) { + // console.log(err); + // } + await expect(request.execute(destination)).resolves.not.toThrow(); }); it('should allow setting custom headers', async () => { diff --git a/test-packages/integration-tests/test/v4/request-builder.spec.ts b/test-packages/integration-tests/test/v4/request-builder.spec.ts index b6ec295a2b..45d0723651 100644 --- a/test-packages/integration-tests/test/v4/request-builder.spec.ts +++ b/test-packages/integration-tests/test/v4/request-builder.spec.ts @@ -29,7 +29,7 @@ function mockCsrfTokenRequest(path?: string) { 'x-csrf-token': 'Fetch' } }) - .head(path ? `${basePath}/${path}` : basePath) + .head(path ? `${basePath}/${path}/` : `${basePath}/`) .reply(200, '', mockedBuildHeaderResponse); } @@ -71,7 +71,7 @@ describe('Request Builder', () => { await expect(request).resolves.not.toThrow(); }); - it('should resolve for getByKey request', async () => { + it('should resolve for create request', async () => { const response = singleTestEntityResponse(); mockCsrfTokenRequest(entityName); @@ -100,10 +100,9 @@ describe('Request Builder', () => { .int16Property(16) .booleanProperty(false) .build() - ) - .execute(destination); + ); - await expect(request).resolves.not.toThrow(); + await expect(request.execute(destination)).resolves.not.toThrow(); }); it('should resolve for update request', async () => { diff --git a/test-resources/jest.common.config.js b/test-resources/jest.common.config.js index 809cd1c7c7..85629c4468 100644 --- a/test-resources/jest.common.config.js +++ b/test-resources/jest.common.config.js @@ -9,5 +9,6 @@ module.exports = { setupFiles: ['/../../test-resources/bootstrap-test.js'], coverageReporters: ['text', 'cobertura', 'html'], coveragePathIgnorePatterns: ['dist/', 'node_modules/', 'test/', '.*.spec.ts'], - reporters: ['default', 'jest-junit'] + reporters: ['default', 'jest-junit'], + prettierPath: null }; diff --git a/test-resources/test/test-util/request-mocker.ts b/test-resources/test/test-util/request-mocker.ts index e3383b124b..92159bcf5d 100644 --- a/test-resources/test/test-util/request-mocker.ts +++ b/test-resources/test/test-util/request-mocker.ts @@ -1,8 +1,5 @@ import nock from 'nock'; import { - EntityApi, - EntityBase, - GetAllRequestBuilderBase, ODataCreateRequestConfig, ODataDeleteRequestConfig, ODataGetAllRequestConfig, @@ -11,11 +8,16 @@ import { } from '@sap-cloud-sdk/odata-common/internal'; import { createODataUri as createODataUriV2 } from '@sap-cloud-sdk/odata-v2/internal'; import { createODataUri as createODataUriV4 } from '@sap-cloud-sdk/odata-v4/internal'; -import { +import { basicHeader } from '@sap-cloud-sdk/connectivity/internal'; +import type { HttpDestination, - Destination, - basicHeader + Destination } from '@sap-cloud-sdk/connectivity/internal'; +import type { + EntityApi, + EntityBase, + GetAllRequestBuilderBase +} from '@sap-cloud-sdk/odata-common/internal'; const defaultCsrfToken = 'mocked-x-csrf-token'; @@ -66,7 +68,16 @@ interface MockRequestParams { responseBody?: Record; responseHeaders?: Record; query?: Record; - method?: string; + method?: + | 'get' + | 'post' + | 'put' + | 'head' + | 'patch' + | 'merge' + | 'delete' + | 'options'; + headers?: Record; delay?: number; } @@ -82,7 +93,7 @@ export function mockCreateRequest>( return mockRequest(requestConfig, { ...params, statusCode: params.statusCode || 200, - method: params.method || 'post', + method: params.method || ('post' as const), responseBody: { d: params.responseBody || params.body } }); } diff --git a/test-resources/test/test-util/xsuaa-service-mocks.ts b/test-resources/test/test-util/xsuaa-service-mocks.ts index 7c6d5a118c..8066ce4141 100644 --- a/test-resources/test/test-util/xsuaa-service-mocks.ts +++ b/test-resources/test/test-util/xsuaa-service-mocks.ts @@ -1,3 +1,4 @@ +import https from 'node:https'; import nock from 'nock'; import { basicHeader } from '@sap-cloud-sdk/connectivity/internal'; import type { ServiceCredentials } from '@sap-cloud-sdk/connectivity'; @@ -30,6 +31,7 @@ export function mockClientCredentialsGrantWithCertCall( serviceCredentials: ServiceCredentials, zoneId?: string ) { + jest.spyOn(https, 'request'); return nock(uri, { reqheaders: xsuaaRequestHeaders(zoneId ? { zid: zoneId } : {}) }) @@ -38,9 +40,18 @@ export function mockClientCredentialsGrantWithCertCall( client_id: serviceCredentials.clientid }) .reply(responseCode, function () { - const agentOptions = (this.req as any).options.agent.options; - expect(agentOptions.cert).toEqual(serviceCredentials.certificate); - expect(agentOptions.key).toEqual(serviceCredentials.key); + expect(https.request).toHaveBeenCalledWith( + expect.anything(), + expect.objectContaining({ + agent: expect.objectContaining({ + options: expect.objectContaining({ + key: serviceCredentials.key, + cert: serviceCredentials.certificate + }) + }) + }), + expect.anything() + ); return response; }); }