File tree Expand file tree Collapse file tree 2 files changed +38
-2
lines changed
app/Http/Controllers/Api/V1 Expand file tree Collapse file tree 2 files changed +38
-2
lines changed Original file line number Diff line number Diff line change @@ -48,9 +48,11 @@ public function register(SiteRequest $request): JsonResponse
4848 return $ this ->error ($ e ->getMessage (), 500 );
4949 }
5050
51- // If successful create or update site
52- $ site = Site::where ( ' url ' , $ url )->where ('key ' , $ key )->first () ?? new Site ();
51+ // Remove older duplicates of the site if registered
52+ Site::query ( )->where ('url ' , $ url )->delete ();
5353
54+ // Create new row
55+ $ site = new Site ();
5456 $ site ->key = $ key ;
5557 $ site ->url = $ url ;
5658 $ site ->last_seen = Carbon::now ();
Original file line number Diff line number Diff line change @@ -58,6 +58,40 @@ 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 " => "abcdefabcdefabcdefabcdefabcdefabcdef " ]
88+ );
89+
90+ $ rows = Site::where ('url ' , 'https://www.joomla.org ' )->get ();
91+ $ this ->assertEquals (1 , $ rows ->count ());
92+ $ this ->assertEquals ('abcdefabcdefabcdefabcdefabcdefabcdef ' , $ rows ->first ()->key );
93+ }
94+
6195 public function testRegisteringASiteFailsWhenHealthCheckFails (): void
6296 {
6397 $ mock = $ this ->getMockBuilder (Connection::class)
You can’t perform that action at this time.
0 commit comments