1
1
import { describe , it , expect } from 'vitest' ;
2
2
import gql from 'graphql-tag' ;
3
- import { queryAsAdmin } from '../../utils/testQuery' ;
3
+ import { ADMIN_USER , queryAsAdmin } from '../../utils/testQuery' ;
4
4
import type { CaseIncident } from '../../../src/generated/graphql' ;
5
+ import { ENTITY_TYPE_CONTAINER_CASE_INCIDENT } from '../../../src/modules/case/case-incident/case-incident-types' ;
5
6
6
- describe ( 'Case Incident Response resolver standard behavior' , ( ) => {
7
- let caseIncidentResponse : CaseIncident ;
7
+ const CREATE_QUERY = gql `
8
+ mutation CaseIncidentAdd($input: CaseIncidentAddInput!) {
9
+ caseIncidentAdd(input: $input){
10
+ id
11
+ standard_id
12
+ name
13
+ description
14
+ authorized_members {
15
+ id
16
+ access_right
17
+ }
18
+ }
19
+ }
20
+ ` ;
8
21
9
- const READ_QUERY = gql `
10
- query caseIncident($id: String!) {
11
- caseIncident(id: $id) {
22
+ const READ_QUERY = gql `
23
+ query caseIncident($id: String!) {
24
+ caseIncident(id: $id) {
25
+ id
26
+ standard_id
27
+ name
28
+ description
29
+ toStix
30
+ authorized_members {
12
31
id
13
- standard_id
14
- name
15
- description
16
- toStix
17
- authorized_members {
18
- id
19
- }
20
32
}
21
33
}
34
+ }
35
+ ` ;
36
+
37
+ const DELETE_QUERY = gql `
38
+ mutation CaseIncidentDelete($id: ID!) {
39
+ caseIncidentDelete(id: $id)
40
+ }
22
41
` ;
23
42
43
+ describe ( 'Case Incident Response resolver standard behavior' , ( ) => {
44
+ let caseIncidentResponse : CaseIncident ;
24
45
it ( 'should Case Incident Response created' , async ( ) => {
25
- const CREATE_QUERY = gql `
26
- mutation CaseIncidentAdd($input: CaseIncidentAddInput!) {
27
- caseIncidentAdd(input: $input){
28
- id
29
- standard_id
30
- name
31
- description
32
- authorized_members {
33
- id
34
- }
35
- }
36
- }
37
- ` ;
38
46
const caseIncidentResponseData = await queryAsAdmin ( {
39
47
query : CREATE_QUERY ,
40
48
variables : {
@@ -45,6 +53,7 @@ describe('Case Incident Response resolver standard behavior', () => {
45
53
} ) ;
46
54
expect ( caseIncidentResponseData ) . not . toBeNull ( ) ;
47
55
expect ( caseIncidentResponseData ?. data ?. caseIncidentAdd . authorized_members ) . not . toBeUndefined ( ) ;
56
+ expect ( caseIncidentResponseData ?. data ?. caseIncidentAdd . authorized_members ) . toEqual ( [ ] ) ; // authorized members not activated
48
57
caseIncidentResponse = caseIncidentResponseData ?. data ?. caseIncidentAdd ;
49
58
} ) ;
50
59
it ( 'should Case Incident Response loaded by internal id' , async ( ) => {
@@ -111,12 +120,8 @@ describe('Case Incident Response resolver standard behavior', () => {
111
120
} ) ;
112
121
expect ( queryResult ?. data ?. stixDomainObjectEdit . fieldPatch . name ) . toEqual ( 'Case - updated' ) ;
113
122
} ) ;
123
+ // TODO ADD context test even if i don't understand what it is?
114
124
it ( 'should Case Incident Response deleted' , async ( ) => {
115
- const DELETE_QUERY = gql `
116
- mutation CaseIncidentDelete($id: ID!) {
117
- caseIncidentDelete(id: $id)
118
- }
119
- ` ;
120
125
// Delete the case
121
126
await queryAsAdmin ( {
122
127
query : DELETE_QUERY ,
@@ -128,3 +133,84 @@ describe('Case Incident Response resolver standard behavior', () => {
128
133
expect ( queryResult ?. data ?. caseIncident ) . toBeNull ( ) ;
129
134
} ) ;
130
135
} ) ;
136
+
137
+ describe ( 'Case Incident Response authorized_members standard behavior' , ( ) => {
138
+ let caseIncidentResponseAuthorizedMembers : CaseIncident ;
139
+ it ( 'should Case Incident Response created with authorized_members activated via settings' , async ( ) => {
140
+ // Activate authorized members for IR
141
+ const ENTITY_SETTINGS_READ_QUERY_BY_TARGET_TYPE = gql `
142
+ query entitySettingsByTargetType($targetType: String!) {
143
+ entitySettingByType(targetType: $targetType) {
144
+ id
145
+ target_type
146
+ platform_entity_files_ref
147
+ platform_hidden_type
148
+ enforce_reference
149
+ }
150
+ }
151
+ ` ;
152
+
153
+ const ENTITY_SETTINGS_UPDATE_QUERY = gql `
154
+ mutation entitySettingsEdit($ids: [ID!]!, $input: [EditInput!]!) {
155
+ entitySettingsFieldPatch(ids: $ids, input: $input) {
156
+ id
157
+ target_type
158
+ platform_entity_files_ref
159
+ platform_hidden_type
160
+ enforce_reference
161
+ attributes_configuration
162
+ }
163
+ }
164
+ ` ;
165
+
166
+ const caseIncidentResponseSettingsQueryResult = await queryAsAdmin ( {
167
+ query : ENTITY_SETTINGS_READ_QUERY_BY_TARGET_TYPE ,
168
+ variables : { targetType : ENTITY_TYPE_CONTAINER_CASE_INCIDENT }
169
+ } ) ;
170
+ expect ( caseIncidentResponseSettingsQueryResult . data ?. entitySettingByType . target_type ) . toEqual ( ENTITY_TYPE_CONTAINER_CASE_INCIDENT ) ;
171
+ const caseIncidentEntitySetting = caseIncidentResponseSettingsQueryResult . data ?. entitySettingByType ;
172
+
173
+ const authorizedMembersConfiguration = JSON . stringify ( [ { name : 'authorized_members' , default_values : [ { id : ADMIN_USER . id , access_right : 'admin' } ] } ] ) ;
174
+
175
+ const updateEntitySettingsResult = await queryAsAdmin ( {
176
+ query : ENTITY_SETTINGS_UPDATE_QUERY ,
177
+ variables : { ids : [ caseIncidentEntitySetting . id ] , input : { key : 'attributes_configuration' , value : [ authorizedMembersConfiguration ] } } ,
178
+ } ) ;
179
+ expect ( updateEntitySettingsResult . data ?. entitySettingsFieldPatch [ 0 ] . attribute_configuration ) . toEqual ( [ authorizedMembersConfiguration ] ) ;
180
+
181
+ const caseIncidentResponseAuthorizedMembersData = await queryAsAdmin ( {
182
+ query : CREATE_QUERY ,
183
+ variables : {
184
+ input : {
185
+ name : 'Case Incident Response With Authorized Members'
186
+ }
187
+ }
188
+ } ) ;
189
+ expect ( caseIncidentResponseAuthorizedMembersData ) . not . toBeNull ( ) ;
190
+ expect ( caseIncidentResponseAuthorizedMembersData ?. data ?. caseIncidentAdd . authorized_members ) . not . toBeUndefined ( ) ;
191
+ expect ( caseIncidentResponseAuthorizedMembersData ?. data ?. caseIncidentAdd . authorized_members ) . toEqual ( [
192
+ {
193
+ id : ADMIN_USER . id ,
194
+ name : ADMIN_USER . name ,
195
+ access_right : 'admin'
196
+ }
197
+ ] ) ;
198
+ caseIncidentResponseAuthorizedMembers = caseIncidentResponseAuthorizedMembersData ?. data ?. caseIncidentAdd ;
199
+ // Clean
200
+ await queryAsAdmin ( {
201
+ query : ENTITY_SETTINGS_UPDATE_QUERY ,
202
+ variables : { ids : [ caseIncidentEntitySetting . id ] , input : { key : 'attributes_configuration' , value : [ ] } } ,
203
+ } ) ;
204
+ } ) ;
205
+ it ( 'should Case Incident Response deleted' , async ( ) => {
206
+ // Delete the case
207
+ await queryAsAdmin ( {
208
+ query : DELETE_QUERY ,
209
+ variables : { id : caseIncidentResponseAuthorizedMembers . id } ,
210
+ } ) ;
211
+ // Verify is no longer found
212
+ const queryResult = await queryAsAdmin ( { query : READ_QUERY , variables : { id : caseIncidentResponseAuthorizedMembers . id } } ) ;
213
+ expect ( queryResult ) . not . toBeNull ( ) ;
214
+ expect ( queryResult ?. data ?. caseIncident ) . toBeNull ( ) ;
215
+ } ) ;
216
+ } ) ;
0 commit comments