@@ -6,7 +6,15 @@ import express from 'express';
6
6
7
7
import { setupServer } from './index.ts' ;
8
8
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
+ > = { } ;
10
18
11
19
export function assertPushMockValid ( expectedCount : number ) : void {
12
20
if ( Object . values ( pushMockState ) . length !== expectedCount ) {
@@ -20,6 +28,8 @@ export function assertPushMockValid(expectedCount: number): void {
20
28
}
21
29
22
30
expect ( state ) . to . deep . equal ( {
31
+ retriedHosts : true ,
32
+ retriedEvents : true ,
23
33
saveObjectsWithTransformation : Number ( numberOfTestSuites ) ,
24
34
partialUpdateObjectsWithTransformation : Number ( numberOfTestSuites ) ,
25
35
} ) ;
@@ -40,7 +50,16 @@ function addRoutes(app: Express): void {
40
50
const lang = match ?. [ 2 ] as string ;
41
51
42
52
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 ;
44
63
}
45
64
46
65
pushMockState [ lang ] [ helper ] = ( pushMockState [ lang ] [ helper ] ?? 0 ) + 1 ;
@@ -55,7 +74,7 @@ function addRoutes(app: Express): void {
55
74
} ) ;
56
75
57
76
res . json ( {
58
- runID : ' b1b7a982-524c-40d2-bb7f-48aab075abda' ,
77
+ runID : ` b1b7a982-524c-40d2-bb7f-48aab075abda_ ${ lang } ` ,
59
78
eventID : '113b2068-6337-4c85-b5c2-e7b213d82925' ,
60
79
message : 'OK' ,
61
80
createdAt : '2022-05-12T06:24:30.049Z' ,
@@ -72,7 +91,7 @@ function addRoutes(app: Express): void {
72
91
} ) ;
73
92
74
93
res . json ( {
75
- runID : ' b1b7a982-524c-40d2-bb7f-48aab075abda' ,
94
+ runID : ` b1b7a982-524c-40d2-bb7f-48aab075abda_ ${ lang } ` ,
76
95
eventID : '113b2068-6337-4c85-b5c2-e7b213d82925' ,
77
96
message : 'OK' ,
78
97
createdAt : '2022-05-12T06:24:30.049Z' ,
@@ -82,8 +101,32 @@ function addRoutes(app: Express): void {
82
101
throw new Error ( 'unknown helper' ) ;
83
102
}
84
103
} ) ;
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 ) ;
85
128
}
86
129
87
130
export function pushMockServer ( ) : Promise < Server > {
88
- return setupServer ( 'pushMock' , 6689 , addRoutes ) ;
131
+ return setupServer ( 'pushMock' , 6688 , addRoutes ) ;
89
132
}
0 commit comments