10_tipitaka_chapter_channels.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. use \WikipaliApi\Api\TipitakaChapterChannelsApi;
  3. /*
  4. * 一章有哪些 channel 及完成度:GET /v3/tipitaka-chapter-channels/{book}/{para}
  5. *
  6. * 只读、无写操作。章节坐标取 fixtures.php 的 chapter_channels_book / chapter_channels_para
  7. * (与 server 无关),核对这一章能匿名列出版本、行的形状与排序对。
  8. * 可见性矩阵(私有 / 共享 / 群组)、排序、N+1 由 api-v13 的 TipitakaChapterChannelV3Test 覆盖。
  9. */
  10. /** 有若干译文版本的某一章的 [book, para] */
  11. function chapter_channel_coord(): array
  12. {
  13. return [(int) fixtures()['chapter_channels_book'], (int) fixtures()['chapter_channels_para']];
  14. }
  15. test('GET /v3/tipitaka-chapter-channels/{book}/{para} → 200,列出版本', function () {
  16. [$book, $para] = chapter_channel_coord();
  17. $res = request(fn () => api(TipitakaChapterChannelsApi::class)
  18. ->getApiV3TipitakaChapterChannelsBookParaWithHttpInfo($book, $para, 200));
  19. assert_status(200, $res, 'tipitaka-chapter-channels');
  20. assert_has_key('data', $res['body'], 'tipitaka-chapter-channels');
  21. assert_has_key('meta', $res['body'], 'tipitaka-chapter-channels');
  22. if ($res['body']['data'] === []) {
  23. fail('tipitaka-chapter-channels:应返回至少一个版本');
  24. }
  25. foreach ($res['body']['data'] as $row) {
  26. assert_eq($book, $row['book'] ?? null, 'book');
  27. assert_eq($para, $row['para'] ?? null, 'para');
  28. foreach (['id', 'progress', 'views', 'updated_at', 'channel', 'studio'] as $key) {
  29. assert_has_key($key, $row, 'tipitaka-chapter-channels 行');
  30. }
  31. }
  32. // 按完成度降序
  33. $progress = array_column($res['body']['data'], 'progress');
  34. $sorted = $progress;
  35. rsort($sorted);
  36. assert_eq($sorted, $progress, '按 progress 降序');
  37. });
  38. test('GET /v3/tipitaka-chapter-channels/{book}/{para}(没有进度的章节)→ 200 空列表', function () {
  39. $res = raw('GET', '/v3/tipitaka-chapter-channels/1/999999');
  40. assert_status(200, $res, '空章节');
  41. assert_eq([], $res['body']['data'] ?? null, '空章节 data');
  42. });
  43. test('GET /v3/tipitaka-chapter-channels/{book}/{para}?per_page=500 → 422', function () {
  44. $res = raw('GET', '/v3/tipitaka-chapter-channels/1/2', ['per_page' => 500]);
  45. assert_status(422, $res, 'per_page 超限');
  46. assert_field_error('per_page', $res, 'per_page 超限');
  47. });
  48. test('GET /v3/tipitaka-chapter-channels/{非数字}/{para} → 404', function () {
  49. assert_status(404, raw('GET', '/v3/tipitaka-chapter-channels/abc/2'), '非数字 book');
  50. });