|
1 | 1 | import { expect, jest, test } from '@jest/globals'; |
2 | | -import Replicate, { ApiError, Prediction } from 'replicate'; |
| 2 | +import Replicate, { ApiError, Model, Prediction } from 'replicate'; |
3 | 3 | import nock from 'nock'; |
4 | 4 | import fetch from 'cross-fetch'; |
5 | 5 |
|
@@ -131,6 +131,30 @@ describe('Replicate client', () => { |
131 | 131 | // Add more tests for error handling, edge cases, etc. |
132 | 132 | }); |
133 | 133 |
|
| 134 | + describe('models.list', () => { |
| 135 | + test('Paginates results', async () => { |
| 136 | + nock(BASE_URL) |
| 137 | + .get('/models') |
| 138 | + .reply(200, { |
| 139 | + results: [{ url: 'https://replicate.com/some-user/model-1' }], |
| 140 | + next: 'https://api.replicate.com/v1/models?cursor=cD0yMDIyLTAxLTIxKzIzJTNBMTglM0EyNC41MzAzNTclMkIwMCUzQTAw', |
| 141 | + }) |
| 142 | + .get('/models?cursor=cD0yMDIyLTAxLTIxKzIzJTNBMTglM0EyNC41MzAzNTclMkIwMCUzQTAw') |
| 143 | + .reply(200, { |
| 144 | + results: [{ url: 'https://replicate.com/some-user/model-2' }], |
| 145 | + next: null, |
| 146 | + }); |
| 147 | + |
| 148 | + const results: Model[] = []; |
| 149 | + for await (const batch of client.paginate(client.models.list)) { |
| 150 | + results.push(...batch); |
| 151 | + } |
| 152 | + expect(results).toEqual([{ url: 'https://replicate.com/some-user/model-1' }, { url: 'https://replicate.com/some-user/model-2' }]); |
| 153 | + |
| 154 | + // Add more tests for error handling, edge cases, etc. |
| 155 | + }); |
| 156 | + }); |
| 157 | + |
134 | 158 | describe('predictions.create', () => { |
135 | 159 | test('Calls the correct API route with the correct payload', async () => { |
136 | 160 | nock(BASE_URL) |
|
0 commit comments