@contrail/flexplm 1.7.8-alpha.48b253c → 1.7.8-alpha.69dcae1
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/lib/util/type-utils.js
CHANGED
|
@@ -14,6 +14,11 @@ class TypeUtils {
|
|
|
14
14
|
id,
|
|
15
15
|
relations: ['typeProperties', 'typeInterfaces']
|
|
16
16
|
});
|
|
17
|
+
// The API answers 200 with an empty body for a missing/deleted type, which the SDK returns as null.
|
|
18
|
+
if (!type) {
|
|
19
|
+
throw new Error('getTypeById: type not found for typeId: ' + id
|
|
20
|
+
+ '. The entity references a type that no longer exists.');
|
|
21
|
+
}
|
|
17
22
|
return type;
|
|
18
23
|
}
|
|
19
24
|
async getByRootAndPath(options) {
|
|
@@ -190,3 +190,16 @@ describe('filterProperties-color', () => {
|
|
|
190
190
|
expect(filteredProps.length).toEqual(len);
|
|
191
191
|
});
|
|
192
192
|
});
|
|
193
|
+
describe('TypeUtils.getTypeById() tests', () => {
|
|
194
|
+
it('throws a descriptive error when the type does not exist', async () => {
|
|
195
|
+
const tu = new type_utils_1.TypeUtils();
|
|
196
|
+
tu['typesObj'] = { getType: jest.fn().mockResolvedValue(null) };
|
|
197
|
+
await expect(tu.getTypeById('missingTypeId')).rejects.toThrow('type not found for typeId: missingTypeId');
|
|
198
|
+
});
|
|
199
|
+
it('returns the type when it exists', async () => {
|
|
200
|
+
const tu = new type_utils_1.TypeUtils();
|
|
201
|
+
const type = { id: 'typeId', typeProperties: [] };
|
|
202
|
+
tu['typesObj'] = { getType: jest.fn().mockResolvedValue(type) };
|
|
203
|
+
expect(await tu.getTypeById('typeId')).toBe(type);
|
|
204
|
+
});
|
|
205
|
+
});
|