]> BookStack Code Mirror - bookstack/commitdiff
Added test for social account detach
authorDan Brown <redacted>
Mon, 14 Jun 2021 21:30:53 +0000 (22:30 +0100)
committerDan Brown <redacted>
Mon, 14 Jun 2021 21:30:53 +0000 (22:30 +0100)
routes/web.php
tests/Auth/SocialAuthTest.php

index 59a6eddc630db85801523895be76970be027520b..b6eda7c5124a8e6146d9684cc4fb3022e436eb68 100644 (file)
@@ -14,7 +14,7 @@ Route::group(['middleware' => 'auth'], function () {
 
     // Shelves
     Route::get('/create-shelf', 'BookshelfController@create');
-    Route::group(['prefix' => 'shelves'], function() {
+    Route::group(['prefix' => 'shelves'], function () {
         Route::get('/', 'BookshelfController@index');
         Route::post('/', 'BookshelfController@store');
         Route::get('/{slug}/edit', 'BookshelfController@edit');
index 4369d8b7abca6faa84780f73c13bdd4176176aac..d412e8c94be16816ed9a34a37c9d515a296b2db6 100644 (file)
@@ -1,5 +1,6 @@
 <?php namespace Tests\Auth;
 
+use BookStack\Auth\SocialAccount;
 use BookStack\Auth\User;
 use DB;
 use Laravel\Socialite\Contracts\Factory;
@@ -83,6 +84,31 @@ class SocialAuthTest extends TestCase
         $resp->assertDontSee("login-form");
     }
 
+    public function test_social_account_detach()
+    {
+        $editor = $this->getEditor();
+        config([
+            'GITHUB_APP_ID' => 'abc123', 'GITHUB_APP_SECRET' => '123abc',
+            'APP_URL' => 'http://localhost'
+        ]);
+
+        $socialAccount = SocialAccount::query()->forceCreate([
+            'user_id' => $editor->id,
+            'driver' => 'github',
+            'driver_id' => 'logintest123',
+        ]);
+
+        $resp = $this->actingAs($editor)->get($editor->getEditUrl());
+        $resp->assertElementContains('a[href$="/login/service/github/detach"]', 'Disconnect Account');
+
+        $resp = $this->get('/login/service/github/detach');
+        $resp->assertRedirect($editor->getEditUrl());
+        $resp = $this->followRedirects($resp);
+        $resp->assertSee('Github account was successfully disconnected from your profile.');
+
+        $this->assertDatabaseMissing('social_accounts', ['id' => $socialAccount->id]);
+    }
+
     public function test_social_autoregister()
     {
         config([