Skip to content

Commit

Permalink
Add tests and fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrooksuk committed Nov 26, 2024
1 parent 14e2dce commit d25bd9e
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Filament/Pages/Integrations/OhDear.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ class OhDear extends Page
protected static string $view = 'cachet::filament.pages.integrations.oh-dear';

public string $url;
public bool $import_sites;
public ?int $component_group_id;
public bool $import_incidents;
public bool $import_sites = false;
public ?int $component_group_id = null;
public bool $import_incidents = false;

/**
* Mount the page.
Expand Down
28 changes: 28 additions & 0 deletions tests/Unit/Actions/Integrations/ImportOhDearFeedTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

use Cachet\Actions\Integrations\ImportOhDearFeed;
use Cachet\Enums\ComponentStatusEnum;
use Cachet\Enums\ExternalProviderEnum;
use Cachet\Enums\IncidentStatusEnum;

it('can import an OhDear feed', function () {
$importOhDearFeed = new ImportOhDearFeed();

$data = json_decode(file_get_contents(__DIR__.'/../../../stubs/ohdear-feed-php.json'), true);

$importOhDearFeed($data, importSites: true, componentGroupId: 1, importIncidents: true);

$this->assertDatabaseHas('components', [
'link' => 'https://www.php.net/',
'name' => 'php.net',
'component_group_id' => 1,
'status' => ComponentStatusEnum::operational,
]);

$this->assertDatabaseHas('incidents', [
'external_provider' => ExternalProviderEnum::OhDear->value,
'external_id' => "1274100",
'name' => 'php.net has recovered.',
'status' => IncidentStatusEnum::fixed,
]);
});
1 change: 1 addition & 0 deletions tests/stubs/ohdear-feed-php.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"title":"PHP.net Status","timezone":"UTC","pinnedUpdate":null,"sites":{"ungrouped":[{"label":"php.net","url":"https:\/\/www.php.net\/","status":"up"},{"label":"pecl.php.net","url":"https:\/\/pecl.php.net","status":"up"},{"label":"bugs.php.net","url":"https:\/\/bugs.php.net","status":"up"},{"label":"museum.php.net","url":"https:\/\/museum.php.net","status":"up"},{"label":"wiki.php.net","url":"https:\/\/wiki.php.net","status":"up"},{"label":"people.php.net","url":"https:\/\/people.php.net","status":"up"},{"label":"news-web.php.net","url":"https:\/\/news-web.php.net","status":"up"},{"label":"downloads.php.net","url":"https:\/\/downloads.php.net","status":"up"}]},"updatesPerDay":{"1732579200":[],"1732492800":[],"1732406400":[{"id":1274100,"title":"php.net has recovered.","text":"","pinned":false,"severity":"resolved","time":1732471160},{"id":1273622,"title":"php.net appears to be down.","text":"","pinned":false,"severity":"warning","time":1732429163},{"id":1273623,"title":"downloads.php.net appears to be down.","text":"","pinned":false,"severity":"warning","time":1732429163}],"1732320000":[],"1732233600":[],"1732147200":[],"1732060800":[]},"summarizedStatus":"up"}

0 comments on commit d25bd9e

Please sign in to comment.