Skip to content

Commit 8014d6f

Browse files
authored
feat(simint): make simulatorIntegrationExternalId optional for routines, revisions and runs (#1346)
`simulatorIntegrationExternalId` is a required field at the moment, which means that it has to be associated with a connector since the creation of the resource, to make it flexible to decide after creation which connector can pick it up, we're making that field optional in this PR. Ref: cognitedata/cognite-sdk-python#2420
1 parent c43ac5f commit 8014d6f

File tree

3 files changed

+167
-19
lines changed

3 files changed

+167
-19
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import nock from 'nock';
2+
import { beforeEach, describe, expect, test } from 'vitest';
3+
import { mockBaseUrl } from '../../../../core/src/__tests__/testUtils';
4+
import type CogniteClientAlpha from '../../cogniteClient';
5+
import { setupMockableClient } from '../testUtils';
6+
7+
describe('Simulator Runs API unit tests', () => {
8+
let client: CogniteClientAlpha;
9+
10+
beforeEach(() => {
11+
nock.cleanAll();
12+
client = setupMockableClient();
13+
});
14+
15+
test('list simulation runs with undefined simulatorIntegrationExternalId', async () => {
16+
const mockedResponse = {
17+
items: [
18+
{
19+
id: 1,
20+
simulatorExternalId: 'simulator-1',
21+
simulatorIntegrationExternalId: undefined,
22+
modelExternalId: 'model-1',
23+
routineExternalId: 'routine-1',
24+
routineRevisionExternalId: 'routine-revision-1',
25+
status: 'success',
26+
runTime: 1765203279461,
27+
simulationTime: 1765203279461,
28+
statusMessage: 'Test Status Message',
29+
dataSetId: 1,
30+
eventId: 1,
31+
runType: 'external',
32+
logId: 1,
33+
createdTime: 1765203279461,
34+
lastUpdatedTime: 1765203279461,
35+
modelRevisionExternalId: 'model-revision-1',
36+
},
37+
],
38+
};
39+
40+
nock(mockBaseUrl)
41+
.post(/\/api\/v1\/projects\/.*\/simulators\/runs\/list/, {})
42+
.reply(200, mockedResponse);
43+
44+
const result = await client.simulators.listRuns();
45+
expect(result.items.length).toBe(1);
46+
const expectedResponse = mockedResponse.items.map((item) => ({
47+
...item,
48+
createdTime: new Date(item.createdTime),
49+
lastUpdatedTime: new Date(item.lastUpdatedTime),
50+
runTime: new Date(item.runTime),
51+
simulationTime: new Date(item.simulationTime),
52+
}));
53+
expect(result.items).toEqual(expectedResponse);
54+
expect(result.items[0].simulatorIntegrationExternalId).toBeUndefined();
55+
});
56+
});

packages/alpha/src/__tests__/api/simulatorRoutinesApi.unit.spec.ts

Lines changed: 107 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { beforeEach, describe, expect, test } from 'vitest';
33
import { mockBaseUrl } from '../../../../core/src/__tests__/testUtils';
44
import type CogniteClientAlpha from '../../cogniteClient';
55
import { setupMockableClient } from '../testUtils';
6+
import { routineRevisionConfiguration, routineRevisionScript } from './seed';
67

78
describe('Simulator Routines API unit tests', () => {
89
let client: CogniteClientAlpha;
@@ -16,21 +17,29 @@ describe('Simulator Routines API unit tests', () => {
1617
const filter = {
1718
simulatorExternalIds: ['simulator-1', 'simulator-2'],
1819
};
19-
const response = {
20+
const mockedResponse = {
2021
items: [
2122
{
2223
id: 1,
23-
externalId: 'routine-1',
24+
externalId: 'test_sim_routine_1',
25+
simulatorExternalId: 'test_sim_1',
26+
modelExternalId: 'test_model_1',
27+
simulatorIntegrationExternalId: 'test_sim_integration_1',
2428
name: 'Test Routine 1',
25-
modelExternalId: 'model-1',
26-
simulatorIntegrationExternalId: 'integration-1',
29+
dataSetId: 1,
30+
createdTime: 1765203279461,
31+
lastUpdatedTime: 1765203279461,
2732
},
2833
{
2934
id: 2,
30-
externalId: 'routine-2',
35+
externalId: 'test_sim_routine_2',
36+
simulatorExternalId: 'test_sim_1',
37+
modelExternalId: 'test_model_1',
38+
simulatorIntegrationExternalId: 'test_sim_integration_1',
3139
name: 'Test Routine 2',
32-
modelExternalId: 'model-2',
33-
simulatorIntegrationExternalId: 'integration-2',
40+
dataSetId: 1,
41+
createdTime: 1765203279461,
42+
lastUpdatedTime: 1765203279461,
3443
},
3544
],
3645
};
@@ -39,12 +48,17 @@ describe('Simulator Routines API unit tests', () => {
3948
.post(/\/api\/v1\/projects\/.*\/simulators\/routines\/list/, {
4049
filter,
4150
})
42-
.reply(200, response);
51+
.reply(200, mockedResponse);
4352

4453
const result = await client.simulators.listRoutines({
4554
filter,
4655
});
47-
expect(result.items).toEqual(response.items);
56+
const expectedResponse = mockedResponse.items.map((item) => ({
57+
...item,
58+
createdTime: new Date(item.createdTime),
59+
lastUpdatedTime: new Date(item.lastUpdatedTime),
60+
}));
61+
expect(result.items).toEqual(expectedResponse);
4862
expect(result.items.length).toBe(2);
4963
});
5064

@@ -54,14 +68,18 @@ describe('Simulator Routines API unit tests', () => {
5468
simulatorIntegrationExternalIds: ['integration-1'],
5569
modelExternalIds: ['model-1'],
5670
};
57-
const response = {
71+
const mockedResponse = {
5872
items: [
5973
{
6074
id: 1,
61-
externalId: 'routine-1',
75+
externalId: 'test_sim_routine_1',
76+
simulatorExternalId: 'test_sim_1',
77+
modelExternalId: 'test_model_1',
78+
simulatorIntegrationExternalId: 'test_sim_integration_1',
6279
name: 'Test Routine 1',
63-
modelExternalId: 'model-1',
64-
simulatorIntegrationExternalId: 'integration-1',
80+
dataSetId: 1,
81+
createdTime: 1765203279461,
82+
lastUpdatedTime: 1765203279461,
6583
},
6684
],
6785
};
@@ -70,12 +88,17 @@ describe('Simulator Routines API unit tests', () => {
7088
.post(/\/api\/v1\/projects\/.*\/simulators\/routines\/list/, {
7189
filter,
7290
})
73-
.reply(200, response);
91+
.reply(200, mockedResponse);
7492

7593
const result = await client.simulators.listRoutines({
7694
filter,
7795
});
78-
expect(result.items).toEqual(response.items);
96+
const expectedResponse = mockedResponse.items.map((item) => ({
97+
...item,
98+
createdTime: new Date(item.createdTime),
99+
lastUpdatedTime: new Date(item.lastUpdatedTime),
100+
}));
101+
expect(result.items).toEqual(expectedResponse);
79102
expect(result.items.length).toBe(1);
80103
});
81104

@@ -99,4 +122,73 @@ describe('Simulator Routines API unit tests', () => {
99122
expect(result.items).toEqual([]);
100123
expect(result.items.length).toBe(0);
101124
});
125+
126+
test('list simulator routines with undefined simulatorIntegrationExternalId', async () => {
127+
const mockedResponse = {
128+
items: [
129+
{
130+
id: 1,
131+
externalId: 'test_sim_routine_1',
132+
simulatorExternalId: 'test_sim_1',
133+
modelExternalId: 'test_model_1',
134+
simulatorIntegrationExternalId: undefined,
135+
name: 'Test Routine 1',
136+
dataSetId: 1,
137+
createdTime: 1765203279461,
138+
lastUpdatedTime: 1765203279461,
139+
},
140+
],
141+
};
142+
143+
nock(mockBaseUrl)
144+
.post(/\/api\/v1\/projects\/.*\/simulators\/routines\/list/, {})
145+
.reply(200, mockedResponse);
146+
147+
const result = await client.simulators.listRoutines();
148+
expect(result.items.length).toBe(1);
149+
const expectedResponse = mockedResponse.items.map((item) => ({
150+
...item,
151+
createdTime: new Date(item.createdTime),
152+
lastUpdatedTime: new Date(item.lastUpdatedTime),
153+
}));
154+
expect(result.items).toEqual(expectedResponse);
155+
expect(result.items[0].simulatorIntegrationExternalId).toBeUndefined();
156+
});
157+
158+
test('list simulator routine revisions with undefined simulatorIntegrationExternalId', async () => {
159+
const mockedResponse = {
160+
items: [
161+
{
162+
id: 1,
163+
externalId: 'test_sim_routine_revision_1',
164+
routineExternalId: 'test_sim_routine_1',
165+
modelExternalId: 'test_model_1',
166+
simulatorIntegrationExternalId: undefined,
167+
configuration: routineRevisionConfiguration,
168+
script: routineRevisionScript,
169+
simulatorExternalId: 'test_sim_1',
170+
dataSetId: 1,
171+
createdByUserId: 'test_user_1',
172+
createdTime: 1765203279461,
173+
versionNumber: 1,
174+
},
175+
],
176+
};
177+
178+
nock(mockBaseUrl)
179+
.post(
180+
/\/api\/v1\/projects\/.*\/simulators\/routines\/revisions\/list/,
181+
{}
182+
)
183+
.reply(200, mockedResponse);
184+
185+
const result = await client.simulators.listRoutineRevisions();
186+
expect(result.items.length).toBe(1);
187+
const expectedResponse = mockedResponse.items.map((item) => ({
188+
...item,
189+
createdTime: new Date(item.createdTime),
190+
}));
191+
expect(result.items).toEqual(expectedResponse);
192+
expect(result.items[0].simulatorIntegrationExternalId).toBeUndefined();
193+
});
102194
});

packages/alpha/src/types.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ export interface SimulationRun {
200200
id: CogniteInternalId;
201201

202202
simulatorExternalId: CogniteExternalId;
203-
simulatorIntegrationExternalId: CogniteExternalId;
203+
simulatorIntegrationExternalId?: CogniteExternalId;
204204
modelExternalId: CogniteExternalId;
205205
modelRevisionExternalId: CogniteExternalId;
206206
routineExternalId: CogniteExternalId;
@@ -450,7 +450,7 @@ export interface SimulatorRoutine {
450450
externalId: CogniteExternalId;
451451
simulatorExternalId: CogniteExternalId;
452452
modelExternalId: CogniteExternalId;
453-
simulatorIntegrationExternalId: CogniteExternalId;
453+
simulatorIntegrationExternalId?: CogniteExternalId;
454454
name: string;
455455
dataSetId: number;
456456
description?: string;
@@ -461,7 +461,7 @@ export interface SimulatorRoutine {
461461
export interface SimulatorRoutineCreate {
462462
externalId: CogniteExternalId;
463463
modelExternalId: CogniteExternalId;
464-
simulatorIntegrationExternalId: CogniteExternalId;
464+
simulatorIntegrationExternalId?: CogniteExternalId;
465465
name: string;
466466
}
467467

@@ -576,7 +576,7 @@ export interface SimulatorRoutineRevisionBase {
576576
externalId: CogniteExternalId;
577577
simulatorExternalId: CogniteExternalId;
578578
routineExternalId: CogniteExternalId;
579-
simulatorIntegrationExternalId: CogniteExternalId;
579+
simulatorIntegrationExternalId?: CogniteExternalId;
580580
modelExternalId: CogniteExternalId;
581581
dataSetId: CogniteInternalId;
582582
createdByUserId: string;

0 commit comments

Comments
 (0)