@@ -43,6 +43,11 @@ func TestRootEndpointReturnsServiceMetadata(t *testing.T) {
4343 if ! containsRoute (routes , "/bench/write" ) {
4444 t .Fatalf ("expected benchmark route in metadata, got %#v" , routes )
4545 }
46+ for _ , route := range []string {"/log" , "/api/v1/log" , "/api/v2/log" } {
47+ if ! containsRoute (routes , route ) {
48+ t .Fatalf ("expected route %q in metadata, got %#v" , route , routes )
49+ }
50+ }
4651}
4752
4853func TestHealthzReportsReadyWhenRedisReachable (t * testing.T ) {
@@ -108,6 +113,10 @@ func TestScriptRouteServesJavaScriptAsset(t *testing.T) {
108113 t .Fatalf ("expected CORS header, got %q" , recorder .Header ().Get ("Access-Control-Allow-Origin" ))
109114 }
110115
116+ if recorder .Header ().Get ("Access-Control-Allow-Credentials" ) != "" {
117+ t .Fatalf ("expected credentialless CORS, got %q" , recorder .Header ().Get ("Access-Control-Allow-Credentials" ))
118+ }
119+
111120 if recorder .Body .String () != scriptContents {
112121 t .Fatalf ("expected script contents %q, got %q" , scriptContents , recorder .Body .String ())
113122 }
@@ -141,6 +150,36 @@ func TestV1RoutesKeepPlainJSONResponseShape(t *testing.T) {
141150 }
142151}
143152
153+ func TestV1PostRoutesKeepPlainJSONResponseShape (t * testing.T ) {
154+ handler := newTestHandler (t , mustStartMiniRedis (t ).Addr ())
155+
156+ for _ , path := range []string {"/log" , "/api/v1/log" } {
157+ t .Run (path , func (t * testing.T ) {
158+ recorder := httptest .NewRecorder ()
159+ request := httptest .NewRequest (http .MethodPost , path , strings .NewReader (`{"url":"file:///bad","isNewUv":true}` ))
160+ request .Header .Set ("Content-Type" , "application/json" )
161+ handler .ServeHTTP (recorder , request )
162+
163+ if recorder .Code != http .StatusOK {
164+ t .Fatalf ("expected 200, got %d" , recorder .Code )
165+ }
166+
167+ var payload map [string ]any
168+ if err := json .Unmarshal (recorder .Body .Bytes (), & payload ); err != nil {
169+ t .Fatalf ("unmarshal v1 response: %v" , err )
170+ }
171+
172+ if _ , hasStatus := payload ["status" ]; hasStatus {
173+ t .Fatalf ("expected plain JSON payload, got envelope %#v" , payload )
174+ }
175+
176+ if payload ["error" ] == nil || payload ["site_uv" ] == nil {
177+ t .Fatalf ("expected legacy v1 fields, got %#v" , payload )
178+ }
179+ })
180+ }
181+ }
182+
144183func TestV2RouteKeepsEnvelopeResponseShape (t * testing.T ) {
145184 handler := newTestHandler (t , mustStartMiniRedis (t ).Addr ())
146185 recorder := httptest .NewRecorder ()
@@ -166,6 +205,33 @@ func TestV2RouteKeepsEnvelopeResponseShape(t *testing.T) {
166205 }
167206}
168207
208+ func TestV2PostRouteKeepsEnvelopeResponseShape (t * testing.T ) {
209+ handler := newTestHandler (t , mustStartMiniRedis (t ).Addr ())
210+ recorder := httptest .NewRecorder ()
211+ request := httptest .NewRequest (http .MethodPost , "/api/v2/log" , strings .NewReader (`{"url":"file:///bad","isNewUv":true}` ))
212+ request .Header .Set ("Content-Type" , "application/json" )
213+
214+ handler .ServeHTTP (recorder , request )
215+
216+ if recorder .Code != http .StatusOK {
217+ t .Fatalf ("expected 200, got %d" , recorder .Code )
218+ }
219+
220+ var payload map [string ]any
221+ if err := json .Unmarshal (recorder .Body .Bytes (), & payload ); err != nil {
222+ t .Fatalf ("unmarshal v2 response: %v" , err )
223+ }
224+
225+ if payload ["status" ] != "success" {
226+ t .Fatalf ("expected success envelope, got %#v" , payload )
227+ }
228+
229+ data , ok := payload ["data" ].(map [string ]any )
230+ if ! ok || data ["site_uv" ] == nil {
231+ t .Fatalf ("expected data envelope, got %#v" , payload )
232+ }
233+ }
234+
169235func TestOptionsRoutesStayAvailable (t * testing.T ) {
170236 handler := newTestHandler (t , mustStartMiniRedis (t ).Addr ())
171237
@@ -174,7 +240,8 @@ func TestOptionsRoutesStayAvailable(t *testing.T) {
174240 path string
175241 expectStatus any
176242 }{
177- {name : "v1 options" , path : "/log" , expectStatus : nil },
243+ {name : "legacy options" , path : "/log" , expectStatus : nil },
244+ {name : "v1 options" , path : "/api/v1/log" , expectStatus : nil },
178245 {name : "v2 options" , path : "/api/v2/log" , expectStatus : "success" },
179246 } {
180247 t .Run (tc .name , func (t * testing.T ) {
@@ -189,6 +256,10 @@ func TestOptionsRoutesStayAvailable(t *testing.T) {
189256 t .Fatalf ("expected CORS header, got %q" , recorder .Header ().Get ("Access-Control-Allow-Origin" ))
190257 }
191258
259+ if recorder .Header ().Get ("Access-Control-Allow-Credentials" ) != "" {
260+ t .Fatalf ("expected credentialless CORS, got %q" , recorder .Header ().Get ("Access-Control-Allow-Credentials" ))
261+ }
262+
192263 var payload map [string ]any
193264 if err := json .Unmarshal (recorder .Body .Bytes (), & payload ); err != nil {
194265 t .Fatalf ("unmarshal options response: %v" , err )
@@ -219,6 +290,10 @@ func TestBenchmarkWriteRouteUsesFixedTargetAndNoStoreHeaders(t *testing.T) {
219290 t .Fatalf ("expected CORS header, got %q" , recorder .Header ().Get ("Access-Control-Allow-Origin" ))
220291 }
221292
293+ if recorder .Header ().Get ("Access-Control-Allow-Credentials" ) != "" {
294+ t .Fatalf ("expected credentialless CORS, got %q" , recorder .Header ().Get ("Access-Control-Allow-Credentials" ))
295+ }
296+
222297 if ! strings .Contains (recorder .Header ().Get ("Cache-Control" ), "no-store" ) {
223298 t .Fatalf ("expected no-store cache header, got %q" , recorder .Header ().Get ("Cache-Control" ))
224299 }
0 commit comments