import { CommentSchemaType , ContextTypeGeneratedAlertType , createAlertsString , isCommentGeneratedAlert , transformConnectorComment , } from '../../../../plugins/cases/server/connectors' ; import { CasePostRequest , CaseResponse , CasesFindResponse , CommentResponse , ConnectorTypes , CommentRequestUserType , CommentRequestAlertType , CommentType , CaseStatuses , CaseType , CasesClientPostRequest , SubCaseResponse , AssociationType , SubCasesFindResponse , CommentRequest , CommentRequestActionsType , } from '../../../../plugins/cases/common/api' ; export const defaultUser = { email : null , full_name : null , username : 'elastic' } ; /**
 * A null filled user will occur when the security plugin is disabled
 */ export const nullUser = { email : null , full_name : null , username : null } ; export const postCaseReq = { description : 'This is a brand new case of a bad meanie defacing data' , title : 'Super Bad Security Issue' , tags : [ 'defacement' ] , connector : { id : 'none' , name : 'none' , type : ConnectorTypes . none , fields : null , } , settings : { syncAlerts : true , } , owner : 'securitySolutionFixture' , } ; /**
 * Return a request for creating a case.
 */ export const getPostCaseRequest = ( req ? ) : CasePostRequest => ( { ... postCaseReq , ... req , } ) ; /**
 * The fields for creating a collection style case.
 */ export const postCollectionReq = { ... postCaseReq , type : CaseType . collection , } ; /**
 * This is needed because the post api does not allow specifying the case type. But the response will include the type.
 */ export const userActionPostResp = { ... postCaseReq , type : CaseType . individual , } ; export const postCommentUserReq = { comment : 'This is a cool comment' , type : CommentType . user , owner : 'securitySolutionFixture' , } ; export const postCommentAlertReq = { alertId : 'test-id' , index : 'test-index' , rule : { id : 'test-rule-id' , name : 'test-index-id' } , type : CommentType . alert , owner : 'securitySolutionFixture' , } ; export const postCommentActionsReq = { comment : 'comment text' , actions : { targets : [ { hostname : 'host-name' , endpointId : 'endpoint-id' , } , ] , type : 'isolate' , } , type : CommentType . actions , owner : 'securitySolutionFixture' , } ; export const postCommentGenAlertReq = { alerts : createAlertsString ( [ { _id : 'test-id' , _index : 'test-index' , ruleId : 'rule-id' , ruleName : 'rule name' } , { _id : 'test-id2' , _index : 'test-index' , ruleId : 'rule-id' , ruleName : 'rule name' } , ] ) , type : CommentType . generatedAlert , owner : 'securitySolutionFixture' , } ; export const postCaseResp = ( id ? , req = postCaseReq ) : Partial < CaseResponse > => ( { ... req , ... ( id != null ? { id } : { } ) , comments : [ ] , totalAlerts : 0 , totalComment : 0 , type : req . type ?? CaseType . individual , closed_by : null , created_by : defaultUser , external_service : null , status : CaseStatuses . open , updated_by : null , } ) ; interface CommentRequestWithID { id : string ; comment : CommentSchemaType | CommentRequest ; } export const commentsResp = ( { comments , associationType , } ) : Array < Partial < CommentResponse > > => { return comments . map ( ( { comment , id } ) => { const baseFields = { id , created_by : defaultUser , pushed_at : null , pushed_by : null , updated_by : null , } ; if ( isCommentGeneratedAlert ( comment ) ) { return { associationType , ... transformConnectorComment ( comment ) , ... baseFields , } ; } else { return { associationType , ... comment , ... baseFields , } ; } } ) ; } ; export const subCaseResp = ( { id , totalAlerts , totalComment , status = CaseStatuses . open , } ) : Partial < SubCaseResponse > => ( { status , id , totalAlerts , totalComment , closed_by : null , created_by : defaultUser , updated_by : defaultUser , } ) ; const findCommon = { page : 1 , per_page : 20 , total : 0 , count_open_cases : 0 , count_closed_cases : 0 , count_in_progress_cases : 0 , } ; export const findCasesResp = { ... findCommon , cases : [ ] , } ; export const findSubCasesResp = { ... findCommon , subCases : [ ] , } ;