11import gql from 'graphql-tag' ;
2- import { describe , expect , it } from 'vitest' ;
2+ import { afterAll , beforeAll , describe , expect , it } from 'vitest' ;
33import { queryAsAdmin } from '../../utils/testQuery' ;
44import { queryAsAdminWithSuccess } from '../../utils/testQueryHelper' ;
55
@@ -11,9 +11,29 @@ const READ_QUERY = gql`
1111 }
1212` ;
1313
14+ const CREATE_REL_QUERY = gql `
15+ mutation StixDomainRelationAdd($input: StixCoreRelationshipAddInput!) {
16+ stixCoreRelationshipAdd(input: $input) {
17+ id
18+ fromType
19+ toType
20+ }
21+ }
22+ ` ;
23+
1424const CREATE_MUTATION = gql `
15- mutation StixCyberObservableAdd($type: String!, $input: IMEIAddInput) {
16- stixCyberObservableAdd(type: $type, IMEI: $input) {
25+ mutation StixCyberObservableAdd(
26+ $type: String!,
27+ $imei: IMEIAddInput,
28+ $iccid: ICCIDAddInput,
29+ $macAddress: MacAddrAddInput,
30+ ) {
31+ stixCyberObservableAdd(
32+ type: $type,
33+ IMEI: $imei,
34+ ICCID: $iccid,
35+ MacAddr: $macAddress,
36+ ) {
1737 id
1838 observable_value
1939 }
@@ -43,49 +63,116 @@ describe('SCO IMEI resolver standard behavior', () => {
4363 let internalId : string ;
4464
4565 it ( 'should not create invalid IMEI' , async ( ) => {
46- const response = await queryAsAdmin ( {
66+ const { errors } = await queryAsAdmin ( {
4767 query : CREATE_MUTATION ,
4868 variables : {
4969 type : 'IMEI' ,
50- input : { value : 'ABC123' } ,
70+ imei : { value : 'ABC123' } ,
5171 } ,
5272 } ) ;
53- expect ( response ?. errors ?. [ 0 ] . message ) . toEqual ( 'Observable is not correctly formatted' ) ;
73+ expect ( errors ?. [ 0 ] . message ) . toEqual ( 'Observable is not correctly formatted' ) ;
5474 } ) ;
5575
5676 it ( 'should create IMEI' , async ( ) => {
57- const response = await queryAsAdmin ( {
77+ const { data } = await queryAsAdmin ( {
5878 query : CREATE_MUTATION ,
5979 variables : {
6080 type : 'IMEI' ,
61- input : { value : '112222223333334' } ,
81+ imei : { value : '112222223333334' } ,
6282 } ,
6383 } ) ;
64- expect ( response . data ?. stixCyberObservableAdd ) . not . toBeNull ( ) ;
65- expect ( response . data ?. stixCyberObservableAdd . observable_value ) . toEqual ( '112222223333334' ) ;
66- internalId = response . data ?. stixCyberObservableAdd . id ?? '' ;
84+ expect ( data ?. stixCyberObservableAdd ) . not . toBeNull ( ) ;
85+ expect ( data ?. stixCyberObservableAdd . observable_value ) . toEqual ( '112222223333334' ) ;
86+ internalId = data ?. stixCyberObservableAdd . id ?? '' ;
6787 } ) ;
6888
6989 it ( 'should not update invalid IMEI' , async ( ) => {
70- const response = await queryAsAdmin ( {
90+ const { errors } = await queryAsAdmin ( {
7191 query : UPDATE_MUTATION ,
7292 variables : {
7393 id : internalId ,
7494 input : { key : 'value' , value : 'ABC123' } ,
7595 } ,
7696 } ) ;
77- expect ( response . errors ?. [ 0 ] . message ) . toEqual ( 'Observable of is not correctly formatted' ) ;
97+ expect ( errors ?. [ 0 ] . message ) . toEqual ( 'Observable of is not correctly formatted' ) ;
7898 } ) ;
7999
80100 it ( 'should update IMEI' , async ( ) => {
81- const response = await queryAsAdminWithSuccess ( {
101+ const { data } = await queryAsAdminWithSuccess ( {
82102 query : UPDATE_MUTATION ,
83103 variables : {
84104 id : internalId ,
85105 input : { key : 'value' , value : '112222223333335' } ,
86106 } ,
87107 } ) ;
88- expect ( response . data ?. stixCyberObservableEdit . fieldPatch . observable_value ) . toEqual ( '112222223333335' ) ;
108+ expect ( data ?. stixCyberObservableEdit . fieldPatch . observable_value ) . toEqual ( '112222223333335' ) ;
109+ } ) ;
110+
111+ describe ( 'Relationships section' , ( ) => {
112+ let macAddressId : string ;
113+ let iccidInternalId : string ;
114+
115+ beforeAll ( async ( ) => {
116+ const { data : dataIccid } = await queryAsAdmin ( {
117+ query : CREATE_MUTATION ,
118+ variables : {
119+ type : 'ICCID' ,
120+ iccid : { value : '123456789012345999' } ,
121+ } ,
122+ } ) ;
123+ const { data : dataMacAddress } = await queryAsAdmin ( {
124+ query : CREATE_MUTATION ,
125+ variables : {
126+ type : 'Mac-Addr' ,
127+ macAddress : { value : '00:1b:63:84:45:e6' } ,
128+ } ,
129+ } ) ;
130+ iccidInternalId = dataIccid ?. stixCyberObservableAdd . id ?? '' ;
131+ macAddressId = dataMacAddress ?. stixCyberObservableAdd . id ?? '' ;
132+ } ) ;
133+
134+ afterAll ( async ( ) => {
135+ await queryAsAdmin ( {
136+ query : DELETE_MUTATION ,
137+ variables : { id : iccidInternalId } ,
138+ } ) ;
139+ await queryAsAdmin ( {
140+ query : DELETE_MUTATION ,
141+ variables : { id : macAddressId } ,
142+ } ) ;
143+ } ) ;
144+
145+ it ( 'should create a rel "uses" between IMEI and ICCID' , async ( ) => {
146+ const { data } = await queryAsAdminWithSuccess ( {
147+ query : CREATE_REL_QUERY ,
148+ variables : {
149+ input : {
150+ fromId : internalId ,
151+ toId : iccidInternalId ,
152+ relationship_type : 'uses' ,
153+ } ,
154+ } ,
155+ } ) ;
156+ expect ( data ?. stixCoreRelationshipAdd ) . not . toBeNull ( ) ;
157+ expect ( data ?. stixCoreRelationshipAdd . fromType ) . toEqual ( 'IMEI' ) ;
158+ expect ( data ?. stixCoreRelationshipAdd . toType ) . toEqual ( 'ICCID' ) ;
159+ } ) ;
160+
161+ it ( 'should create a rel "has" between IMEI and Mac-Addr' , async ( ) => {
162+ const { data } = await queryAsAdminWithSuccess ( {
163+ query : CREATE_REL_QUERY ,
164+ variables : {
165+ input : {
166+ fromId : internalId ,
167+ toId : macAddressId ,
168+ relationship_type : 'has' ,
169+ } ,
170+ } ,
171+ } ) ;
172+ expect ( data ?. stixCoreRelationshipAdd ) . not . toBeNull ( ) ;
173+ expect ( data ?. stixCoreRelationshipAdd . fromType ) . toEqual ( 'IMEI' ) ;
174+ expect ( data ?. stixCoreRelationshipAdd . toType ) . toEqual ( 'Mac-Addr' ) ;
175+ } ) ;
89176 } ) ;
90177
91178 it ( 'should delete IMEI' , async ( ) => {
0 commit comments