fix(#62): webhook plugins are stale for 60 minutes by default

This commit is contained in:
Benjamin Nussbaum 2025-07-10 23:50:41 +02:00
parent c20e1a9a58
commit a44479a48a
3 changed files with 30 additions and 4 deletions

View file

@ -769,7 +769,7 @@ test('device in sleep mode returns sleep image and correct refresh rate', functi
]);
// Freeze time to 20:00 (within sleep window)
\Carbon\Carbon::setTestNow(\Carbon\Carbon::parse('2000-01-01 20:00:00'));
Carbon\Carbon::setTestNow(Carbon\Carbon::parse('2000-01-01 20:00:00'));
$response = $this->withHeaders([
'id' => $device->mac_address,
@ -785,7 +785,7 @@ test('device in sleep mode returns sleep image and correct refresh rate', functi
]);
expect($response['refresh_rate'])->toBeGreaterThan(0);
\Carbon\Carbon::setTestNow(); // Clear test time
Carbon\Carbon::setTestNow(); // Clear test time
});
test('device not in sleep mode returns normal image', function () {
@ -799,7 +799,7 @@ test('device not in sleep mode returns normal image', function () {
]);
// Freeze time to 18:00 (outside sleep window)
\Carbon\Carbon::setTestNow(\Carbon\Carbon::parse('2000-01-01 18:00:00'));
Carbon\Carbon::setTestNow(Carbon\Carbon::parse('2000-01-01 18:00:00'));
$response = $this->withHeaders([
'id' => $device->mac_address,
@ -814,7 +814,7 @@ test('device not in sleep mode returns normal image', function () {
'filename' => 'test-image.bmp',
]);
\Carbon\Carbon::setTestNow(); // Clear test time
Carbon\Carbon::setTestNow(); // Clear test time
});
test('device returns sleep.png and correct refresh time when paused', function () {

View file

@ -71,3 +71,25 @@ test('updateDataPayload sends POST request with body when polling_verb is post',
$request->body() === '{"query": "query { user { id name } }"}';
});
});
test('webhook plugin is stale if webhook event occurred', function () {
$plugin = Plugin::factory()->create([
'data_strategy' => 'webhook',
'data_payload_updated_at' => now()->subMinutes(10),
'data_stale_minutes' => 60, // Should be ignored for webhook
]);
expect($plugin->isDataStale())->toBeTrue();
});
test('webhook plugin data not stale if no webhook event occurred for 1 hour', function () {
$plugin = Plugin::factory()->create([
'data_strategy' => 'webhook',
'data_payload_updated_at' => now()->subMinutes(60),
'data_stale_minutes' => 60, // Should be ignored for webhook
]);
expect($plugin->isDataStale())->toBeFalse();
});