From 42e7ed83c03f94866050aad83cf4962bb44175bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Jaussoin?= Date: Mon, 8 Apr 2024 09:29:11 +0000 Subject: [PATCH] Fix FLEXIAPI-161 Complete the Dictionary tests to cover the collection accessor --- CHANGELOG.md | 1 + .../Api/Admin/AccountDictionaryController.php | 7 ++- flexiapi/composer.lock | 48 +++++++++---------- .../factories/PhoneChangeCodeFactory.php | 8 ++-- .../Feature/ApiAccountDictionaryTest.php | 32 ++++++++----- 5 files changed, 52 insertions(+), 44 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 57571e1..dbc9a99 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ v1.5 ---- +- Fix FLEXIAPI-161 Complete the Dictionary tests to cover the collection accessor - Fix FLEXIAPI-158 Restrict the phone number change API endpoint to return 403 if the account doesn't have a validated Account Creation Token - Fix FLEXIAPI-156 Disable the Phone change web form when PHONE_AUTHENTICATION is disabled - Fix FLEXIAPI-155 Add a new accountServiceAccountUpdatedHook and accountServiceAccountDeletedHook diff --git a/flexiapi/app/Http/Controllers/Api/Admin/AccountDictionaryController.php b/flexiapi/app/Http/Controllers/Api/Admin/AccountDictionaryController.php index 664f8f5..3622d64 100644 --- a/flexiapi/app/Http/Controllers/Api/Admin/AccountDictionaryController.php +++ b/flexiapi/app/Http/Controllers/Api/Admin/AccountDictionaryController.php @@ -21,18 +21,17 @@ namespace App\Http\Controllers\Api\Admin; use App\Http\Controllers\Controller; use App\Account; -use App\AccountDictionaryEntry; use Illuminate\Http\Request; class AccountDictionaryController extends Controller { - public function index(Request $request, int $accountId) + public function index(int $accountId) { return Account::findOrFail($accountId)->dictionary; } - public function show(Request $request, int $accountId, string $key) + public function show(int $accountId, string $key) { return Account::findOrFail($accountId)->dictionaryEntries()->where('key', $key)->first(); } @@ -46,7 +45,7 @@ class AccountDictionaryController extends Controller return Account::findOrFail($accountId)->setDictionaryEntry($key, $request->get('value')); } - public function destroy(Request $request, int $accountId, string $key) + public function destroy(int $accountId, string $key) { return Account::findOrFail($accountId)->dictionaryEntries()->where('key', $key)->delete(); } diff --git a/flexiapi/composer.lock b/flexiapi/composer.lock index e3243ae..e363974 100644 --- a/flexiapi/composer.lock +++ b/flexiapi/composer.lock @@ -2511,16 +2511,16 @@ }, { "name": "league/flysystem", - "version": "3.26.0", + "version": "3.27.0", "source": { "type": "git", "url": "https://github.com/thephpleague/flysystem.git", - "reference": "072735c56cc0da00e10716dd90d5a7f7b40b36be" + "reference": "4729745b1ab737908c7d055148c9a6b3e959832f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/thephpleague/flysystem/zipball/072735c56cc0da00e10716dd90d5a7f7b40b36be", - "reference": "072735c56cc0da00e10716dd90d5a7f7b40b36be", + "url": "https://api.github.com/repos/thephpleague/flysystem/zipball/4729745b1ab737908c7d055148c9a6b3e959832f", + "reference": "4729745b1ab737908c7d055148c9a6b3e959832f", "shasum": "" }, "require": { @@ -2585,7 +2585,7 @@ ], "support": { "issues": "https://github.com/thephpleague/flysystem/issues", - "source": "https://github.com/thephpleague/flysystem/tree/3.26.0" + "source": "https://github.com/thephpleague/flysystem/tree/3.27.0" }, "funding": [ { @@ -2597,7 +2597,7 @@ "type": "github" } ], - "time": "2024-03-25T11:49:53+00:00" + "time": "2024-04-07T19:17:50+00:00" }, { "name": "league/flysystem-local", @@ -3961,16 +3961,16 @@ }, { "name": "phpunit/phpunit", - "version": "9.6.18", + "version": "9.6.19", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "32c2c2d6580b1d8ab3c10b1e9e4dc263cc69bb04" + "reference": "a1a54a473501ef4cdeaae4e06891674114d79db8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/32c2c2d6580b1d8ab3c10b1e9e4dc263cc69bb04", - "reference": "32c2c2d6580b1d8ab3c10b1e9e4dc263cc69bb04", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/a1a54a473501ef4cdeaae4e06891674114d79db8", + "reference": "a1a54a473501ef4cdeaae4e06891674114d79db8", "shasum": "" }, "require": { @@ -4044,7 +4044,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/phpunit/issues", "security": "https://github.com/sebastianbergmann/phpunit/security/policy", - "source": "https://github.com/sebastianbergmann/phpunit/tree/9.6.18" + "source": "https://github.com/sebastianbergmann/phpunit/tree/9.6.19" }, "funding": [ { @@ -4060,7 +4060,7 @@ "type": "tidelift" } ], - "time": "2024-03-21T12:07:32+00:00" + "time": "2024-04-05T04:35:58+00:00" }, { "name": "psr/cache", @@ -9014,16 +9014,16 @@ "packages-dev": [ { "name": "barryvdh/laravel-debugbar", - "version": "v3.13.1", + "version": "v3.13.3", "source": { "type": "git", "url": "https://github.com/barryvdh/laravel-debugbar.git", - "reference": "2f046cb8e0650d1d08b635c90e15c84d09c6288d" + "reference": "241e9bddb04ab42a04a5fe8b2b9654374c864229" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/barryvdh/laravel-debugbar/zipball/2f046cb8e0650d1d08b635c90e15c84d09c6288d", - "reference": "2f046cb8e0650d1d08b635c90e15c84d09c6288d", + "url": "https://api.github.com/repos/barryvdh/laravel-debugbar/zipball/241e9bddb04ab42a04a5fe8b2b9654374c864229", + "reference": "241e9bddb04ab42a04a5fe8b2b9654374c864229", "shasum": "" }, "require": { @@ -9082,7 +9082,7 @@ ], "support": { "issues": "https://github.com/barryvdh/laravel-debugbar/issues", - "source": "https://github.com/barryvdh/laravel-debugbar/tree/v3.13.1" + "source": "https://github.com/barryvdh/laravel-debugbar/tree/v3.13.3" }, "funding": [ { @@ -9094,7 +9094,7 @@ "type": "github" } ], - "time": "2024-04-03T11:41:11+00:00" + "time": "2024-04-04T02:42:49+00:00" }, { "name": "composer/pcre", @@ -9357,16 +9357,16 @@ }, { "name": "maximebf/debugbar", - "version": "v1.22.2", + "version": "v1.22.3", "source": { "type": "git", "url": "https://github.com/maximebf/php-debugbar.git", - "reference": "424be4f885f278edddf4ffa2e3dd41dc04279096" + "reference": "7aa9a27a0b1158ed5ad4e7175e8d3aee9a818b96" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/maximebf/php-debugbar/zipball/424be4f885f278edddf4ffa2e3dd41dc04279096", - "reference": "424be4f885f278edddf4ffa2e3dd41dc04279096", + "url": "https://api.github.com/repos/maximebf/php-debugbar/zipball/7aa9a27a0b1158ed5ad4e7175e8d3aee9a818b96", + "reference": "7aa9a27a0b1158ed5ad4e7175e8d3aee9a818b96", "shasum": "" }, "require": { @@ -9419,9 +9419,9 @@ ], "support": { "issues": "https://github.com/maximebf/php-debugbar/issues", - "source": "https://github.com/maximebf/php-debugbar/tree/v1.22.2" + "source": "https://github.com/maximebf/php-debugbar/tree/v1.22.3" }, - "time": "2024-04-03T11:46:22+00:00" + "time": "2024-04-03T19:39:26+00:00" }, { "name": "mockery/mockery", diff --git a/flexiapi/database/factories/PhoneChangeCodeFactory.php b/flexiapi/database/factories/PhoneChangeCodeFactory.php index f8cfc81..f3da542 100644 --- a/flexiapi/database/factories/PhoneChangeCodeFactory.php +++ b/flexiapi/database/factories/PhoneChangeCodeFactory.php @@ -19,7 +19,7 @@ namespace Database\Factories; -use App\Password; +use App\Account; use App\PhoneChangeCode; use Illuminate\Database\Eloquent\Factories\Factory; @@ -29,11 +29,11 @@ class PhoneChangeCodeFactory extends Factory public function definition() { - $password = Password::factory()->create(); - $password->account->generateApiKey(); + $account = Account::factory()->create(); + $account->generateApiKey(); return [ - 'account_id' => $password->account->id, + 'account_id' => $account->id, 'code' => generatePin(), 'phone' => '+3312341234', ]; diff --git a/flexiapi/tests/Feature/ApiAccountDictionaryTest.php b/flexiapi/tests/Feature/ApiAccountDictionaryTest.php index 2405325..af7efac 100644 --- a/flexiapi/tests/Feature/ApiAccountDictionaryTest.php +++ b/flexiapi/tests/Feature/ApiAccountDictionaryTest.php @@ -19,7 +19,6 @@ namespace Tests\Feature; -use App\Password; use App\Account; use Tests\TestCase; @@ -30,9 +29,7 @@ class ApiAccountDictionaryTest extends TestCase public function testCreate() { - $password = Password::factory()->create(); - $account = $password->account; - + $account = Account::factory()->create(); $admin = Account::factory()->admin()->create(); $admin->generateApiKey(); @@ -43,12 +40,12 @@ class ApiAccountDictionaryTest extends TestCase // First key $this->keyAuthenticated($admin) - ->json($this->method, $this->route . '/' . $account->id . ' /dictionary/' . $key, [ + ->json($this->method, $this->route . '/' . $account->id . '/dictionary/' . $key, [ 'value' => $value ])->assertStatus(201); $this->keyAuthenticated($admin) - ->get($this->route . '/' . $account->id . ' /dictionary') + ->get($this->route . '/' . $account->id . '/dictionary/') ->assertStatus(200) ->assertJson([ $key => $value @@ -63,14 +60,25 @@ class ApiAccountDictionaryTest extends TestCase ] ]); + $this->keyAuthenticated($admin) + ->get($this->route . '/' . $account->id . '/dictionary/' . $key) + ->assertStatus(200) + ->assertJson(['value' => $value]); + + // Test dictionary accessor + $this->keyAuthenticated($admin) + ->get($this->route . '/' . $account->id . '/dictionary/' . $key) + ->assertStatus(200) + ->assertJson(['value' => $account->dictionary->get($key)]); + // Update $this->keyAuthenticated($admin) - ->json($this->method, $this->route . '/' . $account->id . ' /dictionary/' . $key, [ + ->json($this->method, $this->route . '/' . $account->id . '/dictionary/' . $key, [ 'value' => $newValue ])->assertStatus(200); $this->keyAuthenticated($admin) - ->get($this->route . '/' . $account->id . ' /dictionary') + ->get($this->route . '/' . $account->id . '/dictionary/') ->assertStatus(200) ->assertJson([ $key => $newValue @@ -78,12 +86,12 @@ class ApiAccountDictionaryTest extends TestCase // Second key $this->keyAuthenticated($admin) - ->json($this->method, $this->route . '/' . $account->id . ' /dictionary/' . $secondKey, [ + ->json($this->method, $this->route . '/' . $account->id . '/dictionary/' . $secondKey, [ 'value' => $newValue ])->assertStatus(201); $this->keyAuthenticated($admin) - ->get($this->route . '/' . $account->id . ' /dictionary') + ->get($this->route . '/' . $account->id . '/dictionary/') ->assertStatus(200) ->assertJson([ $key => $newValue, @@ -92,11 +100,11 @@ class ApiAccountDictionaryTest extends TestCase // Delete $this->keyAuthenticated($admin) - ->delete($this->route . '/' . $account->id . ' /dictionary/' . $key) + ->delete($this->route . '/' . $account->id . '/dictionary/' . $key) ->assertStatus(200); $this->keyAuthenticated($admin) - ->get($this->route . '/' . $account->id . ' /dictionary') + ->get($this->route . '/' . $account->id . '/dictionary/') ->assertStatus(200) ->assertJson([ $secondKey => $newValue