@@ -4,6 +4,7 @@ import { Job } from 'bull';
44
55import { esMapping , esSettings , StateNode , getId } from '@bit/zencrepes.zindexer.testing-states' ;
66import { esMapping as esMappingRuns , esSettings as esSettingsRuns , RunNode , getRunId } from '@bit/zencrepes.zindexer.testing-runs' ;
7+ import { esMapping as esMappingCases , esSettings as esSettingsCases , CaseNode , getCaseId } from './cases' ;
78import { checkEsIndex , pushEsNodes } from '@bit/zencrepes.zindexer.es-utils' ;
89
910import { ConfigService } from '../config.service' ;
@@ -31,7 +32,7 @@ export class TestingStorePayloadProcessor {
3132 await checkEsIndex ( esClient , userConfig . elasticsearch . dataIndices . testingStates , esMapping , esSettings , console . log ) ;
3233
3334 // Transforming the object, objective is just to match to GitHub's to be consistent with the rest of the app
34- const state : StateNode = {
35+ let state : StateNode = {
3536 ...job . data ,
3637 full : job . data . name + '_' + job . data . version ,
3738 dependencies : {
@@ -48,6 +49,12 @@ export class TestingStorePayloadProcessor {
4849 }
4950 }
5051
52+ // Cases is a more recent addition, it should not be present in the state, not to pollute the index
53+ // with unnecessary data
54+ if ( ( state as any ) . cases !== undefined ) {
55+ delete ( state as any ) . cases ;
56+ }
57+
5158 // Push single document to Elasticsearch
5259 await pushEsNodes ( esClient , userConfig . elasticsearch . dataIndices . testingStates , [ state ] , console . log ) ;
5360
@@ -58,7 +65,7 @@ export class TestingStorePayloadProcessor {
5865 await checkEsIndex ( esClient , userConfig . elasticsearch . dataIndices . testingRuns , esMappingRuns , esSettingsRuns , console . log ) ;
5966
6067 // Transforming the object, objective is just to match to GitHub's to be consistent with the rest of the app
61- const run : RunNode = {
68+ let run : RunNode = {
6269 ...job . data ,
6370 id : getRunId ( job . data ) ,
6471 full : job . data . name + '_' + job . data . version ,
@@ -78,8 +85,39 @@ export class TestingStorePayloadProcessor {
7885 }
7986 }
8087
88+ // Cases is a more recent addition, it should not be present in the state, not to pollute the index
89+ // with unnecessary data
90+ if ( ( run as any ) . cases !== undefined ) {
91+ delete ( run as any ) . cases ;
92+ }
93+
8194 // Push single document to Elasticsearch
8295 await pushEsNodes ( esClient , userConfig . elasticsearch . dataIndices . testingRuns , [ run ] , console . log ) ;
8396
97+ if ( job . data . cases !== undefined && job . data . cases . length > 0 ) {
98+ // Check if the index exists, create it if it does not
99+ await checkEsIndex ( esClient , userConfig . elasticsearch . dataIndices . testingCases , esMappingCases , esSettingsCases , console . log ) ;
100+
101+ // Populating testing Cases
102+ this . logger . log ( `Event for: ${ job . data . name } , version: ${ job . data . version } - Pushing ${ job . data . cases . length } Cases` ) ;
103+
104+ const cases : CaseNode [ ] = job . data . cases . map ( ( c ) => {
105+ const caseObj = {
106+ ...c ,
107+ id : getCaseId ( c ) ,
108+ full : c . suite + ' - ' + c . name ,
109+ runId : run . id ,
110+ url : run . url ,
111+ caseSuccessRate : Math . round ( c . caseSuccess * 100 / c . caseTotal ) ,
112+ caseFailureRate : Math . round ( c . caseFailure * 100 / c . caseTotal ) ,
113+ project : run . name
114+ }
115+ return caseObj
116+ } )
117+
118+ // Push single document to Elasticsearch
119+ await pushEsNodes ( esClient , userConfig . elasticsearch . dataIndices . testingCases , cases , console . log ) ;
120+
121+ }
84122 }
85123}
0 commit comments