basyx-typescript-sdk 0.1.0 → 0.1.2
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.
- package/README.md +7 -0
- package/dist/clients/AasRepositoryClient.d.ts +3 -3
- package/dist/clients/AasRepositoryClient.js +6 -6
- package/dist/generated/sdk.gen.d.ts +822 -0
- package/dist/generated/sdk.gen.js +1705 -0
- package/dist/generated/types.gen.d.ts +10829 -0
- package/dist/lib/convertAasTypes.d.ts +2 -2
- package/dist/lib/convertAasTypes.js +13 -3
- package/dist/lib/createAasRepoClient.d.ts +1 -1
- package/dist/models/aas-repository.d.ts +1 -1
- package/package.json +3 -4
- package/dist/generated/aas-repository/sdk.gen.d.ts +0 -210
- package/dist/generated/aas-repository/sdk.gen.js +0 -430
- package/dist/generated/aas-repository/types.gen.d.ts +0 -3380
- package/src/clients/AasRepositoryClient.ts +0 -501
- package/src/clients/index.ts +0 -1
- package/src/generated/aas-repository/index.ts +0 -3
- package/src/generated/aas-repository/sdk.gen.ts +0 -620
- package/src/generated/aas-repository/types.gen.ts +0 -3786
- package/src/index.ts +0 -1
- package/src/lib/convertAasTypes.ts +0 -123
- package/src/lib/createAasRepoClient.ts +0 -16
- package/src/models/aas-repository.ts +0 -12
- package/src/tests/clients/AasRepositoryClient.test.ts +0 -270
- package/src/tests/lib/convertAasTypes.test.ts +0 -201
- package/src/tests/lib/createAasRepoClient.test.ts +0 -55
- package/src/tests/models/.gitkeep +0 -0
- package/src/tests/utils/.gitkeep +0 -0
- package/src/utils/.gitkeep +0 -0
- /package/dist/generated/{aas-repository/index.d.ts → index.d.ts} +0 -0
- /package/dist/generated/{aas-repository/index.js → index.js} +0 -0
- /package/dist/generated/{aas-repository/types.gen.js → types.gen.js} +0 -0
package/src/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './clients';
|
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
AssetAdministrationShell as CoreAssetAdministrationShell,
|
|
3
|
-
AssetInformation as CoreAssetInformation,
|
|
4
|
-
Reference as CoreReference,
|
|
5
|
-
} from '@aas-core-works/aas-core3.0-typescript/types';
|
|
6
|
-
import type {
|
|
7
|
-
AssetAdministrationShell as ApiAssetAdministrationShell,
|
|
8
|
-
AssetInformation as ApiAssetInformation,
|
|
9
|
-
Reference as ApiReference,
|
|
10
|
-
} from '../generated/aas-repository/types.gen';
|
|
11
|
-
import { jsonization } from '@aas-core-works/aas-core3.0-typescript';
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Convert an API AssetAdministrationShell to a Core Works AssetAdministrationShell
|
|
15
|
-
*
|
|
16
|
-
* @function convertApiAasToCoreAas
|
|
17
|
-
* @param {ApiAssetAdministrationShell} aas - The API AssetAdministrationShell to convert
|
|
18
|
-
* @returns {CoreAssetAdministrationShell} The Core Works AssetAdministrationShell
|
|
19
|
-
*/
|
|
20
|
-
export function convertApiAasToCoreAas(aas: ApiAssetAdministrationShell): CoreAssetAdministrationShell {
|
|
21
|
-
// first stringify
|
|
22
|
-
let shell = JSON.stringify(aas);
|
|
23
|
-
// then parse
|
|
24
|
-
shell = JSON.parse(shell);
|
|
25
|
-
// then jsonize
|
|
26
|
-
const instanceOrError = jsonization.assetAdministrationShellFromJsonable(shell);
|
|
27
|
-
if (instanceOrError.error !== null) {
|
|
28
|
-
throw instanceOrError.error;
|
|
29
|
-
}
|
|
30
|
-
return instanceOrError.mustValue();
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Convert a Core Works AssetAdministrationShell to an API AssetAdministrationShell
|
|
35
|
-
*
|
|
36
|
-
* @function convertCoreAasToApiAas
|
|
37
|
-
* @param {CoreAssetAdministrationShell} aas - The Core Works AssetAdministrationShell to convert
|
|
38
|
-
* @returns {ApiAssetAdministrationShell} The API AssetAdministrationShell
|
|
39
|
-
*/
|
|
40
|
-
export function convertCoreAasToApiAas(aas: CoreAssetAdministrationShell): ApiAssetAdministrationShell {
|
|
41
|
-
// first jsonize
|
|
42
|
-
const jsonableAas = jsonization.toJsonable(aas);
|
|
43
|
-
// then stringify
|
|
44
|
-
const shell = JSON.stringify(jsonableAas);
|
|
45
|
-
// then parse
|
|
46
|
-
return JSON.parse(shell) as ApiAssetAdministrationShell;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Convert an API AssetInformation to a Core Works AssetInformation
|
|
51
|
-
*
|
|
52
|
-
* @function convertApiAssetInformationToCoreAssetInformation
|
|
53
|
-
* @param {ApiAssetInformation} assetInformation - The API AssetInformation to convert
|
|
54
|
-
* @returns {CoreAssetInformation} The Core Works AssetInformation
|
|
55
|
-
*/
|
|
56
|
-
export function convertApiAssetInformationToCoreAssetInformation(
|
|
57
|
-
assetInformation: ApiAssetInformation
|
|
58
|
-
): CoreAssetInformation {
|
|
59
|
-
// first stringify
|
|
60
|
-
let asset = JSON.stringify(assetInformation);
|
|
61
|
-
// then parse
|
|
62
|
-
asset = JSON.parse(asset);
|
|
63
|
-
// then jsonize
|
|
64
|
-
const instanceOrError = jsonization.assetInformationFromJsonable(asset);
|
|
65
|
-
if (instanceOrError.error !== null) {
|
|
66
|
-
throw instanceOrError.error;
|
|
67
|
-
}
|
|
68
|
-
return instanceOrError.mustValue();
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Convert a Core Works AssetInformation to an API AssetInformation
|
|
73
|
-
*
|
|
74
|
-
* @function convertCoreAssetInformationToApiAssetInformation
|
|
75
|
-
* @param {CoreAssetInformation} assetInformation - The Core Works AssetInformation to convert
|
|
76
|
-
* @returns {ApiAssetInformation} The API AssetInformation
|
|
77
|
-
*/
|
|
78
|
-
export function convertCoreAssetInformationToApiAssetInformation(
|
|
79
|
-
assetInformation: CoreAssetInformation
|
|
80
|
-
): ApiAssetInformation {
|
|
81
|
-
// first jsonize
|
|
82
|
-
const jsonableAsset = jsonization.toJsonable(assetInformation);
|
|
83
|
-
// then stringify
|
|
84
|
-
const asset = JSON.stringify(jsonableAsset);
|
|
85
|
-
// then parse
|
|
86
|
-
return JSON.parse(asset) as ApiAssetInformation;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* Convert an API Reference to a Core Works Reference
|
|
91
|
-
*
|
|
92
|
-
* @function convertApiReferenceToCoreReference
|
|
93
|
-
* @param {ApiReference} reference - The API Reference to convert
|
|
94
|
-
* @returns {CoreReference} The Core Works Reference
|
|
95
|
-
*/
|
|
96
|
-
export function convertApiReferenceToCoreReference(reference: ApiReference): CoreReference {
|
|
97
|
-
// first stringify
|
|
98
|
-
let ref = JSON.stringify(reference);
|
|
99
|
-
// then parse
|
|
100
|
-
ref = JSON.parse(ref);
|
|
101
|
-
// then jsonize
|
|
102
|
-
const instanceOrError = jsonization.referenceFromJsonable(ref);
|
|
103
|
-
if (instanceOrError.error !== null) {
|
|
104
|
-
throw instanceOrError.error;
|
|
105
|
-
}
|
|
106
|
-
return instanceOrError.mustValue();
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* Convert a Core Works Reference to an API Reference
|
|
111
|
-
*
|
|
112
|
-
* @function convertCoreReferenceToApiReference
|
|
113
|
-
* @param {CoreReference} reference - The Core Works Reference to convert
|
|
114
|
-
* @returns {ApiReference} The API Reference
|
|
115
|
-
*/
|
|
116
|
-
export function convertCoreReferenceToApiReference(reference: CoreReference): ApiReference {
|
|
117
|
-
// first jsonize
|
|
118
|
-
const jsonableRef = jsonization.toJsonable(reference);
|
|
119
|
-
// then stringify
|
|
120
|
-
const ref = JSON.stringify(jsonableRef);
|
|
121
|
-
// then parse
|
|
122
|
-
return JSON.parse(ref) as ApiReference;
|
|
123
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { createClient } from '@hey-api/client-fetch';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Creates a custom client configuration
|
|
5
|
-
*
|
|
6
|
-
* @function createCustomClient
|
|
7
|
-
* @param baseURL The base URL of the API
|
|
8
|
-
* @param headers The headers to be included in the request
|
|
9
|
-
* @returns {Client} The custom client
|
|
10
|
-
*/
|
|
11
|
-
export function createCustomClient(baseURL: string, headers: Headers = new Headers()) {
|
|
12
|
-
return createClient({
|
|
13
|
-
baseUrl: baseURL,
|
|
14
|
-
headers,
|
|
15
|
-
});
|
|
16
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { AssetAdministrationShell, Reference } from '@aas-core-works/aas-core3.0-typescript/types';
|
|
2
|
-
import type { PagedResultPagingMetadata } from '../generated/aas-repository/types.gen';
|
|
3
|
-
|
|
4
|
-
export interface GetAllAssetAdministrationShellsResponse {
|
|
5
|
-
pagedResult: PagedResultPagingMetadata | undefined;
|
|
6
|
-
result: AssetAdministrationShell[] | undefined;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export interface getAllSubmodelReferencesResponse {
|
|
10
|
-
pagedResult: PagedResultPagingMetadata | undefined;
|
|
11
|
-
result: Reference[] | undefined;
|
|
12
|
-
}
|
|
@@ -1,270 +0,0 @@
|
|
|
1
|
-
// Import necessary types
|
|
2
|
-
import type { GetAssetAdministrationShellsResult } from '../../generated/aas-repository/types.gen';
|
|
3
|
-
import {
|
|
4
|
-
AssetAdministrationShell as CoreAssetAdministrationShell,
|
|
5
|
-
AssetInformation as CoreAssetInformation,
|
|
6
|
-
AssetKind,
|
|
7
|
-
} from '@aas-core-works/aas-core3.0-typescript/types';
|
|
8
|
-
import { AasRepositoryClient } from '../../clients/AasRepositoryClient';
|
|
9
|
-
import { AssetAdministrationShell as ApiAssetAdministrationShell } from '../../generated/aas-repository';
|
|
10
|
-
import * as AasRepository from '../../generated/aas-repository';
|
|
11
|
-
import { convertApiAasToCoreAas, convertCoreAasToApiAas } from '../../lib/convertAasTypes';
|
|
12
|
-
import { createCustomClient } from '../../lib/createAasRepoClient';
|
|
13
|
-
|
|
14
|
-
// Mock the dependencies
|
|
15
|
-
jest.mock('../../lib/createAasRepoClient');
|
|
16
|
-
jest.mock('../../generated/aas-repository');
|
|
17
|
-
jest.mock('../../lib/convertAasTypes');
|
|
18
|
-
|
|
19
|
-
// Define mock constants
|
|
20
|
-
const BASE_URL = 'https://api.example.com';
|
|
21
|
-
const HEADERS = new Headers({ Authorization: 'Bearer token' });
|
|
22
|
-
const ASSET_IDS = ['asset1', 'asset2'];
|
|
23
|
-
const ID_SHORT = 'shellIdShort';
|
|
24
|
-
const LIMIT = 10;
|
|
25
|
-
const CURSOR = 'cursor123';
|
|
26
|
-
const API_AAS1: ApiAssetAdministrationShell = {
|
|
27
|
-
id: 'https://example.com/ids/aas/7600_5912_3951_6917',
|
|
28
|
-
modelType: 'AssetAdministrationShell',
|
|
29
|
-
assetInformation: { assetKind: 'Instance' },
|
|
30
|
-
};
|
|
31
|
-
const API_AAS2: ApiAssetAdministrationShell = {
|
|
32
|
-
id: 'https://example.com/ids/aas/7600_5912_3951_6918',
|
|
33
|
-
modelType: 'AssetAdministrationShell',
|
|
34
|
-
assetInformation: { assetKind: 'Instance' },
|
|
35
|
-
};
|
|
36
|
-
const CORE_AAS1: CoreAssetAdministrationShell = new CoreAssetAdministrationShell(
|
|
37
|
-
'https://example.com/ids/aas/7600_5912_3951_6917',
|
|
38
|
-
new CoreAssetInformation(AssetKind.Instance)
|
|
39
|
-
);
|
|
40
|
-
const CORE_AAS2: CoreAssetAdministrationShell = new CoreAssetAdministrationShell(
|
|
41
|
-
'https://example.com/ids/aas/7600_5912_3951_6918',
|
|
42
|
-
new CoreAssetInformation(AssetKind.Instance)
|
|
43
|
-
);
|
|
44
|
-
|
|
45
|
-
describe('AasRepositoryClient', () => {
|
|
46
|
-
const client = {}; // Mock client object
|
|
47
|
-
const mockCreateCustomClient = createCustomClient as jest.Mock;
|
|
48
|
-
const mockGetAllAssetAdministrationShells = AasRepository.getAllAssetAdministrationShells as jest.Mock;
|
|
49
|
-
const mockPostAssetAdministrationShell = AasRepository.postAssetAdministrationShell as jest.Mock;
|
|
50
|
-
const mockDeleteAssetAdministrationShellById = AasRepository.deleteAssetAdministrationShellById as jest.Mock;
|
|
51
|
-
const mockConvertApiAasToCoreAas = convertApiAasToCoreAas as jest.Mock;
|
|
52
|
-
const mockConvertCoreAasToApiAas = convertCoreAasToApiAas as jest.Mock;
|
|
53
|
-
|
|
54
|
-
// Mock console.error to prevent actual logging during tests
|
|
55
|
-
beforeAll(() => {
|
|
56
|
-
jest.spyOn(console, 'error').mockImplementation(() => {});
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
afterAll(() => {
|
|
60
|
-
(console.error as jest.Mock).mockRestore();
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
beforeEach(() => {
|
|
64
|
-
jest.clearAllMocks(); // Clears call history without resetting implementations
|
|
65
|
-
mockCreateCustomClient.mockReturnValue(client);
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
it('should return Asset Administration Shells on successful response', async () => {
|
|
69
|
-
// Arrange
|
|
70
|
-
const apiResponse: GetAssetAdministrationShellsResult = {
|
|
71
|
-
paging_metadata: {
|
|
72
|
-
cursor: 'cursor123',
|
|
73
|
-
},
|
|
74
|
-
result: [API_AAS1, API_AAS2],
|
|
75
|
-
};
|
|
76
|
-
mockGetAllAssetAdministrationShells.mockResolvedValue({ data: apiResponse, error: null });
|
|
77
|
-
|
|
78
|
-
// Mock convert function to return core AAS
|
|
79
|
-
mockConvertApiAasToCoreAas.mockImplementation((aas: ApiAssetAdministrationShell) => {
|
|
80
|
-
if (aas.id === API_AAS1.id) return CORE_AAS1;
|
|
81
|
-
if (aas.id === API_AAS2.id) return CORE_AAS2;
|
|
82
|
-
throw new Error('Unknown AAS ID');
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
const clientInstance = new AasRepositoryClient();
|
|
86
|
-
|
|
87
|
-
// Act
|
|
88
|
-
const result = await clientInstance.getAllAssetAdministrationShells(
|
|
89
|
-
BASE_URL,
|
|
90
|
-
HEADERS,
|
|
91
|
-
ASSET_IDS,
|
|
92
|
-
ID_SHORT,
|
|
93
|
-
LIMIT,
|
|
94
|
-
CURSOR
|
|
95
|
-
);
|
|
96
|
-
|
|
97
|
-
// Assert
|
|
98
|
-
expect(createCustomClient).toHaveBeenCalledWith(BASE_URL, HEADERS);
|
|
99
|
-
expect(AasRepository.getAllAssetAdministrationShells).toHaveBeenCalledWith({
|
|
100
|
-
client,
|
|
101
|
-
query: {
|
|
102
|
-
assetIds: ASSET_IDS,
|
|
103
|
-
idShort: ID_SHORT,
|
|
104
|
-
limit: LIMIT,
|
|
105
|
-
cursor: CURSOR,
|
|
106
|
-
},
|
|
107
|
-
});
|
|
108
|
-
expect(convertApiAasToCoreAas).toHaveBeenCalledTimes(apiResponse.result!.length);
|
|
109
|
-
expect(result).toEqual({
|
|
110
|
-
pagedResult: apiResponse.paging_metadata,
|
|
111
|
-
result: [CORE_AAS1, CORE_AAS2],
|
|
112
|
-
});
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
it('should throw an error when server returns an error', async () => {
|
|
116
|
-
// Arrange
|
|
117
|
-
const mockError = { messages: ['Invalid request'] };
|
|
118
|
-
mockGetAllAssetAdministrationShells.mockResolvedValue({ data: null, error: mockError });
|
|
119
|
-
|
|
120
|
-
const clientInstance = new AasRepositoryClient();
|
|
121
|
-
|
|
122
|
-
// Act & Assert
|
|
123
|
-
await expect(clientInstance.getAllAssetAdministrationShells(BASE_URL, HEADERS)).rejects.toThrow(
|
|
124
|
-
JSON.stringify(mockError.messages)
|
|
125
|
-
);
|
|
126
|
-
|
|
127
|
-
expect(console.error).toHaveBeenCalledWith('Error from server:', mockError);
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
it('should throw an error when AasRepository throws an exception', async () => {
|
|
131
|
-
// Arrange
|
|
132
|
-
const mockException = new Error('Network error');
|
|
133
|
-
mockGetAllAssetAdministrationShells.mockRejectedValue(mockException);
|
|
134
|
-
|
|
135
|
-
const clientInstance = new AasRepositoryClient();
|
|
136
|
-
|
|
137
|
-
// Act & Assert
|
|
138
|
-
await expect(clientInstance.getAllAssetAdministrationShells(BASE_URL, HEADERS)).rejects.toThrow(
|
|
139
|
-
'Network error'
|
|
140
|
-
);
|
|
141
|
-
|
|
142
|
-
expect(console.error).toHaveBeenCalledWith('Error fetching Asset Administration Shells:', mockException);
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
it('should handle empty result array gracefully', async () => {
|
|
146
|
-
// Arrange
|
|
147
|
-
const apiResponse: GetAssetAdministrationShellsResult = {
|
|
148
|
-
paging_metadata: {
|
|
149
|
-
cursor: undefined,
|
|
150
|
-
},
|
|
151
|
-
result: [],
|
|
152
|
-
};
|
|
153
|
-
mockGetAllAssetAdministrationShells.mockResolvedValue({ data: apiResponse, error: null });
|
|
154
|
-
|
|
155
|
-
const clientInstance = new AasRepositoryClient();
|
|
156
|
-
|
|
157
|
-
// Act
|
|
158
|
-
const result = await clientInstance.getAllAssetAdministrationShells(BASE_URL, HEADERS);
|
|
159
|
-
|
|
160
|
-
// Assert
|
|
161
|
-
expect(result).toEqual({
|
|
162
|
-
pagedResult: apiResponse.paging_metadata,
|
|
163
|
-
result: [],
|
|
164
|
-
});
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
it('should create an Asset Administration Shell successfully', async () => {
|
|
168
|
-
// Arrange
|
|
169
|
-
mockPostAssetAdministrationShell.mockResolvedValue({ data: API_AAS1, error: null });
|
|
170
|
-
|
|
171
|
-
// Mock convert function to return API AAS
|
|
172
|
-
mockConvertCoreAasToApiAas.mockImplementation((aas: CoreAssetAdministrationShell) => {
|
|
173
|
-
if (aas.id === CORE_AAS1.id) return API_AAS1;
|
|
174
|
-
if (aas.id === CORE_AAS2.id) return API_AAS2;
|
|
175
|
-
throw new Error('Unknown AAS ID');
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
const clientInstance = new AasRepositoryClient();
|
|
179
|
-
|
|
180
|
-
// Act
|
|
181
|
-
const result = await clientInstance.postAssetAdministrationShell(BASE_URL, CORE_AAS1, HEADERS);
|
|
182
|
-
|
|
183
|
-
// Assert
|
|
184
|
-
expect(createCustomClient).toHaveBeenCalledWith(BASE_URL, HEADERS);
|
|
185
|
-
expect(AasRepository.postAssetAdministrationShell).toHaveBeenCalledWith({
|
|
186
|
-
client,
|
|
187
|
-
body: API_AAS1,
|
|
188
|
-
});
|
|
189
|
-
expect(convertCoreAasToApiAas).toHaveBeenCalledWith(CORE_AAS1);
|
|
190
|
-
expect(convertApiAasToCoreAas).toHaveBeenCalledWith(API_AAS1);
|
|
191
|
-
expect(result).toEqual(convertApiAasToCoreAas(API_AAS1));
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
it('should throw an error when server returns an error', async () => {
|
|
195
|
-
// Arrange
|
|
196
|
-
const mockError = { messages: ['Invalid request'] };
|
|
197
|
-
mockPostAssetAdministrationShell.mockResolvedValue({ data: null, error: mockError });
|
|
198
|
-
|
|
199
|
-
const clientInstance = new AasRepositoryClient();
|
|
200
|
-
|
|
201
|
-
// Act & Assert
|
|
202
|
-
await expect(clientInstance.postAssetAdministrationShell(BASE_URL, CORE_AAS1, HEADERS)).rejects.toThrow(
|
|
203
|
-
JSON.stringify(mockError.messages)
|
|
204
|
-
);
|
|
205
|
-
|
|
206
|
-
expect(console.error).toHaveBeenCalledWith('Error from server:', mockError);
|
|
207
|
-
});
|
|
208
|
-
|
|
209
|
-
it('should throw an error when AasRepository throws an exception', async () => {
|
|
210
|
-
// Arrange
|
|
211
|
-
const mockException = new Error('Network error');
|
|
212
|
-
mockPostAssetAdministrationShell.mockRejectedValue(mockException);
|
|
213
|
-
|
|
214
|
-
const clientInstance = new AasRepositoryClient();
|
|
215
|
-
|
|
216
|
-
// Act & Assert
|
|
217
|
-
await expect(clientInstance.postAssetAdministrationShell(BASE_URL, CORE_AAS1, HEADERS)).rejects.toThrow(
|
|
218
|
-
'Network error'
|
|
219
|
-
);
|
|
220
|
-
|
|
221
|
-
expect(console.error).toHaveBeenCalledWith('Error creating Asset Administration Shell:', mockException);
|
|
222
|
-
});
|
|
223
|
-
|
|
224
|
-
it('should delete an Asset Administration Shell successfully', async () => {
|
|
225
|
-
// Arrange
|
|
226
|
-
mockDeleteAssetAdministrationShellById.mockResolvedValue({ data: null, error: null });
|
|
227
|
-
|
|
228
|
-
const clientInstance = new AasRepositoryClient();
|
|
229
|
-
|
|
230
|
-
// Act
|
|
231
|
-
await clientInstance.deleteAssetAdministrationShellById(BASE_URL, CORE_AAS1.id, HEADERS);
|
|
232
|
-
|
|
233
|
-
// Assert
|
|
234
|
-
expect(createCustomClient).toHaveBeenCalledWith(BASE_URL, HEADERS);
|
|
235
|
-
expect(AasRepository.deleteAssetAdministrationShellById).toHaveBeenCalledWith({
|
|
236
|
-
client,
|
|
237
|
-
path: { aasIdentifier: CORE_AAS1.id },
|
|
238
|
-
});
|
|
239
|
-
});
|
|
240
|
-
|
|
241
|
-
it('should throw an error when server returns an error', async () => {
|
|
242
|
-
// Arrange
|
|
243
|
-
const mockError = { messages: ['Invalid request'] };
|
|
244
|
-
mockDeleteAssetAdministrationShellById.mockResolvedValue({ data: null, error: mockError });
|
|
245
|
-
|
|
246
|
-
const clientInstance = new AasRepositoryClient();
|
|
247
|
-
|
|
248
|
-
// Act & Assert
|
|
249
|
-
await expect(
|
|
250
|
-
clientInstance.deleteAssetAdministrationShellById(BASE_URL, CORE_AAS1.id, HEADERS)
|
|
251
|
-
).rejects.toThrow(JSON.stringify(mockError.messages));
|
|
252
|
-
|
|
253
|
-
expect(console.error).toHaveBeenCalledWith('Error from server:', mockError);
|
|
254
|
-
});
|
|
255
|
-
|
|
256
|
-
it('should throw an error when AasRepository throws an exception', async () => {
|
|
257
|
-
// Arrange
|
|
258
|
-
const mockException = new Error('Network error');
|
|
259
|
-
mockDeleteAssetAdministrationShellById.mockRejectedValue(mockException);
|
|
260
|
-
|
|
261
|
-
const clientInstance = new AasRepositoryClient();
|
|
262
|
-
|
|
263
|
-
// Act & Assert
|
|
264
|
-
await expect(
|
|
265
|
-
clientInstance.deleteAssetAdministrationShellById(BASE_URL, CORE_AAS1.id, HEADERS)
|
|
266
|
-
).rejects.toThrow('Network error');
|
|
267
|
-
|
|
268
|
-
expect(console.error).toHaveBeenCalledWith('Error deleting Asset Administration Shell:', mockException);
|
|
269
|
-
});
|
|
270
|
-
});
|
|
@@ -1,201 +0,0 @@
|
|
|
1
|
-
import { jsonization } from '@aas-core-works/aas-core3.0-typescript';
|
|
2
|
-
import {
|
|
3
|
-
AssetAdministrationShell as CoreAssetAdministrationShell,
|
|
4
|
-
AssetInformation as CoreAssetInformation,
|
|
5
|
-
AssetKind,
|
|
6
|
-
Key as CoreKey,
|
|
7
|
-
KeyTypes,
|
|
8
|
-
Reference as CoreReference,
|
|
9
|
-
ReferenceTypes,
|
|
10
|
-
} from '@aas-core-works/aas-core3.0-typescript/types';
|
|
11
|
-
import {
|
|
12
|
-
AssetAdministrationShell as ApiAssetAdministrationShell,
|
|
13
|
-
AssetInformation as ApiAssetInformation,
|
|
14
|
-
Reference as ApiReference,
|
|
15
|
-
} from '../../generated/aas-repository/types.gen';
|
|
16
|
-
import {
|
|
17
|
-
convertApiAasToCoreAas,
|
|
18
|
-
convertApiAssetInformationToCoreAssetInformation,
|
|
19
|
-
convertApiReferenceToCoreReference,
|
|
20
|
-
convertCoreAasToApiAas,
|
|
21
|
-
convertCoreAssetInformationToApiAssetInformation,
|
|
22
|
-
convertCoreReferenceToApiReference,
|
|
23
|
-
} from '../../lib/convertAasTypes';
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Mock the jsonization methods used in convertAasTypes.ts
|
|
27
|
-
*/
|
|
28
|
-
jest.mock('@aas-core-works/aas-core3.0-typescript', () => ({
|
|
29
|
-
jsonization: {
|
|
30
|
-
assetAdministrationShellFromJsonable: jest.fn(),
|
|
31
|
-
toJsonable: jest.fn(),
|
|
32
|
-
assetInformationFromJsonable: jest.fn(),
|
|
33
|
-
referenceFromJsonable: jest.fn(),
|
|
34
|
-
},
|
|
35
|
-
}));
|
|
36
|
-
|
|
37
|
-
// Define mock constants
|
|
38
|
-
const API_AAS: ApiAssetAdministrationShell = {
|
|
39
|
-
id: 'https://example.com/ids/aas/7600_5912_3951_6917',
|
|
40
|
-
modelType: 'AssetAdministrationShell',
|
|
41
|
-
assetInformation: { assetKind: 'Instance' },
|
|
42
|
-
};
|
|
43
|
-
const CORE_AAS: CoreAssetAdministrationShell = new CoreAssetAdministrationShell(
|
|
44
|
-
'https://example.com/ids/aas/7600_5912_3951_6917',
|
|
45
|
-
new CoreAssetInformation(AssetKind.Instance)
|
|
46
|
-
);
|
|
47
|
-
const JSONABLE_AAS: jsonization.JsonObject = {
|
|
48
|
-
id: 'https://example.com/ids/aas/7600_5912_3951_6917',
|
|
49
|
-
modelType: 'AssetAdministrationShell',
|
|
50
|
-
assetInformation: { assetKind: 'Instance' },
|
|
51
|
-
};
|
|
52
|
-
const API_ASSET_INFO: ApiAssetInformation = {
|
|
53
|
-
assetKind: 'Instance',
|
|
54
|
-
};
|
|
55
|
-
const CORE_ASSET_INFO: CoreAssetInformation = new CoreAssetInformation(AssetKind.Instance);
|
|
56
|
-
const JSONABLE_ASSET_INFO: jsonization.JsonObject = {
|
|
57
|
-
assetKind: 'Instance',
|
|
58
|
-
};
|
|
59
|
-
const API_REFERENCE: ApiReference = {
|
|
60
|
-
type: 'ExternalReference',
|
|
61
|
-
keys: [
|
|
62
|
-
{
|
|
63
|
-
type: 'GlobalReference',
|
|
64
|
-
value: 'https://example.com/ids/submodel/7600_5912_3951_6917',
|
|
65
|
-
},
|
|
66
|
-
],
|
|
67
|
-
};
|
|
68
|
-
const CORE_REFERENCE: CoreReference = new CoreReference(ReferenceTypes.ExternalReference, [
|
|
69
|
-
new CoreKey(KeyTypes.GlobalReference, 'https://example.com/ids/submodel/7600_5912_3951_6917'),
|
|
70
|
-
]);
|
|
71
|
-
const JSONABLE_REFERENCE: jsonization.JsonObject = {
|
|
72
|
-
type: 'ExternalReference',
|
|
73
|
-
keys: [
|
|
74
|
-
{
|
|
75
|
-
type: 'GlobalReference',
|
|
76
|
-
value: 'https://example.com/ids/submodel/7600_5912_3951_6917',
|
|
77
|
-
},
|
|
78
|
-
],
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
describe('convertAasTypes', () => {
|
|
82
|
-
afterEach(() => {
|
|
83
|
-
jest.clearAllMocks();
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
describe('convertApiAasToCoreAas', () => {
|
|
87
|
-
it('should convert ApiAssetAdministrationShell to CoreAssetAdministrationShell successfully', () => {
|
|
88
|
-
(jsonization.assetAdministrationShellFromJsonable as jest.Mock).mockReturnValue({
|
|
89
|
-
error: null,
|
|
90
|
-
mustValue: () => CORE_AAS,
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
const result = convertApiAasToCoreAas(API_AAS);
|
|
94
|
-
|
|
95
|
-
expect(jsonization.assetAdministrationShellFromJsonable).toHaveBeenCalledWith(
|
|
96
|
-
JSON.parse(JSON.stringify(API_AAS))
|
|
97
|
-
);
|
|
98
|
-
expect(result).toBe(CORE_AAS);
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
it('should throw an error if jsonization.assetAdministrationShellFromJsonable returns an error', () => {
|
|
102
|
-
const error = new Error('Conversion failed');
|
|
103
|
-
|
|
104
|
-
(jsonization.assetAdministrationShellFromJsonable as jest.Mock).mockReturnValue({
|
|
105
|
-
error: error,
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
expect(() => convertApiAasToCoreAas(API_AAS)).toThrow(error);
|
|
109
|
-
expect(jsonization.assetAdministrationShellFromJsonable).toHaveBeenCalledWith(
|
|
110
|
-
JSON.parse(JSON.stringify(API_AAS))
|
|
111
|
-
);
|
|
112
|
-
});
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
describe('convertCoreAasToApiAas', () => {
|
|
116
|
-
it('should convert CoreAssetAdministrationShell to ApiAssetAdministrationShell successfully', () => {
|
|
117
|
-
(jsonization.toJsonable as jest.Mock).mockReturnValue(JSONABLE_AAS);
|
|
118
|
-
|
|
119
|
-
const result = convertCoreAasToApiAas(CORE_AAS);
|
|
120
|
-
|
|
121
|
-
expect(jsonization.toJsonable).toHaveBeenCalledWith(CORE_AAS);
|
|
122
|
-
expect(result).toEqual(API_AAS);
|
|
123
|
-
});
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
describe('convertApiAssetInformationToCoreAssetInformation', () => {
|
|
127
|
-
it('should convert ApiAssetInformation to CoreAssetInformation successfully', () => {
|
|
128
|
-
(jsonization.assetInformationFromJsonable as jest.Mock).mockReturnValue({
|
|
129
|
-
error: null,
|
|
130
|
-
mustValue: () => CORE_ASSET_INFO,
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
const result = convertApiAssetInformationToCoreAssetInformation(API_ASSET_INFO);
|
|
134
|
-
|
|
135
|
-
expect(jsonization.assetInformationFromJsonable).toHaveBeenCalledWith(
|
|
136
|
-
JSON.parse(JSON.stringify(API_ASSET_INFO))
|
|
137
|
-
);
|
|
138
|
-
expect(result).toBe(CORE_ASSET_INFO);
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
it('should throw an error if jsonization.assetInformationFromJsonable returns an error', () => {
|
|
142
|
-
const error = new Error('Conversion failed');
|
|
143
|
-
|
|
144
|
-
(jsonization.assetInformationFromJsonable as jest.Mock).mockReturnValue({
|
|
145
|
-
error: error,
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
expect(() => convertApiAssetInformationToCoreAssetInformation(API_ASSET_INFO)).toThrow(error);
|
|
149
|
-
expect(jsonization.assetInformationFromJsonable).toHaveBeenCalledWith(
|
|
150
|
-
JSON.parse(JSON.stringify(API_ASSET_INFO))
|
|
151
|
-
);
|
|
152
|
-
});
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
describe('convertCoreAssetInformationToApiAssetInformation', () => {
|
|
156
|
-
it('should convert CoreAssetInformation to ApiAssetInformation successfully', () => {
|
|
157
|
-
(jsonization.toJsonable as jest.Mock).mockReturnValue(JSONABLE_ASSET_INFO);
|
|
158
|
-
|
|
159
|
-
const result = convertCoreAssetInformationToApiAssetInformation(CORE_ASSET_INFO);
|
|
160
|
-
|
|
161
|
-
expect(jsonization.toJsonable).toHaveBeenCalledWith(CORE_ASSET_INFO);
|
|
162
|
-
expect(result).toEqual(API_ASSET_INFO);
|
|
163
|
-
});
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
describe('convertApiReferenceToCoreReference', () => {
|
|
167
|
-
it('should convert ApiReference to CoreReference successfully', () => {
|
|
168
|
-
(jsonization.referenceFromJsonable as jest.Mock).mockReturnValue({
|
|
169
|
-
error: null,
|
|
170
|
-
mustValue: () => CORE_REFERENCE,
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
const result = convertApiReferenceToCoreReference(API_REFERENCE);
|
|
174
|
-
|
|
175
|
-
expect(jsonization.referenceFromJsonable).toHaveBeenCalledWith(JSON.parse(JSON.stringify(API_REFERENCE)));
|
|
176
|
-
expect(result).toBe(CORE_REFERENCE);
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
it('should throw an error if jsonization.referenceFromJsonable returns an error', () => {
|
|
180
|
-
const error = new Error('Conversion failed');
|
|
181
|
-
|
|
182
|
-
(jsonization.referenceFromJsonable as jest.Mock).mockReturnValue({
|
|
183
|
-
error: error,
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
expect(() => convertApiReferenceToCoreReference(API_REFERENCE)).toThrow(error);
|
|
187
|
-
expect(jsonization.referenceFromJsonable).toHaveBeenCalledWith(JSON.parse(JSON.stringify(API_REFERENCE)));
|
|
188
|
-
});
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
describe('convertCoreReferenceToApiReference', () => {
|
|
192
|
-
it('should convert CoreReference to ApiReference successfully', () => {
|
|
193
|
-
(jsonization.toJsonable as jest.Mock).mockReturnValue(JSONABLE_REFERENCE);
|
|
194
|
-
|
|
195
|
-
const result = convertCoreReferenceToApiReference(CORE_REFERENCE);
|
|
196
|
-
|
|
197
|
-
expect(jsonization.toJsonable).toHaveBeenCalledWith(CORE_REFERENCE);
|
|
198
|
-
expect(result).toEqual(API_REFERENCE);
|
|
199
|
-
});
|
|
200
|
-
});
|
|
201
|
-
});
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { createClient } from '@hey-api/client-fetch';
|
|
2
|
-
import { createCustomClient } from '../../lib/createAasRepoClient';
|
|
3
|
-
|
|
4
|
-
// Mock the createClient function from @hey-api/client-fetch
|
|
5
|
-
jest.mock('@hey-api/client-fetch', () => ({
|
|
6
|
-
createClient: jest.fn(),
|
|
7
|
-
}));
|
|
8
|
-
|
|
9
|
-
describe('createCustomClient', () => {
|
|
10
|
-
beforeEach(() => {
|
|
11
|
-
// Clear all instances and calls to constructor and all methods:
|
|
12
|
-
jest.clearAllMocks();
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
it('should call createClient with the correct baseUrl and headers', () => {
|
|
16
|
-
const baseURL = 'https://api.example.com';
|
|
17
|
-
const headers = new Headers({
|
|
18
|
-
Authorization: 'Bearer test-token',
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
// Mock return value of createClient
|
|
22
|
-
const mockClient = { some: 'client' };
|
|
23
|
-
(createClient as jest.Mock).mockReturnValue(mockClient);
|
|
24
|
-
|
|
25
|
-
const client = createCustomClient(baseURL, headers);
|
|
26
|
-
|
|
27
|
-
// Assert that createClient was called with the correct parameters
|
|
28
|
-
expect(createClient).toHaveBeenCalledWith({
|
|
29
|
-
baseUrl: baseURL,
|
|
30
|
-
headers: headers,
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
// Assert that the function returns the mocked client
|
|
34
|
-
expect(client).toBe(mockClient);
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it('should use default headers if none are provided', () => {
|
|
38
|
-
const baseURL = 'https://api.example.com';
|
|
39
|
-
|
|
40
|
-
// Mock return value of createClient
|
|
41
|
-
const mockClient = { some: 'client' };
|
|
42
|
-
(createClient as jest.Mock).mockReturnValue(mockClient);
|
|
43
|
-
|
|
44
|
-
const client = createCustomClient(baseURL);
|
|
45
|
-
|
|
46
|
-
// Assert that createClient was called with the correct parameters
|
|
47
|
-
expect(createClient).toHaveBeenCalledWith({
|
|
48
|
-
baseUrl: baseURL,
|
|
49
|
-
headers: new Headers(),
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
// Assert that the function returns the mocked client
|
|
53
|
-
expect(client).toBe(mockClient);
|
|
54
|
-
});
|
|
55
|
-
});
|
|
File without changes
|
package/src/tests/utils/.gitkeep
DELETED
|
File without changes
|
package/src/utils/.gitkeep
DELETED
|
File without changes
|