ibm-cloud-sdk-core 4.3.2 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/.secrets.baseline +4 -4
  2. package/CHANGELOG.md +32 -0
  3. package/MIGRATION-V5.md +15 -0
  4. package/build/docs/ibm-cloud-sdk-core.md +0 -24
  5. package/docs/ibm-cloud-sdk-core.api.json +0 -378
  6. package/es/index.d.ts +1 -3
  7. package/es/index.js +1 -3
  8. package/etc/ibm-cloud-sdk-core.api.md +0 -30
  9. package/ibm-cloud-sdk-core.d.ts +0 -90
  10. package/index.d.ts +1 -3
  11. package/index.js +2 -16
  12. package/package.json +3 -4
  13. package/sdk-test-utilities/README.md +8 -0
  14. package/{es/lib/sdk-test-helpers.js → sdk-test-utilities/index.js} +41 -21
  15. package/sdk-test-utilities/package-lock.json +516 -0
  16. package/sdk-test-utilities/package.json +17 -0
  17. package/temp/ibm-cloud-sdk-core.api.json +0 -378
  18. package/temp/ibm-cloud-sdk-core.api.md +0 -30
  19. package/build/docs/ibm-cloud-sdk-core.unittestutils.checkforsuccessfulexecution.md +0 -53
  20. package/build/docs/ibm-cloud-sdk-core.unittestutils.checkmediaheaders.md +0 -85
  21. package/build/docs/ibm-cloud-sdk-core.unittestutils.checkurlandmethod.md +0 -85
  22. package/build/docs/ibm-cloud-sdk-core.unittestutils.checkuserheader.md +0 -85
  23. package/build/docs/ibm-cloud-sdk-core.unittestutils.expecttobepromise.md +0 -53
  24. package/build/docs/ibm-cloud-sdk-core.unittestutils.getoptions.md +0 -55
  25. package/build/docs/ibm-cloud-sdk-core.unittestutils.md +0 -86
  26. package/es/lib/sdk-test-helpers.browser.d.ts +0 -21
  27. package/es/lib/sdk-test-helpers.browser.js +0 -23
  28. package/es/lib/sdk-test-helpers.d.ts +0 -72
  29. package/lib/sdk-test-helpers.browser.d.ts +0 -21
  30. package/lib/sdk-test-helpers.browser.js +0 -32
  31. package/lib/sdk-test-helpers.d.ts +0 -72
  32. package/lib/sdk-test-helpers.js +0 -100
@@ -1,85 +0,0 @@
1
- <!-- Do not edit this file. It is automatically generated by API Documenter. -->
2
-
3
- [Home](./index.md) &gt; [ibm-cloud-sdk-core](./ibm-cloud-sdk-core.md) &gt; [unitTestUtils](./ibm-cloud-sdk-core.unittestutils.md) &gt; [checkUserHeader](./ibm-cloud-sdk-core.unittestutils.checkuserheader.md)
4
-
5
- ## unitTestUtils.checkUserHeader() function
6
-
7
- Takes the mock object for the `createRequest` method, extracts the headers that were sent with the call, and checks for the expected value for a user-defined header. This is verify that the SDK accepts header parameters and sends them as headers in the request.
8
-
9
- **Signature:**
10
-
11
- ```typescript
12
- export declare function checkUserHeader(createRequestMock: any, userHeaderName: string, userHeaderValue: string): void;
13
- ```
14
-
15
- ## Parameters
16
-
17
- <table><thead><tr><th>
18
-
19
- Parameter
20
-
21
-
22
- </th><th>
23
-
24
- Type
25
-
26
-
27
- </th><th>
28
-
29
- Description
30
-
31
-
32
- </th></tr></thead>
33
- <tbody><tr><td>
34
-
35
- createRequestMock
36
-
37
-
38
- </td><td>
39
-
40
- any
41
-
42
-
43
- </td><td>
44
-
45
- the jest mock object for the `createRequest` method in the `RequestWrapper` class
46
-
47
-
48
- </td></tr>
49
- <tr><td>
50
-
51
- userHeaderName
52
-
53
-
54
- </td><td>
55
-
56
- string
57
-
58
-
59
- </td><td>
60
-
61
- the name of the header passed by the user, e.g. `Contained-Content-Type`
62
-
63
-
64
- </td></tr>
65
- <tr><td>
66
-
67
- userHeaderValue
68
-
69
-
70
- </td><td>
71
-
72
- string
73
-
74
-
75
- </td><td>
76
-
77
- the expected value for the header passed by the user
78
-
79
-
80
- </td></tr>
81
- </tbody></table>
82
- **Returns:**
83
-
84
- void
85
-
@@ -1,53 +0,0 @@
1
- <!-- Do not edit this file. It is automatically generated by API Documenter. -->
2
-
3
- [Home](./index.md) &gt; [ibm-cloud-sdk-core](./ibm-cloud-sdk-core.md) &gt; [unitTestUtils](./ibm-cloud-sdk-core.unittestutils.md) &gt; [expectToBePromise](./ibm-cloud-sdk-core.unittestutils.expecttobepromise.md)
4
-
5
- ## unitTestUtils.expectToBePromise() function
6
-
7
- This method simply ensures that the SDK methods return Promises by checking for the `then` function - common way to assess whether or not an object is a Promise.
8
-
9
- **Signature:**
10
-
11
- ```typescript
12
- export declare function expectToBePromise(sdkPromise: any): void;
13
- ```
14
-
15
- ## Parameters
16
-
17
- <table><thead><tr><th>
18
-
19
- Parameter
20
-
21
-
22
- </th><th>
23
-
24
- Type
25
-
26
-
27
- </th><th>
28
-
29
- Description
30
-
31
-
32
- </th></tr></thead>
33
- <tbody><tr><td>
34
-
35
- sdkPromise
36
-
37
-
38
- </td><td>
39
-
40
- any
41
-
42
-
43
- </td><td>
44
-
45
- the Promise returned by an SDK method
46
-
47
-
48
- </td></tr>
49
- </tbody></table>
50
- **Returns:**
51
-
52
- void
53
-
@@ -1,55 +0,0 @@
1
- <!-- Do not edit this file. It is automatically generated by API Documenter. -->
2
-
3
- [Home](./index.md) &gt; [ibm-cloud-sdk-core](./ibm-cloud-sdk-core.md) &gt; [unitTestUtils](./ibm-cloud-sdk-core.unittestutils.md) &gt; [getOptions](./ibm-cloud-sdk-core.unittestutils.getoptions.md)
4
-
5
- ## unitTestUtils.getOptions() function
6
-
7
- This method extracts the `options` property from the object passed into `createRequest`<!-- -->. This property is an object containing all of the SDK method-specific information (like `path` and `body`<!-- -->) used to build a request. This method is just a convenience method for the unit tests to be able to make assertions on the items in the request.
8
-
9
- **Signature:**
10
-
11
- ```typescript
12
- export declare function getOptions(createRequestMock: any): any;
13
- ```
14
-
15
- ## Parameters
16
-
17
- <table><thead><tr><th>
18
-
19
- Parameter
20
-
21
-
22
- </th><th>
23
-
24
- Type
25
-
26
-
27
- </th><th>
28
-
29
- Description
30
-
31
-
32
- </th></tr></thead>
33
- <tbody><tr><td>
34
-
35
- createRequestMock
36
-
37
-
38
- </td><td>
39
-
40
- any
41
-
42
-
43
- </td><td>
44
-
45
- the jest mock object for the `createRequest` method in the `RequestWrapper` class
46
-
47
-
48
- </td></tr>
49
- </tbody></table>
50
- **Returns:**
51
-
52
- any
53
-
54
- Object
55
-
@@ -1,86 +0,0 @@
1
- <!-- Do not edit this file. It is automatically generated by API Documenter. -->
2
-
3
- [Home](./index.md) &gt; [ibm-cloud-sdk-core](./ibm-cloud-sdk-core.md) &gt; [unitTestUtils](./ibm-cloud-sdk-core.unittestutils.md)
4
-
5
- ## unitTestUtils namespace
6
-
7
- ## Functions
8
-
9
- <table><thead><tr><th>
10
-
11
- Function
12
-
13
-
14
- </th><th>
15
-
16
- Description
17
-
18
-
19
- </th></tr></thead>
20
- <tbody><tr><td>
21
-
22
- [checkForSuccessfulExecution(createRequestMock)](./ibm-cloud-sdk-core.unittestutils.checkforsuccessfulexecution.md)
23
-
24
-
25
- </td><td>
26
-
27
- This method simply ensures that the method executed without any issues by extracting the argument from the mock object for the `createRequest` method and verifying that it is an object.
28
-
29
-
30
- </td></tr>
31
- <tr><td>
32
-
33
- [checkMediaHeaders(createRequestMock, accept, contentType)](./ibm-cloud-sdk-core.unittestutils.checkmediaheaders.md)
34
-
35
-
36
- </td><td>
37
-
38
- Takes the mock object for the `createRequest` method, extracts the headers that were sent with the call, and checks for the expected values for `Accept` and `Content-Type`<!-- -->. This to verify that the SDK sets the correct values in the code.
39
-
40
-
41
- </td></tr>
42
- <tr><td>
43
-
44
- [checkUrlAndMethod(options, url, method)](./ibm-cloud-sdk-core.unittestutils.checkurlandmethod.md)
45
-
46
-
47
- </td><td>
48
-
49
- Takes the request options constructed by the SDK and checks that the `url` and `method` properties were set to their correct values.
50
-
51
-
52
- </td></tr>
53
- <tr><td>
54
-
55
- [checkUserHeader(createRequestMock, userHeaderName, userHeaderValue)](./ibm-cloud-sdk-core.unittestutils.checkuserheader.md)
56
-
57
-
58
- </td><td>
59
-
60
- Takes the mock object for the `createRequest` method, extracts the headers that were sent with the call, and checks for the expected value for a user-defined header. This is verify that the SDK accepts header parameters and sends them as headers in the request.
61
-
62
-
63
- </td></tr>
64
- <tr><td>
65
-
66
- [expectToBePromise(sdkPromise)](./ibm-cloud-sdk-core.unittestutils.expecttobepromise.md)
67
-
68
-
69
- </td><td>
70
-
71
- This method simply ensures that the SDK methods return Promises by checking for the `then` function - common way to assess whether or not an object is a Promise.
72
-
73
-
74
- </td></tr>
75
- <tr><td>
76
-
77
- [getOptions(createRequestMock)](./ibm-cloud-sdk-core.unittestutils.getoptions.md)
78
-
79
-
80
- </td><td>
81
-
82
- This method extracts the `options` property from the object passed into `createRequest`<!-- -->. This property is an object containing all of the SDK method-specific information (like `path` and `body`<!-- -->) used to build a request. This method is just a convenience method for the unit tests to be able to make assertions on the items in the request.
83
-
84
-
85
- </td></tr>
86
- </tbody></table>
@@ -1,21 +0,0 @@
1
- /**
2
- * Copyright 2021 IBM Corp. All Rights Reserved.
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
- export declare function checkUrlAndMethod(options: any, url: string, method: any): void;
17
- export declare function checkMediaHeaders(createRequestMock: any, accept: string, contentType: string): void;
18
- export declare function checkUserHeader(createRequestMock: any, userHeaderName: string, userHeaderValue: string): void;
19
- export declare function checkForSuccessfulExecution(createRequestMock: any): void;
20
- export declare function getOptions(createRequestMock: any): void;
21
- export declare function expectToBePromise(sdkPromise: any): void;
@@ -1,23 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-unused-vars */
2
- /**
3
- * Copyright 2021 IBM Corp. All Rights Reserved.
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- * http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- */
17
- // Dummy for browser
18
- export function checkUrlAndMethod(options, url, method) { }
19
- export function checkMediaHeaders(createRequestMock, accept, contentType) { }
20
- export function checkUserHeader(createRequestMock, userHeaderName, userHeaderValue) { }
21
- export function checkForSuccessfulExecution(createRequestMock) { }
22
- export function getOptions(createRequestMock) { }
23
- export function expectToBePromise(sdkPromise) { }
@@ -1,72 +0,0 @@
1
- /**
2
- * (C) Copyright IBM Corp. 2019, 2022.
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
- /**
17
- * This module provides a set of helper methods used to reduce code duplication in the generated unit tests
18
- * for the SDKs that depend on this core package. Note that these methods are not used by the tests for this
19
- * package - they are meant to be exported and made available to dependent libraries.
20
- */
21
- /**
22
- * Takes the request options constructed by the SDK and checks that the `url` and `method` properties
23
- * were set to their correct values.
24
- *
25
- * @param options - the options object put together by the SDK, retrieved from the createRequest mock
26
- * @param url - The URL path of the service endpoint, from the paths section of the API definition
27
- * @param method - The HTTP method for the request, from the API definition
28
- */
29
- export declare function checkUrlAndMethod(options: any, url: string, method: any): void;
30
- /**
31
- * Takes the mock object for the `createRequest` method, extracts the headers that were sent with the call,
32
- * and checks for the expected values for `Accept` and `Content-Type`. This to verify that the SDK sets
33
- * the correct values in the code.
34
- *
35
- * @param createRequestMock - the jest mock object for the `createRequest` method in the `RequestWrapper` class
36
- * @param accept - the expected value for the `Accept` header
37
- * @param contentType - the expected value for the `Content-Type` header
38
- */
39
- export declare function checkMediaHeaders(createRequestMock: any, accept: string, contentType: string): void;
40
- /**
41
- * Takes the mock object for the `createRequest` method, extracts the headers that were sent with the call,
42
- * and checks for the expected value for a user-defined header. This is verify that the SDK accepts header
43
- * parameters and sends them as headers in the request.
44
- *
45
- * @param createRequestMock - the jest mock object for the `createRequest` method in the `RequestWrapper` class
46
- * @param userHeaderName - the name of the header passed by the user, e.g. `Contained-Content-Type`
47
- * @param userHeaderValue - the expected value for the header passed by the user
48
- */
49
- export declare function checkUserHeader(createRequestMock: any, userHeaderName: string, userHeaderValue: string): void;
50
- /**
51
- * This method simply ensures that the method executed without any issues by extracting
52
- * the argument from the mock object for the `createRequest` method and verifying that it is an object.
53
- *
54
- * @param createRequestMock - the jest mock object for the `createRequest` method in the `RequestWrapper` class
55
- */
56
- export declare function checkForSuccessfulExecution(createRequestMock: any): void;
57
- /**
58
- * This method extracts the `options` property from the object passed into `createRequest`. This property is
59
- * an object containing all of the SDK method-specific information (like `path` and `body`) used to build a request.
60
- * This method is just a convenience method for the unit tests to be able to make assertions on the items in the request.
61
- *
62
- * @param createRequestMock - the jest mock object for the `createRequest` method in the `RequestWrapper` class
63
- * @returns Object
64
- */
65
- export declare function getOptions(createRequestMock: any): any;
66
- /**
67
- * This method simply ensures that the SDK methods return Promises by checking for
68
- * the `then` function - common way to assess whether or not an object is a Promise.
69
- *
70
- * @param sdkPromise - the Promise returned by an SDK method
71
- */
72
- export declare function expectToBePromise(sdkPromise: any): void;
@@ -1,21 +0,0 @@
1
- /**
2
- * Copyright 2021 IBM Corp. All Rights Reserved.
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
- export declare function checkUrlAndMethod(options: any, url: string, method: any): void;
17
- export declare function checkMediaHeaders(createRequestMock: any, accept: string, contentType: string): void;
18
- export declare function checkUserHeader(createRequestMock: any, userHeaderName: string, userHeaderValue: string): void;
19
- export declare function checkForSuccessfulExecution(createRequestMock: any): void;
20
- export declare function getOptions(createRequestMock: any): void;
21
- export declare function expectToBePromise(sdkPromise: any): void;
@@ -1,32 +0,0 @@
1
- "use strict";
2
- /* eslint-disable @typescript-eslint/no-unused-vars */
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.expectToBePromise = exports.getOptions = exports.checkForSuccessfulExecution = exports.checkUserHeader = exports.checkMediaHeaders = exports.checkUrlAndMethod = void 0;
5
- /**
6
- * Copyright 2021 IBM Corp. All Rights Reserved.
7
- *
8
- * Licensed under the Apache License, Version 2.0 (the "License");
9
- * you may not use this file except in compliance with the License.
10
- * You may obtain a copy of the License at
11
- *
12
- * http://www.apache.org/licenses/LICENSE-2.0
13
- *
14
- * Unless required by applicable law or agreed to in writing, software
15
- * distributed under the License is distributed on an "AS IS" BASIS,
16
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
- * See the License for the specific language governing permissions and
18
- * limitations under the License.
19
- */
20
- // Dummy for browser
21
- function checkUrlAndMethod(options, url, method) { }
22
- exports.checkUrlAndMethod = checkUrlAndMethod;
23
- function checkMediaHeaders(createRequestMock, accept, contentType) { }
24
- exports.checkMediaHeaders = checkMediaHeaders;
25
- function checkUserHeader(createRequestMock, userHeaderName, userHeaderValue) { }
26
- exports.checkUserHeader = checkUserHeader;
27
- function checkForSuccessfulExecution(createRequestMock) { }
28
- exports.checkForSuccessfulExecution = checkForSuccessfulExecution;
29
- function getOptions(createRequestMock) { }
30
- exports.getOptions = getOptions;
31
- function expectToBePromise(sdkPromise) { }
32
- exports.expectToBePromise = expectToBePromise;
@@ -1,72 +0,0 @@
1
- /**
2
- * (C) Copyright IBM Corp. 2019, 2022.
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
- /**
17
- * This module provides a set of helper methods used to reduce code duplication in the generated unit tests
18
- * for the SDKs that depend on this core package. Note that these methods are not used by the tests for this
19
- * package - they are meant to be exported and made available to dependent libraries.
20
- */
21
- /**
22
- * Takes the request options constructed by the SDK and checks that the `url` and `method` properties
23
- * were set to their correct values.
24
- *
25
- * @param options - the options object put together by the SDK, retrieved from the createRequest mock
26
- * @param url - The URL path of the service endpoint, from the paths section of the API definition
27
- * @param method - The HTTP method for the request, from the API definition
28
- */
29
- export declare function checkUrlAndMethod(options: any, url: string, method: any): void;
30
- /**
31
- * Takes the mock object for the `createRequest` method, extracts the headers that were sent with the call,
32
- * and checks for the expected values for `Accept` and `Content-Type`. This to verify that the SDK sets
33
- * the correct values in the code.
34
- *
35
- * @param createRequestMock - the jest mock object for the `createRequest` method in the `RequestWrapper` class
36
- * @param accept - the expected value for the `Accept` header
37
- * @param contentType - the expected value for the `Content-Type` header
38
- */
39
- export declare function checkMediaHeaders(createRequestMock: any, accept: string, contentType: string): void;
40
- /**
41
- * Takes the mock object for the `createRequest` method, extracts the headers that were sent with the call,
42
- * and checks for the expected value for a user-defined header. This is verify that the SDK accepts header
43
- * parameters and sends them as headers in the request.
44
- *
45
- * @param createRequestMock - the jest mock object for the `createRequest` method in the `RequestWrapper` class
46
- * @param userHeaderName - the name of the header passed by the user, e.g. `Contained-Content-Type`
47
- * @param userHeaderValue - the expected value for the header passed by the user
48
- */
49
- export declare function checkUserHeader(createRequestMock: any, userHeaderName: string, userHeaderValue: string): void;
50
- /**
51
- * This method simply ensures that the method executed without any issues by extracting
52
- * the argument from the mock object for the `createRequest` method and verifying that it is an object.
53
- *
54
- * @param createRequestMock - the jest mock object for the `createRequest` method in the `RequestWrapper` class
55
- */
56
- export declare function checkForSuccessfulExecution(createRequestMock: any): void;
57
- /**
58
- * This method extracts the `options` property from the object passed into `createRequest`. This property is
59
- * an object containing all of the SDK method-specific information (like `path` and `body`) used to build a request.
60
- * This method is just a convenience method for the unit tests to be able to make assertions on the items in the request.
61
- *
62
- * @param createRequestMock - the jest mock object for the `createRequest` method in the `RequestWrapper` class
63
- * @returns Object
64
- */
65
- export declare function getOptions(createRequestMock: any): any;
66
- /**
67
- * This method simply ensures that the SDK methods return Promises by checking for
68
- * the `then` function - common way to assess whether or not an object is a Promise.
69
- *
70
- * @param sdkPromise - the Promise returned by an SDK method
71
- */
72
- export declare function expectToBePromise(sdkPromise: any): void;
@@ -1,100 +0,0 @@
1
- "use strict";
2
- /**
3
- * (C) Copyright IBM Corp. 2019, 2022.
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- * http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- */
17
- Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.expectToBePromise = exports.getOptions = exports.checkForSuccessfulExecution = exports.checkUserHeader = exports.checkMediaHeaders = exports.checkUrlAndMethod = void 0;
19
- // eslint-disable-next-line import/no-extraneous-dependencies
20
- var globals_1 = require("@jest/globals");
21
- /**
22
- * This module provides a set of helper methods used to reduce code duplication in the generated unit tests
23
- * for the SDKs that depend on this core package. Note that these methods are not used by the tests for this
24
- * package - they are meant to be exported and made available to dependent libraries.
25
- */
26
- /**
27
- * Takes the request options constructed by the SDK and checks that the `url` and `method` properties
28
- * were set to their correct values.
29
- *
30
- * @param options - the options object put together by the SDK, retrieved from the createRequest mock
31
- * @param url - The URL path of the service endpoint, from the paths section of the API definition
32
- * @param method - The HTTP method for the request, from the API definition
33
- */
34
- function checkUrlAndMethod(options, url, method) {
35
- (0, globals_1.expect)(options.url).toEqual(url);
36
- (0, globals_1.expect)(options.method).toEqual(method);
37
- }
38
- exports.checkUrlAndMethod = checkUrlAndMethod;
39
- /**
40
- * Takes the mock object for the `createRequest` method, extracts the headers that were sent with the call,
41
- * and checks for the expected values for `Accept` and `Content-Type`. This to verify that the SDK sets
42
- * the correct values in the code.
43
- *
44
- * @param createRequestMock - the jest mock object for the `createRequest` method in the `RequestWrapper` class
45
- * @param accept - the expected value for the `Accept` header
46
- * @param contentType - the expected value for the `Content-Type` header
47
- */
48
- function checkMediaHeaders(createRequestMock, accept, contentType) {
49
- var headers = createRequestMock.mock.calls[0][0].defaultOptions.headers;
50
- (0, globals_1.expect)(headers.Accept).toEqual(accept);
51
- (0, globals_1.expect)(headers['Content-Type']).toEqual(contentType);
52
- }
53
- exports.checkMediaHeaders = checkMediaHeaders;
54
- /**
55
- * Takes the mock object for the `createRequest` method, extracts the headers that were sent with the call,
56
- * and checks for the expected value for a user-defined header. This is verify that the SDK accepts header
57
- * parameters and sends them as headers in the request.
58
- *
59
- * @param createRequestMock - the jest mock object for the `createRequest` method in the `RequestWrapper` class
60
- * @param userHeaderName - the name of the header passed by the user, e.g. `Contained-Content-Type`
61
- * @param userHeaderValue - the expected value for the header passed by the user
62
- */
63
- function checkUserHeader(createRequestMock, userHeaderName, userHeaderValue) {
64
- var headers = createRequestMock.mock.calls[0][0].defaultOptions.headers;
65
- (0, globals_1.expect)(headers[userHeaderName]).toEqual(userHeaderValue);
66
- }
67
- exports.checkUserHeader = checkUserHeader;
68
- /**
69
- * This method simply ensures that the method executed without any issues by extracting
70
- * the argument from the mock object for the `createRequest` method and verifying that it is an object.
71
- *
72
- * @param createRequestMock - the jest mock object for the `createRequest` method in the `RequestWrapper` class
73
- */
74
- function checkForSuccessfulExecution(createRequestMock) {
75
- var sdkParams = createRequestMock.mock.calls[0][0];
76
- (0, globals_1.expect)(typeof sdkParams).toEqual('object');
77
- }
78
- exports.checkForSuccessfulExecution = checkForSuccessfulExecution;
79
- /**
80
- * This method extracts the `options` property from the object passed into `createRequest`. This property is
81
- * an object containing all of the SDK method-specific information (like `path` and `body`) used to build a request.
82
- * This method is just a convenience method for the unit tests to be able to make assertions on the items in the request.
83
- *
84
- * @param createRequestMock - the jest mock object for the `createRequest` method in the `RequestWrapper` class
85
- * @returns Object
86
- */
87
- function getOptions(createRequestMock) {
88
- return createRequestMock.mock.calls[0][0].options;
89
- }
90
- exports.getOptions = getOptions;
91
- /**
92
- * This method simply ensures that the SDK methods return Promises by checking for
93
- * the `then` function - common way to assess whether or not an object is a Promise.
94
- *
95
- * @param sdkPromise - the Promise returned by an SDK method
96
- */
97
- function expectToBePromise(sdkPromise) {
98
- (0, globals_1.expect)(typeof sdkPromise.then).toBe('function');
99
- }
100
- exports.expectToBePromise = expectToBePromise;