Allow plain text response for plugin data polling

This commit is contained in:
kwlo 2025-11-01 12:59:59 -04:00 committed by Benjamin Nussbaum
parent 882cbff7fe
commit 52dfe92054
2 changed files with 31 additions and 3 deletions

View file

@ -72,7 +72,7 @@ test('plugin parses XML responses and wraps under rss key', function (): void {
expect($plugin->data_payload['rss']['channel']['item'])->toHaveCount(2);
});
test('plugin handles non-XML content-type as JSON', function (): void {
test('plugin parses JSON-parsable response body as JSON', function (): void {
$jsonContent = '{"title": "Test Data", "items": [1, 2, 3]}';
Http::fake([
@ -95,6 +95,28 @@ test('plugin handles non-XML content-type as JSON', function (): void {
]);
});
test('plugin wraps plain text response body as JSON', function (): void {
$jsonContent = 'Lorem ipsum dolor sit amet';
Http::fake([
'example.com/data' => Http::response($jsonContent, 200, ['Content-Type' => 'text/plain']),
]);
$plugin = Plugin::factory()->create([
'data_strategy' => 'polling',
'polling_url' => 'https://example.com/data',
'polling_verb' => 'get',
]);
$plugin->updateDataPayload();
$plugin->refresh();
expect($plugin->data_payload)->toBe([
'text' => 'Lorem ipsum dolor sit amet',
]);
});
test('plugin handles invalid XML gracefully', function (): void {
$invalidXml = '<root><item>unclosed tag';