Files
firecrawl/apps/php-sdk/tests/Unit/ChangeTrackingOriginTest.php
3f8516d054 sdks: product inStock can be null; batch children keep the submitter origin (#6081)
* api: batch scrape children keep the submitter origin

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* js-sdk: v1 client sends the bundled SDK version in its origin from the first request

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* python-sdk: raise when a later crawl or batch page fails validation instead of truncating results

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* python-sdk 4.59.0, js-sdk 4.57.0: product inStock can be null

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* sdks: nullable product inStock and variant gtin, mpn and condition in Java 1.19.0, Go 1.17.0, Rust 2.22.0, Ruby 1.18.0, PHP 1.17.0 and .NET 1.16.0

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* api: test that batch children, batch append, crawl fan-out and sitemap kickoff keep the submitter origin

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* Address review: surface processJobInternal outcome in origin tests; note typed-caller impact in Rust and PHP changelogs

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* elixir-sdk: bundled spec marks product inStock as nullable

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* api: origin tests follow the oxlint rules and mock the crawl-state Redis

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* api: origin tests use typed jobs, named type imports and supertest for oxlint

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

---------

Co-authored-by: E37U-A <288073611+E37U-A@users.noreply.github.com>
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
2026-11-27 13:25:59 -07:00

80 lines
3.1 KiB
PHP

<?php
declare(strict_types=1);
use Firecrawl\Models\BatchScrapeOptions;
use Firecrawl\Models\JsonFormat;
use Firecrawl\Models\ScrapeOptions;
use Firecrawl\Version;
use GuzzleHttp\Psr7\Response;
it('sends changeTracking as a format alongside markdown', function (): void {
expect(ScrapeOptions::with(changeTracking: true)->toArray())
->toBe(['formats' => ['markdown', 'changeTracking']]);
expect(ScrapeOptions::with(formats: ['html'], changeTracking: true)->toArray())
->toBe(['formats' => ['html', 'markdown', 'changeTracking']]);
});
it('keeps existing markdown and changeTracking formats', function (): void {
$options = ScrapeOptions::with(
formats: ['changeTracking', JsonFormat::with(prompt: 'title'), 'markdown'],
changeTracking: true,
);
expect($options->toArray()['formats'])
->toBe(['changeTracking', ['type' => 'json', 'prompt' => 'title'], 'markdown']);
});
it('never sends a top-level changeTracking key', function (): void {
expect(ScrapeOptions::with(formats: [JsonFormat::with(prompt: 'title')], changeTracking: true)->toArray())
->not->toHaveKey('changeTracking');
expect(ScrapeOptions::with(formats: ['html'], changeTracking: false)->toArray())
->toBe(['formats' => ['html']]);
});
it('sends the SDK origin on crawl, batch scrape and map', function (): void {
$history = new ArrayObject();
$client = fakeFirecrawlClient([
new Response(200, [], json_encode(['success' => true, 'id' => 'crawl-1', 'url' => 'https://api.firecrawl.dev/v2/crawl/crawl-1'])),
new Response(200, [], json_encode(['success' => true, 'id' => 'batch-1', 'url' => 'https://api.firecrawl.dev/v2/batch/scrape/batch-1'])),
new Response(200, [], json_encode(['success' => true, 'links' => []])),
], $history);
$client->startCrawl('https://example.com');
$client->startBatchScrape(['https://example.com'], BatchScrapeOptions::with(
options: ScrapeOptions::with(changeTracking: true),
));
$client->map('https://example.com');
$bodies = array_map(
fn (array $entry): array => json_decode((string) $entry['request']->getBody(), true),
$history->getArrayCopy(),
);
foreach ($bodies as $body) {
expect($body['origin'])->toBe('php-sdk@' . Version::SDK_VERSION);
}
expect($bodies[1]['formats'])->toBe(['markdown', 'changeTracking']);
expect($bodies[1])->not->toHaveKey('changeTracking');
});
it('sends the SDK origin on scrape and search', function (): void {
$history = new ArrayObject();
$client = fakeFirecrawlClient([
new Response(200, [], json_encode(['success' => true, 'data' => ['markdown' => '# ok']])),
new Response(200, [], json_encode(['success' => true, 'data' => ['web' => []]])),
], $history);
$client->scrape('https://example.com');
$client->search('widgets');
$bodies = array_map(
fn (array $entry): array => json_decode((string) $entry['request']->getBody(), true),
$history->getArrayCopy(),
);
expect($bodies)->toHaveCount(2);
foreach ($bodies as $body) {
expect($body['origin'])->toBe('php-sdk@' . Version::SDK_VERSION);
}
});