Skip to content

Commit 7f48efd

Browse files
committed
[frontend] fix create Status (#15221)
1 parent 3249db0 commit 7f48efd

4 files changed

Lines changed: 62 additions & 61 deletions

File tree

opencti-platform/opencti-front/src/private/components/common/form/StatusTemplateField.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,9 @@ const StatusTemplateField: FunctionComponent<StatusTemplateFieldProps> = ({
130130
required={required}
131131
noOptionsText={t_i18n('No available options')}
132132
options={statusTemplates}
133-
onInputChange={(event: React.FocusEvent<HTMLInputElement>) => (
134-
handleSearch(event.target?.value)
135-
)}
133+
onInputChange={(_event: React.FocusEvent<HTMLInputElement>, value: string) => {
134+
handleSearch(value);
135+
}}
136136
openCreate={handleOpenStatusTemplateCreation}
137137
renderOption={(
138138
{ key, ...optionProps }: React.HTMLAttributes<HTMLLIElement> & { key?: string | number },

opencti-platform/opencti-graphql/tests/03-integration/02-resolvers/workflow-actions-test.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import gql from 'graphql-tag';
22
import { beforeAll, describe, expect, it } from 'vitest';
3-
import { adminQuery, ADMIN_USER, TEST_ORGANIZATION } from '../../utils/testQuery';
3+
import { ADMIN_USER, TEST_ORGANIZATION } from '../../utils/testQuery';
4+
import { queryAsAdmin } from '../../utils/testQueryHelper';
45

56
const WORKFLOW_DEFINITION_SET_MUTATION = gql`
67
mutation WorkflowDefinitionSet($entityType: String!, $definition: String!) {
@@ -58,13 +59,13 @@ describe('Workflow Actions Resolver', () => {
5859
let draftWorkspaceId: string;
5960

6061
beforeAll(async () => {
61-
const result = await adminQuery({
62+
const result = await queryAsAdmin({
6263
query: CREATE_DRAFT_WORKSPACE_QUERY,
6364
variables: {
6465
input: { name: 'Workflow Action Test Workspace' },
6566
},
6667
});
67-
draftWorkspaceId = result.data.draftWorkspaceAdd.id;
68+
draftWorkspaceId = result.data?.draftWorkspaceAdd.id;
6869
});
6970

7071
it('should update authorized members on workflow event', async () => {
@@ -86,7 +87,7 @@ describe('Workflow Actions Resolver', () => {
8687
{
8788
type: 'updateAuthorizedMembers',
8889
params: {
89-
authorized_members: authorizedMembersInput
90+
authorized_members: authorizedMembersInput,
9091
},
9192
},
9293
],
@@ -96,7 +97,7 @@ describe('Workflow Actions Resolver', () => {
9697
});
9798

9899
// 2. Set the workflow definition
99-
await adminQuery({
100+
await queryAsAdmin({
100101
query: WORKFLOW_DEFINITION_SET_MUTATION,
101102
variables: {
102103
entityType: 'DraftWorkspace',
@@ -105,23 +106,23 @@ describe('Workflow Actions Resolver', () => {
105106
});
106107

107108
// 3. Trigger the event
108-
const triggerResult = await adminQuery({
109+
const triggerResult = await queryAsAdmin({
109110
query: TRIGGER_WORKFLOW_EVENT_MUTATION,
110111
variables: {
111112
entityId: draftWorkspaceId,
112113
eventName: 'restrict_event',
113114
},
114115
});
115-
expect(triggerResult.data.triggerWorkflowEvent.success).toBe(true);
116-
expect(triggerResult.data.triggerWorkflowEvent.newState).toBe('restricted');
116+
expect(triggerResult.data?.triggerWorkflowEvent.success).toBe(true);
117+
expect(triggerResult.data?.triggerWorkflowEvent.newState).toBe('restricted');
117118

118119
// 4. Verify authorized members
119-
const workspaceResult = await adminQuery({
120+
const workspaceResult = await queryAsAdmin({
120121
query: DRAFT_WORKSPACE_QUERY,
121122
variables: { id: draftWorkspaceId },
122123
});
123124

124-
const { authorizedMembers } = workspaceResult.data.draftWorkspace;
125+
const { authorizedMembers } = workspaceResult.data?.draftWorkspace || {};
125126
expect(authorizedMembers.length).toBe(2);
126127
expect(authorizedMembers).toEqual(expect.arrayContaining([
127128
expect.objectContaining({ member_id: ADMIN_USER.id, access_right: 'admin' }),
@@ -130,7 +131,7 @@ describe('Workflow Actions Resolver', () => {
130131
});
131132

132133
it('should cleanup after tests', async () => {
133-
await adminQuery({
134+
await queryAsAdmin({
134135
query: WORKFLOW_DEFINITION_DELETE_MUTATION,
135136
variables: {
136137
entityType: 'DraftWorkspace',

opencti-platform/opencti-graphql/tests/03-integration/02-resolvers/workflow-conditions-test.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import gql from 'graphql-tag';
22
import { beforeAll, describe, expect, it } from 'vitest';
3-
import { adminQuery } from '../../utils/testQuery';
3+
import { queryAsAdmin } from '../../utils/testQueryHelper';
44

55
const WORKFLOW_DEFINITION_ADD_MUTATION = gql`
66
mutation WorkflowDefinitionSet($entityType: String!, $definition: String!) {
@@ -68,16 +68,16 @@ describe('Workflow Conditions Resolver', () => {
6868

6969
beforeAll(async () => {
7070
// 1. Create a workspace
71-
const result = await adminQuery({
71+
const result = await queryAsAdmin({
7272
query: CREATE_DRAFT_WORKSPACE_QUERY,
7373
variables: {
7474
input: { name: workspaceName },
7575
},
7676
});
77-
draftWorkspaceId = result.data.draftWorkspaceAdd.id;
77+
draftWorkspaceId = result.data?.draftWorkspaceAdd.id;
7878

7979
// 2. Set the workflow definition
80-
await adminQuery({
80+
await queryAsAdmin({
8181
query: WORKFLOW_DEFINITION_ADD_MUTATION,
8282
variables: {
8383
entityType: 'DraftWorkspace',
@@ -87,38 +87,38 @@ describe('Workflow Conditions Resolver', () => {
8787
});
8888

8989
it('should pass named condition (isAdmin)', async () => {
90-
const result = await adminQuery({
90+
const result = await queryAsAdmin({
9191
query: TRIGGER_WORKFLOW_EVENT_MUTATION,
9292
variables: {
9393
entityId: draftWorkspaceId,
9494
eventName: 'named_condition_event',
9595
},
9696
});
97-
expect(result.data.triggerWorkflowEvent.success).toBe(true);
98-
expect(result.data.triggerWorkflowEvent.newState).toBe('step1');
97+
expect(result.data?.triggerWorkflowEvent.success).toBe(true);
98+
expect(result.data?.triggerWorkflowEvent.newState).toBe('step1');
9999
});
100100

101101
it('should pass field comparison (entity.name eq workspaceName)', async () => {
102-
const result = await adminQuery({
102+
const result = await queryAsAdmin({
103103
query: TRIGGER_WORKFLOW_EVENT_MUTATION,
104104
variables: {
105105
entityId: draftWorkspaceId,
106106
eventName: 'field_comparison_event',
107107
},
108108
});
109-
expect(result.data.triggerWorkflowEvent.success).toBe(true);
110-
expect(result.data.triggerWorkflowEvent.newState).toBe('step2');
109+
expect(result.data?.triggerWorkflowEvent.success).toBe(true);
110+
expect(result.data?.triggerWorkflowEvent.newState).toBe('step2');
111111
});
112112

113113
it('should pass mixed conditions (named + field)', async () => {
114-
const result = await adminQuery({
114+
const result = await queryAsAdmin({
115115
query: TRIGGER_WORKFLOW_EVENT_MUTATION,
116116
variables: {
117117
entityId: draftWorkspaceId,
118118
eventName: 'mixed_conditions_event',
119119
},
120120
});
121-
expect(result.data.triggerWorkflowEvent.success).toBe(true);
122-
expect(result.data.triggerWorkflowEvent.newState).toBe('done');
121+
expect(result.data?.triggerWorkflowEvent.success).toBe(true);
122+
expect(result.data?.triggerWorkflowEvent.newState).toBe('done');
123123
});
124124
});

opencti-platform/opencti-graphql/tests/03-integration/02-resolvers/workflow-test.ts

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import gql from 'graphql-tag';
22
import { beforeAll, describe, expect, it } from 'vitest';
3-
import { adminQuery } from '../../utils/testQuery';
3+
import { queryAsAdmin } from '../../utils/testQueryHelper';
44

55
const WORKFLOW_DEFINITION_ADD_MUTATION = gql`
66
mutation WorkflowDefinitionSet($entityType: String!, $definition: String!) {
@@ -102,7 +102,7 @@ describe('Workflow Resolver', () => {
102102
});
103103

104104
beforeAll(async () => {
105-
const result = await adminQuery({
105+
const result = await queryAsAdmin({
106106
query: CREATE_DRAFT_WORKSPACE_QUERY,
107107
variables: {
108108
input: { name: 'Workflow Test Workspace' },
@@ -111,118 +111,118 @@ describe('Workflow Resolver', () => {
111111
if (result.errors) {
112112
console.error('DraftWorkspaceAdd Error:', JSON.stringify(result.errors, null, 2));
113113
}
114-
draftWorkspaceId = result.data.draftWorkspaceAdd.id;
114+
draftWorkspaceId = result.data?.draftWorkspaceAdd.id;
115115
});
116116

117117
it('should create a workflow definition', async () => {
118-
const result = await adminQuery({
118+
const result = await queryAsAdmin({
119119
query: WORKFLOW_DEFINITION_ADD_MUTATION,
120120
variables: {
121121
entityType: 'DraftWorkspace',
122122
definition: workflowDefinition,
123123
},
124124
});
125-
expect(result.data.workflowDefinitionSet.target_type).toBe('DraftWorkspace');
126-
expect(result.data.workflowDefinitionSet.workflow_id).toBeDefined();
125+
expect(result.data?.workflowDefinitionSet.target_type).toBe('DraftWorkspace');
126+
expect(result.data?.workflowDefinitionSet.workflow_id).toBeDefined();
127127
});
128128

129129
it('should query a workflow definition', async () => {
130-
const result = await adminQuery({
130+
const result = await queryAsAdmin({
131131
query: WORKFLOW_DEFINITION_QUERY,
132132
variables: {
133133
entityType: 'DraftWorkspace',
134134
},
135135
});
136-
expect(result.data.workflowDefinition.initialState).toBe('open');
137-
expect(result.data.workflowDefinition.states.length).toBe(2);
138-
expect(result.data.workflowDefinition.transitions[0].event).toBe('validate_event');
136+
expect(result.data?.workflowDefinition.initialState).toBe('open');
137+
expect(result.data?.workflowDefinition.states.length).toBe(2);
138+
expect(result.data?.workflowDefinition.transitions[0].event).toBe('validate_event');
139139
});
140140

141141
it('should query a workflow instance', async () => {
142-
const instanceResult = await adminQuery({
142+
const instanceResult = await queryAsAdmin({
143143
query: WORKFLOW_INSTANCE_QUERY,
144144
variables: {
145145
entityId: draftWorkspaceId,
146146
},
147147
});
148-
expect(instanceResult.data.workflowInstance.currentState).toBe('open');
149-
expect(instanceResult.data.workflowInstance.allowedTransitions.length).toBe(1);
150-
expect(instanceResult.data.workflowInstance.allowedTransitions[0].event).toBe('validate_event');
151-
expect(instanceResult.data.workflowInstance.allowedTransitions[0].actions).toContain('validateDraft');
148+
expect(instanceResult.data?.workflowInstance.currentState).toBe('open');
149+
expect(instanceResult.data?.workflowInstance.allowedTransitions.length).toBe(1);
150+
expect(instanceResult.data?.workflowInstance.allowedTransitions[0].event).toBe('validate_event');
151+
expect(instanceResult.data?.workflowInstance.allowedTransitions[0].actions).toContain('validateDraft');
152152
});
153153

154154
it('should query a workflow instance via nested draftWorkspace', async () => {
155-
const instanceResult = await adminQuery({
155+
const instanceResult = await queryAsAdmin({
156156
query: WORKFLOW_INSTANCE_NESTED_QUERY,
157157
variables: {
158158
entityId: draftWorkspaceId,
159159
},
160160
});
161-
expect(instanceResult.data.draftWorkspace.workflowInstance.currentState).toBe('open');
162-
expect(instanceResult.data.draftWorkspace.workflowInstance.allowedTransitions.length).toBe(1);
163-
expect(instanceResult.data.draftWorkspace.workflowInstance.allowedTransitions[0].event).toBe('validate_event');
161+
expect(instanceResult.data?.draftWorkspace.workflowInstance.currentState).toBe('open');
162+
expect(instanceResult.data?.draftWorkspace.workflowInstance.allowedTransitions.length).toBe(1);
163+
expect(instanceResult.data?.draftWorkspace.workflowInstance.allowedTransitions[0].event).toBe('validate_event');
164164
});
165165

166166
it('should trigger a workflow event', async () => {
167-
const result = await adminQuery({
167+
const result = await queryAsAdmin({
168168
query: TRIGGER_WORKFLOW_EVENT_MUTATION,
169169
variables: {
170170
entityId: draftWorkspaceId,
171171
eventName: 'validate_event',
172172
},
173173
});
174-
expect(result.data.triggerWorkflowEvent.success).toBe(true);
175-
expect(result.data.triggerWorkflowEvent.newState).toBe('validated');
174+
expect(result.data?.triggerWorkflowEvent.success).toBe(true);
175+
expect(result.data?.triggerWorkflowEvent.newState).toBe('validated');
176176

177177
// Check if the entity was actually updated
178-
const instanceResult = await adminQuery({
178+
const instanceResult = await queryAsAdmin({
179179
query: WORKFLOW_INSTANCE_QUERY,
180180
variables: {
181181
entityId: draftWorkspaceId,
182182
},
183183
});
184-
expect(instanceResult.data.workflowInstance.currentState).toBe('validated');
185-
expect(instanceResult.data.workflowInstance.allowedTransitions.length).toBe(0);
184+
expect(instanceResult.data?.workflowInstance.currentState).toBe('validated');
185+
expect(instanceResult.data?.workflowInstance.allowedTransitions.length).toBe(0);
186186
});
187187

188188
it('should fail to trigger an invalid event', async () => {
189-
const result = await adminQuery({
189+
const result = await queryAsAdmin({
190190
query: TRIGGER_WORKFLOW_EVENT_MUTATION,
191191
variables: {
192192
entityId: draftWorkspaceId,
193193
eventName: 'invalid_event',
194194
},
195195
});
196-
expect(result.data.triggerWorkflowEvent.success).toBe(false);
197-
expect(result.data.triggerWorkflowEvent.reason).toContain('No transition found');
196+
expect(result.data?.triggerWorkflowEvent.success).toBe(false);
197+
expect(result.data?.triggerWorkflowEvent.reason).toContain('No transition found');
198198
});
199199

200200
it('should delete a workflow definition', async () => {
201201
// 1. Delete the workflow definition
202-
const deleteResult = await adminQuery({
202+
const deleteResult = await queryAsAdmin({
203203
query: WORKFLOW_DEFINITION_DELETE_MUTATION,
204204
variables: {
205205
entityType: 'DraftWorkspace',
206206
},
207207
});
208-
expect(deleteResult.data.workflowDefinitionDelete.workflow_id).toBeNull();
208+
expect(deleteResult.data?.workflowDefinitionDelete.workflow_id).toBeNull();
209209

210210
// 2. Check if the definition is gone
211-
const queryResult = await adminQuery({
211+
const queryResult = await queryAsAdmin({
212212
query: WORKFLOW_DEFINITION_QUERY,
213213
variables: {
214214
entityType: 'DraftWorkspace',
215215
},
216216
});
217-
expect(queryResult.data.workflowDefinition).toBeNull();
217+
expect(queryResult.data?.workflowDefinition).toBeNull();
218218

219219
// 3. Check if instance now returns null
220-
const instanceResult = await adminQuery({
220+
const instanceResult = await queryAsAdmin({
221221
query: WORKFLOW_INSTANCE_QUERY,
222222
variables: {
223223
entityId: draftWorkspaceId,
224224
},
225225
});
226-
expect(instanceResult.data.workflowInstance).toBeNull();
226+
expect(instanceResult.data?.workflowInstance).toBeNull();
227227
});
228228
});

0 commit comments

Comments
 (0)