|
1 | 1 | package client |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "encoding/json" |
4 | 5 | "fmt" |
5 | 6 | "strconv" |
6 | 7 |
|
@@ -1350,43 +1351,133 @@ func (c *ZboxClient) GetTransactionsList(t *test.SystemTest, pitId string) (*mod |
1350 | 1351 | } |
1351 | 1352 |
|
1352 | 1353 | // CreateMetadata posts transcoding metadata to the server and returns parsed response. |
1353 | | -func (c *ZboxClient) CreateMetadata(t *test.SystemTest, headers map[string]string, body map[string]string) (*model.ZboxTranscodingDataResponse, *resty.Response, error) { |
| 1354 | +func (c *ZboxClient) CreateMetadata(t *test.SystemTest, headers map[string]string, body map[string]interface{}) (*model.TranscodingEntity, *resty.Response, error) { |
1354 | 1355 | t.Logf("creating transcoding metadata for user [%v] using 0box...", headers["X-App-User-ID"]) |
1355 | 1356 |
|
1356 | | - var res *model.ZboxTranscodingDataResponse |
| 1357 | + // Log request body |
| 1358 | + bodyJSON, err := json.Marshal(body) |
| 1359 | + if err == nil { |
| 1360 | + t.Logf("CreateMetadata request body: %s", string(bodyJSON)) |
| 1361 | + } else { |
| 1362 | + t.Logf("CreateMetadata request body (marshal error): %v", body) |
| 1363 | + } |
| 1364 | + |
| 1365 | + var res *model.GetTranscodingEntityResponse |
1357 | 1366 |
|
1358 | 1367 | urlBuilder := NewURLBuilder() |
1359 | | - err := urlBuilder.MustShiftParse(c.zboxEntrypoint) |
| 1368 | + err = urlBuilder.MustShiftParse(c.zboxEntrypoint) |
1360 | 1369 | require.NoError(t, err, "URL parse error") |
1361 | 1370 | urlBuilder.SetPath("/v2/metadata") |
1362 | 1371 |
|
| 1372 | + // Ensure Content-Type is set to JSON |
| 1373 | + jsonHeaders := make(map[string]string) |
| 1374 | + for k, v := range headers { |
| 1375 | + jsonHeaders[k] = v |
| 1376 | + } |
| 1377 | + jsonHeaders["Content-Type"] = "application/json" |
| 1378 | + |
1363 | 1379 | resp, err := c.executeForServiceProvider(t, urlBuilder.String(), model.ExecutionRequest{ |
1364 | 1380 | Dst: &res, |
1365 | | - Headers: headers, |
1366 | | - FormData: body, |
| 1381 | + Headers: jsonHeaders, |
| 1382 | + Body: body, |
1367 | 1383 | RequiredStatusCode: 201, |
1368 | 1384 | }, HttpPOSTMethod) |
1369 | 1385 |
|
1370 | | - return res, resp, err |
| 1386 | + if err != nil { |
| 1387 | + t.Errorf("CreateMetadata response error: %v, response body: %s", err, string(resp.Body())) |
| 1388 | + return nil, resp, err |
| 1389 | + } |
| 1390 | + |
| 1391 | + // Log response body |
| 1392 | + t.Logf("CreateMetadata response status: %d, response body: %s", resp.StatusCode(), string(resp.Body())) |
| 1393 | + |
| 1394 | + if res != nil && res.Data.ID != 0 { |
| 1395 | + return &res.Data, resp, nil |
| 1396 | + } |
| 1397 | + |
| 1398 | + return nil, resp, fmt.Errorf("transcoding entity not found in response") |
1371 | 1399 | } |
1372 | 1400 |
|
1373 | 1401 | // UpdateUploadStatus updates status for an uploaded file and returns parsed response. |
1374 | | -func (c *ZboxClient) UpdateUploadStatus(t *test.SystemTest, headers map[string]string, body map[string]string) (*model.ZboxTranscodingDataResponse, *resty.Response, error) { |
| 1402 | +func (c *ZboxClient) UpdateUploadStatus(t *test.SystemTest, headers map[string]string, body map[string]interface{}) (*model.TranscodingEntity, *resty.Response, error) { |
1375 | 1403 | t.Logf("updating upload status for user [%v] using 0box...", headers["X-App-User-ID"]) |
1376 | 1404 |
|
1377 | | - var res *model.ZboxTranscodingDataResponse |
| 1405 | + // Log request body |
| 1406 | + bodyJSON, err := json.Marshal(body) |
| 1407 | + if err == nil { |
| 1408 | + t.Logf("UpdateUploadStatus request body: %s", string(bodyJSON)) |
| 1409 | + } else { |
| 1410 | + t.Logf("UpdateUploadStatus request body (marshal error): %v", body) |
| 1411 | + } |
| 1412 | + |
| 1413 | + var res *model.GetTranscodingEntityResponse |
1378 | 1414 |
|
1379 | 1415 | urlBuilder := NewURLBuilder() |
1380 | | - err := urlBuilder.MustShiftParse(c.zboxEntrypoint) |
| 1416 | + err = urlBuilder.MustShiftParse(c.zboxEntrypoint) |
1381 | 1417 | require.NoError(t, err, "URL parse error") |
1382 | 1418 | urlBuilder.SetPath("/v2/updateUploadStatus") |
1383 | 1419 |
|
| 1420 | + // Ensure Content-Type is set to JSON |
| 1421 | + jsonHeaders := make(map[string]string) |
| 1422 | + for k, v := range headers { |
| 1423 | + jsonHeaders[k] = v |
| 1424 | + } |
| 1425 | + jsonHeaders["Content-Type"] = "application/json" |
| 1426 | + |
1384 | 1427 | resp, err := c.executeForServiceProvider(t, urlBuilder.String(), model.ExecutionRequest{ |
1385 | 1428 | Dst: &res, |
1386 | | - Headers: headers, |
1387 | | - FormData: body, |
| 1429 | + Headers: jsonHeaders, |
| 1430 | + Body: body, |
1388 | 1431 | RequiredStatusCode: 201, |
1389 | 1432 | }, HttpPUTMethod) |
1390 | 1433 |
|
1391 | | - return res, resp, err |
| 1434 | + if err != nil { |
| 1435 | + t.Errorf("UpdateUploadStatus response error: %v, response body: %s", err, string(resp.Body())) |
| 1436 | + return nil, resp, err |
| 1437 | + } |
| 1438 | + |
| 1439 | + // Log response body |
| 1440 | + t.Logf("UpdateUploadStatus response status: %d, response body: %s", resp.StatusCode(), string(resp.Body())) |
| 1441 | + |
| 1442 | + if res != nil && res.Data.ID != 0 { |
| 1443 | + return &res.Data, resp, nil |
| 1444 | + } |
| 1445 | + |
| 1446 | + return nil, resp, fmt.Errorf("transcoding entity not found in response") |
| 1447 | +} |
| 1448 | + |
| 1449 | +// GetMetadata gets transcoding entity metadata and returns parsed response. |
| 1450 | +func (c *ZboxClient) GetMetadata(t *test.SystemTest, headers map[string]string, queryParams map[string]string) (*model.TranscodingEntity, *resty.Response, error) { |
| 1451 | + t.Logf("getting transcoding metadata for user [%v] using 0box...", headers["X-App-User-ID"]) |
| 1452 | + |
| 1453 | + // Log query parameters |
| 1454 | + t.Logf("GetMetadata query params: %v", queryParams) |
| 1455 | + |
| 1456 | + var res *model.GetTranscodingEntityResponse |
| 1457 | + |
| 1458 | + urlBuilder := NewURLBuilder() |
| 1459 | + err := urlBuilder.MustShiftParse(c.zboxEntrypoint) |
| 1460 | + require.NoError(t, err, "URL parse error") |
| 1461 | + urlBuilder.SetPath("/v2/metadata") |
| 1462 | + |
| 1463 | + resp, err := c.executeForServiceProvider(t, urlBuilder.String(), model.ExecutionRequest{ |
| 1464 | + Dst: &res, |
| 1465 | + Headers: headers, |
| 1466 | + QueryParams: queryParams, |
| 1467 | + RequiredStatusCode: 200, |
| 1468 | + }, HttpGETMethod) |
| 1469 | + |
| 1470 | + if err != nil { |
| 1471 | + t.Errorf("GetMetadata response error: %v, response body: %s", err, string(resp.Body())) |
| 1472 | + return nil, resp, err |
| 1473 | + } |
| 1474 | + |
| 1475 | + // Log response body |
| 1476 | + t.Logf("GetMetadata response status: %d, response body: %s", resp.StatusCode(), string(resp.Body())) |
| 1477 | + |
| 1478 | + if res != nil && res.Data.ID != 0 { |
| 1479 | + return &res.Data, resp, nil |
| 1480 | + } |
| 1481 | + |
| 1482 | + return nil, resp, fmt.Errorf("transcoding entity not found in response") |
1392 | 1483 | } |
0 commit comments