2
0

05_tipitaka.php 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. use \WikipaliApi\Api\TipitakaReadingApi;
  3. use \WikipaliApi\Api\TipitakaRelatedParagraphsApi;
  4. test('GET /v3/tipitaka-reading/{channel} → 200(无过滤,取首块)', function () {
  5. $res = request(fn () => api(TipitakaReadingApi::class)->getApiV3TipitakaReadingChannelWithHttpInfo(fixtures()['channel'], null, null, null, null, null, 2));
  6. assert_status(200, $res, 'tipitaka-reading');
  7. assert_has_key('data', $res['body'], 'tipitaka-reading');
  8. assert_has_key('meta', $res['body'], 'tipitaka-reading');
  9. // next_cursor 为 null 时(取完)生成模型会把它丢掉,这里只看非空字段。
  10. assert_eq('para', $res['body']['meta']['page_size_unit'] ?? null, 'tipitaka-reading.meta.page_size_unit');
  11. });
  12. test('GET /v3/tipitaka-reading/{channel}?book=… → 200(带 total)', function () {
  13. $res = request(fn () => api(TipitakaReadingApi::class)->getApiV3TipitakaReadingChannelWithHttpInfo(fixtures()['channel'], 65, null, null, null, null, 2));
  14. assert_status(200, $res, 'tipitaka-reading book 过滤');
  15. assert_has_key('total', $res['body']['meta'] ?? [], 'tipitaka-reading.meta.total');
  16. });
  17. test('GET /v3/tipitaka-reading/{非 uuid} → 404', function () {
  18. $res = raw('GET', '/v3/tipitaka-reading/not-a-uuid');
  19. assert_status(404, $res, 'tipitaka-reading 非 uuid');
  20. assert_problem($res, 'tipitaka-reading 非 uuid');
  21. });
  22. test('GET /v3/tipitaka-related-paragraphs?book_name=…&cs_para=… → 200', function () {
  23. $res = request(fn () => api(TipitakaRelatedParagraphsApi::class)->getApiV3TipitakaRelatedParagraphsWithHttpInfo(
  24. null, null, fixtures()['book_name'], fixtures()['cs_para']
  25. ));
  26. assert_status(200, $res, 'related-paragraphs');
  27. assert_has_key('data', $res['body'], 'related-paragraphs');
  28. assert_has_key('count', $res['body']['meta'] ?? [], 'related-paragraphs.meta.count');
  29. });
  30. test('GET /v3/tipitaka-related-paragraphs(两组坐标互斥)→ 422', function () {
  31. $res = raw('GET', '/v3/tipitaka-related-paragraphs', [
  32. 'book' => fixtures()['book'],
  33. 'para' => fixtures()['para'],
  34. 'book_name' => fixtures()['book_name'],
  35. 'cs_para' => fixtures()['cs_para'],
  36. ]);
  37. assert_status(422, $res, 'related-paragraphs 互斥');
  38. assert_problem($res, 'related-paragraphs 互斥');
  39. });
  40. test('GET /v3/tipitaka-related-paragraphs(两组都没给)→ 422', function () {
  41. $res = raw('GET', '/v3/tipitaka-related-paragraphs');
  42. assert_status(422, $res, 'related-paragraphs 缺坐标');
  43. assert_problem($res, 'related-paragraphs 缺坐标');
  44. });
  45. test('GET /v3/tipitaka-related-paragraphs/aggregate → 200', function () {
  46. $res = request(fn () => api(TipitakaRelatedParagraphsApi::class)->getApiV3TipitakaRelatedParagraphsAggregateWithHttpInfo());
  47. assert_status(200, $res, 'aggregate');
  48. assert_has_key('data', $res['body'], 'aggregate');
  49. $first = $res['body']['data'][0] ?? null;
  50. assert_has_key('book_name', $first, 'aggregate.data[0]');
  51. });
  52. test('GET /v3/tipitaka-related-paragraphs/aggregate/{book_name} → 200', function () {
  53. $res = request(fn () => api(TipitakaRelatedParagraphsApi::class)->getApiV3TipitakaRelatedParagraphsAggregateBookNameWithHttpInfo(fixtures()['book_name']));
  54. assert_status(200, $res, 'aggregate/{book_name}');
  55. assert_has_key('data', $res['body'], 'aggregate/{book_name}');
  56. $first = $res['body']['data'][0] ?? null;
  57. assert_has_key('cs_para', $first, 'aggregate.data[0]');
  58. });