|
233 | 233 | ->assertJsonPath('meta.next_cursor', null); |
234 | 234 | }); |
235 | 235 |
|
| 236 | +it('shows as many reply previews as the client asks for, newest first', function (): void { |
| 237 | + $commit = Commit::factory()->create(['created_at' => now()->subHour()]); |
| 238 | + $replies = Commit::factory()->for($commit, 'parent')->count(4) |
| 239 | + ->state(new Sequence(fn (Sequence $sequence): array => ['created_at' => now()->subMinutes(10 - $sequence->index)])) |
| 240 | + ->create(); |
| 241 | + |
| 242 | + $response = signedApiRequest($this->keyPair, 'GET', route('api-log.show', ['latest', 'replies_per_page' => 3])); |
| 243 | + |
| 244 | + $response->assertOk() |
| 245 | + ->assertJsonPath('data.0.reply_preview.data.*.id', [$replies[3]->id, $replies[2]->id, $replies[1]->id]); |
| 246 | + |
| 247 | + expect($response->json('data.0.reply_preview.next_cursor'))->toBeString(); |
| 248 | +}); |
| 249 | + |
| 250 | +it('shows one reply preview when the client asks for a count the web does not offer', function (string $count): void { |
| 251 | + $commit = Commit::factory()->create(['created_at' => now()->subHour()]); |
| 252 | + Commit::factory()->for($commit, 'parent')->count(4)->create(); |
| 253 | + |
| 254 | + $response = signedApiRequest($this->keyPair, 'GET', route('api-log.show', ['latest', 'replies_per_page' => $count])); |
| 255 | + |
| 256 | + $response->assertOk()->assertJsonCount(1, 'data.0.reply_preview.data'); |
| 257 | +})->with(['7', '3abc']); |
| 258 | + |
236 | 259 | it('does not query each commit or author', function (): void { |
237 | 260 | Queue::fake([DetectCommitLanguage::class]); |
238 | 261 | signedApiRequest($this->keyPair, 'GET', route('api-log.show', 'latest'))->assertOk(); |
|
0 commit comments