Skip to content

Commit 3b7e1f2

Browse files
committed
add test case
1 parent a10ae58 commit 3b7e1f2

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

tests/Feature/Api/SiteControllerTest.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,39 @@ public function testRegisteringASiteWithUrlAndKeyCreatesRow(): void
5858
Queue::assertPushed(CheckSiteHealth::class);
5959
}
6060

61+
public function testRegisteringASiteTwiceCreatesOnlyOneRow(): void
62+
{
63+
Queue::fake();
64+
65+
$mock = $this->getMockBuilder(Connection::class)
66+
->disableOriginalConstructor()
67+
->getMock();
68+
69+
$mock->method('__call')->willReturn(HealthCheck::from([
70+
"php_version" => "1.0.0",
71+
"db_type" => "mysqli",
72+
"db_version" => "1.0.0",
73+
"cms_version" => "1.0.0",
74+
"server_os" => "Joomla OS 1.0.0",
75+
"update_requirement_state" => true
76+
]));
77+
78+
$this->app->bind(Connection::class, fn () => $mock);
79+
80+
$this->postJson(
81+
'/api/v1/register',
82+
["url" => "https://www.joomla.org", "key" => "foobar123foobar123foobar123foobar123"]
83+
);
84+
85+
$this->postJson(
86+
'/api/v1/register',
87+
["url" => "https://www.joomla.org", "key" => "foobar123foobar123foobar123foobar123"]
88+
);
89+
90+
$count = Site::where('url', 'https://www.joomla.org')->count();
91+
$this->assertEquals(1, $count);
92+
}
93+
6194
public function testRegisteringASiteFailsWhenHealthCheckFails(): void
6295
{
6396
$mock = $this->getMockBuilder(Connection::class)

0 commit comments

Comments
 (0)