(t *testing.T, method string, target string, body any, userID int)
| 182 | } |
| 183 | |
| 184 | func newAuthenticatedContext(t *testing.T, method string, target string, body any, userID int) (*gin.Context, *httptest.ResponseRecorder) { |
| 185 | t.Helper() |
| 186 | |
| 187 | var requestBody *bytes.Reader |
| 188 | if body != nil { |
| 189 | payload, err := common.Marshal(body) |
| 190 | if err != nil { |
| 191 | t.Fatalf("failed to marshal request body: %v", err) |
| 192 | } |
| 193 | requestBody = bytes.NewReader(payload) |
| 194 | } else { |
| 195 | requestBody = bytes.NewReader(nil) |
| 196 | } |
| 197 | |
| 198 | recorder := httptest.NewRecorder() |
| 199 | ctx, _ := gin.CreateTestContext(recorder) |
| 200 | ctx.Request = httptest.NewRequest(method, target, requestBody) |
| 201 | if body != nil { |
| 202 | ctx.Request.Header.Set("Content-Type", "application/json") |
| 203 | } |
| 204 | ctx.Set("id", userID) |
| 205 | return ctx, recorder |
| 206 | } |
| 207 | |
| 208 | func decodeAPIResponse(t *testing.T, recorder *httptest.ResponseRecorder) tokenAPIResponse { |
| 209 | t.Helper() |
no test coverage detected