@@ -6,7 +6,15 @@ import express from 'express';
66
77import { setupServer } from './index.ts' ;
88
9- const pushMockState : Record < string , any > = { } ;
9+ const pushMockState : Record <
10+ string ,
11+ {
12+ retriedEvents : boolean ;
13+ retriedHosts : boolean ;
14+ saveObjectsWithTransformation : number ;
15+ partialUpdateObjectsWithTransformation : number ;
16+ }
17+ > = { } ;
1018
1119export function assertPushMockValid ( expectedCount : number ) : void {
1220 if ( Object . values ( pushMockState ) . length !== expectedCount ) {
@@ -20,6 +28,8 @@ export function assertPushMockValid(expectedCount: number): void {
2028 }
2129
2230 expect ( state ) . to . deep . equal ( {
31+ retriedHosts : true ,
32+ retriedEvents : true ,
2333 saveObjectsWithTransformation : Number ( numberOfTestSuites ) ,
2434 partialUpdateObjectsWithTransformation : Number ( numberOfTestSuites ) ,
2535 } ) ;
@@ -40,7 +50,16 @@ function addRoutes(app: Express): void {
4050 const lang = match ?. [ 2 ] as string ;
4151
4252 if ( ! pushMockState [ lang ] ) {
43- pushMockState [ lang ] = { } ;
53+ // simulate a retry at the hosts level
54+ pushMockState [ lang ] = {
55+ retriedHosts : true ,
56+ retriedEvents : false ,
57+ saveObjectsWithTransformation : 0 ,
58+ partialUpdateObjectsWithTransformation : 0 ,
59+ } ;
60+
61+ res . status ( 500 ) . json ( { message : 'error test server response' } ) ;
62+ return ;
4463 }
4564
4665 pushMockState [ lang ] [ helper ] = ( pushMockState [ lang ] [ helper ] ?? 0 ) + 1 ;
@@ -55,7 +74,7 @@ function addRoutes(app: Express): void {
5574 } ) ;
5675
5776 res . json ( {
58- runID : ' b1b7a982-524c-40d2-bb7f-48aab075abda' ,
77+ runID : ` b1b7a982-524c-40d2-bb7f-48aab075abda_ ${ lang } ` ,
5978 eventID : '113b2068-6337-4c85-b5c2-e7b213d82925' ,
6079 message : 'OK' ,
6180 createdAt : '2022-05-12T06:24:30.049Z' ,
@@ -72,7 +91,7 @@ function addRoutes(app: Express): void {
7291 } ) ;
7392
7493 res . json ( {
75- runID : ' b1b7a982-524c-40d2-bb7f-48aab075abda' ,
94+ runID : ` b1b7a982-524c-40d2-bb7f-48aab075abda_ ${ lang } ` ,
7695 eventID : '113b2068-6337-4c85-b5c2-e7b213d82925' ,
7796 message : 'OK' ,
7897 createdAt : '2022-05-12T06:24:30.049Z' ,
@@ -82,8 +101,32 @@ function addRoutes(app: Express): void {
82101 throw new Error ( 'unknown helper' ) ;
83102 }
84103 } ) ;
104+
105+ app . get ( '/1/runs/:runID/events/:eventID' , ( req , res ) => {
106+ const lang = req . params . runID . match ( / ^ b 1 b 7 a 9 8 2 - 5 2 4 c - 4 0 d 2 - b b 7 f - 4 8 a a b 0 7 5 a b d a _ ( .* ) $ / ) ?. [ 1 ] as string ;
107+
108+ if ( pushMockState [ lang ] && ! pushMockState [ lang ] ?. retriedEvents ) {
109+ pushMockState [ lang ] . retriedEvents = true ;
110+ res . status ( 404 ) . json ( { message : 'error test server response' } ) ;
111+
112+ return ;
113+ }
114+
115+ res . json ( {
116+ status : 'succeeded' ,
117+ eventID : req . params . eventID ,
118+ runID : req . params . runID ,
119+ type : 'fetch' ,
120+ batchSize : 1 ,
121+ publishedAt : '2022-05-12T06:24:30.049Z' ,
122+ } ) ;
123+ } ) ;
124+ }
125+
126+ export function pushMockServerRetriedOnce ( ) : Promise < Server > {
127+ return setupServer ( 'pushMockRetriedOnce' , 6689 , addRoutes ) ;
85128}
86129
87130export function pushMockServer ( ) : Promise < Server > {
88- return setupServer ( 'pushMock' , 6689 , addRoutes ) ;
131+ return setupServer ( 'pushMock' , 6688 , addRoutes ) ;
89132}
0 commit comments