Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(deps-dev): bump nock from 14.0.0-beta.7 to 14.0.0-beta.15 #5005

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
2 changes: 1 addition & 1 deletion packages/connectivity/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
},
"devDependencies": {
"mock-fs": "^5.3.0",
"nock": "^14.0.0-beta.6",
"nock": "^14.0.0-beta.15",
"typescript": "~5.6.3"
}
}
2 changes: 1 addition & 1 deletion packages/http-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
},
"devDependencies": {
"https-proxy-agent": "^7.0.5",
"nock": "^14.0.0-beta.6",
"nock": "^14.0.0-beta.15",
"typescript": "~5.6.3",
"jsonwebtoken": "^9.0.2"
}
Expand Down
2 changes: 1 addition & 1 deletion packages/odata-v2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"devDependencies": {
"@sap-cloud-sdk/test-services-odata-v2": "^3.22.2",
"@sap-cloud-sdk/resilience": "^3.22.2",
"nock": "^14.0.0-beta.6",
"nock": "^14.0.0-beta.15",
"typescript": "~5.6.3"
}
}
202 changes: 202 additions & 0 deletions packages/odata-v2/src/request-builder/a-debug.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
import {
testFunctionImportGet,
testFunctionImportPost,
testService
} from '@sap-cloud-sdk/test-services-odata-v2/test-service';
import nock from 'nock';
import {
BatchChangeSet,
ODataCreateRequestConfig,
ODataRequest
} from '@sap-cloud-sdk/odata-common';
import { createODataUri as createODataUriV2 } from '@sap-cloud-sdk/odata-v2/internal';
import {
defaultDestination,
defaultHost,
defaultRequestHeaders
} from '../../../../test-resources/test/test-util';
import { CreateRequestBuilder } from './create-request-builder';
import type { DefaultDeSerializers } from '../de-serializers';
const regexUuid = '\\w{8}-\\w{4}-\\w{4}-\\w{4}-\\w{12}';
const responseBoundary = 'responseBoundary';

describe('debug', () => {
const { batch, testEntityApi, operations } = testService();

const getHeader = contentType => `Content-Type: ${contentType}
Content-Length: 3886
content-transfer-encoding: binary

HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
Content-Length: 3679
sap-metadata-last-modified: Wed, 22 Dec 2021 22:29:24 GMT
cache-control: no-store, no-cache
dataserviceversion: 2.0`;

const getAllResponse = `--${responseBoundary}
${getHeader('application/http')}

{"d":{"results":[{"StringProperty":"4711"}]}}
--${responseBoundary}--
`;

const functionImportResponse = `--${responseBoundary}
${getHeader('application/http')}

{"d": {"TestFunctionImportGET":"MyText"}}

--${responseBoundary}--
`;

const postResponse = `--${responseBoundary}
${getHeader('multipart/mixed; boundary=batchId')}

--batchId
--partId
HTTP/1.1 200 OK

{"d": {"TestFunctionImportPOST":true}}
--batchId

--${responseBoundary}--
`;

const baseUrl = 'https://some.sdk.test.url.com';

it('batch works with function imports', async () => {
const body = [
`--batch_${regexUuid}`,
'Content-Type: application/http',
'Content-Transfer-Encoding: binary',
'',
'GET /sap/opu/odata/sap/API_TEST_SRV/TestFunctionImportGET HTTP/1.1',
'Content-Type: application/json',
'Accept: application/json',
'',
'',
`--batch_${regexUuid}--`,
''
].join('\r\n');

nock(baseUrl)
.post('/sap/opu/odata/sap/API_TEST_SRV/$batch', new RegExp(body))
.reply(202, functionImportResponse, {
'content-type': `multipart/mixed; boundary=${responseBoundary}`
});
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');
}
});

it('batch works with POST function imports', async () => {
const body = [
`--batch_${regexUuid}`,
`Content-Type: multipart/mixed; boundary=changeset_${regexUuid}`,
'',
`--changeset_${regexUuid}`,
'Content-Type: application/http',
'Content-Transfer-Encoding: binary',
`Content-Id: ${regexUuid}`,
'',
"POST /sap/opu/odata/sap/API_TEST_SRV/TestFunctionImportPOST\\?SimpleParam='someValue' HTTP/1.1",
'Content-Type: application/json',
'Accept: application/json',
'',
'',
'',
`--changeset_${regexUuid}--`,
`--batch_${regexUuid}--`,
''
].join('\r\n');
nock(baseUrl)
.post('/sap/opu/odata/sap/API_TEST_SRV/$batch', new RegExp(body))
.reply(202, postResponse, {
'content-type': `multipart/mixed; boundary=${responseBoundary}`
});

const requestBuilder = testFunctionImportPost({
simpleParam: 'someValue'
});
const changeSet = new BatchChangeSet<DefaultDeSerializers>([
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);
}
});

it('executes a getAll request', async () => {
nock(baseUrl)
.post('/sap/opu/odata/sap/API_TEST_SRV/$batch')
.reply(202, getAllResponse, {
'content-type': `multipart/mixed; boundary=${responseBoundary}`
});
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');
}
});

it('create', async () => {
const requestConfig = new ODataCreateRequestConfig(
testEntityApi,
createODataUriV2(testEntityApi.deSerializers)
);

const request = new ODataRequest(requestConfig, defaultDestination);

nock(defaultHost).head(`/${request.relativeServiceUrl()}`).reply(200);

nock(defaultHost)
.post(`/${request.relativeServiceUrl()}`, () => true)
// .query({})
// .delay(0)
.reply(500, { d: undefined });

const someEntity = testEntityApi.entityBuilder().stringProperty('').build();

const createRequest = new CreateRequestBuilder(
testEntityApi,
someEntity
).execute(defaultDestination);

await expect(createRequest).rejects.toThrowErrorMatchingInlineSnapshot(
'"Create request failed!"'
);
});
});

function getRequestHeaders(

Check failure on line 186 in packages/odata-v2/src/request-builder/a-debug.spec.ts

View workflow job for this annotation

GitHub Actions / linting

'getRequestHeaders' is defined but never used

Check failure on line 186 in packages/odata-v2/src/request-builder/a-debug.spec.ts

View workflow job for this annotation

GitHub Actions / checks

'getRequestHeaders' is defined but never used
method: string,
additionalHeaders?: Record<string, any>,
headers?: Record<string, any>
) {
if (headers) {
return { reqheaders: headers };
}

if (additionalHeaders) {
const initialHeaders =
method === 'get'
? defaultRequestHeaders
: { ...defaultRequestHeaders, 'x-csrf-token': 'mocked-x-csrf-token' };
return { reqheaders: { ...initialHeaders, ...additionalHeaders } };
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
});

Expand Down Expand Up @@ -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');
}
});

Expand All @@ -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');
}
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,6 @@ describe('CreateRequestBuilder', () => {
it('throws an error when request execution fails', async () => {
mockCreateRequest(
{
body: () => true,
statusCode: 500
},
testEntityApi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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(
Expand All @@ -108,7 +108,7 @@ describe('GetByKeyRequestBuilder', () => {
expected.keyPropertyString
),
responseBody: { d: entityData },
responseHeaders: { Etag: versionIdentifier }
responseHeaders: { etag: versionIdentifier }
},
testEntityApi
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
Expand All @@ -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');
});
});
});
2 changes: 1 addition & 1 deletion packages/odata-v4/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
},
"devDependencies": {
"@sap-cloud-sdk/test-services-odata-v4": "^3.22.2",
"nock": "^14.0.0-beta.6",
"nock": "^14.0.0-beta.15",
"typescript": "~5.6.3"
}
}
Loading
Loading