1
1
import { describe , it , expect } from 'vitest' ;
2
2
import gql from 'graphql-tag' ;
3
3
import { queryAsAdmin } from '../../utils/testQuery' ;
4
+ import type { CaseIncident } from '../../../src/generated/graphql' ;
4
5
5
6
describe ( 'Case Incident Response resolver standard behavior' , ( ) => {
6
- let caseIncidentResponseId = '' ;
7
+ let caseIncidentResponse : CaseIncident ;
7
8
8
9
const READ_QUERY = gql `
9
10
query caseIncident($id: String!) {
@@ -44,7 +45,71 @@ describe('Case Incident Response resolver standard behavior', () => {
44
45
} ) ;
45
46
expect ( caseIncidentResponseData ) . not . toBeNull ( ) ;
46
47
expect ( caseIncidentResponseData ?. data ?. caseIncidentAdd . authorized_members ) . not . toBeUndefined ( ) ;
47
- caseIncidentResponseId = caseIncidentResponseData ?. data ?. caseIncidentAdd . id ;
48
+ caseIncidentResponse = caseIncidentResponseData ?. data ?. caseIncidentAdd ;
49
+ } ) ;
50
+ it ( 'should Case Incident Response loaded by internal id' , async ( ) => {
51
+ const queryResult = await queryAsAdmin ( { query : READ_QUERY , variables : { id : caseIncidentResponse . id } } ) ;
52
+ expect ( queryResult ) . not . toBeNull ( ) ;
53
+ expect ( queryResult ?. data ?. caseIncident ) . not . toBeNull ( ) ;
54
+ expect ( queryResult ?. data ?. caseIncident . id ) . toEqual ( caseIncidentResponse . id ) ;
55
+ expect ( queryResult ?. data ?. caseIncident . toStix . length ) . toBeGreaterThan ( 5 ) ;
56
+ } ) ;
57
+ it ( 'should Case Incident Response loaded by standard id' , async ( ) => {
58
+ const queryResult = await queryAsAdmin ( { query : READ_QUERY , variables : { id : caseIncidentResponse . standard_id } } ) ;
59
+ expect ( queryResult ) . not . toBeNull ( ) ;
60
+ expect ( queryResult ?. data ?. caseIncident ) . not . toBeNull ( ) ;
61
+ expect ( queryResult ?. data ?. caseIncident . id ) . toEqual ( caseIncidentResponse . id ) ;
62
+ } ) ;
63
+ it ( 'should list Case Incident Response' , async ( ) => {
64
+ const LIST_QUERY = gql `
65
+ query caseIncidents(
66
+ $first: Int
67
+ $after: ID
68
+ $orderBy: CaseIncidentsOrdering
69
+ $orderMode: OrderingMode
70
+ $filters: FilterGroup
71
+ $search: String
72
+ $toStix: Boolean
73
+ ) {
74
+ caseIncidents(
75
+ first: $first
76
+ after: $after
77
+ orderBy: $orderBy
78
+ orderMode: $orderMode
79
+ filters: $filters
80
+ search: $search
81
+ toStix: $toStix
82
+ ) {
83
+ edges {
84
+ node {
85
+ id
86
+ standard_id
87
+ }
88
+ }
89
+ }
90
+ }
91
+ ` ;
92
+ const queryResult = await queryAsAdmin ( { query : LIST_QUERY , variables : { first : 10 } } ) ;
93
+ expect ( queryResult ?. data ?. caseIncidents . edges . length ) . toEqual ( 1 ) ;
94
+ } ) ;
95
+ it ( 'should update case' , async ( ) => {
96
+ const UPDATE_QUERY = gql `
97
+ mutation CaseIncident($id: ID!, $input: [EditInput]!) {
98
+ stixDomainObjectEdit(id: $id) {
99
+ fieldPatch(input: $input) {
100
+ id
101
+ ... on Case {
102
+ name
103
+ }
104
+ }
105
+ }
106
+ }
107
+ ` ;
108
+ const queryResult = await queryAsAdmin ( {
109
+ query : UPDATE_QUERY ,
110
+ variables : { id : caseIncidentResponse . id , input : { key : 'name' , value : [ 'Case - updated' ] } } ,
111
+ } ) ;
112
+ expect ( queryResult ?. data ?. stixDomainObjectEdit . fieldPatch . name ) . toEqual ( 'Case - updated' ) ;
48
113
} ) ;
49
114
it ( 'should Case Incident Response deleted' , async ( ) => {
50
115
const DELETE_QUERY = gql `
@@ -55,10 +120,10 @@ describe('Case Incident Response resolver standard behavior', () => {
55
120
// Delete the case
56
121
await queryAsAdmin ( {
57
122
query : DELETE_QUERY ,
58
- variables : { id : caseIncidentResponseId } ,
123
+ variables : { id : caseIncidentResponse . id } ,
59
124
} ) ;
60
125
// Verify is no longer found
61
- const queryResult = await queryAsAdmin ( { query : READ_QUERY , variables : { id : caseIncidentResponseId } } ) ;
126
+ const queryResult = await queryAsAdmin ( { query : READ_QUERY , variables : { id : caseIncidentResponse . id } } ) ;
62
127
expect ( queryResult ) . not . toBeNull ( ) ;
63
128
expect ( queryResult ?. data ?. caseIncident ) . toBeNull ( ) ;
64
129
} ) ;
0 commit comments