From 4adf29ccae38bb6a0e99931dbb11b03cfb43279f Mon Sep 17 00:00:00 2001 From: Nathan Curtis Date: Wed, 3 Apr 2024 10:47:03 -0700 Subject: [PATCH 01/44] [TM-785] Move constants to avoid a problem in PHPUnit. --- .../Middleware/ModelInterfaceBindingMiddleware.php | 3 +++ routes/api_v2.php | 12 +++++------- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/app/Http/Middleware/ModelInterfaceBindingMiddleware.php b/app/Http/Middleware/ModelInterfaceBindingMiddleware.php index 5fe437e89..c317824de 100644 --- a/app/Http/Middleware/ModelInterfaceBindingMiddleware.php +++ b/app/Http/Middleware/ModelInterfaceBindingMiddleware.php @@ -17,6 +17,9 @@ */ class ModelInterfaceBindingMiddleware { + public const ENTITY_TYPES_PLURAL = ['projects', 'project-reports', 'sites', 'site-reports', 'nurseries', 'nursery-reports']; + public const ENTITY_TYPES_SINGULAR = ['project', 'project-report', 'site', 'site-report', 'nursery', 'nursery-report']; + private const CONCRETE_MODELS = [ // EntityModel concrete classes 'projects' => Project::class, diff --git a/routes/api_v2.php b/routes/api_v2.php index 9d5a8e245..3adf4b85c 100644 --- a/routes/api_v2.php +++ b/routes/api_v2.php @@ -191,6 +191,7 @@ use App\Http\Controllers\V2\Workdays\GetWorkdaysForEntityController; use App\Http\Controllers\V2\Workdays\StoreWorkdayController; use App\Http\Controllers\V2\Workdays\UpdateWorkdayController; +use App\Http\Middleware\ModelInterfaceBindingMiddleware; use Illuminate\Support\Facades\Route; /* @@ -204,9 +205,6 @@ | */ -const ENTITY_TYPES_PLURAL = ['projects', 'project-reports', 'sites', 'site-reports', 'nurseries', 'nursery-reports']; -const ENTITY_TYPES_SINGULAR = ['project', 'project-report', 'site', 'site-report', 'nursery', 'nursery-report']; - Route::get('debug/error', function () { throw new Exception('Test exception', 500); }); @@ -298,7 +296,7 @@ Route::get('/{entity}/export/{framework}', ExportAllMonitoredEntitiesController::class); Route::prefix('{modelSlug}') - ->whereIn('modelSlug', ENTITY_TYPES_PLURAL) + ->whereIn('modelSlug', ModelInterfaceBindingMiddleware::ENTITY_TYPES_PLURAL) ->middleware('modelInterface') ->group(function() { Route::put('/{entity}/{status}', AdminStatusEntityController::class); @@ -411,7 +409,7 @@ Route::get('/{form}', ViewFormController::class)->middleware('i18n'); Route::prefix('{modelSlug}') - ->whereIn('modelSlug', ENTITY_TYPES_PLURAL) + ->whereIn('modelSlug', ModelInterfaceBindingMiddleware::ENTITY_TYPES_PLURAL) ->middleware('modelInterface') ->group(function() { Route::get('/{entity}', ViewEntityWithFormController::class)->middleware('i18n'); @@ -554,7 +552,7 @@ }); Route::prefix('{modelSlug}') - ->whereIn('modelSlug', ENTITY_TYPES_PLURAL) + ->whereIn('modelSlug', ModelInterfaceBindingMiddleware::ENTITY_TYPES_PLURAL) ->middleware('modelInterface') ->group(function() { Route::get('/{entity}', ViewEntityController::class); @@ -615,7 +613,7 @@ Route::delete('/{updateRequest}', AdminSoftDeleteUpdateRequestController::class); Route::prefix('/{modelSlug}') - ->whereIn('modelSlug', ENTITY_TYPES_SINGULAR) + ->whereIn('modelSlug', ModelInterfaceBindingMiddleware::ENTITY_TYPES_SINGULAR) ->middleware('modelInterface') ->group(function () { Route::get('/{entity}', EntityUpdateRequestsController::class); From 57900bab94b2b6d2d6c74d900688be703ae03cf8 Mon Sep 17 00:00:00 2001 From: Nathan Curtis Date: Wed, 3 Apr 2024 10:48:48 -0700 Subject: [PATCH 02/44] [TM-785] Fix old migration that was throwing an error in PHPUnit --- database/migrations/2023_08_16_091316_create_v2_sites_table.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/database/migrations/2023_08_16_091316_create_v2_sites_table.php b/database/migrations/2023_08_16_091316_create_v2_sites_table.php index c8bbc6484..5db7c15c8 100644 --- a/database/migrations/2023_08_16_091316_create_v2_sites_table.php +++ b/database/migrations/2023_08_16_091316_create_v2_sites_table.php @@ -20,7 +20,7 @@ public function up() $table->string('framework_key', 20)->nullable()->index(); $table->foreignIdFor(Project::class)->nullable(); $table->string('name')->nullable(); - $table->string('status')->default(Site::STATUS_STARTED); + $table->string('status')->default(\App\StateMachines\EntityStatusStateMachine::STARTED); $table->boolean('control_site')->nullable(); $table->longText('boundary_geojson')->nullable(); $table->text('land_use_types')->nullable(); From 0d5d2ca778572cbded0d907bb5cf7f09a9bed321 Mon Sep 17 00:00:00 2001 From: Nathan Curtis Date: Wed, 3 Apr 2024 13:37:40 -0700 Subject: [PATCH 03/44] [TM-785] Fail gracefully if SNS is not enabled. --- .env.example | 2 +- app/Services/PushService.php | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.env.example b/.env.example index 1abd5b9cf..cd310d83b 100644 --- a/.env.example +++ b/.env.example @@ -24,7 +24,7 @@ SESSION_LIFETIME=120 SNS_PLATFORM_ARN_IOS=arn:aws:sns:us-west-2:123456789012:app/APNS/wri_rm_ios SNS_PLATFORM_ARN_ANDROID=arn:aws:sns:us-west-2:123456789012:app/FCM/wri_rm_android SNS_PREFIX=http://motocker:9911 -SNS_ENABLED=true +SNS_ENABLED=false REDIS_HOST=redis REDIS_PASSWORD= diff --git a/app/Services/PushService.php b/app/Services/PushService.php index b3ab82827..dc33e3126 100644 --- a/app/Services/PushService.php +++ b/app/Services/PushService.php @@ -18,8 +18,12 @@ public function __construct() $this->snsClient = App::make('CustomSnsClient'); } - public function fetchEndpointArn(string $os, string $pushToken): string + public function fetchEndpointArn(string $os, string $pushToken): ?string { + if (!config('app.sns.enabled')) { + return null; + } + if (! in_array($os, ['android', 'ios']) || empty($pushToken)) { throw new Exception(); } From 1c18d99d0c8ccdec9377c35e564971577375d523 Mon Sep 17 00:00:00 2001 From: Nathan Curtis Date: Fri, 5 Apr 2024 12:41:56 -0700 Subject: [PATCH 04/44] [TM-785] Remove the legacy unit tests. --- phpunit.xml | 9 - tests/Legacy/Feature/AdminsControllerTest.php | 199 --- tests/Legacy/Feature/AimControllerTest.php | 108 -- tests/Legacy/Feature/AuthControllerTest.php | 319 ----- ...bonCertificationVersionsControllerTest.php | 199 --- .../CarbonCertificationsControllerTest.php | 177 --- tests/Legacy/Feature/CommandsTest.php | 554 -------- .../Feature/CustomReportControllerTest.php | 247 ---- tests/Legacy/Feature/DataControllerTest.php | 182 --- .../Legacy/Feature/DefaultControllerTest.php | 18 - .../Legacy/Feature/DevicesControllerTest.php | 137 -- .../Feature/DirectSeedingControllerTest.php | 50 - .../Feature/DocumentFileControllerTest.php | 162 --- .../Feature/DocumentationControllerTest.php | 34 - tests/Legacy/Feature/DraftsControllerTest.php | 1155 ----------------- .../Feature/DueSubmissionControllerTest.php | 30 - .../Feature/ElevatorVideosControllerTest.php | 65 - .../FrameworkInviteCodeControllerTest.php | 110 -- .../Feature/InterestsControllerTest.php | 137 -- .../Legacy/Feature/InvasiveControllerTest.php | 34 - .../Feature/LandTenureControllerTest.php | 34 - .../LegacySatelliteMonitorControllerTest.php | 188 --- .../Legacy/Feature/MatchesControllerTest.php | 148 --- .../Feature/MediaUploadControllerTest.php | 38 - .../Feature/MonitoringsControllerTest.php | 869 ------------- .../Feature/NotificationsControllerTest.php | 63 - .../Feature/OfferContactsControllerTest.php | 121 -- .../Feature/OfferDocumentsControllerTest.php | 141 -- tests/Legacy/Feature/OffersControllerTest.php | 436 ------- ...nisationDocumentVersionsControllerTest.php | 203 --- .../OrganisationDocumentsControllerTest.php | 189 --- .../OrganisationFileControllerTest.php | 181 --- .../OrganisationPhotoControllerTest.php | 99 -- .../OrganisationVersionsControllerTest.php | 284 ---- .../Feature/OrganisationsControllerTest.php | 302 ----- .../Legacy/Feature/PendingControllerTest.php | 49 - .../Feature/PitchContactsControllerTest.php | 121 -- .../PitchDocumentVersionsControllerTest.php | 203 --- .../Feature/PitchDocumentsControllerTest.php | 187 --- .../Feature/PitchVersionsControllerTest.php | 299 ----- .../Legacy/Feature/PitchesControllerTest.php | 694 ---------- .../Feature/ProgrammeControllerTest.php | 217 ---- .../Feature/ProgrammeInviteControllerTest.php | 278 ---- .../ProgrammeTreeSpeciesControllerTest.php | 263 ---- .../ProgrammeTreeSpeciesCsvControllerTest.php | 152 --- .../Feature/ProgressUpdatesControllerTest.php | 309 ----- .../Legacy/Feature/ReportsControllerTest.php | 102 -- ...tionMethodMetricVersionsControllerTest.php | 224 ---- ...RestorationMethodMetricsControllerTest.php | 204 --- .../Feature/SatelliteMapsControllerTest.php | 133 -- .../Feature/SeedDetailControllerTest.php | 84 -- tests/Legacy/Feature/SiteControllerTest.php | 466 ------- .../SiteRestorationMethodsControllerTest.php | 34 - .../Feature/SiteSubmissionControllerTest.php | 185 --- ...iteSubmissionDisturbanceControllerTest.php | 328 ----- .../Feature/SiteTreeSpeciesControllerTest.php | 145 --- .../SiteTreeSpeciesCsvControllerTest.php | 133 -- .../SocioeconomicBenefitsControllerTest.php | 148 --- .../Feature/StratificationControllerTest.php | 24 - .../Feature/SubmissionControllerTest.php | 191 --- .../SubmissionMediaUploadControllerTest.php | 61 - .../Legacy/Feature/TargetsControllerTest.php | 242 ---- tests/Legacy/Feature/TasksControllerTest.php | 236 ---- .../Feature/TeamMembersControllerTest.php | 192 --- ...cyTerrafundDueSubmissionControllerTest.php | 183 --- .../LegacyTerrafundFileControllerTest.php | 263 ---- .../LegacyTerrafundNurseryControllerTest.php | 172 --- ...LegacyTerrafundProgrammeControllerTest.php | 386 ------ ...rafundProgrammeNurseriesControllerTest.php | 57 - ...yTerrafundProgrammeSitesControllerTest.php | 75 -- ...gacyTerrafundTreeSpeciesControllerTest.php | 138 -- .../TerrafundCsvImportControllerTest.php | 119 -- ...TerrafundProgrammeInviteControllerTest.php | 159 --- .../Terrafund/TerrafundSiteControllerTest.php | 234 ---- .../Feature/TreeSpeciesControllerTest.php | 232 ---- .../TreeSpeciesVersionsControllerTest.php | 245 ---- .../Legacy/Feature/UploadsControllerTest.php | 87 -- tests/Legacy/Feature/UsersControllerTest.php | 473 ------- tests/Legacy/LegacyTestCase.php | 169 --- .../Legacy/Other/ActionAuthorisationTest.php | 19 - tests/Legacy/Other/ActionTypeHintsTest.php | 30 - tests/Legacy/Other/DraftValidatorTest.php | 105 -- .../Legacy/Other/NoDebuggingRemainingTest.php | 18 - .../Other/RoutesAndSwaggerMatchTest.php | 56 - .../Other/ValidationRulesDocumentedTest.php | 27 - tests/Legacy/Unit/ArrayArrayExtensionTest.php | 54 - .../Legacy/Unit/ArrayObjectExtensionTest.php | 40 - .../CreateProgrammeTreeSpeciesJobTest.php | 19 - .../Jobs/CreateSiteTreeSpeciesJobTest.php | 31 - .../CreateTerrafundTreeSpeciesJobTest.php | 23 - ...oveProgrammeTreeSpeciesByImportJobTest.php | 33 - .../RemoveSiteTreeSpeciesByImportJobTest.php | 23 - ...oveTerrafundTreeSpeciesByImportJobTest.php | 23 - tests/Legacy/Unit/JsonPatchHelperTest.php | 138 -- .../Unit/Models/CarbonCertificationTest.php | 17 - .../Models/CarbonCertificationVersionTest.php | 17 - tests/Legacy/Unit/Models/DeviceTest.php | 17 - tests/Legacy/Unit/Models/DraftTest.php | 17 - .../Legacy/Unit/Models/ElevatorVideoTest.php | 25 - tests/Legacy/Unit/Models/FilterRecordTest.php | 25 - tests/Legacy/Unit/Models/InterestTest.php | 33 - tests/Legacy/Unit/Models/MatchTest.php | 25 - tests/Legacy/Unit/Models/MonitoringTest.php | 26 - tests/Legacy/Unit/Models/NotificationTest.php | 17 - tests/Legacy/Unit/Models/OfferContactTest.php | 33 - .../Legacy/Unit/Models/OfferDocumentTest.php | 17 - tests/Legacy/Unit/Models/OfferTest.php | 17 - .../Unit/Models/OrganisationDocumentTest.php | 17 - .../OrganisationDocumentVersionTest.php | 17 - .../Unit/Models/OrganisationVersionTest.php | 19 - .../Legacy/Unit/Models/PasswordResetTest.php | 19 - tests/Legacy/Unit/Models/PitchContactTest.php | 28 - .../Legacy/Unit/Models/PitchDocumentTest.php | 19 - .../Unit/Models/PitchDocumentVersionTest.php | 28 - tests/Legacy/Unit/Models/PitchTest.php | 19 - tests/Legacy/Unit/Models/PitchVersionTest.php | 28 - .../Legacy/Unit/Models/ProgressUpdateTest.php | 28 - .../Models/RestorationMethodMetricTest.php | 19 - .../RestorationMethodMetricVersionTest.php | 28 - tests/Legacy/Unit/Models/SatelliteMapTest.php | 28 - tests/Legacy/Unit/Models/TargetTest.php | 36 - tests/Legacy/Unit/Models/TeamMemberTest.php | 19 - tests/Legacy/Unit/Models/TreeSpeciesTest.php | 19 - .../Unit/Models/TreeSpeciesVersionTest.php | 28 - tests/Legacy/Unit/Models/UploadTest.php | 17 - tests/Legacy/Unit/Models/UserTest.php | 17 - tests/Legacy/Unit/Models/VerificationTest.php | 19 - 127 files changed, 17495 deletions(-) delete mode 100644 tests/Legacy/Feature/AdminsControllerTest.php delete mode 100644 tests/Legacy/Feature/AimControllerTest.php delete mode 100644 tests/Legacy/Feature/AuthControllerTest.php delete mode 100644 tests/Legacy/Feature/CarbonCertificationVersionsControllerTest.php delete mode 100644 tests/Legacy/Feature/CarbonCertificationsControllerTest.php delete mode 100644 tests/Legacy/Feature/CommandsTest.php delete mode 100644 tests/Legacy/Feature/CustomReportControllerTest.php delete mode 100644 tests/Legacy/Feature/DataControllerTest.php delete mode 100644 tests/Legacy/Feature/DefaultControllerTest.php delete mode 100644 tests/Legacy/Feature/DevicesControllerTest.php delete mode 100644 tests/Legacy/Feature/DirectSeedingControllerTest.php delete mode 100644 tests/Legacy/Feature/DocumentFileControllerTest.php delete mode 100644 tests/Legacy/Feature/DocumentationControllerTest.php delete mode 100644 tests/Legacy/Feature/DraftsControllerTest.php delete mode 100644 tests/Legacy/Feature/DueSubmissionControllerTest.php delete mode 100644 tests/Legacy/Feature/ElevatorVideosControllerTest.php delete mode 100644 tests/Legacy/Feature/FrameworkInviteCodeControllerTest.php delete mode 100644 tests/Legacy/Feature/InterestsControllerTest.php delete mode 100644 tests/Legacy/Feature/InvasiveControllerTest.php delete mode 100644 tests/Legacy/Feature/LandTenureControllerTest.php delete mode 100644 tests/Legacy/Feature/LegacySatelliteMonitorControllerTest.php delete mode 100644 tests/Legacy/Feature/MatchesControllerTest.php delete mode 100644 tests/Legacy/Feature/MediaUploadControllerTest.php delete mode 100644 tests/Legacy/Feature/MonitoringsControllerTest.php delete mode 100644 tests/Legacy/Feature/NotificationsControllerTest.php delete mode 100644 tests/Legacy/Feature/OfferContactsControllerTest.php delete mode 100644 tests/Legacy/Feature/OfferDocumentsControllerTest.php delete mode 100644 tests/Legacy/Feature/OffersControllerTest.php delete mode 100644 tests/Legacy/Feature/OrganisationDocumentVersionsControllerTest.php delete mode 100644 tests/Legacy/Feature/OrganisationDocumentsControllerTest.php delete mode 100644 tests/Legacy/Feature/OrganisationFileControllerTest.php delete mode 100644 tests/Legacy/Feature/OrganisationPhotoControllerTest.php delete mode 100644 tests/Legacy/Feature/OrganisationVersionsControllerTest.php delete mode 100644 tests/Legacy/Feature/OrganisationsControllerTest.php delete mode 100644 tests/Legacy/Feature/PendingControllerTest.php delete mode 100644 tests/Legacy/Feature/PitchContactsControllerTest.php delete mode 100644 tests/Legacy/Feature/PitchDocumentVersionsControllerTest.php delete mode 100644 tests/Legacy/Feature/PitchDocumentsControllerTest.php delete mode 100644 tests/Legacy/Feature/PitchVersionsControllerTest.php delete mode 100644 tests/Legacy/Feature/PitchesControllerTest.php delete mode 100644 tests/Legacy/Feature/ProgrammeControllerTest.php delete mode 100644 tests/Legacy/Feature/ProgrammeInviteControllerTest.php delete mode 100644 tests/Legacy/Feature/ProgrammeTreeSpeciesControllerTest.php delete mode 100644 tests/Legacy/Feature/ProgrammeTreeSpeciesCsvControllerTest.php delete mode 100644 tests/Legacy/Feature/ProgressUpdatesControllerTest.php delete mode 100644 tests/Legacy/Feature/ReportsControllerTest.php delete mode 100644 tests/Legacy/Feature/RestorationMethodMetricVersionsControllerTest.php delete mode 100644 tests/Legacy/Feature/RestorationMethodMetricsControllerTest.php delete mode 100644 tests/Legacy/Feature/SatelliteMapsControllerTest.php delete mode 100644 tests/Legacy/Feature/SeedDetailControllerTest.php delete mode 100644 tests/Legacy/Feature/SiteControllerTest.php delete mode 100644 tests/Legacy/Feature/SiteRestorationMethodsControllerTest.php delete mode 100644 tests/Legacy/Feature/SiteSubmissionControllerTest.php delete mode 100644 tests/Legacy/Feature/SiteSubmissionDisturbanceControllerTest.php delete mode 100644 tests/Legacy/Feature/SiteTreeSpeciesControllerTest.php delete mode 100644 tests/Legacy/Feature/SiteTreeSpeciesCsvControllerTest.php delete mode 100644 tests/Legacy/Feature/SocioeconomicBenefitsControllerTest.php delete mode 100644 tests/Legacy/Feature/StratificationControllerTest.php delete mode 100644 tests/Legacy/Feature/SubmissionControllerTest.php delete mode 100644 tests/Legacy/Feature/SubmissionMediaUploadControllerTest.php delete mode 100644 tests/Legacy/Feature/TargetsControllerTest.php delete mode 100644 tests/Legacy/Feature/TasksControllerTest.php delete mode 100644 tests/Legacy/Feature/TeamMembersControllerTest.php delete mode 100644 tests/Legacy/Feature/Terrafund/LegacyTerrafundDueSubmissionControllerTest.php delete mode 100644 tests/Legacy/Feature/Terrafund/LegacyTerrafundFileControllerTest.php delete mode 100644 tests/Legacy/Feature/Terrafund/LegacyTerrafundNurseryControllerTest.php delete mode 100644 tests/Legacy/Feature/Terrafund/LegacyTerrafundProgrammeControllerTest.php delete mode 100644 tests/Legacy/Feature/Terrafund/LegacyTerrafundProgrammeNurseriesControllerTest.php delete mode 100644 tests/Legacy/Feature/Terrafund/LegacyTerrafundProgrammeSitesControllerTest.php delete mode 100644 tests/Legacy/Feature/Terrafund/LegacyTerrafundTreeSpeciesControllerTest.php delete mode 100644 tests/Legacy/Feature/Terrafund/TerrafundCsvImportControllerTest.php delete mode 100644 tests/Legacy/Feature/Terrafund/TerrafundProgrammeInviteControllerTest.php delete mode 100644 tests/Legacy/Feature/Terrafund/TerrafundSiteControllerTest.php delete mode 100644 tests/Legacy/Feature/TreeSpeciesControllerTest.php delete mode 100644 tests/Legacy/Feature/TreeSpeciesVersionsControllerTest.php delete mode 100644 tests/Legacy/Feature/UploadsControllerTest.php delete mode 100644 tests/Legacy/Feature/UsersControllerTest.php delete mode 100644 tests/Legacy/LegacyTestCase.php delete mode 100644 tests/Legacy/Other/ActionAuthorisationTest.php delete mode 100644 tests/Legacy/Other/ActionTypeHintsTest.php delete mode 100644 tests/Legacy/Other/DraftValidatorTest.php delete mode 100644 tests/Legacy/Other/NoDebuggingRemainingTest.php delete mode 100644 tests/Legacy/Other/RoutesAndSwaggerMatchTest.php delete mode 100644 tests/Legacy/Other/ValidationRulesDocumentedTest.php delete mode 100644 tests/Legacy/Unit/ArrayArrayExtensionTest.php delete mode 100644 tests/Legacy/Unit/ArrayObjectExtensionTest.php delete mode 100644 tests/Legacy/Unit/Jobs/CreateProgrammeTreeSpeciesJobTest.php delete mode 100644 tests/Legacy/Unit/Jobs/CreateSiteTreeSpeciesJobTest.php delete mode 100644 tests/Legacy/Unit/Jobs/CreateTerrafundTreeSpeciesJobTest.php delete mode 100644 tests/Legacy/Unit/Jobs/RemoveProgrammeTreeSpeciesByImportJobTest.php delete mode 100644 tests/Legacy/Unit/Jobs/RemoveSiteTreeSpeciesByImportJobTest.php delete mode 100644 tests/Legacy/Unit/Jobs/RemoveTerrafundTreeSpeciesByImportJobTest.php delete mode 100644 tests/Legacy/Unit/JsonPatchHelperTest.php delete mode 100644 tests/Legacy/Unit/Models/CarbonCertificationTest.php delete mode 100644 tests/Legacy/Unit/Models/CarbonCertificationVersionTest.php delete mode 100644 tests/Legacy/Unit/Models/DeviceTest.php delete mode 100644 tests/Legacy/Unit/Models/DraftTest.php delete mode 100644 tests/Legacy/Unit/Models/ElevatorVideoTest.php delete mode 100644 tests/Legacy/Unit/Models/FilterRecordTest.php delete mode 100644 tests/Legacy/Unit/Models/InterestTest.php delete mode 100644 tests/Legacy/Unit/Models/MatchTest.php delete mode 100644 tests/Legacy/Unit/Models/MonitoringTest.php delete mode 100644 tests/Legacy/Unit/Models/NotificationTest.php delete mode 100644 tests/Legacy/Unit/Models/OfferContactTest.php delete mode 100644 tests/Legacy/Unit/Models/OfferDocumentTest.php delete mode 100644 tests/Legacy/Unit/Models/OfferTest.php delete mode 100644 tests/Legacy/Unit/Models/OrganisationDocumentTest.php delete mode 100644 tests/Legacy/Unit/Models/OrganisationDocumentVersionTest.php delete mode 100644 tests/Legacy/Unit/Models/OrganisationVersionTest.php delete mode 100644 tests/Legacy/Unit/Models/PasswordResetTest.php delete mode 100644 tests/Legacy/Unit/Models/PitchContactTest.php delete mode 100644 tests/Legacy/Unit/Models/PitchDocumentTest.php delete mode 100644 tests/Legacy/Unit/Models/PitchDocumentVersionTest.php delete mode 100644 tests/Legacy/Unit/Models/PitchTest.php delete mode 100644 tests/Legacy/Unit/Models/PitchVersionTest.php delete mode 100644 tests/Legacy/Unit/Models/ProgressUpdateTest.php delete mode 100644 tests/Legacy/Unit/Models/RestorationMethodMetricTest.php delete mode 100644 tests/Legacy/Unit/Models/RestorationMethodMetricVersionTest.php delete mode 100644 tests/Legacy/Unit/Models/SatelliteMapTest.php delete mode 100644 tests/Legacy/Unit/Models/TargetTest.php delete mode 100644 tests/Legacy/Unit/Models/TeamMemberTest.php delete mode 100644 tests/Legacy/Unit/Models/TreeSpeciesTest.php delete mode 100644 tests/Legacy/Unit/Models/TreeSpeciesVersionTest.php delete mode 100644 tests/Legacy/Unit/Models/UploadTest.php delete mode 100644 tests/Legacy/Unit/Models/UserTest.php delete mode 100644 tests/Legacy/Unit/Models/VerificationTest.php diff --git a/phpunit.xml b/phpunit.xml index b323217bf..e474e20a4 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -14,15 +14,6 @@ ./tests/Other - - ./tests/Legacy/Feature - - - ./tests/Legacy/Unit - - - ./tests/Legacy/Other - ./tests/V2 diff --git a/tests/Legacy/Feature/AdminsControllerTest.php b/tests/Legacy/Feature/AdminsControllerTest.php deleted file mode 100644 index c8da5ffcc..000000000 --- a/tests/Legacy/Feature/AdminsControllerTest.php +++ /dev/null @@ -1,199 +0,0 @@ - 'jane@example.com', - 'password' => 'Password123', - ]); - $data = [ - 'email_address' => 'anna@example.com', - ]; - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $response = $this->postJson('/api/admins/invite', $data, $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(201); - $response->assertJsonStructure([ - 'data' => [ - 'id', - 'first_name', - 'last_name', - 'email_address', - 'role', - 'email_address_verified_at', - 'last_logged_in_at', - ], - ]); - $response->assertJson([ - 'data' => [ - 'first_name' => null, - 'last_name' => null, - 'email_address' => 'anna@example.com', - 'role' => 'admin', - 'email_address_verified_at' => null, - 'last_logged_in_at' => null, - ], - ]); - } - - public function testAcceptAction(): void - { - $data = [ - 'first_name' => 'Tom', - 'last_name' => 'Doe', - 'email_address' => 'tom@example.com', - 'password' => 'Password123', - 'job_role' => 'Manager', - ]; - $headers = [ - 'Content-Type' => 'application/json', - ]; - $response = $this->postJson('/api/admins/accept', $data, $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(201); - $response->assertJsonStructure([ - 'data' => [ - 'id', - 'first_name', - 'last_name', - 'email_address', - 'role', - 'email_address_verified_at', - 'last_logged_in_at', - 'job_role', - ], - ]); - $response->assertJson([ - 'data' => [ - 'first_name' => 'Tom', - 'last_name' => 'Doe', - 'email_address' => 'tom@example.com', - ], - ]); - } - - public function testReadAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'jane@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->getJson('/api/admins/2', $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure([ - 'data' => [ - 'id', - 'first_name', - 'last_name', - 'email_address', - 'role', - 'last_logged_in_at', - 'email_address_verified_at', - ], - ]); - } - - public function testReadAllAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'jane@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->getJson('/api/admins', $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonCount(4, 'data'); - $response->assertJsonFragment([ - 'id' => 2, - 'role' => 'admin', - ]); - $response->assertJsonFragment([ - 'id' => 5, - 'role' => 'admin', - ]); - $response->assertJsonFragment([ - 'id' => 15, - 'role' => 'terrafund_admin', - ]); - $response->assertJsonStructure([ - 'data' => [ - [ - 'id', - 'first_name', - 'last_name', - 'email_address', - 'role', - 'last_logged_in_at', - 'email_address_verified_at', - ], - ], - 'meta' => [ - 'count', - ], - ]); - } - - public function testUpdateAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'jane@example.com', - 'password' => 'Password123', - ]); - $data = [ - 'first_name' => 'Joan', - ]; - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $response = $this->patchJson('/api/admins/2', $data, $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure([ - 'data' => [ - 'id', - 'first_name', - 'last_name', - 'email_address', - 'role', - 'email_address_verified_at', - 'last_logged_in_at', - ], - ]); - $response->assertJson([ - 'data' => [ - 'first_name' => 'Joan', - ], - ]); - } - - public function testUnsubscribeAction(): void - { - $encryptedId = Crypt::encryptString('2'); - $response = $this->get('/admins/' . $encryptedId . '/unsubscribe'); - $response->assertStatus(302); - $url = config('app.front_end'). '/unsubscribe'; - $response->assertHeader('Location', $url); - $admin = AdminModel::findOrFail(2); - $this->assertFalse($admin->is_subscribed); - } -} diff --git a/tests/Legacy/Feature/AimControllerTest.php b/tests/Legacy/Feature/AimControllerTest.php deleted file mode 100644 index de9230bcb..000000000 --- a/tests/Legacy/Feature/AimControllerTest.php +++ /dev/null @@ -1,108 +0,0 @@ - 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $this->getJson('/api/programme/1/aims', $headers) - ->assertStatus(200) - ->assertJsonFragment([ - 'programme_id' => 1, - 'year_five_trees' => 1000, - 'restoration_hectares' => 1234, - 'survival_rate' => 50, - 'year_five_crown_cover' => 1000, - ]); - } - - public function testReadActionRequiresBelongingToProgramme(): void - { - $token = Auth::attempt([ - 'email_address' => 'sue@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $this->getJson('/api/programme/1/aims', $headers) - ->assertStatus(403); - } - - public function testReadActionWhenNoTargetsExist(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - User::where('id', 3)->firstOrFail()->programmes()->sync(2, false); - - $this->getJson('/api/programme/2/aims', $headers) - ->assertStatus(404); - } - - public function testUpdateAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $this->postJson('/api/programme/1/aims', [ - 'year_five_trees' => 1234, - 'restoration_hectares' => 61000, - 'survival_rate' => 100, - 'year_five_crown_cover' => 1000, - ], $headers) - ->assertStatus(201) - ->assertJsonFragment([ - 'programme_id' => 1, - 'year_five_trees' => 1234, - 'restoration_hectares' => 61000, - 'survival_rate' => 100, - 'year_five_crown_cover' => 1000, - ]); - } - - public function testUpdateActionRequiresBelongingToProgramme(): void - { - $token = Auth::attempt([ - 'email_address' => 'sue@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $this->postJson('/api/programme/1/aims', [ - 'year_five_trees' => 1234, - 'restoration_hectares' => 61000, - 'survival_rate' => 100, - 'year_five_crown_cover' => 1000, - ], $headers) - ->assertStatus(403); - } -} diff --git a/tests/Legacy/Feature/AuthControllerTest.php b/tests/Legacy/Feature/AuthControllerTest.php deleted file mode 100644 index dbdf19116..000000000 --- a/tests/Legacy/Feature/AuthControllerTest.php +++ /dev/null @@ -1,319 +0,0 @@ - 'joe@example.com', - 'password' => 'Password123', - ]; - $headers = [ - 'Content-Type' => 'application/json', - ]; - $response = $this->postJson('/api/auth/login', $data, $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure([ - 'data' => [ - 'token', - ], - ]); - $this->assertNotEmpty($response->json('data.token')); - } - - public function testLogoutAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'joe@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->getJson('/api/auth/logout', $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJson([ - 'data' => [], - ]); - } - - public function testRefreshAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'joe@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->getJson('/api/auth/refresh', $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure([ - 'data' => [ - 'token', - ], - ]); - $this->assertNotEmpty($response->json('data.token')); - } - - public function testResendAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'joe@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->getJson('/api/auth/resend', $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJson([ - 'data' => [], - ]); - $this->assertDatabaseHas('verifications', ['user_id' => 1]); - } - - public function testVerifyAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'joe@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $data = [ - 'token' => 'ejyNeH1Rc26qNJeok932fGUv8GyNqMs4', - ]; - $response = $this->patchJson('/api/auth/verify', $data, $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJson([ - 'data' => [], - ]); - $this->assertDatabaseMissing('verifications', ['user_id' => 1]); - } - - public function testVerifyUnauthorizedAction(): void - { - $data = [ - 'token' => 'fjyNeH1Rc26qNJeok932fGUv8GyNqMs4', - ]; - $response = $this->patchJson('/api/v2/auth/verify', $data); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJson([ - 'data' => [], - ]); - $this->assertDatabaseMissing('verifications', ['user_id' => 2]); - } - - public function testResetAction(): void - { - Queue::fake(); - - $data = [ - 'email_address' => 'jane@example.com', - ]; - $headers = [ - 'Content-Type' => 'application/json', - ]; - $response = $this->postJson('/api/auth/reset', $data, $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJson([ - 'data' => [], - ]); - - Queue::assertPushed(ResetPasswordJob::class); - } - - public function testResetActionAsAdmin(): void - { - Queue::fake(); - - $data = [ - 'email_address' => 'steve@example.com', - ]; - $token = Auth::attempt([ - 'email_address' => 'jane@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->postJson('/api/auth/reset', $data, $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJson([ - 'data' => [], - ]); - - Queue::assertPushed(ResetPasswordJob::class); - } - - public function testChangeAction(): void - { - $headers = [ - 'Content-Type' => 'application/json', - ]; - $data = [ - 'token' => 'kmaBxJbn2NyfbLAIAAQtQGGdiJmyIblS', - 'password' => 'Password456', - ]; - $response = $this->patchJson('/api/auth/change', $data, $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJson([ - 'data' => [], - ]); - $this->assertDatabaseMissing('password_resets', ['user_id' => 1]); - } - - public function testMeAction(): void - { - $this->callMeActionAsAdmin(); - $this->callMeActionAsUser(); - $this->callMeActionAsUserWithNoApprovedOrganisation(); - } - - private function callMeActionAsAdmin() - { - $token = Auth::attempt([ - 'email_address' => 'jane@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->getJson('/api/auth/me', $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure([ - 'data' => [ - 'uuid', - 'first_name', - 'last_name', - 'email_address', - 'role', -// 'last_logged_in_at', -// 'email_address_verified_at', - ], - ]); - } - - private function callMeActionAsUser() - { - $token = Auth::attempt([ - 'email_address' => 'joe@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->getJson('/api/auth/me', $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure([ - 'data' => [ - 'uuid', -// 'organisation_id', -// 'my_organisation', -// 'my_monitoring_organisations', - 'first_name', - 'last_name', - 'email_address', - 'role', -// 'email_address_verified_at', -// 'last_logged_in_at', -// 'twitter', -// 'facebook', -// 'linkedin', -// 'instagram', -// 'phone_number', -// 'has_ppc_projects', -// 'has_terrafund_projects', - ], -// 'meta' => [], - ]); - } - - private function callMeActionAsUserWithNoApprovedOrganisation() - { - $token = Auth::attempt([ - 'email_address' => 'ian@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->getJson('/api/auth/me', $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure([ - 'data' => [ - 'uuid', -// 'organisation_id', -// 'organisation_name', -// 'my_organisation', -// 'my_monitoring_organisations', - 'first_name', - 'last_name', - 'email_address', - 'role', -// 'email_address_verified_at', -// 'last_logged_in_at', -// 'twitter', -// 'facebook', -// 'linkedin', -// 'instagram', -// 'phone_number', - ], -// 'meta' => [], - ]); - } - - public function testDeleteMeActionSuccess(): void - { - $notAnAdmin = User::factory()->create(); - $userId = $notAnAdmin->id; - - $this->actingAs($notAnAdmin); - - $this->deleteJson( - '/api/auth/delete_me', - [], - $this->getHeadersForUser($notAnAdmin->email_address) - ) - ->assertStatus(200); - - $record = User::withTrashed()->find($userId); - $this->assertIsInt($record->id); - $this->assertNull($record->first_name); - $this->assertNull($record->last_name); - $this->assertNull($record->phone_number); - $this->assertTrue(Str::isUuid($record->email_address)); - - $record = User::find($userId); - $this->assertNull($record); - } - - public function testGuestDeleteMeActionFails(): void - { - $this->deleteJson('/api/auth/delete_me') - ->assertStatus(401); - } -} diff --git a/tests/Legacy/Feature/CarbonCertificationVersionsControllerTest.php b/tests/Legacy/Feature/CarbonCertificationVersionsControllerTest.php deleted file mode 100644 index ef597342f..000000000 --- a/tests/Legacy/Feature/CarbonCertificationVersionsControllerTest.php +++ /dev/null @@ -1,199 +0,0 @@ - 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->getJson('/api/carbon_certification_versions/1', $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure([ - 'data' => [ - 'id', - 'status', - 'approved_rejected_by', - 'rejected_reason', - 'rejected_reason_body', - 'data' => [ - 'id', - 'pitch_id', - 'type', - 'link', - ], - ], - ]); - } - - public function testApproveAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'jane@example.com', - 'password' => 'Password123', - ]); - $data = []; - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $response = $this->patchJson('/api/carbon_certification_versions/2/approve', $data, $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure([ - 'data' => [ - 'id', - 'status', - 'approved_rejected_by', - 'rejected_reason', - 'rejected_reason_body', - 'data' => [ - 'id', - 'pitch_id', - 'type', - 'link', - ], - ], - ]); - $response->assertJson([ - 'data' => [ - 'status' => 'approved', - ], - ]); - } - - public function testRejectAction(): void - { - ; - $token = Auth::attempt([ - 'email_address' => 'jane@example.com', - 'password' => 'Password123', - ]); - $data = [ - 'rejected_reason' => 'cannot_verify', - 'rejected_reason_body' => 'Lorem ipsum dolor sit amet', - ]; - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $response = $this->patchJson('/api/carbon_certification_versions/2/reject', $data, $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure([ - 'data' => [ - 'id', - 'status', - 'approved_rejected_by', - 'rejected_reason', - 'rejected_reason_body', - 'data' => [ - 'id', - 'pitch_id', - 'type', - 'link', - ], - ], - ]); - $response->assertJson([ - 'data' => [ - 'status' => 'rejected', - ], - ]); - } - - public function testDeleteAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->deleteJson('/api/carbon_certification_versions/2', $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJson([ - 'data' => [], - ]); - } - - public function testReadAllByCarbonCertificationAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->getJson('/api/carbon_certifications/1/carbon_certification_versions', $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure([ - 'data' => [ - [ - 'id', - 'status', - 'approved_rejected_by', - 'approved_rejected_at', - 'rejected_reason', - 'rejected_reason_body', - 'data' => [ - 'id', - 'pitch_id', - 'type', - 'link', - ], - ], - ], - ]); - } - - public function testReviveAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'jane@example.com', - 'password' => 'Password123', - ]); - $data = []; - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $response = $this->patchJson('/api/carbon_certification_versions/3/revive', $data, $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure([ - 'data' => [ - 'id', - 'status', - 'approved_rejected_by', - 'rejected_reason', - 'rejected_reason_body', - 'data' => [ - 'id', - 'pitch_id', - 'type', - 'link', - ], - ], - ]); - $response->assertJson([ - 'data' => [ - 'status' => 'approved', - ], - ]); - } -} diff --git a/tests/Legacy/Feature/CarbonCertificationsControllerTest.php b/tests/Legacy/Feature/CarbonCertificationsControllerTest.php deleted file mode 100644 index 2f6f6de10..000000000 --- a/tests/Legacy/Feature/CarbonCertificationsControllerTest.php +++ /dev/null @@ -1,177 +0,0 @@ - 'steve@example.com', - 'password' => 'Password123', - ]); - $data = [ - 'pitch_id' => 1, - 'type' => 'other', - 'other_value' => 'foo bar baz', - 'link' => 'http://www.example.com/carbon_certification.pdf', - ]; - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $response = $this->postJson('/api/carbon_certifications', $data, $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(201); - $response->assertJsonStructure([ - 'data' => [ - 'id', - 'status', - 'approved_rejected_by', - 'rejected_reason', - 'rejected_reason_body', - 'data' => [ - 'id', - 'pitch_id', - 'type', - 'other_value', - 'link', - ], - ], - ]); - } - - public function testReadAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->getJson('/api/carbon_certifications/1', $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure([ - 'data' => [ - 'id', - 'pitch_id', - 'type', - 'other_value', - 'link', - ], - ]); - } - - public function testUpdateAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $data = [ - 'type' => 'plan_vivo', - 'other_value' => null, - ]; - $response = $this->patchJson('/api/carbon_certifications/1', $data, $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure([ - 'data' => [ - 'id', - 'status', - 'approved_rejected_by', - 'rejected_reason', - 'rejected_reason_body', - 'data' => [ - 'id', - 'pitch_id', - 'type', - 'other_value', - 'link', - ], - ], - ]); - } - - public function testReadAllByPitchAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->getJson('/api/pitches/1/carbon_certifications', $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure([ - 'data' => [ - [ - 'id', - 'pitch_id', - 'type', - 'other_value', - 'link', - ], - ], - ]); - } - - public function testInspectByPitchAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->getJson('/api/pitches/1/carbon_certifications/inspect', $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure([ - 'data' => [ - [ - 'id', - 'status', - 'approved_rejected_by', - 'approved_rejected_at', - 'rejected_reason', - 'rejected_reason_body', - 'data' => [ - 'id', - 'pitch_id', - 'type', - 'other_value', - 'link', - ], - ], - ], - ]); - } - - public function testDeleteAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $response = $this->deleteJson('/api/carbon_certifications/1', $headers); - $response->assertStatus(200); - $this->assertNull(CarbonCertificationModel::find(1)); - } -} diff --git a/tests/Legacy/Feature/CommandsTest.php b/tests/Legacy/Feature/CommandsTest.php deleted file mode 100644 index 52422a8af..000000000 --- a/tests/Legacy/Feature/CommandsTest.php +++ /dev/null @@ -1,554 +0,0 @@ - 2, - 'secondary_interest_id' => 1, - 'created_at' => $past, - 'updated_at' => $past, - ]); - - $match->save(); - - $this->artisan('create-visibility-notifications') - ->assertExitCode(0); - - Queue::assertPushed(NotifyUpdateVisibilityJob::class); - } - - public function testFindMatchesCommand(): void - { - $presentDate = new \DateTime('now', new \DateTimeZone('UTC')); - - $interest = InterestModel::create([ - 'organisation_id' => 2, - 'initiator' => 'offer', - 'offer_id' => 3, - 'pitch_id' => 1, - 'created_at' => $presentDate, - 'updated_at' => $presentDate, - ]); - $interest->save(); - $interest = InterestModel::create([ - 'organisation_id' => 1, - 'initiator' => 2, - 'offer_id' => 3, - 'pitch_id' => 1, - 'created_at' => $presentDate, - 'updated_at' => $presentDate, - ]); - $interest->save(); - - $this->artisan('find-matches') - ->assertExitCode(0); - - $this->assertDatabaseHas('interests', ['has_matched' => true]); - $this->assertDatabaseHas('matches', ['primary_interest_id' => 3]); - } - - public function testRemoveElevatorCommand(): void - { - $pastDate = new \DateTime('now - 2 day', new \DateTimeZone('UTC')); - $elevatorVideo = ElevatorVideoModel::create([ - 'user_id' => 2, - 'status' => 'errored', - 'created_at' => $pastDate, - 'updated_at' => $pastDate, - 'upload_id' => 1, - ]); - $elevatorVideo->save(); - - $this->artisan('remove-elevator-videos') - ->assertExitCode(0); - - $this->assertModelMissing($elevatorVideo); - } - - public function testRemoveFilterRecordsCommand(): void - { - $pastDate = new \DateTime('now - 29 days', new \DateTimeZone('UTC')); - $filterRecord = FilterRecordModel::create([ - 'user_id' => 2, - 'organisation_id' => 1, - 'type' => 'offers', - 'created_at' => $pastDate, - 'updated_at' => $pastDate, - ]); - $filterRecord->save(); - - $this->artisan('remove-filter-records') - ->assertExitCode(0); - - $this->assertModelMissing($filterRecord); - } - - public function testRemoveNotificationsBuffersCommand(): void - { - $pastDate = new \DateTime('now - 6 minutes', new \DateTimeZone('UTC')); - $notificationBuffer = NotificationsBufferModel::create([ - 'identifier' => 'test_buffer_identifier', - 'created_at' => $pastDate, - 'updated_at' => $pastDate, - ]); - $notificationBuffer->save(); - - $this->artisan('remove-notifications-buffers') - ->assertExitCode(0); - - $this->assertModelMissing($notificationBuffer); - } - - public function testRemoveNotificationsCommand(): void - { - $pastDate = new \DateTime('now - 91 days', new \DateTimeZone('UTC')); - $notification = NotificationModel::create([ - 'user_id' => 2, - 'title' => 'test_notification', - 'body' => 'Lorem ipsum ', - 'unread' => 0, - 'created_at' => $pastDate, - 'updated_at' => $pastDate, - ]); - $notification->save(); - - $this->artisan('remove-notifications') - ->assertExitCode(0); - - $this->assertModelMissing($notification); - } - - public function testRemovePasswordResetsCommand(): void - { - $pastDate = new \DateTime('now - 4 hours', new \DateTimeZone('UTC')); - $passwordReset = PasswordResetModel::create([ - 'token' => 'token123', - 'user_id' => 2, - 'created_at' => $pastDate, - 'updated_at' => $pastDate, - ]); - $passwordReset->save(); - - $this->artisan('remove-password-resets') - ->assertExitCode(0); - - $this->assertModelMissing($passwordReset); - } - - public function testRemoveUploadsCommand(): void - { - $past = new \DateTime('now - 1 day', new \DateTimeZone('UTC')); - $uploads = UploadModel::create([ - 'user_id' => 2, - 'location' => 'http://127.0.0.1:9000/wri/UT/Uu/test.mp4', - 'created_at' => $past, - 'updated_at' => $past, - ]); - $uploads->save(); - - $elevatorVideo = ElevatorVideoModel::create([ - 'user_id' => 2, - 'status' => 'finished', - 'created_at' => $past, - 'updated_at' => $past, - 'upload_id' => $uploads->id, - ]); - $elevatorVideo->save(); - - $this->artisan('remove-uploads') - ->assertExitCode(0); - - $this->assertModelMissing($uploads); - $this->assertModelMissing($elevatorVideo); - } - - public function testRemoveVerificationsCommand(): void - { - $pastDate = new \DateTime('now - 49 hours', new \DateTimeZone('UTC')); - $verification = VerificationModel::create([ - 'token' => 'token123', - 'user_id' => 2, - 'created_at' => $pastDate, - 'updated_at' => $pastDate, - ]); - $verification->save(); - - $this->artisan('remove-verifications') - ->assertExitCode(0); - - $this->assertModelMissing($verification); - } - - public function testRemoveOldExportFiles(): void - { - $this->artisan('remove-export-files') - ->assertExitCode(0); - } - - public function testRemoveElevatorVideosCommand(): void - { - $this->artisan('remove-elevator-videos') - ->assertExitCode(0); - } - - public function testCreateVisibilityNotificationsCommand(): void - { - $this->artisan('create-visibility-notifications') - ->assertExitCode(0); - } - - public function testSendUpcomingProgressUpdateNotifications(): void - { - $this->artisan('send-upcoming-progress-update-notifications') - ->assertExitCode(0); - } - - public function testAddTestDataForSiteSubmissions(): void - { - $this->artisan('send-upcoming-progress-update-notifications') - ->assertExitCode(0); - } - - public function testGenerateDueSubmissions(): void - { - $this->artisan('generate-control-site-due-submissions') - ->assertExitCode(0); - } - - public function testImportProgrammeCsv(): void - { - $this->artisan('import-programme-csv blank.csv') - ->assertExitCode(0); - } - - public function testImportSiteCsv(): void - { - $this->artisan('import-site-csv blank.csv') - ->assertExitCode(0); - } - - public function testImportSiteSubmissionCsv(): void - { - $this->artisan('import-site-submission-csv blank.csv') - ->assertExitCode(0); - } - - public function testImportProgrammeSubmissionCsv(): void - { - $this->artisan('import-programme-submission-csv blank.csv') - ->assertExitCode(0); - } - - public function testSendTerrafundSiteAndNurseryRemindersCommand(): void - { - Mail::fake(); - - $programme = TerrafundProgramme::factory()->create([ - 'name' => 'Command test', - ]); - $user = User::factory()->create([ - 'organisation_id' => $programme->organisation_id, - ]); - $user->terrafundProgrammes()->attach($programme); - - $this->artisan('send-terrafund-site-and-nursery-reminders') - ->assertExitCode(0); - - Mail::assertQueued(TerrafundSiteAndNurseryReminder::class, function ($mail) use ($user) { - return $mail->hasTo($user->email_address); - }); - } - - public function testSendTerrafundReportRemindersCommand(): void - { - Mail::fake(); - - $programme = TerrafundProgramme::factory()->create([ - 'name' => 'Command test', - ]); - TerrafundNursery::factory()->create([ - 'terrafund_programme_id' => $programme->id, - ]); - $user = User::factory()->create([ - 'organisation_id' => $programme->organisation_id, - ]); - $user->terrafundProgrammes()->attach($programme); - - $this->artisan('send-terrafund-report-reminders') - ->assertExitCode(0); - - Mail::assertQueued(TerrafundReportReminder::class, function ($mail) use ($user) { - return $mail->hasTo($user->email_address); - }); - } - - public function testUpdateDraftBlueprintsCommand(): void - { - /** - * Note: if this first assertion has failed, - * check that you've also updated the draft seeding - * to reflect your new or removed blueprint properties and structure. - */ - $this->artisan('update-draft-blueprints') - ->assertExitCode(0); - - foreach (Draft::all() as $draft) { - $id = $draft->id; - $jsonData = $draft->data; - $newData = json_decode($jsonData); - $newData->testNode = 'test'; - $draft->data = json_encode($newData); - $draft->save(); - - $this->artisan('update-draft-blueprints') - ->assertExitCode(1); - - $updated = Draft::find($id); - $this->assertEquals($jsonData, $updated->data); - } - } - - public function testDeleteProgrammeCommand(): void - { - $programme = Programme::factory()->create(); - - $this->artisan('delete-programme ' . $programme->id) - ->assertExitCode(0); - - $programme->refresh(); - $this->assertNotNull($programme->deleted_at); - } - - public function testDeleteProgrammeSubmissionCommand(): void - { - $submission = Submission::factory()->create(); - - $this->artisan('delete-programme-submission ' . $submission->id) - ->assertExitCode(0); - - $submission->refresh(); - $this->assertNotNull($submission->deleted_at); - } - - public function testDeleteSiteCommand(): void - { - $site = Site::factory()->create(); - - $this->artisan('delete-site ' . $site->id) - ->assertExitCode(0); - - $site->refresh(); - $this->assertNotNull($site->deleted_at); - } - - public function testDeleteSiteSubmissionCommand(): void - { - $submission = SiteSubmission::factory()->create(); - - $this->artisan('delete-site-submission ' . $submission->id) - ->assertExitCode(0); - - $submission->refresh(); - $this->assertNotNull($submission->deleted_at); - } - - public function testDeleteTerrafundProgrammeCommand(): void - { - $programme = TerrafundProgramme::factory()->create(); - - $this->artisan('delete-terrafund-programme ' . $programme->id) - ->assertExitCode(0); - - $programme->refresh(); - $this->assertNotNull($programme->deleted_at); - } - - public function testDeleteTerrafundProgrammeSubmissionCommand(): void - { - $submission = TerrafundProgrammeSubmission::factory()->create(); - - $this->artisan('delete-terrafund-programme-submission ' . $submission->id) - ->assertExitCode(0); - - $submission->refresh(); - $this->assertNotNull($submission->deleted_at); - } - - public function testDeleteTerrafundSiteCommand(): void - { - $site = TerrafundSite::factory()->create(); - - $this->artisan('delete-terrafund-site ' . $site->id) - ->assertExitCode(0); - - $site->refresh(); - $this->assertNotNull($site->deleted_at); - } - - public function testDeleteTerrafundSiteSubmissionCommand(): void - { - $submission = TerrafundSiteSubmission::factory()->create(); - - $this->artisan('delete-terrafund-site-submission ' . $submission->id) - ->assertExitCode(0); - - $submission->refresh(); - $this->assertNotNull($submission->deleted_at); - } - - public function testDeleteTerrafundNurseryCommand(): void - { - $nursery = TerrafundNursery::factory()->create(); - - $this->artisan('delete-terrafund-nursery ' . $nursery->id) - ->assertExitCode(0); - - $nursery->refresh(); - $this->assertNotNull($nursery->deleted_at); - } - - public function testDeleteTerrafundNurserySubmissionCommand(): void - { - $submission = TerrafundNurserySubmission::factory()->create(); - - $this->artisan('delete-terrafund-nursery-submission ' . $submission->id) - ->assertExitCode(0); - - $submission->refresh(); - $this->assertNotNull($submission->deleted_at); - } - - public function testResetUserPasswordCommand(): void - { - $user = User::factory()->create(); - - $this->artisan("reset-user-password $user->id newtestpassword") - ->assertExitCode(0); - - $user->refresh(); - $this->assertTrue(Hash::check('newtestpassword', $user->password)); - } - - public function testVerifyUserCommand(): void - { - $user = User::factory()->create([ - 'email_address_verified_at' => null, - ]); - - $this->assertNull($user->email_address_verified_at); - - $this->artisan("verify-user $user->id") - ->assertExitCode(0); - - $user->refresh(); - $this->assertNotNull($user->email_address_verified_at); - } - - public function testV2MigrateOrganisationsCommand(): void - { - Organisation::factory()->count(3)->create(); - - $organisation = Organisation::first(); - $this->assertNull($organisation->name); - - $this->artisan('v2-migrate-organisations') - ->assertExitCode(0); - - $organisation->refresh(); - - $this->assertNotNull($organisation->uuid); - $this->assertNotNull($organisation->name); - } - - public function testV2MigratePendingOrganisationsCommand() - { - Organisation::factory()->count(3)->create(); - - $this->artisan('v2-migrate-pending-organisations') - ->assertExitCode(0); - } - - public function testV2MigrateUsersCommand() - { - $user = User::factory()->create(); - - $user->uuid = null; - $user->save(); - $this->assertNull($user->uuid); - - $this->artisan('v2-migrate-users') - ->assertExitCode(0); - - $user->refresh(); - - $this->assertNotNull($user->uuid); - } - - public function testV2CustomFormUpdateDataCommand(): void - { - $this->artisan('v2-custom-form-update-data') - ->assertExitCode(0); - } - - public function testV2CustomFormPrepPhase2Command(): void - { - $this->artisan('v2-custom-form-prep-phase2') - ->assertExitCode(0); - } - - public function testV2GenerateTranslationFileCommand(): void - { - $this->artisan('v2-translation-file-generate --testing') - ->assertExitCode(0); - } - - /** @group slow */ - public function testV2ImportTranslationFileCommand() - { - $this->artisan('v2-translation-file-import --testing') - ->assertExitCode(0); - } - - public function testV2CustomFormRFPUpdateDataCommand() - { - $this->artisan('v2-custom-form-rfp-update-data') - ->assertExitCode(0); - } -} diff --git a/tests/Legacy/Feature/CustomReportControllerTest.php b/tests/Legacy/Feature/CustomReportControllerTest.php deleted file mode 100644 index 6822a4201..000000000 --- a/tests/Legacy/Feature/CustomReportControllerTest.php +++ /dev/null @@ -1,247 +0,0 @@ -getHeaders('steve@example.com', 'Password123'); - - $this->getJson('/api/exports/site/field_list', $headers) - ->assertJsonFragment(['data' => array_merge(SiteReport::AVAILABLE_FIELDS, SiteReport::AVAILABLE_FIlES) ]) - ->assertStatus(200); - } - - public function testFetchAvailableFieldsControlSiteAction(): void - { - $headers = $this->getHeaders('steve@example.com', 'Password123'); - - $this->getJson('/api/exports/control_site/field_list', $headers) - ->assertStatus(200) - ->assertJsonFragment(['data' => array_merge(ControlSiteReport::AVAILABLE_FIELDS, ControlSiteReport::AVAILABLE_FIlES) ]); - } - - public function testFetchAvailableFieldsControlSiteSubmissionAction(): void - { - $headers = $this->getHeaders('steve@example.com', 'Password123'); - - $this->getJson('/api/exports/control_site_submission/field_list', $headers) - ->assertJsonFragment(['data' => array_merge(ControlSiteSubmissionReport::AVAILABLE_FIELDS, ControlSiteSubmissionReport::AVAILABLE_FIlES) ]) - ->assertStatus(200); - } - - public function testFetchAvailableFieldsProgrammeAction(): void - { - $headers = $this->getHeaders('steve@example.com', 'Password123'); - - $this->getJson('/api/exports/programme/field_list', $headers) - ->assertJsonFragment(['data' => array_merge(ProgrammeReport::AVAILABLE_FIELDS, ProgrammeReport::AVAILABLE_FIlES) ]) - ->assertStatus(200); - } - - public function testFetchAvailableFieldsSubmissionAction(): void - { - $headers = $this->getHeaders('steve@example.com', 'Password123'); - - $this->getJson('/api/exports/submission/field_list', $headers) - ->assertJsonFragment(['data' => array_merge(ProgrammeSubmissionReport::AVAILABLE_FIELDS, ProgrammeSubmissionReport::AVAILABLE_FIlES) ]) - ->assertStatus(200); - } - - public function testFetchAvailableFieldsSiteSubmissionAction(): void - { - $headers = $this->getHeaders('steve@example.com', 'Password123'); - - $this->getJson('/api/exports/site_submission/field_list', $headers) - ->assertJsonFragment(['data' => array_merge(SiteSubmissionReport::AVAILABLE_FIELDS, SiteSubmissionReport::AVAILABLE_FIlES) ]) - ->assertStatus(200); - } - - #[Group('skipPipeline')] - public function testGenerateCustomSiteReportAction(): void - { - $headers = $this->getHeaders('jane@example.com', 'Password123'); - - $data = [ - 'exportable_type' => 'site', - 'exportable_id' => 1, - 'duration' => 6, - 'format' => 'csv', - 'field_list' => array_keys(array_merge(SiteReport::AVAILABLE_FIELDS, SiteReport::AVAILABLE_FIlES)), - ]; - - $this->postJson('/api/exports/custom', $data, $headers) - ->assertStatus(200); - } - - #[Group('skipPipeline')] - public function testGenerateCustomSiteSubmissionReportWithDocumentFilesAction(): void - { - $headers = $this->getHeaders('jane@example.com', 'Password123'); - - Queue::fake(); - - $uploadResponse = $this->post('/api/uploads', [ - 'upload' => $this->fakeValidCsv(), - ], $headers); - - $this->postJson('/api/document_files/file', [ - 'document_fileable_id' => 1, - 'document_fileable_type' => 'site_submission', - 'upload' => $uploadResponse->json('data.id'), - 'title' => 'file for export test', - 'collection' => 'to-be-deleted', - 'is_public' => false, - ], $headers) - ->assertStatus(201); - - - $data = [ - 'exportable_type' => 'site_submission', - 'exportable_id' => 1, - 'duration' => 6, - 'format' => 'csv', - 'field_list' => array_keys(array_merge(SiteSubmissionReport::AVAILABLE_FIELDS, SiteSubmissionReport::AVAILABLE_FIlES)), - ]; - - $this->postJson('/api/exports/custom', $data, $headers) - ->assertStatus(200); - } - - #[Group('skipPipeline')] - public function testGenerateCustomProgrammeReportAction(): void - { - $headers = $this->getHeaders('jane@example.com', 'Password123'); - - $data = [ - 'exportable_type' => 'programme', - 'exportable_id' => 1, - 'format' => 'csv', - 'field_list' => array_keys(array_merge(ProgrammeReport::AVAILABLE_FIELDS, ProgrammeReport::AVAILABLE_FIlES)), - ]; - - $this->postJson('/api/exports/custom', $data, $headers) - ->assertStatus(200); - } - - #[Group('skipPipeline')] - public function testGenerateCustomProgrammeSubmissionReportAction(): void - { - $headers = $this->getHeaders('jane@example.com', 'Password123'); - - $data = [ - 'exportable_type' => 'submission', - 'exportable_id' => 1, - 'format' => 'csv', - 'field_list' => array_keys(array_merge(ProgrammeSubmissionReport::AVAILABLE_FIELDS, ProgrammeSubmissionReport::AVAILABLE_FIlES)), - ]; - - $this->postJson('/api/exports/custom', $data, $headers) - ->assertStatus(200); - } - - public function testGenerateCustomSiteNoFilesReportAction(): void - { - $headers = $this->getHeaders('jane@example.com', 'Password123'); - - $data = [ - 'exportable_type' => 'site', - 'exportable_id' => 1, - 'duration' => 6, - 'format' => 'csv', - 'field_list' => array_keys(SiteReport::AVAILABLE_FIELDS), - ]; - - $this->postJson('/api/exports/custom', $data, $headers) - ->assertStatus(200); - } - - public function testGenerateCustomControlSiteNoFilesReportAction(): void - { - $headers = $this->getHeaders('jane@example.com', 'Password123'); - - $data = [ - 'exportable_type' => 'control_site', - 'exportable_id' => 8, - 'duration' => 6, - 'format' => 'csv', - 'field_list' => array_keys(ControlSiteReport::AVAILABLE_FIELDS), - ]; - - $this->postJson('/api/exports/custom', $data, $headers) - ->assertStatus(200); - } - - public function testGenerateCustomControlSiteSubmissionNoFilesReportAction(): void - { - $headers = $this->getHeaders('jane@example.com', 'Password123'); - - $data = [ - 'exportable_type' => 'control_site_submission', - 'exportable_id' => 4, - 'duration' => 6, - 'format' => 'csv', - 'field_list' => array_keys(ControlSiteSubmissionReport::AVAILABLE_FIELDS), - ]; - - $this->postJson('/api/exports/custom', $data, $headers) - ->assertStatus(200); - } - - public function testGenerateCustomSiteSubmissionNoFilesReportAction(): void - { - $headers = $this->getHeaders('jane@example.com', 'Password123'); - - $data = [ - 'exportable_type' => 'site_submission', - 'exportable_id' => 1, - 'duration' => 6, - 'format' => 'csv', - 'field_list' => array_keys(SiteSubmissionReport::AVAILABLE_FIELDS), - ]; - - $this->postJson('/api/exports/custom', $data, $headers) - ->assertStatus(200); - } - - public function testGenerateCustomProgrammeNoFilesReportAction(): void - { - $headers = $this->getHeaders('jane@example.com', 'Password123'); - - $data = [ - 'exportable_type' => 'programme', - 'exportable_id' => 1, - 'format' => 'csv', - 'field_list' => array_keys(ProgrammeReport::AVAILABLE_FIELDS), - ]; - - $this->postJson('/api/exports/custom', $data, $headers) - ->assertStatus(200); - } - - public function testGenerateCustomProgrammeSubmissionNoFilesReportAction(): void - { - $headers = $this->getHeaders('jane@example.com', 'Password123'); - - $data = [ - 'exportable_type' => 'submission', - 'exportable_id' => 1, - 'format' => 'csv', - 'field_list' => array_keys(ProgrammeSubmissionReport::AVAILABLE_FIELDS), - ]; - - $this->postJson('/api/exports/custom', $data, $headers) - ->assertStatus(200); - } -} diff --git a/tests/Legacy/Feature/DataControllerTest.php b/tests/Legacy/Feature/DataControllerTest.php deleted file mode 100644 index c4f022ad5..000000000 --- a/tests/Legacy/Feature/DataControllerTest.php +++ /dev/null @@ -1,182 +0,0 @@ -getJson('/api/countries'); - $response->assertStatus(200); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertJsonStructure(['data' => [['name', 'code', 'continent']]]); - } - - public function testReadAllOrganisationTypesAction(): void - { - $response = $this->getJson('/api/organisation_types'); - $response->assertStatus(200); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertJsonStructure(['data' => [['name', 'type']]]); - } - - public function testReadAllOrganisationCategoriesAction(): void - { - $response = $this->getJson('/api/organisation_categories'); - $response->assertStatus(200); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertJsonStructure(['data' => [['name', 'category']]]); - } - - public function testReadAllDocumentTypesAction(): void - { - $response = $this->getJson('/api/document_types'); - $response->assertStatus(200); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertJsonStructure(['data' => [['name', 'type']]]); - } - - public function testReadAllLandTypesAction(): void - { - $response = $this->getJson('/api/land_types'); - $response->assertStatus(200); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertJsonStructure(['data' => [['name', 'type']]]); - } - - public function testReadAllLandOwnershipsAction(): void - { - $response = $this->getJson('/api/land_ownerships'); - $response->assertStatus(200); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertJsonStructure(['data' => [['name', 'ownership']]]); - } - - public function testReadAllRestorationMethodsAction(): void - { - $response = $this->getJson('/api/restoration_methods'); - $response->assertStatus(200); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertJsonStructure(['data' => [['name', 'method']]]); - } - - public function testReadAllRestorationGoalsAction(): void - { - $response = $this->getJson('/api/restoration_goals'); - $response->assertStatus(200); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertJsonStructure(['data' => [['name', 'goal']]]); - } - - public function testReadAllFundingSourcesAction(): void - { - $response = $this->getJson('/api/funding_sources'); - $response->assertStatus(200); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertJsonStructure(['data' => [['name', 'source']]]); - } - - public function testReadAllSustainableDevelopmentGoalsAction(): void - { - $response = $this->getJson('/api/sustainable_development_goals'); - $response->assertStatus(200); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertJsonStructure(['data' => [['name', 'goal']]]); - } - - public function testReadAllReportingLevelsAction(): void - { - $response = $this->getJson('/api/reporting_levels'); - $response->assertStatus(200); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertJsonStructure(['data' => [['name', 'level']]]); - } - - public function testReadAllReportingFrequenciesAction(): void - { - $response = $this->getJson('/api/reporting_frequencies'); - $response->assertStatus(200); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertJsonStructure(['data' => [['name', 'frequency']]]); - } - - public function testReadAllContinentsAction(): void - { - $response = $this->getJson('/api/continents'); - $response->assertStatus(200); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertJsonStructure(['data' => [['name', 'continent']]]); - } - - public function testReadAllRevenueDriversAction(): void - { - $response = $this->getJson('/api/revenue_drivers'); - $response->assertStatus(200); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertJsonStructure(['data' => [['name', 'driver']]]); - } - - public function testReadAllCarbonCertificationTypesAction(): void - { - $response = $this->getJson('/api/carbon_certification_types'); - $response->assertStatus(200); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertJsonStructure(['data' => [['name', 'type']]]); - } - - public function testReadAllLandSizesAction(): void - { - $response = $this->getJson('/api/land_sizes'); - $response->assertStatus(200); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertJsonStructure(['data' => [['name', 'size']]]); - } - - public function testReadAllRejectedReasonsAction(): void - { - $response = $this->getJson('/api/rejected_reasons'); - $response->assertStatus(200); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertJsonStructure(['data' => [['name', 'reason']]]); - } - - public function testReadAllFundingBracketsAction(): void - { - $response = $this->getJson('/api/funding_brackets'); - $response->assertStatus(200); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertJsonStructure(['data' => [['name', 'bracket']]]); - } - - public function testReadAllVisibilitiesAction(): void - { - $response = $this->getJson('/api/visibilities'); - $response->assertStatus(200); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertJsonStructure(['data' => [['name', 'visibility']]]); - } - - public function testReadAllTerrafundLandTenuresAction(): void - { - $response = $this->getJson('/api/terrafund/site/land_tenures'); - $response->assertStatus(200); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertJsonFragment([ - 'name' => 'Public', - 'key' => 'public', - ]); - } - - public function testReadAllTerrafundRestorationMethodsAction(): void - { - $response = $this->getJson('/api/terrafund/site/restoration_methods'); - $response->assertStatus(200); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertJsonFragment([ - 'name' => 'Mangrove Tree Restoration', - 'key' => 'mangrove_tree_restoration', - ]); - } -} diff --git a/tests/Legacy/Feature/DefaultControllerTest.php b/tests/Legacy/Feature/DefaultControllerTest.php deleted file mode 100644 index f7e304f2d..000000000 --- a/tests/Legacy/Feature/DefaultControllerTest.php +++ /dev/null @@ -1,18 +0,0 @@ -getJson('/'); - $response->assertStatus(200); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertJson([ - 'data' => [], - ]); - } -} diff --git a/tests/Legacy/Feature/DevicesControllerTest.php b/tests/Legacy/Feature/DevicesControllerTest.php deleted file mode 100644 index a328be5b9..000000000 --- a/tests/Legacy/Feature/DevicesControllerTest.php +++ /dev/null @@ -1,137 +0,0 @@ - 'ios', - 'uuid' => Str::random(16), - 'push_token' => Str::random(16), - ]; - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $response = $this->postJson('/api/devices', $data, $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(201); - $response->assertJsonStructure([ - 'data' => [ - 'id', - 'user_id', - 'os', - 'uuid', - 'push_token', - 'created_at', - ], - 'meta' => [], - ]); - } - - public function testReadAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->getJson('/api/devices/1', $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure([ - 'data' => [ - 'id', - 'user_id', - 'os', - 'uuid', - 'push_token', - 'created_at', - ], - 'meta' => [], - ]); - } - - public function testReadAllAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->getJson('/api/devices', $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure([ - 'data' => [ - [ - 'id', - 'user_id', - 'os', - 'uuid', - 'push_token', - 'created_at', - ], - ], - 'meta' => [], - ]); - } - - public function testUpdateAction(): void - { - $data = [ - 'push_token' => Str::random(16), - ]; - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $response = $this->patchJson('/api/devices/1', $data, $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure([ - 'data' => [ - 'id', - 'user_id', - 'os', - 'uuid', - 'push_token', - 'created_at', - ], - 'meta' => [], - ]); - } - - public function testDeleteAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->deleteJson('/api/devices/1', $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure(['data' => []]); - } -} diff --git a/tests/Legacy/Feature/DirectSeedingControllerTest.php b/tests/Legacy/Feature/DirectSeedingControllerTest.php deleted file mode 100644 index dffdabe0a..000000000 --- a/tests/Legacy/Feature/DirectSeedingControllerTest.php +++ /dev/null @@ -1,50 +0,0 @@ - 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $data = [ - 'name' => 'seed name', - 'weight' => 123, - ]; - - $this->postJson('/api/site/submission/1/direct_seeding', $data, $headers) - ->assertHeader('Content-Type', 'application/json') - ->assertStatus(201) - ->assertJsonFragment([ - 'name' => 'seed name', - 'weight' => 123, - 'site_submission_id' => 1, - ]); - } - - public function testDeleteAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $this->deleteJson('/api/site/submission/direct_seeding/1', $headers) - ->assertHeader('Content-Type', 'application/json') - ->assertStatus(200); - } -} diff --git a/tests/Legacy/Feature/DocumentFileControllerTest.php b/tests/Legacy/Feature/DocumentFileControllerTest.php deleted file mode 100644 index 673d97ca6..000000000 --- a/tests/Legacy/Feature/DocumentFileControllerTest.php +++ /dev/null @@ -1,162 +0,0 @@ -getHeaders('jane@example.com', 'Password123'); - - Queue::fake(); - - $uploadResponse = $this->post('/api/uploads', [ - 'upload' => $this->fakeValidCsv(), - ], $headers); - - $this->postJson('/api/document_files/file', [ - 'document_fileable_id' => 1, - 'document_fileable_type' => 'submission', - 'upload' => $uploadResponse->json('data.id'), - 'title' => 'test csv file', - 'collection' => '', - 'is_public' => false, - ], $headers) - ->assertStatus(201); - - $response = $this->getJson('/api/programme/submission/1', $headers) - ->assertStatus(200) - ->assertJsonPath('data.id', 1) - ->assertJsonCount(2, 'data.document_files'); - } - - public function testCreateDocumentOnSiteSubmissionsAction(): void - { - $headers = $this->getHeaders('jane@example.com', 'Password123'); - - Queue::fake(); - - for ($i = 1 ; $i <= 2 ; $i++) { - $uploadResponse = $this->post('/api/uploads', [ - 'upload' => $this->fakeValidCsv(), - ], $headers); - - $this->postJson('/api/document_files/file', [ - 'document_fileable_id' => 1, - 'document_fileable_type' => 'site_submission', - 'upload' => $uploadResponse->json('data.id'), - 'title' => "test csv file $i", - 'collection' => 'testing', - 'is_public' => false, - ], $headers) - ->assertStatus(201); - } - - $response = $this->getJson('/api/site/submission/1', $headers) - ->assertStatus(200) - ->assertJsonPath('data.id', 1) - ->assertJsonCount(3, 'data.document_files'); - } - - public function testUpdateDocumentAction(): void - { - $headers = $this->getHeaders('jane@example.com', 'Password123'); - - Queue::fake(); - - $uploadResponse = $this->post('/api/uploads', [ - 'upload' => $this->fakeValidCsv(), - ], $headers); - - $docResponse = $this->postJson('/api/document_files/file', [ - 'document_fileable_id' => 1, - 'document_fileable_type' => 'site_submission', - 'upload' => $uploadResponse->json('data.id'), - 'title' => 'test csv file 1', - 'collection' => 'testing', - 'is_public' => false, - ], $headers) - ->assertStatus(201); - - $this->putJson('/api/document_files/' . $docResponse->json('data.uuid'), ['title' => 'new title'], $headers) - ->assertSuccessful() - ->assertJsonFragment([ - 'title' => 'new title', - 'type' => 'file', - 'collection' => 'testing', - 'is_public' => false, - ]); - } - - public function testCreateDraftDocumentForSubmissionsAction(): void - { - $headers = $this->getHeaders('steve@example.com', 'Password123'); - - Queue::fake(); - - $data = [ - 'name' => 'testing site submission', - 'type' => 'site_submission', - 'due_submission_id' => 2, - 'is_from_mobile' => false, - ]; - - $draftResponse = $this->postJson('/api/drafts', $data, $headers) - ->assertStatus(201) - ->assertJsonPath('data.id', 18); - - $uploadResponse = $this->post('/api/uploads', [ - 'upload' => $this->fakeValidCsv(), - ], $headers); - - $this->postJson('/api/document_files/file', [ - 'document_fileable_id' => 1, - 'document_fileable_type' => 'submission', - 'upload' => $uploadResponse->json('data.id'), - 'title' => 'test csv file', - 'collection' => 'testing', - 'is_public' => false, - ], $headers) - ->assertStatus(201); - } - - public function testDeleteDocumentFileAction(): void - { - $headers = $this->getHeaders('jane@example.com', 'Password123'); - - Queue::fake(); - - $uploadResponse = $this->post('/api/uploads', [ - 'upload' => $this->fakeValidCsv(), - ], $headers); - - $this->postJson('/api/document_files/file', [ - 'document_fileable_id' => 1, - 'document_fileable_type' => 'site_submission', - 'upload' => $uploadResponse->json('data.id'), - 'title' => 'file for delete test', - 'collection' => 'to-be-deleted', - 'is_public' => false, - ], $headers) - ->assertStatus(201); - - $this->getJson('/api/site/submission/1', $headers) - ->assertStatus(200) - ->assertJsonPath('data.id', 1) - ->assertJsonCount(2, 'data.document_files'); - - $file = DocumentFile::where('collection', '=', 'to-be-deleted')->first(); - - $this->deleteJson('/api/document_files/' . $file->uuid, $headers) - ->assertStatus(200) - ->assertJsonFragment(['data' => ['delete request has been processed']]); - - $this->getJson('/api/site/submission/1', $headers) - ->assertStatus(200) - ->assertJsonCount(1, 'data.document_files'); - } -} diff --git a/tests/Legacy/Feature/DocumentationControllerTest.php b/tests/Legacy/Feature/DocumentationControllerTest.php deleted file mode 100644 index b48049b6b..000000000 --- a/tests/Legacy/Feature/DocumentationControllerTest.php +++ /dev/null @@ -1,34 +0,0 @@ -get('/documentation'); - $response->assertStatus(200); - $response->assertHeader('Content-Type', 'text/html; charset=UTF-8'); - $response->assertHeader('Content-Type', 'text/html; charset=UTF-8'); - $response->assertSee('', false); - } - - public function testReadSwaggerAsHtmlAction(): void - { - $response = $this->get('/documentation/swagger'); - $response->assertStatus(200); - $response->assertHeader('Content-Type', 'text/html; charset=UTF-8'); - $response->assertHeader('Content-Type', 'text/html; charset=UTF-8'); - $response->assertSee('
', false); - } - - public function testReadAsYamlAction(): void - { - $response = $this->get('/documentation/raw'); - $response->assertStatus(200); - $response->assertHeader('Content-Type', 'text/plain; charset=UTF-8'); - $response->assertSeeText("swagger: '2.0'", false); - } -} diff --git a/tests/Legacy/Feature/DraftsControllerTest.php b/tests/Legacy/Feature/DraftsControllerTest.php deleted file mode 100644 index 4a885612d..000000000 --- a/tests/Legacy/Feature/DraftsControllerTest.php +++ /dev/null @@ -1,1155 +0,0 @@ - 'Example Draft', - 'type' => 'offer', - ]; - $headers = $this->getHeaders('steve@example.com', 'Password123'); - - $response = $this->postJson('/api/drafts', $data, $headers); - $response->assertStatus(201); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertJsonStructure([ - 'data' => [ - 'id', - 'organisation_id', - 'name', - 'is_from_mobile', - 'type', - 'data', - 'created_at', - 'created_by', - 'updated_at', - 'updated_by', - ], - ]); - } - - public function testCreateActionFromMobile(): void - { - $data = [ - 'name' => 'Example Draft', - 'type' => 'offer', - 'is_from_mobile' => true, - ]; - $headers = $this->getHeaders('steve@example.com', 'Password123'); - - $response = $this->postJson('/api/drafts', $data, $headers); - $response->assertStatus(201); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertJsonStructure([ - 'data' => [ - 'id', - 'organisation_id', - 'name', - 'is_from_mobile', - 'type', - 'data', - 'created_at', - 'created_by', - 'updated_at', - 'updated_by', - ], - ]); - } - - public function testCreateActionWithDueSubmission(): void - { - $data = [ - 'name' => 'Assigning draft to due submission', - 'type' => 'site_submission', - 'due_submission_id' => 2, - ]; - $headers = $this->getHeaders('steve@example.com', 'Password123'); - - $response = $this->postJson('/api/drafts', $data, $headers); - $response->assertStatus(201); - $this->assertDatabaseHas('drafts', [ - 'id' => $response['data']['id'], - 'due_submission_id' => 2, - ]); - } - - public function testMergeAction(): void - { - $data = [ - 'draft_ids' => [7, 9], - 'type' => 'site_submission', - ]; - $headers = $this->getHeaders('steve@example.com', 'Password123'); - - $response = $this->patchJson('/api/drafts/merge', $data, $headers); - $response->assertStatus(200); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertJsonStructure([ - 'data' => [ - 'id', - 'organisation_id', - 'name', - 'type', - 'data', - 'created_at', - 'created_by', - 'updated_at', - 'updated_by', - ], - ]); - $this->assertDatabaseHas('drafts', [ - 'id' => 7, - 'is_merged' => true, - ]); - $this->assertDatabaseMissing('drafts', [ - 'id' => 9, - ]); - } - - public function testMergeActionRequiresMatchingDraftTypes(): void - { - $data = [ - 'draft_ids' => [7, 8], - 'type' => 'site_submission', - ]; - $headers = $this->getHeaders('steve@example.com', 'Password123'); - - $response = $this->patchJson('/api/drafts/merge', $data, $headers); - $response->assertStatus(422); - } - - public function testReadAction(): void - { - $headers = $this->getHeaders('steve@example.com', 'Password123'); - - $response = $this->getJson('/api/drafts/1', $headers); - $response->assertStatus(200); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertJsonStructure([ - 'data' => [ - 'id', - 'organisation_id', - 'name', - 'type', - 'data', - 'created_at', - 'created_by', - 'updated_at', - 'updated_by', - ], - ]); - } - - public function testReadAllByTypeAction(): void - { - $this->callReadAllByTypeActionAsOffer(); - $this->callReadAllByTypeActionAsPitch(); - $this->callReadAllByTypeActionAsProgramme(); - $this->callReadAllByTypeActionAsSite(); - $this->callReadAllByTypeActionAsSiteSubmission(); - $this->callReadAllByTypeActionAsProgrammeSubmission(); - $this->callReadAllByTypeActionAsTerrafundProgramme(); - $this->callReadAllByTypeActionAsTerrafundNursery(); - $this->callReadAllByTypeActionAsTerrafundSite(); - $this->callReadAllByTypeActionAsOrganisation(); - $this->callReadAllByTypeActionAsTerrafundNurserySubmission(); - $this->callReadAllByTypeActionAsTerrafundSiteSubmission(); - $this->callReadAllByTypeActionAsTerrafundProgrammeSubmission(); - } - - private function callReadAllByTypeActionAsOffer() - { - $headers = $this->getHeaders('steve@example.com', 'Password123'); - - $response = $this->getJson('/api/drafts/offers', $headers); - $response->assertStatus(200); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertJsonStructure([ - 'data' => [ - [ - 'id', - 'organisation_id', - 'name', - 'type', - 'data', - 'created_at', - 'created_by', - 'updated_at', - 'updated_by', - ], - ], - ]); - } - - private function callReadAllByTypeActionAsPitch() - { - $headers = $this->getHeaders('steve@example.com', 'Password123'); - - $response = $this->getJson('/api/drafts/pitches', $headers); - $response->assertStatus(200); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertJsonStructure([ - 'data' => [ - [ - 'id', - 'organisation_id', - 'name', - 'type', - 'data', - 'created_at', - 'created_by', - 'updated_at', - 'updated_by', - ], - ], - ]); - } - - private function callReadAllByTypeActionAsProgramme() - { - $headers = $this->getHeaders('steve@example.com', 'Password123'); - - $response = $this->getJson('/api/drafts/programmes', $headers); - $response->assertStatus(200); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertJsonStructure([ - 'data' => [ - [ - 'id', - 'organisation_id', - 'name', - 'type', - 'data', - 'created_at', - 'created_by', - 'updated_at', - 'updated_by', - ], - ], - ]); - } - - private function callReadAllByTypeActionAsSite() - { - $headers = $this->getHeaders('steve@example.com', 'Password123'); - - $response = $this->getJson('/api/drafts/sites', $headers); - $response->assertStatus(200); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertJsonStructure([ - 'data' => [ - [ - 'id', - 'organisation_id', - 'name', - 'type', - 'data', - 'created_at', - 'created_by', - 'updated_at', - 'updated_by', - ], - ], - ]); - } - - private function callReadAllByTypeActionAsSiteSubmission() - { - $headers = $this->getHeaders('steve@example.com', 'Password123'); - - $response = $this->getJson('/api/drafts/site_submissions', $headers); - $response->assertStatus(200); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertJsonStructure([ - 'data' => [ - [ - 'id', - 'organisation_id', - 'name', - 'type', - 'data', - 'created_at', - 'created_by', - 'updated_at', - 'updated_by', - ], - ], - ]); - } - - private function callReadAllByTypeActionAsProgrammeSubmission() - { - $headers = $this->getHeaders('steve@example.com', 'Password123'); - - $response = $this->getJson('/api/drafts/programme_submissions', $headers); - $response->assertStatus(200); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertJsonStructure([ - 'data' => [ - [ - 'id', - 'organisation_id', - 'name', - 'type', - 'data', - 'created_at', - 'created_by', - 'updated_at', - 'updated_by', - ], - ], - ]); - } - - private function callReadAllByTypeActionAsTerrafundProgramme() - { - $headers = $this->getHeaders('steve@example.com', 'Password123'); - - $response = $this->getJson('/api/drafts/terrafund_programmes', $headers); - $response->assertStatus(200); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertJsonStructure([ - 'data' => [ - [ - 'id', - 'organisation_id', - 'name', - 'type', - 'data', - 'created_at', - 'created_by', - 'updated_at', - 'updated_by', - ], - ], - ]); - } - - private function callReadAllByTypeActionAsTerrafundNursery() - { - $headers = $this->getHeaders('steve@example.com', 'Password123'); - - $response = $this->getJson('/api/drafts/terrafund_nurserys', $headers); - $response->assertStatus(200); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertJsonStructure([ - 'data' => [ - [ - 'id', - 'organisation_id', - 'name', - 'type', - 'data', - 'created_at', - 'created_by', - 'updated_at', - 'updated_by', - ], - ], - ]); - } - - private function callReadAllByTypeActionAsTerrafundNurserySubmission() - { - $headers = $this->getHeaders('steve@example.com', 'Password123'); - - $response = $this->getJson('/api/drafts/terrafund_nursery_submissions', $headers); - $response->assertStatus(200); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertJsonStructure([ - 'data' => [ - [ - 'id', - 'organisation_id', - 'name', - 'type', - 'data', - 'created_at', - 'created_by', - 'updated_at', - 'updated_by', - ], - ], - ]); - } - - private function callReadAllByTypeActionAsTerrafundSiteSubmission() - { - $headers = $this->getHeaders('steve@example.com', 'Password123'); - - $response = $this->getJson('/api/drafts/terrafund_site_submissions', $headers); - $response->assertStatus(200); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertJsonStructure([ - 'data' => [ - [ - 'id', - 'organisation_id', - 'name', - 'type', - 'data', - 'created_at', - 'created_by', - 'updated_at', - 'updated_by', - ], - ], - ]); - } - - private function callReadAllByTypeActionAsTerrafundProgrammeSubmission() - { - $headers = $this->getHeaders('steve@example.com', 'Password123'); - - $response = $this->getJson('/api/drafts/terrafund_programme_submissions', $headers); - $response->assertStatus(200); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertJsonStructure([ - 'data' => [ - [ - 'id', - 'organisation_id', - 'name', - 'type', - 'data', - 'created_at', - 'created_by', - 'updated_at', - 'updated_by', - ], - ], - ]); - } - - private function callReadAllByTypeActionAsTerrafundSite() - { - $headers = $this->getHeaders('steve@example.com', 'Password123'); - - $response = $this->getJson('/api/drafts/terrafund_sites', $headers); - $response->assertStatus(200); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertJsonStructure([ - 'data' => [ - [ - 'id', - 'organisation_id', - 'name', - 'type', - 'data', - 'created_at', - 'created_by', - 'updated_at', - 'updated_by', - ], - ], - ]); - } - - private function callReadAllByTypeActionAsOrganisation() - { - $headers = $this->getHeaders('terrafund.orphan@example.com', 'Password123'); - - $response = $this->getJson('/api/drafts/organisations', $headers); - $response->assertStatus(200); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertJsonStructure([ - 'data' => [ - [ - 'id', - 'organisation_id', - 'name', - 'type', - 'data', - 'created_at', - 'created_by', - 'updated_at', - 'updated_by', - ], - ], - ]); - } - - public function testUpdateAction(): void - { - $data = [ - [ - 'op' => 'add', - 'path' => '/offer/name', - 'value' => 'foo', - ], - ]; - $headers = $this->getHeaders('steve@example.com', 'Password123'); - - $response = $this->patchJson('/api/drafts/1', $data, $headers); - $response->assertStatus(200); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertJsonStructure([ - 'data' => [ - 'id', - 'organisation_id', - 'name', - 'type', - 'data', - 'created_at', - 'created_by', - 'updated_at', - 'updated_by', - ], - ]); - $response->assertJson([ - 'data' => [ - 'data' => [ - 'offer' => [ - 'name' => 'foo', - ], - ], - ], - ]); - } - - public function testDeleteAction(): void - { - $headers = $this->getHeaders('steve@example.com', 'Password123'); - - $response = $this->deleteJson('/api/drafts/1', $headers); - $response->assertStatus(200); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertJson([ - 'data' => [], - ]); - } - - public function testSiteSubmissionFlowWithUploadAction(): void - { - $headers = $this->getHeaders('steve@example.com', 'Password123'); - - $this->assertDatabaseHas('drafts', [ - 'id' => 7, - 'due_submission_id' => 2, - ]); - - Queue::fake(); - - $uploadResponse1 = $this->post('/api/uploads', [ - 'upload' => $this->fakeValidCsv(), - ], $headers); - - $uploadResponse2 = $this->post('/api/uploads', [ - 'upload' => $this->fakeImage(), - ], $headers); - - $input = [ - [ - 'op' => 'replace', - 'path' => '/progress/direct_seeding_skipped', - 'value' => false, - ], - [ - 'op' => 'add', - 'path' => '/document_files/0', - 'value' => [ - 'upload' => $uploadResponse2->json('data.id'), - 'title' => 'test2 image file', - 'collection' => 'testing', - 'is_public' => false, - ], - ], - [ - 'op' => 'add', - 'path' => '/document_files/1', - 'value' => [ - 'upload' => $uploadResponse1->json('data.id'), - 'title' => 'test1 csv file', - 'collection' => 'testing', - 'is_public' => false, - ], - ], - ]; - - $response = $this->patchJson('/api/drafts/7', $input, $headers) - ->assertStatus(200); - - $response = $this->patchJson('/api/drafts/7/publish', $headers); - $response->assertStatus(201); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertJsonStructure([ - 'data' => [ - 'site_submission_id', - ], - ]); - - $siteSubmission = SiteSubmission::with('documentFiles')->find($response->json('data.site_submission_id')); - - $this->assertEquals(2, $siteSubmission->documentFiles->count()); - } - - public function testSiteFlowWithUploadAction(): void - { - $headers = $this->getHeaders('steve@example.com', 'Password123'); - - $this->assertDatabaseHas('drafts', [ - 'id' => 6, - ]); - - Queue::fake(); - - $uploadResponse1 = $this->post('/api/uploads', [ - 'upload' => $this->fakeValidCsv(), - ], $headers); - - $uploadResponse2 = $this->post('/api/uploads', [ - 'upload' => $this->fakeImage(), - ], $headers); - - $input = [ - [ - 'op' => 'replace', - 'path' => '/progress/invasives_skipped', - 'value' => false, - ], - [ - 'op' => 'add', - 'path' => '/document_files/0', - 'value' => [ - 'upload' => $uploadResponse2->json('data.id'), - 'title' => 'test2 image file', - 'collection' => 'testing', - 'is_public' => false, - ], - ], - [ - 'op' => 'add', - 'path' => '/document_files/1', - 'value' => [ - 'upload' => $uploadResponse1->json('data.id'), - 'title' => 'test1 csv file', - 'collection' => 'testing', - 'is_public' => false, - ], - ], - ]; - - $this->patchJson('/api/drafts/6', $input, $headers) - ->assertStatus(200); - - $response = $this->patchJson('/api/drafts/6/publish', $headers); - $response->assertStatus(201); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertJsonStructure([ - 'data' => [ - 'site_id', - ], - ]); - - $site = Site::with('documentFiles')->find($response->json('data.site_id')); - - $this->assertEquals(2, $site->documentFiles->count()); - } - - public function testProgrammeSubmissionFlowWithUploadAction(): void - { - $headers = $this->getHeaders('steve@example.com', 'Password123'); - - $this->assertDatabaseHas('drafts', [ - 'id' => 8, - 'due_submission_id' => 1, - ]); - - Queue::fake(); - - $uploadResponse1 = $this->post('/api/uploads', [ - 'upload' => $this->fakeValidCsv(), - ], $headers); - - $uploadResponse2 = $this->post('/api/uploads', [ - 'upload' => $this->fakeImage(), - ], $headers); - - $input = [ - [ - 'op' => 'add', - 'path' => '/document_files', - 'value' => [ - [ - 'upload' => $uploadResponse1->json('data.id'), - 'title' => 'test1 csv file', - 'collection' => 'testing', - 'is_public' => false, - ], - [ - 'upload' => $uploadResponse2->json('data.id'), - 'title' => 'test2 image file', - 'collection' => 'testing', - 'is_public' => false, - ], - ], - ], - ]; - - $this->patchJson('/api/drafts/8', $input, $headers) - ->assertStatus(200); - - $response = $this->patchJson('/api/drafts/8/publish', $headers); - $response->assertStatus(201); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertJsonStructure([ - 'data' => [ - 'programme_submission_id', - ], - ]); - - $submission = Submission::with('documentFiles')->find($response->json('data.programme_submission_id')); - - $this->assertEquals(2, $submission->documentFiles->count()); - } - - public function testProgrammeFlowWithUploadAction(): void - { - $headers = $this->getHeaders('steve@example.com', 'Password123'); - - $this->assertDatabaseHas('drafts', [ - 'id' => 5, - ]); - - Queue::fake(); - - $uploadResponse1 = $this->post('/api/uploads', [ - 'upload' => $this->fakeValidCsv(), - ], $headers); - - $uploadResponse2 = $this->post('/api/uploads', [ - 'upload' => $this->fakeValidCsv(), - ], $headers); - - $input = [ - [ - 'op' => 'add', - 'path' => '/document_files', - 'value' => [ - [ - 'upload' => $uploadResponse1->json('data.id'), - 'title' => 'test1 csv file', - 'collection' => 'testing', - 'is_public' => false, - ], - [ - 'upload' => $uploadResponse2->json('data.id'), - 'title' => 'test2 csv file', - 'collection' => 'testing', - 'is_public' => false, - ], - ], - ], - ]; - - $this->patchJson('/api/drafts/5', $input, $headers); - - $response = $this->patchJson('/api/drafts/5/publish', $headers); - $response->assertStatus(201); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertJsonStructure([ - 'data' => [ - 'programme_id', - ], - ]); - - $programme = Programme::with('documentFiles')->find($response->json('data.programme_id')); - - $this->assertEquals(2, $programme->documentFiles->count()); - } - - public function testProgrammeAdditionalTreeSpeciesUploadAction(): void - { - $headers = $this->getHeaders('steve@example.com', 'Password123'); - - $this->assertDatabaseHas('drafts', [ - 'id' => 5, - ]); - - Queue::fake(); - - $uploadResponse1 = $this->post('/api/uploads', [ - 'upload' => $this->fakeValidCsv(), - ], $headers); - - $input = [ - [ - 'op' => 'add', - 'path' => '/additional_tree_species', - 'value' => $uploadResponse1->json('data.id'), - ], - ]; - - $this->patchJson('/api/drafts/5', $input, $headers) - ->assertStatus(200); - - $response = $this->patchJson('/api/drafts/5/publish', $headers); - $response->assertStatus(201); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertJsonStructure([ - 'data' => [ - 'programme_id', - ], - ]); - // $programme = Programme::with('documentFiles')->find($response->json('data.programme_id')); - // dump(new ProgrammeResource($programme)); - // - // $siteSubmission = SiteSubmission::with('documentFiles')->find($response->json('data.site_submission_id')); - } - - public function testProgrammeSubmissionAdditionalTreeSpeciesUploadAction(): void - { - $headers = $this->getHeaders('steve@example.com', 'Password123'); - - $this->assertDatabaseHas('drafts', [ - 'id' => 8, - ]); - - Queue::fake(); - - $uploadResponse1 = $this->post('/api/uploads', [ - 'upload' => $this->fakeValidCsv(), - ], $headers); - - $input = [ - [ - 'op' => 'add', - 'path' => '/additional_tree_species', - 'value' => $uploadResponse1->json('data.id'), - ], - ]; - - $this->patchJson('/api/drafts/8', $input, $headers) - ->assertStatus(200); - - $response = $this->patchJson('/api/drafts/8/publish', $headers); - $response->assertStatus(201); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertJsonStructure([ - 'data' => [ - 'programme_submission_id', - ], - ]); - } - - public function testSiteAdditionalTreeSpeciesUploadAction(): void - { - $headers = $this->getHeaders('steve@example.com', 'Password123'); - - $this->assertDatabaseHas('drafts', [ - 'id' => 6, - ]); - - Queue::fake(); - - $uploadResponse1 = $this->post('/api/uploads', [ - 'upload' => $this->fakeValidCsv(), - ], $headers); - - $input = [ - [ - 'op' => 'add', - 'path' => '/additional_tree_species', - 'value' => $uploadResponse1->json('data.id'), - ], - ]; - - $this->patchJson('/api/drafts/6', $input, $headers) - ->assertStatus(200); - - $response = $this->patchJson('/api/drafts/6/publish', $headers); - $response->assertStatus(201); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertJsonStructure([ - 'data' => [ - 'site_id', - ], - ]); - } - - public function testSiteSubmissionAdditionalTreeSpeciesUploadAction(): void - { - $headers = $this->getHeaders('steve@example.com', 'Password123'); - - $this->assertDatabaseHas('drafts', [ - 'id' => 9, - ]); - - Queue::fake(); - - $uploadResponse1 = $this->post('/api/uploads', [ - 'upload' => $this->fakeValidCsv(), - ], $headers); - - $input = [ - [ - 'op' => 'add', - 'path' => '/additional_tree_species', - 'value' => $uploadResponse1->json('data.id'), - ], - ]; - - $this->patchJson('/api/drafts/9', $input, $headers) - ->assertStatus(200); - - $response = $this->patchJson('/api/drafts/9/publish', $headers); - $response->assertStatus(201); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertJsonStructure([ - 'data' => [ - 'site_submission_id', - ], - ]); - } - - public function testPublishAction(): void - { - $this->callPublishActionAsOffer(); - $this->callPublishActionAsPitch(); - $this->callPublishActionAsProgramme(); - $this->callPublishActionAsSite(); - $this->callPublishActionAsSiteSubmission(); - $this->callPublishActionAsProgrammeSubmission(); - $this->callPublishActionAsTerrafundProgramme(); - $this->callPublishActionAsTerrafundNursery(); - $this->callPublishActionAsTerrafundSite(); - $this->callPublishActionAsOrganisation(); - $this->callPublishActionAsTerrafundNurserySubmission(); - $this->callPublishActionAsTerrafundSiteSubmission(); - $this->callPublishActionAsTerrafundProgrammeSubmission(); - } - - private function callPublishActionAsOffer() - { - $data = []; - $headers = $this->getHeaders('steve@example.com', 'Password123'); - - $response = $this->patchJson('/api/drafts/3/publish', $data, $headers); - $response->assertStatus(201); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertJsonStructure([ - 'data' => [ - 'offer_id', - ], - ]); - } - - private function callPublishActionAsPitch() - { - $data = []; - $headers = $this->getHeaders('steve@example.com', 'Password123'); - - $response = $this->patchJson('/api/drafts/4/publish', $data, $headers); - $response->assertStatus(201); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertJsonStructure([ - 'data' => [ - 'pitch_id', - ], - ]); - } - - private function callPublishActionAsProgramme() - { - $data = []; - $headers = $this->getHeaders('steve@example.com', 'Password123'); - - $response = $this->patchJson('/api/drafts/5/publish', $data, $headers); - $response->assertStatus(201); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertJsonStructure([ - 'data' => [ - 'programme_id', - ], - ]); - } - - private function callPublishActionAsSite() - { - $data = []; - $headers = $this->getHeaders('steve@example.com', 'Password123'); - - $response = $this->patchJson('/api/drafts/6/publish', $data, $headers); - $response->assertStatus(201); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertJsonStructure([ - 'data' => [ - 'site_id', - ], - ]); - } - - private function callPublishActionAsSiteSubmission() - { - $data = []; - $headers = $this->getHeaders('steve@example.com', 'Password123'); - - $this->assertDatabaseHas('drafts', [ - 'id' => 7, - 'due_submission_id' => 2, - ]); - - $this->assertDatabaseHas('due_submissions', [ - 'id' => 2, - 'is_submitted' => false, - ]); - - $response = $this->patchJson('/api/drafts/7/publish', $data, $headers); - - $response->assertStatus(201); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertJsonStructure([ - 'data' => [ - 'site_submission_id', - ], - ]); - - $siteSubmission = SiteSubmission::find($response['data']['site_submission_id']); - - $this->assertSame(2, $siteSubmission->due_submission_id); - - $this->assertDatabaseMissing('drafts', [ - 'id' => 7, - 'due_submission_id' => 2, - ]); - $this->assertDatabaseHas('due_submissions', [ - 'id' => 2, - 'is_submitted' => true, - ]); - } - - private function callPublishActionAsProgrammeSubmission() - { - $data = []; - $headers = $this->getHeaders('steve@example.com', 'Password123'); - - $response = $this->patchJson('/api/drafts/8/publish', $data, $headers); - $response->assertStatus(201); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertJsonStructure([ - 'data' => [ - 'programme_submission_id', - ], - ]); - - $this->assertDatabaseMissing('drafts', [ - 'id' => 8, - 'due_submission_id' => 1, - ]); - } - - private function callPublishActionAsTerrafundProgramme() - { - $data = []; - $headers = $this->getHeaders('terrafund@example.com', 'Password123'); - - $response = $this->patchJson('/api/drafts/11/publish', $data, $headers); - $response->assertStatus(201); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertJsonStructure([ - 'data' => [ - 'terrafund_programme_id', - ], - ]); - } - - private function callPublishActionAsTerrafundNursery() - { - $data = []; - $headers = $this->getHeaders('terrafund@example.com', 'Password123'); - - $response = $this->patchJson('/api/drafts/12/publish', $data, $headers); - $response->assertStatus(201); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertJsonStructure([ - 'data' => [ - 'terrafund_nursery_id', - ], - ]); - } - - private function callPublishActionAsTerrafundNurserySubmission() - { - $data = []; - $headers = $this->getHeaders('terrafund@example.com', 'Password123'); - - $response = $this->patchJson('/api/drafts/15/publish', $data, $headers); - $response->assertStatus(201); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertJsonStructure([ - 'data' => [ - 'terrafund_nursery_submission_id', - ], - ]); - } - - private function callPublishActionAsTerrafundSiteSubmission() - { - $data = []; - $headers = $this->getHeaders('terrafund@example.com', 'Password123'); - - $response = $this->patchJson('/api/drafts/16/publish', $data, $headers); - $response->assertStatus(201); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertJsonStructure([ - 'data' => [ - 'terrafund_site_submission_id', - ], - ]); - } - - private function callPublishActionAsTerrafundProgrammeSubmission() - { - $data = []; - $headers = $this->getHeaders('terrafund@example.com', 'Password123'); - - $response = $this->patchJson('/api/drafts/17/publish', $data, $headers); - $response->assertStatus(201); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertJsonStructure([ - 'data' => [ - 'terrafund_programme_submission_id', - ], - ]); - } - - private function callPublishActionAsTerrafundSite() - { - $data = []; - $headers = $this->getHeaders('terrafund@example.com', 'Password123'); - - $response = $this->patchJson('/api/drafts/14/publish', $data, $headers); - $response->assertStatus(201); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertJsonStructure([ - 'data' => [ - 'terrafund_site_id', - ], - ]); - } - - private function callPublishActionAsOrganisation() - { - $data = []; - $headers = $this->getHeaders('terrafund.orphan@example.com', 'Password123'); - - $response = $this->patchJson('/api/drafts/13/publish', $data, $headers); - $response->assertStatus(201); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertJsonStructure([ - 'data' => [ - 'organisation_id', - ], - ]); - } -} diff --git a/tests/Legacy/Feature/DueSubmissionControllerTest.php b/tests/Legacy/Feature/DueSubmissionControllerTest.php deleted file mode 100644 index a88e38077..000000000 --- a/tests/Legacy/Feature/DueSubmissionControllerTest.php +++ /dev/null @@ -1,30 +0,0 @@ -getHeaders('steve@example.com', 'Password123'); - - $this->getJson('/api/site/submission/due', $headers) - ->assertHeader('Content-Type', 'application/json') - ->assertStatus(200) - ->assertJsonCount(2, 'data') - ->assertJsonPath('data.0.id', 2) - ->assertJsonPath('data.1.id', 3); - } - - public function testReadAllDueProgrammeSubmissionsForUserAction(): void - { - $headers = $this->getHeaders('steve@example.com', 'Password123'); - - $this->getJson('/api/programme/submission/due', $headers) - ->assertHeader('Content-Type', 'application/json') - ->assertStatus(200) - ->assertJsonPath('data.0.id', 1); - } -} diff --git a/tests/Legacy/Feature/ElevatorVideosControllerTest.php b/tests/Legacy/Feature/ElevatorVideosControllerTest.php deleted file mode 100644 index 65c4ccfdb..000000000 --- a/tests/Legacy/Feature/ElevatorVideosControllerTest.php +++ /dev/null @@ -1,65 +0,0 @@ - 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - foreach (['a', 'b', 'c'] as $variable) { - $data = [ - 'upload' => $this->fakeVideo(), - ]; - $response = $this->post('/api/uploads', $data, $headers); - $$variable = $response->json('data.id'); - } - $data = [ - 'introduction' => $a, - 'aims' => $b, - 'importance' => $c, - ]; - $response = $this->postJson('/api/elevator_videos', $data, $headers); - $response->assertStatus(201); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertJsonStructure([ - 'data' => [ - 'id', - 'status', - 'uploaded_at', - ], - ]); - } - - public function testReadAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->getJson('/api/elevator_videos/1', $headers); - $response->assertStatus(200); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertJsonStructure([ - 'data' => [ - 'id', - 'upload_id', - 'preview', - 'status', - 'uploaded_at', - ], - ]); - } -} diff --git a/tests/Legacy/Feature/FrameworkInviteCodeControllerTest.php b/tests/Legacy/Feature/FrameworkInviteCodeControllerTest.php deleted file mode 100644 index a62fb3fff..000000000 --- a/tests/Legacy/Feature/FrameworkInviteCodeControllerTest.php +++ /dev/null @@ -1,110 +0,0 @@ - 'jane@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $this->postJson('/api/framework/access_code', [ - 'code' => 'gfd432', - 'framework' => 'ppc', - ], $headers) - ->assertStatus(201); - } - - public function testReadAllAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'jane@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - - $response = $this->getJson('/api/framework/access_code/all', $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure([ - 'data' => [ - '*' => [ - 'id', - 'code', - 'framework_id', - 'created_at', - 'updated_at', - ], - ], - 'meta' => [], - ]); - } - - public function testDeleteAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'jane@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->deleteJson('/api/framework/access_code/1', $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure(['data' => []]); - } - - public function testJoinAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'andrew@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $this->postJson('/api/framework/access_code/join', [ - 'code' => 'kcs0611', - ], $headers) - ->assertStatus(200) - ->assertJsonFragment([ - 'id' => 1, - 'code' => 'kcs0611', - ]); - - $this->assertDatabaseHas('framework_user', [ - 'user_id' => 4, - 'framework_id' => 1, - ]); - } - - public function testJoinActionInvalidCodeThrowsError(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $this->postJson('/api/framework/access_code/join', [ - 'code' => 'notavalidcodeohno', - ], $headers) - ->assertStatus(422); - } -} diff --git a/tests/Legacy/Feature/InterestsControllerTest.php b/tests/Legacy/Feature/InterestsControllerTest.php deleted file mode 100644 index 69db12399..000000000 --- a/tests/Legacy/Feature/InterestsControllerTest.php +++ /dev/null @@ -1,137 +0,0 @@ - 'offer', - 'offer_id' => 3, - 'pitch_id' => 1, - ]; - $token = Auth::attempt([ - 'email_address' => 'andrew@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $response = $this->postJson('/api/interests', $data, $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(201); - $response->assertJsonStructure([ - 'data' => [ - 'id', - 'organisation_id', - 'offer_id', - 'pitch_id', - 'initiator', - 'matched', - 'created_at', - ], - 'meta' => [], - ]); - } - - public function testReadAllByTypeAction(): void - { - $this->callReadAllActionAsInitiated(); - $this->callReadAllActionAsReceived(); - } - - public function callReadAllActionAsInitiated() - { - $token = Auth::attempt([ - 'email_address' => 'andrew@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->getJson('/api/interests/initiated', $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure([ - 'data' => [ - [ - 'id', - 'organisation_id', - 'offer_id', - 'pitch_id', - 'initiator', - 'matched', - 'created_at', - ], - ], - ]); - foreach ($response->json('data') as $interest) { - $this->assertSame(2, $interest['organisation_id']); - } - } - - public function callReadAllActionAsReceived() - { - $token = Auth::attempt([ - 'email_address' => 'andrew@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->getJson('/api/interests/received', $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure([ - 'data' => [ - [ - 'id', - 'organisation_id', - 'offer_id', - 'pitch_id', - 'initiator', - 'matched', - 'created_at', - ], - ], - ]); - foreach ($response->json('data') as $interest) { - $this->assertNotSame(2, $interest['organisation_id']); - } - } - - public function testDeleteAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'andrew@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->deleteJson('/api/interests/1', $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJson(['data' => []]); - } - - public function testDeleteActionMonitoringExistsException(): void - { - $token = Auth::attempt([ - 'email_address' => 'andrew@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->deleteJson('/api/interests/4', $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(422); - $response->assertJson(['errors' => []]); - } -} diff --git a/tests/Legacy/Feature/InvasiveControllerTest.php b/tests/Legacy/Feature/InvasiveControllerTest.php deleted file mode 100644 index 47fe8a4c1..000000000 --- a/tests/Legacy/Feature/InvasiveControllerTest.php +++ /dev/null @@ -1,34 +0,0 @@ - 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $data = [ - 'name' => 'test name', - 'type' => 'common', - ]; - - $this->postJson('/api/site/1/invasives', $data, $headers) - ->assertHeader('Content-Type', 'application/json') - ->assertStatus(201) - ->assertJsonFragment([ - 'name' => 'test name', - 'type' => 'common', - 'site_id' => 1, - ]); - } -} diff --git a/tests/Legacy/Feature/LandTenureControllerTest.php b/tests/Legacy/Feature/LandTenureControllerTest.php deleted file mode 100644 index cc243e751..000000000 --- a/tests/Legacy/Feature/LandTenureControllerTest.php +++ /dev/null @@ -1,34 +0,0 @@ - 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $this->getJson('/api/site/land_tenures', $headers) - ->assertStatus(200) - ->assertJsonFragment([ - 'id' => 1, - 'name' => 'Public', - 'key' => 'public', - ]) - ->assertJsonFragment([ - 'id' => 2, - 'name' => 'Private', - 'key' => 'private', - ]); - } -} diff --git a/tests/Legacy/Feature/LegacySatelliteMonitorControllerTest.php b/tests/Legacy/Feature/LegacySatelliteMonitorControllerTest.php deleted file mode 100644 index db72d7b0f..000000000 --- a/tests/Legacy/Feature/LegacySatelliteMonitorControllerTest.php +++ /dev/null @@ -1,188 +0,0 @@ - $this->fakeMap(), - ]; - $token = Auth::attempt([ - 'email_address' => 'jane@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->post('/api/uploads', $data, $headers); - $id = json_decode($response->getContent())->data->id; - $data = [ - 'satellite_monitorable_type' => Programme::class, - 'satellite_monitorable_id' => 1, - 'map' => $id, - 'alt_text' => 'Lorem ipsum dolor sit amet', - ]; - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $response = $this->postJson('/api/satellite_monitor', $data, $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(201); - $response->assertJsonStructure([ - 'data' => [ - 'id', - 'satellite_monitorable_type', - 'satellite_monitorable_id', - 'map', - 'alt_text', - 'created_at', - ], - ]); - $response->assertJson([ - 'data' => [ - 'map' => null, - ], - ]); - } - - public function testCreateActionUsingStringAsModel(): void - { - $data = [ - 'upload' => $this->fakeMap(), - ]; - $token = Auth::attempt([ - 'email_address' => 'jane@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->post('/api/uploads', $data, $headers); - $id = json_decode($response->getContent())->data->id; - $data = [ - 'satellite_monitorable_type' => 'site', - 'satellite_monitorable_id' => 1, - 'map' => $id, - 'alt_text' => 'Lorem ipsum dolor sit amet', - ]; - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $response = $this->postJson('/api/satellite_monitor', $data, $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(201); - $response->assertJsonStructure([ - 'data' => [ - 'id', - 'satellite_monitorable_type', - 'satellite_monitorable_id', - 'map', - 'alt_text', - 'created_at', - ], - ]); - $response->assertJson([ - 'data' => [ - 'map' => null, - ], - ]); - } - - public function testReadByProgrammeAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $response = $this->getJson('/api/satellite_monitor/programme/1', $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonFragment([ - 'id' => 3, - 'satellite_monitorable_type' => \App\Models\Programme::class, - 'satellite_monitorable_id' => 1, - ]); - $response->assertJsonFragment([ - 'id' => 3, - 'satellite_monitorable_type' => \App\Models\Programme::class, - 'satellite_monitorable_id' => 1, - ]); - } - - public function testReadLatestByProgrammeAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'jane@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $response = $this->getJson('/api/satellite_monitor/programme/1/latest', $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonFragment([ - 'id' => 3, - 'satellite_monitorable_type' => \App\Models\Programme::class, - 'satellite_monitorable_id' => 1, - ]); - } - - public function testReadBySiteAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'jane@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $response = $this->getJson('/api/satellite_monitor/site/1', $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonFragment([ - 'id' => 2, - 'satellite_monitorable_type' => \App\Models\Site::class, - 'satellite_monitorable_id' => 1, - ]); - $response->assertJsonFragment([ - 'id' => 4, - 'satellite_monitorable_type' => \App\Models\Site::class, - 'satellite_monitorable_id' => 1, - ]); - } - - public function testReadLatestBySiteAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'jane@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $response = $this->getJson('/api/satellite_monitor/site/1/latest', $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonFragment([ - 'id' => 4, - 'satellite_monitorable_type' => \App\Models\Site::class, - 'satellite_monitorable_id' => 1, - ]); - } -} diff --git a/tests/Legacy/Feature/MatchesControllerTest.php b/tests/Legacy/Feature/MatchesControllerTest.php deleted file mode 100644 index 02cd55065..000000000 --- a/tests/Legacy/Feature/MatchesControllerTest.php +++ /dev/null @@ -1,148 +0,0 @@ -callReadAllActionAsFirstUser(); - $this->callReadAllActionAsSecondUser(); - } - - public function callReadAllActionAsFirstUser() - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->getJson('/api/matches', $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure(['data' => [ - [ - 'id', - 'offer_id', - 'offer_name', - 'offer_interest_id', - 'offer_contacts' => [ - [ - 'first_name', - 'last_name', - 'avatar', - 'email_address', - 'phone_number', - ], - ], - 'pitch_id', - 'pitch_name', - 'pitch_interest_id', - 'pitch_contacts' => [ - [ - 'first_name', - 'last_name', - 'avatar', - 'email_address', - 'phone_number', - ], - ], - 'monitoring_id', - 'matched_at', - ], - ]]); - } - - public function callReadAllActionAsSecondUser() - { - $token = Auth::attempt([ - 'email_address' => 'andrew@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->getJson('/api/matches', $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure(['data' => [ - [ - 'id', - 'offer_id', - 'offer_name', - 'offer_interest_id', - 'offer_contacts' => [ - [ - 'first_name', - 'last_name', - 'avatar', - 'email_address', - 'phone_number', - ], - ], - 'pitch_id', - 'pitch_name', - 'pitch_interest_id', - 'pitch_contacts' => [ - [ - 'first_name', - 'last_name', - 'avatar', - 'email_address', - 'phone_number', - ], - ], - 'monitoring_id', - 'matched_at', - ], - ]]); - } - - public function testReadAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->getJson('/api/matches/1', $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure(['data' => [ - 'id', - 'offer_id', - 'offer_name', - 'offer_interest_id', - 'offer_contacts' => [ - [ - 'first_name', - 'last_name', - 'avatar', - 'email_address', - 'phone_number', - ], - ], - 'pitch_id', - 'pitch_name', - 'pitch_interest_id', - 'pitch_contacts' => [ - [ - 'first_name', - 'last_name', - 'avatar', - 'email_address', - 'phone_number', - ], - ], - 'monitoring_id', - 'matched_at', - ]]); - } -} diff --git a/tests/Legacy/Feature/MediaUploadControllerTest.php b/tests/Legacy/Feature/MediaUploadControllerTest.php deleted file mode 100644 index bfcc637db..000000000 --- a/tests/Legacy/Feature/MediaUploadControllerTest.php +++ /dev/null @@ -1,38 +0,0 @@ -getHeaders('steve@example.com', 'Password123'); - - $data = [ - 'is_public' => true, - 'programme_id' => 1, - 'upload' => 1, - ]; - - $response = $this->postJson('/api/uploads/site_programme_media', $data, $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(201); - } - - public function testCreateActionDoesNotRequireMediaTitle(): void - { - $headers = $this->getHeaders('steve@example.com', 'Password123'); - - $data = [ - 'is_public' => true, - 'programme_id' => 1, - 'upload' => 1, - ]; - - $response = $this->postJson('/api/uploads/site_programme_media', $data, $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(201); - } -} diff --git a/tests/Legacy/Feature/MonitoringsControllerTest.php b/tests/Legacy/Feature/MonitoringsControllerTest.php deleted file mode 100644 index af0a296f7..000000000 --- a/tests/Legacy/Feature/MonitoringsControllerTest.php +++ /dev/null @@ -1,869 +0,0 @@ - 'dominic@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $data = [ - 'visibility' => 'fully_invested_funded', - ]; - $this->patchJson('/api/pitches/1/visibility', $data, $headers); - $data = [ - 'match_id' => 1, - ]; - $response = $this->postJson('/api/monitorings', $data, $headers); - $response->assertStatus(201); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertJsonStructure([ - 'data' => [ - 'id', - 'match_id', - 'initiator', - 'stage', - 'negotiating', - 'created_by', - 'created_at', - 'pitch' => [ - 'id', - 'organisation_id', - 'name', - 'description', - 'land_types', - 'land_ownerships', - 'land_size', - 'land_continent', - 'land_country', - 'land_geojson', - 'restoration_methods', - 'restoration_goals', - 'funding_sources', - 'funding_amount', - 'revenue_drivers', - 'estimated_timespan', - 'long_term_engagement', - 'reporting_frequency', - 'reporting_level', - 'sustainable_development_goals', - 'avatar', - 'cover_photo', - 'video', - 'problem', - 'anticipated_outcome', - 'who_is_involved', - 'local_community_involvement', - 'training_involved', - 'training_type', - 'training_amount_people', - 'people_working_in', - 'people_amount_nearby', - 'people_amount_abroad', - 'people_amount_employees', - 'people_amount_volunteers', - 'benefited_people', - 'future_maintenance', - 'use_of_resources', - 'facebook', - 'twitter', - 'instagram', - 'successful', - 'visibility', - ], - 'offer' => [ - 'id', - 'organisation_id', - 'name', - 'description', - 'land_types', - 'land_ownerships', - 'land_size', - 'land_continent', - 'land_country', - 'restoration_methods', - 'restoration_goals', - 'funding_sources', - 'funding_amount', - 'funding_bracket', - 'price_per_tree', - 'long_term_engagement', - 'reporting_frequency', - 'reporting_level', - 'sustainable_development_goals', - 'cover_photo', - 'video', - 'created_at', - 'successful', - ], - 'updated_at', - ], - ]); - } - - public function testReadAction(): void - { - $this->callReadActionAsUser(); - $this->callReadActionAsAdmin(); - } - - private function callReadActionAsUser() - { - $token = Auth::attempt([ - 'email_address' => 'dominic@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->getJson('/api/monitorings/1', $headers); - $response->assertStatus(200); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertJsonStructure([ - 'data' => [ - 'id', - 'match_id', - 'initiator', - 'stage', - 'negotiating', - 'created_by', - 'created_at', - 'pitch' => [ - 'id', - 'organisation_id', - 'name', - 'description', - 'land_types', - 'land_ownerships', - 'land_size', - 'land_continent', - 'land_country', - 'land_geojson', - 'restoration_methods', - 'restoration_goals', - 'funding_sources', - 'funding_amount', - 'revenue_drivers', - 'estimated_timespan', - 'long_term_engagement', - 'reporting_frequency', - 'reporting_level', - 'sustainable_development_goals', - 'avatar', - 'cover_photo', - 'video', - 'problem', - 'anticipated_outcome', - 'who_is_involved', - 'local_community_involvement', - 'training_involved', - 'training_type', - 'training_amount_people', - 'people_working_in', - 'people_amount_nearby', - 'people_amount_abroad', - 'people_amount_employees', - 'people_amount_volunteers', - 'benefited_people', - 'future_maintenance', - 'use_of_resources', - 'facebook', - 'twitter', - 'instagram', - 'successful', - 'visibility', - ], - 'offer' => [ - 'id', - 'organisation_id', - 'name', - 'description', - 'land_types', - 'land_ownerships', - 'land_size', - 'land_continent', - 'land_country', - 'restoration_methods', - 'restoration_goals', - 'funding_sources', - 'funding_amount', - 'funding_bracket', - 'price_per_tree', - 'long_term_engagement', - 'reporting_frequency', - 'reporting_level', - 'sustainable_development_goals', - 'cover_photo', - 'video', - 'created_at', - 'successful', - ], - 'updated_at', - ], - ]); - } - - private function callReadActionAsAdmin() - { - $token = Auth::attempt([ - 'email_address' => 'jane@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->getJson('/api/monitorings/1', $headers); - $response->assertStatus(200); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertJsonStructure([ - 'data' => [ - 'id', - 'match_id', - 'initiator', - 'stage', - 'negotiating', - 'created_by', - 'created_at', - 'pitch' => [ - 'id', - 'organisation_id', - 'name', - 'description', - 'land_types', - 'land_ownerships', - 'land_size', - 'land_continent', - 'land_country', - 'land_geojson', - 'restoration_methods', - 'restoration_goals', - 'funding_sources', - 'funding_amount', - 'revenue_drivers', - 'estimated_timespan', - 'long_term_engagement', - 'reporting_frequency', - 'reporting_level', - 'sustainable_development_goals', - 'avatar', - 'cover_photo', - 'video', - 'problem', - 'anticipated_outcome', - 'who_is_involved', - 'local_community_involvement', - 'training_involved', - 'training_type', - 'training_amount_people', - 'people_working_in', - 'people_amount_nearby', - 'people_amount_abroad', - 'people_amount_employees', - 'people_amount_volunteers', - 'benefited_people', - 'future_maintenance', - 'use_of_resources', - 'facebook', - 'twitter', - 'instagram', - 'successful', - 'visibility', - ], - 'offer' => [ - 'id', - 'organisation_id', - 'name', - 'description', - 'land_types', - 'land_ownerships', - 'land_size', - 'land_continent', - 'land_country', - 'restoration_methods', - 'restoration_goals', - 'funding_sources', - 'funding_amount', - 'funding_bracket', - 'price_per_tree', - 'long_term_engagement', - 'reporting_frequency', - 'reporting_level', - 'sustainable_development_goals', - 'cover_photo', - 'video', - 'created_at', - 'successful', - ], - 'updated_at', - ], - ]); - } - - public function testReadAllByOfferAction(): void - { - $this->callReadAllByOfferActionAsOwner(); - $this->callReadAllByOfferActionAsNotOwner(); - } - - private function callReadAllByOfferActionAsOwner() - { - $token = Auth::attempt([ - 'email_address' => 'andrew@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->getJson('/api/offers/4/monitorings', $headers); - $response->assertStatus(200); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertJsonStructure([ - 'data' => [ - [ - 'id', - 'match_id', - 'initiator', - 'stage', - 'negotiating', - 'created_by', - 'created_at', - 'pitch' => [ - 'id', - 'organisation_id', - 'name', - 'description', - 'land_types', - 'land_ownerships', - 'land_size', - 'land_continent', - 'land_country', - 'land_geojson', - 'restoration_methods', - 'restoration_goals', - 'funding_sources', - 'funding_amount', - 'revenue_drivers', - 'estimated_timespan', - 'long_term_engagement', - 'reporting_frequency', - 'reporting_level', - 'sustainable_development_goals', - 'avatar', - 'cover_photo', - 'video', - 'problem', - 'anticipated_outcome', - 'who_is_involved', - 'local_community_involvement', - 'training_involved', - 'training_type', - 'training_amount_people', - 'people_working_in', - 'people_amount_nearby', - 'people_amount_abroad', - 'people_amount_employees', - 'people_amount_volunteers', - 'benefited_people', - 'future_maintenance', - 'use_of_resources', - 'facebook', - 'twitter', - 'instagram', - 'successful', - 'visibility', - ], - 'offer' => [ - 'id', - 'organisation_id', - 'name', - 'description', - 'land_types', - 'land_ownerships', - 'land_size', - 'land_continent', - 'land_country', - 'restoration_methods', - 'restoration_goals', - 'funding_sources', - 'funding_amount', - 'funding_bracket', - 'price_per_tree', - 'long_term_engagement', - 'reporting_frequency', - 'reporting_level', - 'sustainable_development_goals', - 'cover_photo', - 'video', - 'created_at', - 'successful', - ], - 'updated_at', - ], - ], - ]); - } - - private function callReadAllByOfferActionAsNotOwner() - { - $token = Auth::attempt([ - 'email_address' => 'dominic@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->getJson('/api/offers/4/monitorings', $headers); - $response->assertStatus(200); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertJsonStructure([ - 'data' => [ - [ - 'id', - 'match_id', - 'initiator', - 'stage', - 'negotiating', - 'created_by', - 'created_at', - 'pitch' => [ - 'id', - 'organisation_id', - 'name', - 'description', - 'land_types', - 'land_ownerships', - 'land_size', - 'land_continent', - 'land_country', - 'land_geojson', - 'restoration_methods', - 'restoration_goals', - 'funding_sources', - 'funding_amount', - 'revenue_drivers', - 'estimated_timespan', - 'long_term_engagement', - 'reporting_frequency', - 'reporting_level', - 'sustainable_development_goals', - 'avatar', - 'cover_photo', - 'video', - 'problem', - 'anticipated_outcome', - 'who_is_involved', - 'local_community_involvement', - 'training_involved', - 'training_type', - 'training_amount_people', - 'people_working_in', - 'people_amount_nearby', - 'people_amount_abroad', - 'people_amount_employees', - 'people_amount_volunteers', - 'benefited_people', - 'future_maintenance', - 'use_of_resources', - 'facebook', - 'twitter', - 'instagram', - 'successful', - 'visibility', - ], - 'offer' => [ - 'id', - 'organisation_id', - 'name', - 'description', - 'land_types', - 'land_ownerships', - 'land_size', - 'land_continent', - 'land_country', - 'restoration_methods', - 'restoration_goals', - 'funding_sources', - 'funding_amount', - 'funding_bracket', - 'price_per_tree', - 'long_term_engagement', - 'reporting_frequency', - 'reporting_level', - 'sustainable_development_goals', - 'cover_photo', - 'video', - 'created_at', - 'successful', - ], - 'updated_at', - ], - ], - ]); - } - - public function testReadAllByPitchAction(): void - { - $this->callReadAllByPitchActionAsOwner(); - $this->callReadAllByPitchActionAsNotOwner(); - } - - private function callReadAllByPitchActionAsOwner() - { - $token = Auth::attempt([ - 'email_address' => 'dominic@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->getJson('/api/pitches/2/monitorings', $headers); - $response->assertStatus(200); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertJsonStructure([ - 'data' => [ - [ - 'id', - 'match_id', - 'initiator', - 'stage', - 'negotiating', - 'created_by', - 'created_at', - 'pitch' => [ - 'id', - 'organisation_id', - 'name', - 'description', - 'land_types', - 'land_ownerships', - 'land_size', - 'land_continent', - 'land_country', - 'land_geojson', - 'restoration_methods', - 'restoration_goals', - 'funding_sources', - 'funding_amount', - 'revenue_drivers', - 'estimated_timespan', - 'long_term_engagement', - 'reporting_frequency', - 'reporting_level', - 'sustainable_development_goals', - 'avatar', - 'cover_photo', - 'video', - 'problem', - 'anticipated_outcome', - 'who_is_involved', - 'local_community_involvement', - 'training_involved', - 'training_type', - 'training_amount_people', - 'people_working_in', - 'people_amount_nearby', - 'people_amount_abroad', - 'people_amount_employees', - 'people_amount_volunteers', - 'benefited_people', - 'future_maintenance', - 'use_of_resources', - 'facebook', - 'twitter', - 'instagram', - 'successful', - 'visibility', - ], - 'offer' => [ - 'id', - 'organisation_id', - 'name', - 'description', - 'land_types', - 'land_ownerships', - 'land_size', - 'land_continent', - 'land_country', - 'restoration_methods', - 'restoration_goals', - 'funding_sources', - 'funding_amount', - 'funding_bracket', - 'price_per_tree', - 'long_term_engagement', - 'reporting_frequency', - 'reporting_level', - 'sustainable_development_goals', - 'cover_photo', - 'video', - 'created_at', - 'successful', - ], - 'updated_at', - ], - ], - ]); - } - - private function callReadAllByPitchActionAsNotOwner() - { - $token = Auth::attempt([ - 'email_address' => 'andrew@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->getJson('/api/pitches/2/monitorings', $headers); - $response->assertStatus(200); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertJsonStructure([ - 'data' => [ - [ - 'id', - 'match_id', - 'initiator', - 'stage', - 'negotiating', - 'created_by', - 'created_at', - 'pitch' => [ - 'id', - 'organisation_id', - 'name', - 'description', - 'land_types', - 'land_ownerships', - 'land_size', - 'land_continent', - 'land_country', - 'land_geojson', - 'restoration_methods', - 'restoration_goals', - 'funding_sources', - 'funding_amount', - 'revenue_drivers', - 'estimated_timespan', - 'long_term_engagement', - 'reporting_frequency', - 'reporting_level', - 'sustainable_development_goals', - 'avatar', - 'cover_photo', - 'video', - 'problem', - 'anticipated_outcome', - 'who_is_involved', - 'local_community_involvement', - 'training_involved', - 'training_type', - 'training_amount_people', - 'people_working_in', - 'people_amount_nearby', - 'people_amount_abroad', - 'people_amount_employees', - 'people_amount_volunteers', - 'benefited_people', - 'future_maintenance', - 'use_of_resources', - 'facebook', - 'twitter', - 'instagram', - 'successful', - 'visibility', - ], - 'offer' => [ - 'id', - 'organisation_id', - 'name', - 'description', - 'land_types', - 'land_ownerships', - 'land_size', - 'land_continent', - 'land_country', - 'restoration_methods', - 'restoration_goals', - 'funding_sources', - 'funding_amount', - 'funding_bracket', - 'price_per_tree', - 'long_term_engagement', - 'reporting_frequency', - 'reporting_level', - 'sustainable_development_goals', - 'cover_photo', - 'video', - 'created_at', - 'successful', - ], - 'updated_at', - ], - ], - ]); - } - - public function testReadAllAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'dominic@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->getJson('/api/monitorings', $headers); - $response->assertStatus(200); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertJsonStructure([ - 'data' => [ - [ - 'id', - 'match_id', - 'initiator', - 'stage', - 'negotiating', - 'created_by', - 'created_at', - 'pitch' => [ - 'id', - 'organisation_id', - 'name', - 'description', - 'land_types', - 'land_ownerships', - 'land_size', - 'land_continent', - 'land_country', - 'land_geojson', - 'restoration_methods', - 'restoration_goals', - 'funding_sources', - 'funding_amount', - 'revenue_drivers', - 'estimated_timespan', - 'long_term_engagement', - 'reporting_frequency', - 'reporting_level', - 'sustainable_development_goals', - 'avatar', - 'cover_photo', - 'video', - 'problem', - 'anticipated_outcome', - 'who_is_involved', - 'local_community_involvement', - 'training_involved', - 'training_type', - 'training_amount_people', - 'people_working_in', - 'people_amount_nearby', - 'people_amount_abroad', - 'people_amount_employees', - 'people_amount_volunteers', - 'benefited_people', - 'future_maintenance', - 'use_of_resources', - 'facebook', - 'twitter', - 'instagram', - 'successful', - 'visibility', - ], - 'offer' => [ - 'id', - 'organisation_id', - 'name', - 'description', - 'land_types', - 'land_ownerships', - 'land_size', - 'land_continent', - 'land_country', - 'restoration_methods', - 'restoration_goals', - 'funding_sources', - 'funding_amount', - 'funding_bracket', - 'price_per_tree', - 'long_term_engagement', - 'reporting_frequency', - 'reporting_level', - 'sustainable_development_goals', - 'cover_photo', - 'video', - 'created_at', - 'successful', - ], - 'updated_at', - ], - ], - ]); - } - - public function testSummariseAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'dominic@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->getJson('/api/monitorings/2/summarise', $headers); - $response->assertStatus(200); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertJsonStructure([ - 'data' => [ - [ - 'attribute', - 'target', - 'progress_update', - 'updated_at', - ], - ], - ]); - $response->assertJson([ - 'data' => [ - 0 => [ - 'attribute' => 'trees_planted', - 'target' => 123, - 'progress_update' => 9, - ], - 2 => [ - 'attribute' => 'survival_rate', - 'target' => 75, - 'progress_update' => 100, - ], - ], - ]); - } - - public function testReadLandGeoJsonAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'jane@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->getJson('/api/monitorings/2/land_geojson', $headers); - $response->assertStatus(200); - $response->assertHeader('Content-Type', 'text/plain; charset=UTF-8'); - $response->assertHeader('Content-Disposition', 'attachment; filename="monitoring_2_land_geojson.geojson"'); - json_decode($response->getContent()); - $this->assertEquals(0, json_last_error()); - $response->assertSee('"type": "Polygon"', false); - } -} diff --git a/tests/Legacy/Feature/NotificationsControllerTest.php b/tests/Legacy/Feature/NotificationsControllerTest.php deleted file mode 100644 index 08c77b1fc..000000000 --- a/tests/Legacy/Feature/NotificationsControllerTest.php +++ /dev/null @@ -1,63 +0,0 @@ - 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->getJson('/api/notifications', $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure(['data' => [ - [ - 'id', - 'user_id', - 'title', - 'body', - 'unread', - 'created_at', - ], - ]]); - $response->assertJson([ - 'data' => [ - [ - 'unread' => true, - ], - ], - ]); - } - - public function testMarkAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->patchJson('/api/notifications/1/mark', $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure(['data' => [ - 'id', - 'user_id', - 'title', - 'body', - 'unread', - 'created_at', - ]]); - $response->assertJson(['data' => ['unread' => false]]); - } -} diff --git a/tests/Legacy/Feature/OfferContactsControllerTest.php b/tests/Legacy/Feature/OfferContactsControllerTest.php deleted file mode 100644 index 8ab2cbd3a..000000000 --- a/tests/Legacy/Feature/OfferContactsControllerTest.php +++ /dev/null @@ -1,121 +0,0 @@ -callCreateActionWithUser(); - $this->callCreateActionWithTeamMember(); - } - - private function callCreateActionWithUser() - { - $data = [ - 'offer_id' => 1, - 'user_id' => 3, - ]; - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $response = $this->postJson('/api/offer_contacts', $data, $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(201); - $response->assertJsonStructure([ - 'data' => [ - 'id', - 'user_id', - 'offer_id', - 'first_name', - 'last_name', - ], - 'meta' => [], - ]); - } - - private function callCreateActionWithTeamMember() - { - $data = [ - 'offer_id' => 1, - 'team_member_id' => 1, - ]; - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $response = $this->postJson('/api/offer_contacts', $data, $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(201); - $response->assertJsonStructure([ - 'data' => [ - 'id', - 'team_member_id', - 'offer_id', - 'first_name', - 'last_name', - ], - 'meta' => [], - ]); - } - - public function testReadAllByOfferAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->getJson('/api/offers/2/offer_contacts', $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure([ - 'data' => [ - [ - 'id', - 'offer_id', - 'first_name', - 'last_name', - ], - ], - ]); - } - - public function testDeleteAction(): void - { - $data = [ - 'offer_id' => 2, - 'team_member_id' => 3, - ]; - $token = Auth::attempt([ - 'email_address' => 'andrew@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $this->postJson('/api/offer_contacts', $data, $headers); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->deleteJson('/api/offer_contacts/4', $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJson(['data' => []]); - } -} diff --git a/tests/Legacy/Feature/OfferDocumentsControllerTest.php b/tests/Legacy/Feature/OfferDocumentsControllerTest.php deleted file mode 100644 index e29356cf8..000000000 --- a/tests/Legacy/Feature/OfferDocumentsControllerTest.php +++ /dev/null @@ -1,141 +0,0 @@ - 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $data = [ - 'upload' => $this->fakeFile(), - ]; - $response = $this->post('/api/uploads', $data, $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(201); - $id = json_decode($response->getContent())->data->id; - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $data = [ - 'offer_id' => 1, - 'name' => 'Foo', - 'type' => 'legal', - 'document' => $id, - ]; - $response = $this->postJson('/api/offer_documents', $data, $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(201); - $response->assertJsonStructure([ - 'data' => [ - 'id', - 'offer_id', - 'name', - 'type', - 'document', - ], - 'meta' => [], - ]); - } - - public function testReadAllByOfferAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->getJson('/api/offers/1/offer_documents', $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure([ - 'data' => [ - [ - 'id', - 'offer_id', - 'name', - 'type', - 'document', - ], - ], - ]); - } - - public function testReadAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->getJson('/api/offer_documents/1', $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure([ - 'data' => [ - 'id', - 'offer_id', - 'name', - 'type', - 'document', - ], - 'meta' => [], - ]); - } - - public function testUpdateAction(): void - { - $data = [ - 'name' => 'Bar', - ]; - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $response = $this->patchJson('/api/offer_documents/1', $data, $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure([ - 'data' => [ - 'id', - 'offer_id', - 'name', - 'type', - 'document', - ], - ]); - } - - public function testDeleteAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->deleteJson('/api/offer_documents/1', $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJson(['data' => []]); - } -} diff --git a/tests/Legacy/Feature/OffersControllerTest.php b/tests/Legacy/Feature/OffersControllerTest.php deleted file mode 100644 index 6bc65df80..000000000 --- a/tests/Legacy/Feature/OffersControllerTest.php +++ /dev/null @@ -1,436 +0,0 @@ - 'Example Offer', - 'description' => 'Lorem ipsum dolor sit amet', - 'land_types' => ['cropland', 'mangrove'], - 'land_ownerships' => ['private'], - 'land_size' => 'lt_10', - 'land_continent' => 'europe', - 'land_country' => null, - 'restoration_methods' => ['agroforestry', 'riparian_buffers'], - 'restoration_goals' => ['agriculture_and_commodities'], - 'funding_sources' => ['equity_investment', 'loan_debt', 'grant_with_reporting'], - 'funding_amount' => 1000000, - 'funding_bracket' => 'gt_1m', - 'price_per_tree' => 1.5, - 'long_term_engagement' => false, - 'reporting_frequency' => 'gt_quarterly', - 'reporting_level' => 'low', - 'sustainable_development_goals' => ['goal_1', 'goal_7', 'goal_9', 'goal_13'], - 'cover_photo' => null, - 'video' => null, - ]; - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $response = $this->postJson('/api/offers', $data, $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(201); - $response->assertJsonStructure([ - 'data' => [ - 'id', - 'organisation_id', - 'name', - 'description', - 'land_types', - 'land_ownerships', - 'land_size', - 'land_continent', - 'land_country', - 'restoration_methods', - 'restoration_goals', - 'funding_sources', - 'funding_amount', - 'funding_bracket', - 'price_per_tree', - 'long_term_engagement', - 'reporting_frequency', - 'reporting_level', - 'sustainable_development_goals', - 'cover_photo', - 'video', - 'created_at', - 'successful', - ], - 'meta' => [], - ]); - } - - public function testReadAllByOrganisationAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'andrew@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->getJson('/api/organisations/1/offers', $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure([ - 'data' => [ - [ - 'id', - 'organisation_id', - 'name', - 'description', - 'land_types', - 'land_ownerships', - 'land_size', - 'land_continent', - 'land_country', - 'restoration_methods', - 'restoration_goals', - 'funding_sources', - 'funding_amount', - 'price_per_tree', - 'long_term_engagement', - 'reporting_frequency', - 'reporting_level', - 'sustainable_development_goals', - 'cover_photo', - 'video', - 'created_at', - 'successful', - ], - ], - 'meta' => [], - ]); - } - - public function testReadAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->getJson('/api/offers/1', $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure([ - 'data' => [ - 'id', - 'organisation_id', - 'name', - 'description', - 'land_types', - 'land_ownerships', - 'land_size', - 'land_continent', - 'land_country', - 'restoration_methods', - 'restoration_goals', - 'funding_sources', - 'funding_amount', - 'price_per_tree', - 'long_term_engagement', - 'reporting_frequency', - 'reporting_level', - 'sustainable_development_goals', - 'cover_photo', - 'video', - 'created_at', - 'successful', - 'visibility', - ], - 'meta' => [], - ]); - } - - public function testUpdateAction(): void - { - $data = [ - 'name' => 'Bar', - ]; - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $response = $this->patchJson('/api/offers/1', $data, $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure([ - 'data' => [ - 'id', - 'organisation_id', - 'name', - 'description', - 'land_types', - 'land_ownerships', - 'land_size', - 'land_continent', - 'land_country', - 'restoration_methods', - 'restoration_goals', - 'funding_sources', - 'funding_amount', - 'price_per_tree', - 'long_term_engagement', - 'reporting_frequency', - 'reporting_level', - 'sustainable_development_goals', - 'cover_photo', - 'video', - 'created_at', - 'successful', - ], - 'meta' => [], - ]); - $response->assertJson([ - 'data' => [ - 'name' => 'Bar', - ], - ]); - } - - public function testSearchAction(): void - { - Queue::fake(); - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $data = [ - 'filters' => [ - [ - 'attribute' => 'land_types', - 'operator' => 'contains', - 'value' => [ - 'mangrove', - 'cropland', - ], - ], - [ - 'attribute' => 'funding_bracket', - 'operator' => 'in', - 'value' => [ - 'lt_50k', - ], - ], - ], - 'sortDirection' => 'desc', - 'page' => 1, - ]; - $response = $this->postJson('/api/offers/search', $data, $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure([ - 'data' => [ - [ - 'id', - 'organisation_id', - 'name', - 'description', - 'land_types', - 'land_ownerships', - 'land_size', - 'land_continent', - 'land_country', - 'restoration_methods', - 'restoration_goals', - 'funding_sources', - 'funding_amount', - 'price_per_tree', - 'long_term_engagement', - 'reporting_frequency', - 'reporting_level', - 'sustainable_development_goals', - 'cover_photo', - 'video', - 'created_at', - 'compatibility_score', - 'successful', - ], - ], - 'meta' => [], - ]); - } - - public function testInspectByOrganisationAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->getJson('/api/organisations/1/offers/inspect', $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure([ - 'data' => [ - [ - 'id', - 'organisation_id', - 'name', - 'description', - 'land_types', - 'land_ownerships', - 'land_size', - 'land_continent', - 'land_country', - 'restoration_methods', - 'restoration_goals', - 'funding_sources', - 'funding_amount', - 'price_per_tree', - 'long_term_engagement', - 'reporting_frequency', - 'reporting_level', - 'sustainable_development_goals', - 'cover_photo', - 'video', - 'created_at', - 'successful', - ], - ], - 'meta' => [], - ]); - } - - public function testMostRecentAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'andrew@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - - $response = $this->getJson('/api/offers/most_recent', $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure([ - 'data' => [ - [ - 'id', - 'organisation_id', - 'name', - 'description', - 'land_types', - 'land_ownerships', - 'land_size', - 'land_continent', - 'land_country', - 'restoration_methods', - 'restoration_goals', - 'funding_sources', - 'funding_amount', - 'price_per_tree', - 'long_term_engagement', - 'reporting_frequency', - 'reporting_level', - 'sustainable_development_goals', - 'cover_photo', - 'video', - 'created_at', - 'successful', - ], - ], - 'meta' => [ - 'count', - ], - ]); - } - - public function testUpdateVisibilityAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $data = [ - 'visibility' => 'talking', - ]; - $response = $this->patchJson('/api/offers/1/visibility', $data, $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure([ - 'data' => [ - 'id', - 'organisation_id', - 'name', - 'description', - 'land_types', - 'land_ownerships', - 'land_size', - 'land_continent', - 'land_country', - 'restoration_methods', - 'restoration_goals', - 'funding_sources', - 'funding_amount', - 'price_per_tree', - 'long_term_engagement', - 'reporting_frequency', - 'reporting_level', - 'sustainable_development_goals', - 'cover_photo', - 'video', - 'created_at', - 'successful', - 'visibility', - ], - 'meta' => [], - ]); - $response->assertJson([ - 'data' => [ - 'visibility' => 'talking', - ], - ]); - } - - public function testUpdateVisibilityActionMonitoringExistsException(): void - { - $token = Auth::attempt([ - 'email_address' => 'andrew@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $data = [ - 'visibility' => 'talking', - ]; - $response = $this->patchJson('/api/offers/4/visibility', $data, $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(422); - $response->assertJsonStructure([ - 'errors' => [], - ]); - } -} diff --git a/tests/Legacy/Feature/OrganisationDocumentVersionsControllerTest.php b/tests/Legacy/Feature/OrganisationDocumentVersionsControllerTest.php deleted file mode 100644 index b94c47ba2..000000000 --- a/tests/Legacy/Feature/OrganisationDocumentVersionsControllerTest.php +++ /dev/null @@ -1,203 +0,0 @@ - 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->getJson('/api/organisation_document_versions/1', $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure([ - 'data' => [ - 'id', - 'status', - 'approved_rejected_by', - 'rejected_reason', - 'rejected_reason_body', - 'data' => [ - 'id', - 'organisation_id', - 'name', - 'type', - 'document', - ], - ], - ]); - } - - public function testApproveAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'jane@example.com', - 'password' => 'Password123', - ]); - $data = []; - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $response = $this->patchJson('/api/organisation_document_versions/2/approve', $data, $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure([ - 'data' => [ - 'id', - 'status', - 'approved_rejected_by', - 'rejected_reason', - 'rejected_reason_body', - 'data' => [ - 'id', - 'organisation_id', - 'name', - 'type', - 'document', - ], - ], - ]); - $response->assertJson([ - 'data' => [ - 'status' => 'approved', - ], - ]); - } - - public function testRejectAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'jane@example.com', - 'password' => 'Password123', - ]); - $data = [ - 'rejected_reason' => 'cannot_verify', - 'rejected_reason_body' => 'Lorem ipsum dolor sit amet', - ]; - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $response = $this->patchJson('/api/organisation_document_versions/2/reject', $data, $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure([ - 'data' => [ - 'id', - 'status', - 'approved_rejected_by', - 'rejected_reason', - 'rejected_reason_body', - 'data' => [ - 'id', - 'organisation_id', - 'name', - 'type', - 'document', - ], - ], - ]); - $response->assertJson([ - 'data' => [ - 'status' => 'rejected', - ], - ]); - } - - public function testDeleteAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->deleteJson('/api/organisation_document_versions/2', $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJson([ - 'data' => [], - ]); - } - - public function testReadAllByOrganisationDocumentAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->getJson('/api/organisation_documents/1/organisation_document_versions', $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure([ - 'data' => [ - [ - 'id', - 'status', - 'approved_rejected_by', - 'approved_rejected_at', - 'rejected_reason', - 'rejected_reason_body', - 'data' => [ - 'id', - 'organisation_id', - 'name', - 'type', - 'document', - ], - ], - ], - ]); - } - - public function testReviveAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'jane@example.com', - 'password' => 'Password123', - ]); - $data = []; - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $response = $this->patchJson('/api/organisation_document_versions/3/revive', $data, $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure([ - 'data' => [ - 'id', - 'status', - 'approved_rejected_by', - 'rejected_reason', - 'rejected_reason_body', - 'data' => [ - 'id', - 'organisation_id', - 'name', - 'type', - 'document', - ], - ], - ]); - $response->assertJson([ - 'data' => [ - 'status' => 'approved', - ], - ]); - } -} diff --git a/tests/Legacy/Feature/OrganisationDocumentsControllerTest.php b/tests/Legacy/Feature/OrganisationDocumentsControllerTest.php deleted file mode 100644 index 3bbca4cb0..000000000 --- a/tests/Legacy/Feature/OrganisationDocumentsControllerTest.php +++ /dev/null @@ -1,189 +0,0 @@ - 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $data = [ - 'upload' => $this->fakeFile(), - ]; - $response = $this->post('/api/uploads', $data, $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(201); - $id = json_decode($response->getContent())->data->id; - $data = [ - 'name' => 'Example Award', - 'type' => 'award', - 'document' => $id, - ]; - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $response = $this->postJson('/api/organisation_documents', $data, $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(201); - $response->assertJsonStructure([ - 'data' => [ - 'id', - 'rejected_reason', - 'rejected_reason_body', - 'approved_rejected_by', - 'approved_rejected_at', - 'status', - 'data' => [ - 'id', - 'organisation_id', - 'name', - 'type', - 'document', - ], - ], - 'meta' => [], - ]); - } - - public function testReadAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->getJson('/api/organisation_documents/1', $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure([ - 'data' => [ - 'id', - 'organisation_id', - 'name', - 'type', - 'document', - ], - ]); - } - - public function testUpdateAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $data = [ - 'name' => 'Example Award 2', - ]; - $response = $this->patchJson('/api/organisation_documents/1', $data, $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure([ - 'data' => [ - 'id', - 'rejected_reason', - 'rejected_reason_body', - 'approved_rejected_by', - 'approved_rejected_at', - 'status', - 'data' => [ - 'id', - 'organisation_id', - 'name', - 'type', - 'document', - ], - ], - 'meta' => [], - ]); - } - - public function testReadAllByOrganisationAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->getJson('/api/organisations/1/organisation_documents', $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure([ - 'data' => [ - [ - 'id', - 'organisation_id', - 'name', - 'type', - 'document', - ], - ], - ]); - } - - public function testInspectByOrganisationAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->getJson('/api/organisations/1/organisation_documents/inspect', $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure([ - 'data' => [ - [ - 'id', - 'status', - 'approved_rejected_by', - 'approved_rejected_at', - 'rejected_reason', - 'rejected_reason_body', - 'data' => [ - 'id', - 'organisation_id', - 'name', - 'type', - 'document', - ], - ], - ], - ]); - } - - public function testDeleteAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $response = $this->deleteJson('/api/organisation_documents/1', $headers); - $response->assertStatus(200); - $this->assertNull(OrganisationDocumentModel::find(1)); - } -} diff --git a/tests/Legacy/Feature/OrganisationFileControllerTest.php b/tests/Legacy/Feature/OrganisationFileControllerTest.php deleted file mode 100644 index 5d97d61cd..000000000 --- a/tests/Legacy/Feature/OrganisationFileControllerTest.php +++ /dev/null @@ -1,181 +0,0 @@ - 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $response = $this->post('/api/uploads', [ - 'upload' => $file, - ], $headers); - - return $response->json('data.id'); - } - - public function testReadByOrganisationAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'terrafund@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $this->getJson('/api/organisations/1/files', $headers) - ->assertStatus(200) - ->assertJsonCount(1, 'data') - ->assertJsonFragment([ - 'id' => 1, - 'organisation_id' => 1, - 'type' => 'financial_statement', - ]); - } - - public function testCreateActionAsLetterOfReference(): void - { - $token = Auth::attempt([ - 'email_address' => 'terrafund@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $uploadId = $this->uploadFile($token, $this->fakeFile()); - - $this->postJson('/api/organisations/file', [ - 'organisation_id' => 1, - 'upload' => $uploadId, - 'type' => 'letter_of_reference', - ], $headers) - ->assertStatus(201) - ->assertJsonFragment([ - 'organisation_id' => 1, - 'type' => 'letter_of_reference', - ]); - } - - public function testReadByOrganisationActionRequiresBeingInOrganisation(): void - { - $token = Auth::attempt([ - 'email_address' => 'andrew@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $this->getJson('/api/organisations/1/files', $headers) - ->assertStatus(403); - } - - public function testCreateAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'terrafund@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $uploadId = $this->uploadFile($token, $this->fakeFile()); - - $this->postJson('/api/organisations/file', [ - 'organisation_id' => 1, - 'upload' => $uploadId, - 'type' => 'financial_statement', - ], $headers) - ->assertStatus(201) - ->assertJsonFragment([ - 'organisation_id' => 1, - 'type' => 'financial_statement', - ]); - } - - public function testCreateActionRequiresValidType(): void - { - $token = Auth::attempt([ - 'email_address' => 'terrafund@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $uploadId = $this->uploadFile($token, $this->fakeImage()); - - $this->postJson('/api/organisations/file', [ - 'organisation_id' => 1, - 'upload' => $uploadId, - 'type' => 'not_a_valid_type', - ], $headers) - ->assertStatus(422); - } - - public function testCreateActionRequiresBeingInOrganisation(): void - { - $token = Auth::attempt([ - 'email_address' => 'andrew@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $uploadId = $this->uploadFile($token, $this->fakeImage()); - - $this->postJson('/api/organisations/file', [ - 'organisation_id' => 1, - 'upload' => $uploadId, - 'type' => 'financial_statement', - ], $headers) - ->assertStatus(403); - } - - public function testDeleteAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'terrafund@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $this->deleteJson('/api/organisations/file/1', $headers) - ->assertStatus(200); - } - - public function testDeleteActionRequiresBeingInOrganisation(): void - { - $token = Auth::attempt([ - 'email_address' => 'andrew@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $this->deleteJson('/api/organisations/file/1', $headers) - ->assertStatus(403); - } -} diff --git a/tests/Legacy/Feature/OrganisationPhotoControllerTest.php b/tests/Legacy/Feature/OrganisationPhotoControllerTest.php deleted file mode 100644 index 729d98cb8..000000000 --- a/tests/Legacy/Feature/OrganisationPhotoControllerTest.php +++ /dev/null @@ -1,99 +0,0 @@ - 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $response = $this->post('/api/uploads', [ - 'upload' => $file, - ], $headers); - - return $response->json('data.id'); - } - - public function testCreateAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'terrafund@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $uploadId = $this->uploadFile($token, $this->fakeImage()); - - $this->postJson('/api/organisations/photo', [ - 'organisation_id' => 1, - 'upload' => $uploadId, - 'is_public' => false, - ], $headers) - ->assertStatus(201) - ->assertJsonFragment([ - 'organisation_id' => 1, - 'is_public' => false, - ]); - } - - public function testCreateActionRequiresBeingInOrganisation(): void - { - $token = Auth::attempt([ - 'email_address' => 'andrew@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $uploadId = $this->uploadFile($token, $this->fakeImage()); - - $this->postJson('/api/organisations/photo', [ - 'organisation_id' => 1, - 'upload' => $uploadId, - 'is_public' => false, - ], $headers) - ->assertStatus(403); - } - - public function testDeleteAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'terrafund@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $this->deleteJson('/api/organisations/photo/1', $headers) - ->assertStatus(200); - } - - public function testDeleteActionRequiresBeingInOrganisation(): void - { - $token = Auth::attempt([ - 'email_address' => 'andrew@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $this->deleteJson('/api/organisations/photo/1', $headers) - ->assertStatus(403); - } -} diff --git a/tests/Legacy/Feature/OrganisationVersionsControllerTest.php b/tests/Legacy/Feature/OrganisationVersionsControllerTest.php deleted file mode 100644 index 01b57424a..000000000 --- a/tests/Legacy/Feature/OrganisationVersionsControllerTest.php +++ /dev/null @@ -1,284 +0,0 @@ - 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->getJson('/api/organisation_versions/1', $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure([ - 'data' => [ - 'id', - 'status', - 'approved_rejected_by', - 'rejected_reason', - 'rejected_reason_body', - 'data' => [ - 'id', - 'name', - 'description', - 'address_1', - 'address_2', - 'city', - 'state', - 'zip_code', - 'country', - 'phone_number', - 'website', - 'type', - 'category', - 'facebook', - 'twitter', - 'linkedin', - 'instagram', - 'cover_photo', - 'avatar', - 'video', - 'founded_at', - 'photos', - 'files', - ], - ], - ]); - } - - public function testApproveAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'jane@example.com', - 'password' => 'Password123', - ]); - $data = []; - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $response = $this->patchJson('/api/organisation_versions/2/approve', $data, $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure([ - 'data' => [ - 'id', - 'status', - 'approved_rejected_by', - 'rejected_reason', - 'rejected_reason_body', - 'data' => [ - 'id', - 'name', - 'description', - 'address_1', - 'address_2', - 'city', - 'state', - 'zip_code', - 'country', - 'phone_number', - 'website', - 'type', - 'category', - 'facebook', - 'twitter', - 'linkedin', - 'instagram', - 'cover_photo', - 'avatar', - 'video', - 'founded_at', - ], - ], - ]); - $response->assertJson([ - 'data' => [ - 'status' => 'approved', - ], - ]); - } - - public function testRejectAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'jane@example.com', - 'password' => 'Password123', - ]); - $data = [ - 'rejected_reason' => 'cannot_verify', - 'rejected_reason_body' => 'Lorem ipsum dolor sit amet', - ]; - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $response = $this->patchJson('/api/organisation_versions/2/reject', $data, $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure([ - 'data' => [ - 'id', - 'status', - 'approved_rejected_by', - 'rejected_reason', - 'rejected_reason_body', - 'data' => [ - 'id', - 'name', - 'description', - 'address_1', - 'address_2', - 'city', - 'state', - 'zip_code', - 'country', - 'phone_number', - 'website', - 'type', - 'category', - 'facebook', - 'twitter', - 'linkedin', - 'instagram', - 'cover_photo', - 'avatar', - 'video', - 'founded_at', - ], - ], - ]); - $response->assertJson([ - 'data' => [ - 'status' => 'rejected', - ], - ]); - } - - public function testDeleteAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->deleteJson('/api/organisation_versions/2', $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJson([ - 'data' => [], - ]); - } - - public function testReadAllByOrganisationAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->getJson('/api/organisations/1/organisation_versions', $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure([ - 'data' => [ - [ - 'id', - 'status', - 'approved_rejected_by', - 'approved_rejected_at', - 'rejected_reason', - 'rejected_reason_body', - 'data' => [ - 'id', - 'name', - 'description', - 'address_1', - 'address_2', - 'city', - 'state', - 'zip_code', - 'country', - 'phone_number', - 'website', - 'type', - 'category', - 'facebook', - 'twitter', - 'linkedin', - 'instagram', - 'avatar', - 'cover_photo', - 'founded_at', - ], - ], - ], - ]); - } - - public function testReviveAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'jane@example.com', - 'password' => 'Password123', - ]); - $data = []; - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $response = $this->patchJson('/api/organisation_versions/4/revive', $data, $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure([ - 'data' => [ - 'id', - 'status', - 'approved_rejected_by', - 'rejected_reason', - 'rejected_reason_body', - 'data' => [ - 'id', - 'name', - 'description', - 'address_1', - 'address_2', - 'city', - 'state', - 'zip_code', - 'country', - 'phone_number', - 'website', - 'type', - 'category', - 'facebook', - 'twitter', - 'linkedin', - 'instagram', - 'cover_photo', - 'avatar', - 'video', - 'founded_at', - ], - ], - ]); - $response->assertJson([ - 'data' => [ - 'status' => 'approved', - ], - ]); - } -} diff --git a/tests/Legacy/Feature/OrganisationsControllerTest.php b/tests/Legacy/Feature/OrganisationsControllerTest.php deleted file mode 100644 index 99cd0ce8c..000000000 --- a/tests/Legacy/Feature/OrganisationsControllerTest.php +++ /dev/null @@ -1,302 +0,0 @@ - 'Acme Corporation', - 'description' => 'Lorem ipsum dolor sit amet', - 'address_1' => '1 Foo Road', - 'address_2' => null, - 'city' => 'Bar Town', - 'state' => 'Baz State', - 'zip_code' => 'Qux', - 'country' => 'GB', - 'phone_number' => '0123456789', - 'full_time_permanent_employees' => '200', - 'seasonal_employees' => '30', - 'part_time_permanent_employees' => '100', - 'percentage_female' => '50', - 'website' => 'http://www.example.com', - 'key_contact' => 'K. Contact', - 'type' => 'other', - 'account_type' => 'ppc', - 'category' => 'both', - 'facebook' => null, - 'twitter' => null, - 'linkedin' => null, - 'instagram' => null, - 'avatar' => null, - 'cover_photo' => null, - 'video' => null, - 'founded_at' => '2000-01-01', - 'revenues_19' => null, - 'revenues_20' => null, - 'revenues_21' => null, - 'community_engagement_strategy' => 'strategy', - 'three_year_community_engagement' => 'engagement', - 'women_farmer_engagement' => 57, - 'young_people_engagement' => 89, - 'monitoring_and_evaluation_experience' => 'experience', - 'community_follow_up' => 'follow up', - 'total_hectares_restored' => 1010, - 'hectares_restored_three_years' => 4321, - 'total_trees_grown' => 10000, - 'tree_survival_rate' => 90, - 'tree_maintenance_and_aftercare' => 'some maintenance', - ]; - $token = Auth::attempt([ - 'email_address' => 'joe@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $response = $this->postJson('/api/organisations', $data, $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(201); - $response->assertJsonStructure([ - 'data' => [ - 'id', - 'rejected_reason', - 'rejected_reason_body', - 'approved_rejected_by', - 'approved_rejected_at', - 'status', - 'data' => [ - 'id', - 'name', - 'description', - 'address_1', - 'address_2', - 'city', - 'state', - 'zip_code', - 'country', - 'phone_number', - 'website', - 'key_contact', - 'type', - 'category', - 'facebook', - 'twitter', - 'linkedin', - 'instagram', - 'cover_photo', - 'avatar', - 'video', - 'founded_at', - 'community_engagement_strategy', - 'three_year_community_engagement', - 'women_farmer_engagement', - 'young_people_engagement', - 'monitoring_and_evaluation_experience', - 'community_follow_up', - 'total_hectares_restored', - 'total_trees_grown', - 'tree_survival_rate', - 'hectares_restored_three_years', - 'tree_maintenance_and_aftercare', - 'founded_at', - 'revenues_19', - 'revenues_20', - 'revenues_21', - ], - ], - 'meta' => [], - ]); - } - - public function testReadAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->getJson('/api/organisations/2', $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure([ - 'data' => [ - 'id', - 'name', - 'description', - 'city', - 'state', - 'country', - 'website', - 'key_contact', - 'type', - 'category', - 'facebook', - 'twitter', - 'linkedin', - 'instagram', - 'cover_photo', - 'avatar', - 'video', - 'founded_at', - 'community_engagement_strategy', - 'three_year_community_engagement', - 'women_farmer_engagement', - 'young_people_engagement', - 'monitoring_and_evaluation_experience', - 'community_follow_up', - 'total_hectares_restored', - 'total_trees_grown', - 'tree_survival_rate', - 'hectares_restored_three_years', - 'tree_maintenance_and_aftercare', - ], - ]); - } - - public function testInspectAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - - $this->getJson('/api/organisations/1/inspect', $headers) - ->assertHeader('Content-Type', 'application/json') - ->assertStatus(200) - ->assertJsonStructure([ - 'data' => [ - 'id', - 'name', - 'description', - 'address_1', - 'address_2', - 'city', - 'state', - 'zip_code', - 'country', - 'phone_number', - 'website', - 'key_contact', - 'type', - 'category', - 'facebook', - 'twitter', - 'linkedin', - 'instagram', - 'cover_photo', - 'avatar', - 'video', - 'founded_at', - 'community_engagement_strategy', - 'three_year_community_engagement', - 'women_farmer_engagement', - 'young_people_engagement', - 'monitoring_and_evaluation_experience', - 'community_follow_up', - 'total_hectares_restored', - 'total_trees_grown', - 'tree_survival_rate', - 'hectares_restored_three_years', - 'tree_maintenance_and_aftercare', - ], - ]); - } - - public function testUpdateAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $data = [ - 'name' => 'Acme Corporation 3', - 'phone_number' => '+44123456789', - 'website' => 'https://www.example.com', - 'key_contact' => 'Key C', - ]; - - $this->patchJson('/api/organisations/1', $data, $headers) - ->assertHeader('Content-Type', 'application/json') - ->assertStatus(200) - ->assertJsonStructure([ - 'data' => [ - 'id', - 'status', - 'rejected_reason', - 'rejected_reason_body', - 'approved_rejected_by', - 'data' => [ - 'id', - 'name', - 'description', - 'address_1', - 'address_2', - 'city', - 'state', - 'zip_code', - 'country', - 'phone_number', - 'website', - 'key_contact', - 'type', - 'category', - 'facebook', - 'twitter', - 'linkedin', - 'instagram', - 'cover_photo', - 'avatar', - 'video', - 'founded_at', - 'community_engagement_strategy', - 'three_year_community_engagement', - 'women_farmer_engagement', - 'young_people_engagement', - 'monitoring_and_evaluation_experience', - 'community_follow_up', - 'total_hectares_restored', - 'total_trees_grown', - 'tree_survival_rate', - 'hectares_restored_three_years', - 'tree_maintenance_and_aftercare', - ], - ], - ]); - } - - public function testReadAllAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'jane@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->getJson('/api/organisations', $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure([ - 'data' => [ - [ - 'id', - 'name', - ], - ], - ]); - } -} diff --git a/tests/Legacy/Feature/PendingControllerTest.php b/tests/Legacy/Feature/PendingControllerTest.php deleted file mode 100644 index 95b81486d..000000000 --- a/tests/Legacy/Feature/PendingControllerTest.php +++ /dev/null @@ -1,49 +0,0 @@ - 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $response = $this->getJson('/api/pending/programme', $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonFragment([ - 'total_reports' => 4, - 'outstanding_reports' => 1, - ]); - } - - public function testReadPendingSiteSubmissionsAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $response = $this->getJson('/api/pending/site', $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonFragment([ - 'total_reports' => 6, - 'outstanding_reports' => 2, - ]); - } -} diff --git a/tests/Legacy/Feature/PitchContactsControllerTest.php b/tests/Legacy/Feature/PitchContactsControllerTest.php deleted file mode 100644 index 5defef777..000000000 --- a/tests/Legacy/Feature/PitchContactsControllerTest.php +++ /dev/null @@ -1,121 +0,0 @@ -callCreateActionWithUser(); - $this->callCreateActionWithTeamMember(); - } - - private function callCreateActionWithUser() - { - $data = [ - 'pitch_id' => 1, - 'user_id' => 6, - ]; - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $response = $this->postJson('/api/pitch_contacts', $data, $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(201); - $response->assertJsonStructure([ - 'data' => [ - 'id', - 'user_id', - 'pitch_id', - 'first_name', - 'last_name', - ], - 'meta' => [], - ]); - } - - private function callCreateActionWithTeamMember() - { - $data = [ - 'pitch_id' => 1, - 'team_member_id' => 1, - ]; - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $response = $this->postJson('/api/pitch_contacts', $data, $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(201); - $response->assertJsonStructure([ - 'data' => [ - 'id', - 'team_member_id', - 'pitch_id', - 'first_name', - 'last_name', - ], - 'meta' => [], - ]); - } - - public function testReadAllByPitchAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->getJson('/api/pitches/1/pitch_contacts', $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure([ - 'data' => [ - [ - 'id', - 'pitch_id', - 'first_name', - 'last_name', - ], - ], - ]); - } - - public function testDeleteAction(): void - { - $data = [ - 'pitch_id' => 1, - 'user_id' => 6, - ]; - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $this->postJson('/api/pitch_contacts', $data, $headers); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->deleteJson('/api/pitch_contacts/3', $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJson(['data' => []]); - } -} diff --git a/tests/Legacy/Feature/PitchDocumentVersionsControllerTest.php b/tests/Legacy/Feature/PitchDocumentVersionsControllerTest.php deleted file mode 100644 index c6d4904dd..000000000 --- a/tests/Legacy/Feature/PitchDocumentVersionsControllerTest.php +++ /dev/null @@ -1,203 +0,0 @@ - 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->getJson('/api/pitch_document_versions/1', $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure([ - 'data' => [ - 'id', - 'status', - 'approved_rejected_by', - 'rejected_reason', - 'rejected_reason_body', - 'data' => [ - 'id', - 'pitch_id', - 'name', - 'type', - 'document', - ], - ], - ]); - } - - public function testApproveAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'jane@example.com', - 'password' => 'Password123', - ]); - $data = []; - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $response = $this->patchJson('/api/pitch_document_versions/2/approve', $data, $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure([ - 'data' => [ - 'id', - 'status', - 'approved_rejected_by', - 'rejected_reason', - 'rejected_reason_body', - 'data' => [ - 'id', - 'pitch_id', - 'name', - 'type', - 'document', - ], - ], - ]); - $response->assertJson([ - 'data' => [ - 'status' => 'approved', - ], - ]); - } - - public function testRejectAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'jane@example.com', - 'password' => 'Password123', - ]); - $data = [ - 'rejected_reason' => 'cannot_verify', - 'rejected_reason_body' => 'Lorem ipsum dolor sit amet', - ]; - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $response = $this->patchJson('/api/pitch_document_versions/2/reject', $data, $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure([ - 'data' => [ - 'id', - 'status', - 'approved_rejected_by', - 'rejected_reason', - 'rejected_reason_body', - 'data' => [ - 'id', - 'pitch_id', - 'name', - 'type', - 'document', - ], - ], - ]); - $response->assertJson([ - 'data' => [ - 'status' => 'rejected', - ], - ]); - } - - public function testDeleteAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->deleteJson('/api/pitch_document_versions/2', $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJson([ - 'data' => [], - ]); - } - - public function testReadAllByPitchDocumentAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->getJson('/api/pitch_documents/1/pitch_document_versions', $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure([ - 'data' => [ - [ - 'id', - 'status', - 'approved_rejected_by', - 'approved_rejected_at', - 'rejected_reason', - 'rejected_reason_body', - 'data' => [ - 'id', - 'pitch_id', - 'name', - 'type', - 'document', - ], - ], - ], - ]); - } - - public function testReviveAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'jane@example.com', - 'password' => 'Password123', - ]); - $data = []; - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $response = $this->patchJson('/api/pitch_document_versions/3/revive', $data, $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure([ - 'data' => [ - 'id', - 'status', - 'approved_rejected_by', - 'rejected_reason', - 'rejected_reason_body', - 'data' => [ - 'id', - 'pitch_id', - 'name', - 'type', - 'document', - ], - ], - ]); - $response->assertJson([ - 'data' => [ - 'status' => 'approved', - ], - ]); - } -} diff --git a/tests/Legacy/Feature/PitchDocumentsControllerTest.php b/tests/Legacy/Feature/PitchDocumentsControllerTest.php deleted file mode 100644 index 5f46cc94d..000000000 --- a/tests/Legacy/Feature/PitchDocumentsControllerTest.php +++ /dev/null @@ -1,187 +0,0 @@ - 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $data = [ - 'upload' => $this->fakeFile(), - 'title' => 'Test file', - ]; - $response = $this->post('/api/uploads', $data, $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(201); - $id = json_decode($response->getContent())->data->id; - $data = [ - 'pitch_id' => 1, - 'name' => 'Example Document', - 'type' => 'award', - 'document' => $id, - ]; - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $response = $this->postJson('/api/pitch_documents', $data, $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(201); - $response->assertJsonStructure([ - 'data' => [ - 'id', - 'status', - 'approved_rejected_by', - 'rejected_reason', - 'rejected_reason_body', - 'data' => [ - 'id', - 'pitch_id', - 'name', - 'type', - 'document', - ], - ], - ]); - } - - public function testReadAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->getJson('/api/pitch_documents/1', $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure([ - 'data' => [ - 'id', - 'pitch_id', - 'name', - 'type', - 'document', - ], - ]); - } - - public function testUpdateAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $data = [ - 'name' => 'Example Document', - ]; - $response = $this->patchJson('/api/pitch_documents/1', $data, $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure([ - 'data' => [ - 'id', - 'status', - 'approved_rejected_by', - 'rejected_reason', - 'rejected_reason_body', - 'data' => [ - 'id', - 'pitch_id', - 'name', - 'type', - 'document', - ], - ], - ]); - } - - public function testReadAllByPitchAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->getJson('/api/pitches/1/pitch_documents', $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure([ - 'data' => [ - [ - 'id', - 'pitch_id', - 'name', - 'type', - 'document', - ], - ], - ]); - } - - public function testInspectByPitchAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->getJson('/api/pitches/1/pitch_documents/inspect', $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure([ - 'data' => [ - [ - 'id', - 'status', - 'approved_rejected_by', - 'approved_rejected_at', - 'rejected_reason', - 'rejected_reason_body', - 'data' => [ - 'id', - 'pitch_id', - 'name', - 'type', - 'document', - ], - ], - ], - ]); - } - - public function testDeleteAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $response = $this->deleteJson('/api/pitch_documents/1', $headers); - $response->assertStatus(200); - $this->assertNull(PitchDocumentModel::find(1)); - } -} diff --git a/tests/Legacy/Feature/PitchVersionsControllerTest.php b/tests/Legacy/Feature/PitchVersionsControllerTest.php deleted file mode 100644 index 2fa39c178..000000000 --- a/tests/Legacy/Feature/PitchVersionsControllerTest.php +++ /dev/null @@ -1,299 +0,0 @@ - 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->getJson('/api/pitch_versions/1', $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure([ - 'data' => [ - 'id', - 'status', - 'approved_rejected_by', - 'rejected_reason', - 'rejected_reason_body', - 'data' => [ - 'id', - 'organisation_id', - 'name', - 'description', - 'land_types', - 'land_ownerships', - 'land_size', - 'land_continent', - 'land_country', - 'land_geojson', - 'restoration_methods', - 'restoration_goals', - 'funding_sources', - 'funding_amount', - 'funding_bracket', - 'revenue_drivers', - 'estimated_timespan', - 'long_term_engagement', - 'reporting_frequency', - 'reporting_level', - 'sustainable_development_goals', - 'avatar', - 'cover_photo', - 'video', - 'successful', - 'visibility', - ], - ], - ]); - } - - public function testApproveAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'jane@example.com', - 'password' => 'Password123', - ]); - $data = []; - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $response = $this->patchJson('/api/pitch_versions/2/approve', $data, $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure([ - 'data' => [ - 'id', - 'status', - 'approved_rejected_by', - 'rejected_reason', - 'rejected_reason_body', - 'data' => [ - 'id', - 'organisation_id', - 'name', - 'description', - 'land_types', - 'land_ownerships', - 'land_size', - 'land_continent', - 'land_country', - 'land_geojson', - 'restoration_methods', - 'restoration_goals', - 'funding_sources', - 'funding_amount', - 'revenue_drivers', - 'estimated_timespan', - 'long_term_engagement', - 'reporting_frequency', - 'reporting_level', - 'sustainable_development_goals', - 'avatar', - 'cover_photo', - 'video', - 'successful', - ], - ], - ]); - $response->assertJson([ - 'data' => [ - 'status' => 'approved', - ], - ]); - } - - public function testRejectAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'jane@example.com', - 'password' => 'Password123', - ]); - $data = [ - 'rejected_reason' => 'cannot_verify', - 'rejected_reason_body' => 'Lorem ipsum dolor sit amet', - ]; - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $response = $this->patchJson('/api/pitch_versions/2/reject', $data, $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure([ - 'data' => [ - 'id', - 'status', - 'approved_rejected_by', - 'rejected_reason', - 'rejected_reason_body', - 'data' => [ - 'id', - 'organisation_id', - 'name', - 'description', - 'land_types', - 'land_ownerships', - 'land_size', - 'land_continent', - 'land_country', - 'land_geojson', - 'restoration_methods', - 'restoration_goals', - 'funding_sources', - 'funding_amount', - 'revenue_drivers', - 'estimated_timespan', - 'long_term_engagement', - 'reporting_frequency', - 'reporting_level', - 'sustainable_development_goals', - 'avatar', - 'cover_photo', - 'video', - 'successful', - ], - ], - ]); - $response->assertJson([ - 'data' => [ - 'status' => 'rejected', - ], - ]); - } - - public function testDeleteAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->deleteJson('/api/pitch_versions/2', $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJson([ - 'data' => [], - ]); - } - - public function testReadAllByPitchAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->getJson('/api/pitches/1/pitch_versions', $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure([ - 'data' => [ - [ - 'id', - 'status', - 'approved_rejected_by', - 'rejected_reason', - 'rejected_reason_body', - 'data' => [ - 'id', - 'organisation_id', - 'name', - 'description', - 'land_types', - 'land_ownerships', - 'land_size', - 'land_continent', - 'land_country', - 'land_geojson', - 'restoration_methods', - 'restoration_goals', - 'funding_sources', - 'funding_amount', - 'revenue_drivers', - 'estimated_timespan', - 'long_term_engagement', - 'reporting_frequency', - 'reporting_level', - 'sustainable_development_goals', - 'avatar', - 'cover_photo', - 'video', - 'successful', - ], - ], - ], - ]); - } - - public function testReviveAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'jane@example.com', - 'password' => 'Password123', - ]); - $data = []; - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $response = $this->patchJson('/api/pitch_versions/3/revive', $data, $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure([ - 'data' => [ - 'id', - 'status', - 'approved_rejected_by', - 'rejected_reason', - 'rejected_reason_body', - 'data' => [ - 'id', - 'organisation_id', - 'name', - 'description', - 'land_types', - 'land_ownerships', - 'land_size', - 'land_continent', - 'land_country', - 'land_geojson', - 'restoration_methods', - 'restoration_goals', - 'funding_sources', - 'funding_amount', - 'revenue_drivers', - 'estimated_timespan', - 'long_term_engagement', - 'reporting_frequency', - 'reporting_level', - 'sustainable_development_goals', - 'avatar', - 'cover_photo', - 'video', - 'successful', - ], - ], - ]); - $response->assertJson([ - 'data' => [ - 'status' => 'approved', - ], - ]); - } -} diff --git a/tests/Legacy/Feature/PitchesControllerTest.php b/tests/Legacy/Feature/PitchesControllerTest.php deleted file mode 100644 index 6fe976d32..000000000 --- a/tests/Legacy/Feature/PitchesControllerTest.php +++ /dev/null @@ -1,694 +0,0 @@ - 'Example Pitch 2', - 'description' => 'Lorem ipsum dolor sit amet', - 'land_types' => ['bare_land', 'wetland'], - 'land_ownerships' => ['public'], - 'land_size' => 'lt_10', - 'land_continent' => 'australia', - 'land_country' => 'AU', - 'land_geojson' => '{"type":"Polygon","coordinates":[[[-1.864006519317627,50.7219083651253],[-1.8627190589904783,50.7219083651253],[-1.8627190589904783,50.72276418262861],[-1.864006519317627,50.72276418262861],[-1.864006519317627,50.7219083651253]]]}', - 'restoration_methods' => ['assisted_natural', 'riparian_buffers'], - 'restoration_goals' => ['agriculture_and_commodities'], - 'funding_sources' => ['grant_with_limited_reporting'], - 'funding_amount' => 1234, - 'funding_bracket' => 'lt_50k', - 'revenue_drivers' => [], - 'estimated_timespan' => 36, - 'long_term_engagement' => null, - 'reporting_frequency' => 'bi_annually', - 'reporting_level' => 'high', - 'sustainable_development_goals' => [], - 'cover_photo' => null, - 'video' => null, - 'problem' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum', - 'anticipated_outcome' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum', - 'who_is_involved' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.', - 'local_community_involvement' => true, - 'training_involved' => true, - 'training_type' => 'remote', - 'training_amount_people' => 33, - 'people_working_in' => 'test string', - 'people_amount_nearby' => 10, - 'people_amount_abroad' => 3, - 'people_amount_employees' => 4, - 'people_amount_volunteers' => 4, - 'benefited_people' => 404, - 'future_maintenance' => 'Lorem ipsum dolor sit amet, consec...', - 'use_of_resources' => 'Lorem ipsum dolor sit amet, consec...', - ]; - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $response = $this->postJson('/api/pitches', $data, $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(201); - $response->assertJsonStructure([ - 'data' => [ - 'id', - 'status', - 'approved_rejected_by', - 'rejected_reason', - 'rejected_reason_body', - 'data' => [ - 'id', - 'organisation_id', - 'name', - 'description', - 'land_types', - 'land_ownerships', - 'land_size', - 'land_continent', - 'land_country', - 'land_geojson', - 'restoration_methods', - 'restoration_goals', - 'funding_sources', - 'funding_amount', - 'funding_bracket', - 'revenue_drivers', - 'estimated_timespan', - 'long_term_engagement', - 'reporting_frequency', - 'reporting_level', - 'sustainable_development_goals', - 'avatar', - 'cover_photo', - 'video', - 'problem', - 'anticipated_outcome', - 'who_is_involved', - 'local_community_involvement', - 'training_involved', - 'training_type', - 'training_amount_people', - 'people_working_in', - 'people_amount_nearby', - 'people_amount_abroad', - 'people_amount_employees', - 'people_amount_volunteers', - 'benefited_people', - 'future_maintenance', - 'use_of_resources', - 'facebook', - 'twitter', - 'instagram', - 'successful', - ], - ], - ]); - } - - public function testReadAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->getJson('/api/pitches/1', $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure([ - 'data' => [ - 'id', - 'organisation_id', - 'name', - 'description', - 'land_types', - 'land_ownerships', - 'land_size', - 'land_continent', - 'land_country', - 'land_geojson', - 'restoration_methods', - 'restoration_goals', - 'funding_sources', - 'funding_amount', - 'revenue_drivers', - 'estimated_timespan', - 'long_term_engagement', - 'reporting_frequency', - 'reporting_level', - 'sustainable_development_goals', - 'avatar', - 'cover_photo', - 'video', - 'problem', - 'anticipated_outcome', - 'who_is_involved', - 'local_community_involvement', - 'training_involved', - 'training_type', - 'training_amount_people', - 'people_working_in', - 'people_amount_nearby', - 'people_amount_abroad', - 'people_amount_employees', - 'people_amount_volunteers', - 'benefited_people', - 'future_maintenance', - 'use_of_resources', - 'facebook', - 'twitter', - 'instagram', - 'successful', - 'visibility', - ], - ]); - } - - public function testUpdateAction(): void - { - $data = [ - 'name' => 'Another Example Pitch', - 'training_type' => 'Minima cumque tenetur magni quos sed delectus eos cupiditate. Esse sint ipsam sapiente nobis vitae consequatur asperiores voluptatibus. At est voluptatem quidem voluptas commodi eum odit. Rerum dolorem voluptatem ut. Rerum nobis necessitatibus inventore et magni qui. Est magnam rerum voluptatem. Quis in reiciendis cupiditate omnis quod enim. Culpa libero voluptatem iste expedita ullam. Numquam omnis molestias eius.', - ]; - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $response = $this->patchJson('/api/pitches/1', $data, $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure([ - 'data' => [ - 'id', - 'status', - 'approved_rejected_by', - 'rejected_reason', - 'rejected_reason_body', - 'data' => [ - 'id', - 'organisation_id', - 'name', - 'description', - 'land_types', - 'land_ownerships', - 'land_size', - 'land_continent', - 'land_country', - 'land_geojson', - 'restoration_methods', - 'restoration_goals', - 'funding_sources', - 'funding_amount', - 'revenue_drivers', - 'estimated_timespan', - 'long_term_engagement', - 'reporting_frequency', - 'reporting_level', - 'sustainable_development_goals', - 'avatar', - 'cover_photo', - 'video', - 'problem', - 'anticipated_outcome', - 'who_is_involved', - 'local_community_involvement', - 'training_involved', - 'training_type', - 'training_amount_people', - 'people_working_in', - 'people_amount_nearby', - 'people_amount_abroad', - 'people_amount_employees', - 'people_amount_volunteers', - 'benefited_people', - 'future_maintenance', - 'use_of_resources', - 'facebook', - 'twitter', - 'instagram', - 'successful', - ], - ], - ]); - } - - public function testReadAllByOrganisationAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->getJson('/api/organisations/1/pitches', $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure([ - 'data' => [ - [ - 'id', - 'organisation_id', - 'name', - 'description', - 'land_types', - 'land_ownerships', - 'land_size', - 'land_continent', - 'land_country', - 'land_geojson', - 'restoration_methods', - 'restoration_goals', - 'funding_sources', - 'funding_amount', - 'revenue_drivers', - 'estimated_timespan', - 'long_term_engagement', - 'reporting_frequency', - 'reporting_level', - 'sustainable_development_goals', - 'avatar', - 'cover_photo', - 'video', - 'problem', - 'anticipated_outcome', - 'who_is_involved', - 'local_community_involvement', - 'training_involved', - 'training_type', - 'training_amount_people', - 'people_working_in', - 'people_amount_nearby', - 'people_amount_abroad', - 'people_amount_employees', - 'people_amount_volunteers', - 'benefited_people', - 'future_maintenance', - 'use_of_resources', - 'facebook', - 'twitter', - 'instagram', - 'successful', - ], - ], - ]); - } - - public function testSearchAction(): void - { - Queue::fake(); - $token = Auth::attempt([ - 'email_address' => 'andrew@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $data = [ - 'filters' => [[ - 'attribute' => 'land_types', - 'operator' => 'contains', - 'value' => [ - 'mangrove', - 'cropland', - ], ]], - 'sortDirection' => 'desc', - 'page' => 1, - ]; - $response = $this->postJson('/api/pitches/search', $data, $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure([ - 'data' => [ - [ - 'id', - 'organisation_id', - 'name', - 'description', - 'land_types', - 'land_ownerships', - 'land_size', - 'land_continent', - 'land_country', - 'land_geojson', - 'restoration_methods', - 'restoration_goals', - 'funding_sources', - 'funding_amount', - 'revenue_drivers', - 'estimated_timespan', - 'long_term_engagement', - 'reporting_frequency', - 'reporting_level', - 'sustainable_development_goals', - 'avatar', - 'cover_photo', - 'video', - 'problem', - 'anticipated_outcome', - 'who_is_involved', - 'local_community_involvement', - 'training_involved', - 'training_type', - 'training_amount_people', - 'people_working_in', - 'people_amount_nearby', - 'people_amount_abroad', - 'people_amount_employees', - 'people_amount_volunteers', - 'benefited_people', - 'future_maintenance', - 'use_of_resources', - 'facebook', - 'twitter', - 'instagram', - 'compatibility_score', - 'successful', - ], - ], - ]); - } - - public function testMostRecentAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'andrew@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $data = [ - 'filters' => [[ - 'attribute' => 'land_types', - 'operator' => 'contains', - 'value' => [ - 'mangrove', - 'cropland', - ], ]], - 'sortDirection' => 'desc', - 'page' => 1, - ]; - $response = $this->getJson('/api/pitches/most_recent', $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure([ - 'data' => [ - [ - 'id', - 'organisation_id', - 'name', - 'description', - 'land_types', - 'land_ownerships', - 'land_size', - 'land_continent', - 'land_country', - 'land_geojson', - 'restoration_methods', - 'restoration_goals', - 'funding_sources', - 'funding_amount', - 'revenue_drivers', - 'estimated_timespan', - 'long_term_engagement', - 'reporting_frequency', - 'reporting_level', - 'sustainable_development_goals', - 'avatar', - 'cover_photo', - 'video', - 'problem', - 'anticipated_outcome', - 'who_is_involved', - 'local_community_involvement', - 'training_involved', - 'training_type', - 'training_amount_people', - 'people_working_in', - 'people_amount_nearby', - 'people_amount_abroad', - 'people_amount_employees', - 'people_amount_volunteers', - 'benefited_people', - 'future_maintenance', - 'use_of_resources', - 'facebook', - 'twitter', - 'instagram', - 'successful', - ], - ], - ]); - } - - public function testInspectByOrganisationAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->getJson('/api/organisations/1/pitches/inspect', $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure([ - 'data' => [ - [ - 'id', - 'status', - 'approved_rejected_by', - 'rejected_reason', - 'rejected_reason_body', - 'data' => [ - 'id', - 'organisation_id', - 'name', - 'description', - 'land_types', - 'land_ownerships', - 'land_size', - 'land_continent', - 'land_country', - 'land_geojson', - 'restoration_methods', - 'restoration_goals', - 'funding_sources', - 'funding_amount', - 'revenue_drivers', - 'estimated_timespan', - 'long_term_engagement', - 'reporting_frequency', - 'reporting_level', - 'sustainable_development_goals', - 'avatar', - 'cover_photo', - 'video', - 'problem', - 'anticipated_outcome', - 'who_is_involved', - 'local_community_involvement', - 'training_involved', - 'training_type', - 'training_amount_people', - 'people_working_in', - 'people_amount_nearby', - 'people_amount_abroad', - 'people_amount_employees', - 'people_amount_volunteers', - 'benefited_people', - 'future_maintenance', - 'use_of_resources', - 'facebook', - 'twitter', - 'instagram', - 'successful', - ], - ], - ], - ]); - } - - public function testCountByContinentAction(): void - { - $response = $this->getJson('/api/continents/pitches'); - $response->assertStatus(200); - $response->assertJson([ - 'data' => [ - [ - 'land_continent' => 'australia', - 'count' => 2, - ], - ], - ]); - } - - public function testReadAllByContinentAction(): void - { - $response = $this->getJson('/api/continents/doesntexist/pitches'); - $response->assertStatus(404); - $response->assertJson([ - 'errors' => [], - 'meta' => ['count' => 0], - ]); - - $response = $this->getJson('/api/continents/australia/pitches'); - $response->assertJsonStructure([ - 'data' => [ - [ - 'id', - 'organisation_id', - 'name', - 'description', - 'land_types', - 'land_ownerships', - 'land_size', - 'land_continent', - 'land_country', - 'land_geojson', - 'restoration_methods', - 'restoration_goals', - 'funding_sources', - 'funding_amount', - 'revenue_drivers', - 'estimated_timespan', - 'long_term_engagement', - 'reporting_frequency', - 'reporting_level', - 'sustainable_development_goals', - 'avatar', - 'cover_photo', - 'video', - 'problem', - 'anticipated_outcome', - 'who_is_involved', - 'local_community_involvement', - 'training_involved', - 'training_type', - 'training_amount_people', - 'people_working_in', - 'people_amount_nearby', - 'people_amount_abroad', - 'people_amount_employees', - 'people_amount_volunteers', - 'benefited_people', - 'future_maintenance', - 'use_of_resources', - 'facebook', - 'twitter', - 'instagram', - 'successful', - ], - ], - ]); - } - - public function testUpdateVisibilityAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $data = [ - 'visibility' => 'talking', - ]; - $response = $this->patchJson('/api/pitches/1/visibility', $data, $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure([ - 'data' => [ - 'id', - 'organisation_id', - 'name', - 'description', - 'land_types', - 'land_ownerships', - 'land_size', - 'land_continent', - 'land_country', - 'land_geojson', - 'restoration_methods', - 'restoration_goals', - 'funding_sources', - 'funding_amount', - 'revenue_drivers', - 'estimated_timespan', - 'long_term_engagement', - 'reporting_frequency', - 'reporting_level', - 'sustainable_development_goals', - 'avatar', - 'cover_photo', - 'video', - 'problem', - 'anticipated_outcome', - 'who_is_involved', - 'local_community_involvement', - 'training_involved', - 'training_type', - 'training_amount_people', - 'people_working_in', - 'people_amount_nearby', - 'people_amount_abroad', - 'people_amount_employees', - 'people_amount_volunteers', - 'benefited_people', - 'future_maintenance', - 'use_of_resources', - 'facebook', - 'twitter', - 'instagram', - 'successful', - 'visibility', - ], - ]); - $response->assertJson([ - 'data' => [ - 'visibility' => 'talking', - ], - ]); - } - - public function testUpdateVisibilityActionMonitoringExistsException(): void - { - $token = Auth::attempt([ - 'email_address' => 'dominic@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $data = [ - 'visibility' => 'talking', - ]; - $response = $this->patchJson('/api/pitches/2/visibility', $data, $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(422); - $response->assertJsonStructure([ - 'errors' => [], - ]); - } -} diff --git a/tests/Legacy/Feature/ProgrammeControllerTest.php b/tests/Legacy/Feature/ProgrammeControllerTest.php deleted file mode 100644 index 1605b9bec..000000000 --- a/tests/Legacy/Feature/ProgrammeControllerTest.php +++ /dev/null @@ -1,217 +0,0 @@ -getHeaders('steve@example.com', 'Password123'); - - $response = $this->getJson('/api/programme/1/overview', $headers) - ->assertStatus(200) - ->assertJsonFragment([ - 'id' => 1, - 'name' => 'Example programme', - 'workdays_paid' => 62, - 'workdays_volunteer' => 96, - 'total_workdays' => 158, - ]) - ->assertJsonPath('data.submissions.0.id', 1); - } - - public function testReadActionAllowsAdminsToRead(): void - { - $headers = $this->getHeaders('jane@example.com', 'Password123'); - - $this->getJson('/api/programme/1/overview', $headers) - ->assertStatus(200) - ->assertJsonFragment([ - 'id' => 1, - 'name' => 'Example programme', - 'workdays_paid' => 62, - 'workdays_volunteer' => 96, - ]) - ->assertJsonPath('data.submissions.0.id', 1); - } - - public function testReadAllAction(): void - { - $headers = $this->getHeaders('jane@example.com', 'Password123'); - - $this->getJson('/api/programmes', $headers) - ->assertStatus(200) - ->assertJsonFragment([ - 'id' => 1, - 'name' => 'Example programme', - ]); - } - - public function testReadAllPersonalAction(): void - { - $headers = $this->getHeaders('steve@example.com', 'Password123'); - - $response = $this->getJson('/api/programmes/personal', $headers); - $response->assertStatus(200); - $response->assertJsonFragment([ - 'id' => 1, - 'name' => 'Example programme', - ]); - } - - public function testReadAllActionRequiresBeingAnAdmin(): void - { - $headers = $this->getHeaders('joe@example.com', 'Password123'); - - $this->getJson('/api/programmes', $headers) - ->assertStatus(403); - } - - public function testReadActionRequiresBelongingToProgramme(): void - { - $headers = $this->getHeaders('sue@example.com', 'Password123'); - - $this->getJson('/api/programme/1/overview', $headers) - ->assertStatus(403); - } - - public function testCreateAction(): void - { - $headers = $this->getHeaders('steve@example.com', 'Password123'); - - $response = $this->postJson('/api/programme', [ - 'name' => 'Steve\'s new programme', - 'continent' => 'europe', - 'country' => 'SE', - 'end_date' => '2031-10-06', - ], $headers) - ->assertStatus(201) - ->assertJsonFragment([ - 'name' => "Steve's new programme", - 'continent' => 'europe', - 'country' => 'SE', - 'end_date' => '2031-10-06', - 'framework_id' => 1, - 'organisation_id' => 1, - ]); - - $this->assertDatabaseHas('programme_user', [ - 'user_id' => 3, - 'programme_id' => $response->json('data.id'), - ]); - } - - public function testUpdateAction(): void - { - $headers = $this->getHeaders('steve@example.com', 'Password123'); - - $this->patchJson('/api/programme/1', [ - 'name' => 'Steve\'s updated programme name', - ], $headers) - ->assertStatus(200) - ->assertJsonFragment([ - 'name' => 'Steve\'s updated programme name', - ]); - } - - public function testUpdateAdditionalTreeSpeciesAction(): void - { - $headers = $this->getHeaders('steve@example.com', 'Password123'); - - Queue::fake(); - - $uploadResponse = $this->post('/api/uploads', [ - 'upload' => $this->fakeValidCsv(), - ], $headers); - - - $data = [ - 'name' => 'Steve\'s updated programme name', - 'additional_tree_species' => $uploadResponse->json('data.id'), - ]; - - $response = $this->patchJson('/api/programme/1', $data, $headers) - ->assertHeader('Content-Type', 'application/json') - ->assertStatus(200) - ->assertJsonFragment([ - 'name' => 'Steve\'s updated programme name', - ]); - } - - public function testCreateActionRequiresPPCUser(): void - { - $headers = $this->getHeaders('andrew@example.com', 'Password123'); - - $response = $this->postJson('/api/programme', [ - 'name' => 'Andrew\'s new programme', - 'continent' => 'europe', - 'country' => 'SE', - 'end_date' => '2031-10-06', - ], $headers) - ->assertStatus(403); - } - - public function testCreateActionNameIsRequired(): void - { - $headers = $this->getHeaders('steve@example.com', 'Password123'); - - $this->postJson('/api/programme', [ - 'continent' => 'europe', - 'country' => 'SE', - 'end_date' => '2031-10-06', - ], $headers) - ->assertStatus(422); - } - - public function testCreateActionCountryIsRequired(): void - { - $headers = $this->getHeaders('steve@example.com', 'Password123'); - - $this->postJson('/api/programme', [ - 'name' => "Steve's new programme", - 'continent' => 'europe', - 'end_date' => '2031-10-06', - ], $headers) - ->assertStatus(422); - } - - public function testCreateActionContinentIsRequired(): void - { - $headers = $this->getHeaders('steve@example.com', 'Password123'); - - $this->postJson('/api/programme', [ - 'name' => "Steve's new programme", - 'country' => 'SE', - 'end_date' => '2031-10-06', - ], $headers) - ->assertStatus(422); - } - - public function testCreateActionEndDateIsRequired(): void - { - $headers = $this->getHeaders('steve@example.com', 'Password123'); - - $this->postJson('/api/programme', [ - 'name' => "Steve's new programme", - 'continent' => 'europe', - 'country' => 'SE', - ], $headers) - ->assertStatus(422); - } - - public function testAddBoundaryToProgrammeAction(): void - { - $headers = $this->getHeaders('steve@example.com', 'Password123'); - - $data = [ - 'programme_id' => 1, - 'boundary_geojson' => '{"type":"Polygon","coordinates":[[[-1.864006519317627,50.7219083651253],[-1.8627190589904783,50.7219083651253],[-1.8627190589904783,50.72276418262861],[-1.864006519317627,50.72276418262861],[-1.864006519317627,50.7219083651253]]]}', - ]; - $response = $this->postJson('/api/programme/boundary', $data, $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - } -} diff --git a/tests/Legacy/Feature/ProgrammeInviteControllerTest.php b/tests/Legacy/Feature/ProgrammeInviteControllerTest.php deleted file mode 100644 index 93dddc8ce..000000000 --- a/tests/Legacy/Feature/ProgrammeInviteControllerTest.php +++ /dev/null @@ -1,278 +0,0 @@ - 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $this->postJson('/api/programme/1/invite', [ - 'email_address' => 'sue@example.com', - 'callback_url' => 'https://testing-this.com/', - ], $headers) - ->assertStatus(201) - ->assertJsonFragment([ - 'programme_id' => 1, - 'accepted_at' => null, - 'email_address' => 'sue@example.com', - ]); - - Mail::assertQueued(ProgrammeInviteReceived::class, function ($mail) { - return $mail->hasTo('sue@example.com'); - }); - - Mail::assertNotQueued(UserInvited::class, function ($mail) { - return $mail->hasTo('a.new.user@email.com'); - }); - } - - public function testCreateActionWhenUserIsAlreadyPartOfProgramme(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $this->postJson('/api/programme/1/invite', [ - 'email_address' => 'monitoring.partner.3@monitor.com', - ], $headers) - ->assertStatus(422); - } - - public function testCreateActionWithNewTerramatchUser(): void - { - Mail::fake(); - Carbon::setTestNow(Carbon::createFromDate('2021-07-23')); - - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $this->postJson('/api/programme/1/invite', [ - 'email_address' => 'a.new.user@email.com', - 'callback_url' => 'https://testing-this.com/', - ], $headers) - ->assertStatus(201) - ->assertJsonFragment([ - 'programme_id' => 1, - 'accepted_at' => '2021-07-23T00:00:00.000000Z', - 'email_address' => 'a.new.user@email.com', - ]); - - Mail::assertNotQueued(ProgrammeInviteReceived::class, function ($mail) { - return $mail->hasTo('a.new.user@email.com'); - }); - - Mail::assertQueued(UserInvited::class, function ($mail) { - return $mail->hasTo('a.new.user@email.com'); - }); - } - - public function testCreateActionEmailAddressIsRequired(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $this->postJson('/api/programme/1/invite', $headers) - ->assertStatus(422); - } - - public function testCreateActionProgrammeIdHasToExist(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $this->postJson('/api/programme/6102000/invite', [ - 'email_address' => 'a.new.user@email.com', - ], $headers) - ->assertStatus(404); - } - - public function testAcceptAction(): void - { - Carbon::setTestNow(Carbon::createFromDate('2021-07-23')); - $token = Auth::attempt([ - 'email_address' => 'monitoring.partner.1@monitor.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $data = [ - 'token' => 'tlvOSFc5kpR2VqrCUiwI3gabz5OeLr7LdUmhyyF693agCu7fyW9d8p4pBtEGORmj', - ]; - - $response = $this->postJson('/api/programme/invite/accept', $data, $headers); - $response->assertStatus(200); - $response->assertJsonFragment([ - 'id' => 1, - 'programme_id' => 1, - 'accepted_at' => '2021-07-23T00:00:00.000000Z', - ]); - - $this->assertDatabaseHas('programme_user', [ - 'user_id' => 8, - 'programme_id' => 1, - 'is_monitoring' => true, - ]); - } - - public function testAcceptActionRequiresEmailAndTokenToMatch(): void - { - $token = Auth::attempt([ - 'email_address' => 'monitoring.partner.2@monitor.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $data = [ - 'token' => 'tlvOSFc5kpR2VqrCUiwI3gabz5OeLr7LdUmhyyF693agCu7fyW9d8p4pBtEGORmj', - ]; - - $this->postJson('/api/programme/invite/accept', $data, $headers) - ->assertStatus(404); - } - - public function testAcceptActionRequiresUnacceptedInvite(): void - { - $token = Auth::attempt([ - 'email_address' => 'monitoring.partner.1@monitor.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $data = [ - 'token' => 'QhiKk66GX9fkLaEZY06T6KLEw8ALhPkeBtmN5e9wgNo48cSmmhlRlFrczRjLtz3S', - ]; - - $this->postJson('/api/programme/invite/accept', $data, $headers) - ->assertStatus(422); - } - - public function testReadAllAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->getJson('/api/programme/1/partners', $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure([ - 'data' => [ - '*' => [ - 'id', - 'organisation_id', - 'first_name', - 'last_name', - 'email_address', - 'role', - 'email_address_verified_at', - 'last_logged_in_at', - 'twitter', - 'linkedin', - 'instagram', - 'facebook', - 'phone_number', - 'avatar', - ], - ], - ]); - } - - public function testRemoveUserAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'monitoring.partner.1@monitor.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $data = [ - 'user_id' => 3, - 'programme_id' => 1, - ]; - - $response = $this->deleteJson('/api/programme/invite/remove', $data, $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure(['data' => []]); - } - - public function testDeleteAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $this->deleteJson('/api/programme/invite/2', $headers) - ->assertStatus(200); - } - - public function testDeleteActionRequiresBeingPartOfProgramme(): void - { - $token = Auth::attempt([ - 'email_address' => 'sue@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $this->deleteJson('/api/programme/invite/2', $headers) - ->assertStatus(403); - } -} diff --git a/tests/Legacy/Feature/ProgrammeTreeSpeciesControllerTest.php b/tests/Legacy/Feature/ProgrammeTreeSpeciesControllerTest.php deleted file mode 100644 index cf85d96bc..000000000 --- a/tests/Legacy/Feature/ProgrammeTreeSpeciesControllerTest.php +++ /dev/null @@ -1,263 +0,0 @@ - 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $this->postJson('/api/programme/tree_species', [ - 'name' => 'Some tree species', - 'programme_id' => 1, - ], $headers) - ->assertStatus(201) - ->assertJsonFragment([ - 'programme_id' => 1, - 'name' => 'Some tree species', - ]); - } - - public function testCreateBulkAction() - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $this->postJson('/api/programme/1/tree_species/bulk', [ - 'tree_species' => [ - [ - 'name' => 'tree 1', - ], [ - 'name' => 'tree 2', - ], - ], - ], $headers) - ->assertStatus(201); - - $this->assertDatabaseCount('programme_tree_species', 2); // 2 for this submission - - $this->postJson('/api/programme/1/tree_species/bulk', [ - 'tree_species' => [], - ], $headers) - ->assertStatus(201); - - $this->assertDatabaseCount('programme_tree_species', 0); // 0 for this submission - } - - public function testCreateBulkForSubmissionAction() - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $this->assertDatabaseCount('programme_tree_species', 9); // 8 for this submission, 1 elsewhere - - $this->postJson('/api/programme/submission/1/tree_species/bulk', [ - 'tree_species' => [ - [ - 'name' => 'tree 1', - 'amount' => 1, - ], [ - 'name' => 'tree 2', - 'amount' => 2, - ], - ], - ], $headers) - ->assertStatus(201) - ->assertJsonFragment([ - 'name' => 'tree 1', - 'amount' => 1, - ]) - ->assertJsonFragment([ - 'name' => 'tree 2', - 'amount' => 2, - ]); - - $this->assertDatabaseCount('programme_tree_species', 3); // 2 for this submission, 1 elsewhere - - $this->postJson('/api/programme/submission/1/tree_species/bulk', [ - 'tree_species' => [], - ], $headers) - ->assertStatus(201); - - $this->assertDatabaseCount('programme_tree_species', 1); // 0 for this submission, 1 elsewhere - } - - public function testCreateActionNameIsRequired() - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $this->postJson('/api/programme/tree_species', [ - 'programme_id' => 1, - ], $headers) - ->assertStatus(422); - } - - public function testCreateActionProgrammeIdIsRequired(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $this->postJson('/api/programme/tree_species', [ - 'name' => 'Some tree species', - ], $headers) - ->assertStatus(422); - } - - public function testCreateActionProgrammeIdHasToExist(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $r = $this->postJson('/api/programme/tree_species', [ - 'name' => 'Some tree species', - 'programme_id' => 4565654, - ], $headers) - ->assertStatus(422); - } - - public function testDeleteAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $this->deleteJson('/api/programme/tree_species/1', $headers) - ->assertStatus(200); - } - - public function testDeleteActionRequiresBelongingToTreeSpeciesProgramme(): void - { - $token = Auth::attempt([ - 'email_address' => 'sue@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $this->deleteJson('/api/programme/tree_species/1', $headers) - ->assertStatus(403); - } - - public function testReadAllByProgrammeAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $response = $this->getJson('/api/programme/1/tree_species', $headers) - ->assertStatus(200) - ->assertJsonFragment([ - 'id' => 9, - 'name' => 'A tree species', - 'programme_id' => 1, - ]); - } - - public function testReadAllByProgrammeActionRequiresBelongingToTreeSpeciesProgramme(): void - { - $token = Auth::attempt([ - 'email_address' => 'sue@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $this->getJson('/api/programme/1/tree_species', $headers) - ->assertStatus(403); - } - - public function testReadAllAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $response = $this->getJson('/api/programmes/tree_species', $headers); - $response->assertStatus(200); - } - - public function testSearchTreeSpeciesAction(): void - { - $mock = new MockHandler([ - new Response(200, [], json_encode([ - 'tree name', - ])), - new Response(200, [], json_encode([])), - new RequestException('Error Communicating with Server', new Request('GET', 'test')), - ]); - - $handlerStack = HandlerStack::create($mock); - $client = new Client(['handler' => $handlerStack]); - - $treeSpeciesClient = new TreeSpeciesClient($client); - - $response = $treeSpeciesClient->search('test'); - $this->assertContains('tree name', $response); - - $response = $treeSpeciesClient->search('empty response'); - $this->assertEmpty($response); - - $this->expectException(ExternalAPIException::class); - $treeSpeciesClient->search('server fail'); - } -} diff --git a/tests/Legacy/Feature/ProgrammeTreeSpeciesCsvControllerTest.php b/tests/Legacy/Feature/ProgrammeTreeSpeciesCsvControllerTest.php deleted file mode 100644 index ffcca6ed7..000000000 --- a/tests/Legacy/Feature/ProgrammeTreeSpeciesCsvControllerTest.php +++ /dev/null @@ -1,152 +0,0 @@ - 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - Queue::fake(); - - $response = $this->post('/api/uploads', [ - 'upload' => $this->fakeValidCsv(), - ], $headers); - - $this->postJson('/api/programme/tree_species/csv', [ - 'programme_id' => 1, - 'upload_id' => $response->json('data.id'), - ], $headers) - ->assertStatus(200) - ->assertJsonFragment([ - 'completed_rows' => 0, - 'total_rows' => 33, - ]); - - Queue::assertNotPushed(CreateProgrammeTreeSpeciesJob::class, function ($job) { - return $job->getName() === 'Tree Species'; - }); - - Queue::assertPushed(CreateProgrammeTreeSpeciesJob::class, function ($job) { - return $job->getName() === 'Tree species 01'; - }); - } - - public function testCreateActionFileIsRequired(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $this->postJson('/api/programme/tree_species/csv', [ - 'programme_id' => 1, - ], $headers) - ->assertStatus(422); - } - - public function testCreateActionProgrammeIdIsRequired(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $response = $this->post('/api/uploads', [ - 'upload' => $this->fakeValidCsv(), - ], $headers); - - $this->postJson('/api/programme/tree_species/csv', [ - 'upload_id' => $response->json('data.id'), - ], $headers) - ->assertStatus(404); - } - - public function testCreateActionRequiresBelongingToTreeSpeciesProgramme(): void - { - $token = Auth::attempt([ - 'email_address' => 'sue@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $this->postJson('/api/programme/tree_species/csv', [ - 'programme_id' => 1, - 'file' => $this->fakeValidCsv(), - ], $headers) - ->assertStatus(403); - } - - public function testReadAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $this->getJson('/api/programme/tree_species/csv/1', $headers) - ->assertStatus(200) - ->assertJsonFragment([ - 'id' => 1, - 'completed_rows' => 1, - 'total_rows' => 10, - 'status' => 'pending', - ]); - } - - public function testReadTreeSpeciesAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $this->getJson('/api/programme/tree_species/csv/1/trees', $headers) - ->assertStatus(200) - ->assertJsonFragment([ - 'id' => 2, - 'name' => 'A tree species', - 'programme_id' => 1, - ]); - } - - public function testDownloadCsvTemplateAction(): void - { - $headers = [ - 'Content-Type' => 'application/json', - ]; - - $this->getJson('/api/uploads/socioeconomic_benefits/template/csv', $headers) - ->assertStatus(200); - } -} diff --git a/tests/Legacy/Feature/ProgressUpdatesControllerTest.php b/tests/Legacy/Feature/ProgressUpdatesControllerTest.php deleted file mode 100644 index b9b8ab97b..000000000 --- a/tests/Legacy/Feature/ProgressUpdatesControllerTest.php +++ /dev/null @@ -1,309 +0,0 @@ -callCreateActionAsUser(); - $this->callCreateActionAsAdmin(); - } - - private function callCreateActionAsUser() - { - $data = [ - 'upload' => $this->fakeImage(), - ]; - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->post('/api/uploads', $data, $headers); - $id = json_decode($response->getContent())->data->id; - $data = [ - 'monitoring_id' => 2, - 'grouping' => 'general', - 'title' => 'Foo foo foo', - 'breakdown' => 'Bar bar bar', - 'summary' => 'Baz baz baz', - 'data' => [ - 'planting_date' => '2021-01-01', - 'trees_planted' => [ - [ - 'name' => 'maple', - 'value' => 1, - ], - [ - 'name' => 'oak', - 'value' => 2, - ], - [ - 'name' => 'sycamore', - 'value' => 3, - ], - ], - 'survival_rate' => 100, - 'supported_nurseries' => 123, - 'short_term_jobs_amount' => [ - 'male' => 1, - 'female' => 2, - ], - 'biodiversity_update' => 'Norf norf norf', - ], - 'images' => [ - [ - 'image' => $id, - 'caption' => 'Qux qux qux', - ], - ], - ]; - $response = $this->postJson('/api/progress_updates', $data, $headers); - $response->assertStatus(201); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertJsonStructure([ - 'data' => [ - 'id', - 'monitoring_id', - 'title', - 'breakdown', - 'summary', - 'data' => [ - 'planting_date', - 'trees_planted' => [ - [ - 'name', - 'value', - ], - ], - 'trees_planted_total', - 'survival_rate', - 'supported_nurseries', - 'short_term_jobs_amount' => [ - 'male', - 'female', - ], - 'short_term_jobs_amount_total', - 'biodiversity_update', - ], - 'images' => [ - [ - 'image', - 'caption', - 'thumbnail', - ], - ], - 'created_by', - 'created_by_admin', - 'created_at', - ], - ]); - $response->assertJson([ - 'data' => [ - 'created_by_admin' => false, - ], - ]); - } - - private function callCreateActionAsAdmin() - { - $data = [ - 'upload' => $this->fakeImage(), - ]; - $token = Auth::attempt([ - 'email_address' => 'jane@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->post('/api/uploads', $data, $headers); - $id = json_decode($response->getContent())->data->id; - $data = [ - 'monitoring_id' => 2, - 'grouping' => 'general', - 'title' => 'Foo foo foo', - 'breakdown' => 'Bar bar bar', - 'summary' => 'Baz baz baz', - 'data' => [ - 'planting_date' => '2021-01-01', - 'trees_planted' => [ - [ - 'name' => 'maple', - 'value' => 1, - ], - [ - 'name' => 'oak', - 'value' => 2, - ], - [ - 'name' => 'sycamore', - 'value' => 3, - ], - ], - 'survival_rate' => 100, - 'short_term_jobs_amount' => [ - 'male' => 1, - 'female' => 2, - ], - 'biodiversity_update' => 'Norf norf norf', - ], - 'images' => [ - [ - 'image' => $id, - 'caption' => 'Qux qux qux', - ], - ], - ]; - $response = $this->postJson('/api/progress_updates', $data, $headers); - $response->assertStatus(201); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertJsonStructure([ - 'data' => [ - 'id', - 'monitoring_id', - 'title', - 'breakdown', - 'summary', - 'data' => [ - 'planting_date', - 'trees_planted' => [ - [ - 'name', - 'value', - ], - ], - 'trees_planted_total', - 'survival_rate', - 'short_term_jobs_amount' => [ - 'male', - 'female', - ], - 'short_term_jobs_amount_total', - 'biodiversity_update', - ], - 'images' => [ - [ - 'image', - 'caption', - 'thumbnail', - ], - ], - 'created_by', - 'created_by_admin', - 'created_at', - ], - ]); - $response->assertJson([ - 'data' => [ - 'created_by_admin' => true, - ], - ]); - } - - public function testReadAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->getJson('/api/progress_updates/1', $headers); - $response->assertStatus(200); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertJsonStructure([ - 'data' => [ - 'id', - 'monitoring_id', - 'title', - 'breakdown', - 'summary', - 'data' => [ - 'planting_date', - 'trees_planted' => [ - [ - 'name', - 'value', - ], - ], - 'trees_planted_total', - 'survival_rate', - 'short_term_jobs_amount' => [ - 'male', - 'female', - ], - 'short_term_jobs_amount_total', - 'biodiversity_update', - ], - 'images' => [ - [ - 'image', - 'caption', - 'thumbnail', - ], - ], - 'created_by', - 'created_at', - ], - ]); - } - - public function testReadAllByMonitoringAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->getJson('/api/monitorings/2/progress_updates', $headers); - $response->assertStatus(200); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertJsonStructure([ - 'data' => [ - [ - 'id', - 'monitoring_id', - 'title', - 'breakdown', - 'summary', - 'data' => [ - 'planting_date', - 'trees_planted' => [ - [ - 'name', - 'value', - ], - ], - 'trees_planted_total', - 'survival_rate', - 'short_term_jobs_amount' => [ - 'male', - 'female', - ], - 'short_term_jobs_amount_total', - 'biodiversity_update', - ], - 'images' => [ - [ - 'image', - 'caption', - 'thumbnail', - ], - ], - 'created_by', - 'created_at', - ], - ], - ]); - } -} diff --git a/tests/Legacy/Feature/ReportsControllerTest.php b/tests/Legacy/Feature/ReportsControllerTest.php deleted file mode 100644 index ae4aef811..000000000 --- a/tests/Legacy/Feature/ReportsControllerTest.php +++ /dev/null @@ -1,102 +0,0 @@ - 'jane@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->get($endpoint, $headers); - $response->assertStatus(200); - /** - * This section asserts that the filename is correct (by looking at the - * content disposition header). However this test occasionally fails - * when generating the report takes more than one second, so we check - * three headers (the current second and one second either side of it). - */ - $contentDispositionHeaders = $response->headers->get('Content-Disposition'); - $now = Carbon::now(); - $possibleContentDispositionHeaders = [ - 'Content-Disposition', 'attachment; filename="' . $filename . '_' . $now->subSecond()->format('Y-m-d_H:i:s') . '.csv"', - 'Content-Disposition', 'attachment; filename="' . $filename . '_' . $now->format('Y-m-d_H:i:s') . '.csv"', - 'Content-Disposition', 'attachment; filename="' . $filename . '_' . $now->addSecond()->format('Y-m-d_H:i:s') . '.csv"', - ]; - $this->assertIsOneOf($possibleContentDispositionHeaders, $contentDispositionHeaders); - } - - public function testReadAllApprovedOrganisationsAction(): void - { - $this->callReportingAction('/api/reports/approved_organisations', 'approved_organisations'); - } - - public function testReadAllRejectedOrganisationsAction(): void - { - $this->callReportingAction('/api/reports/rejected_organisations', 'rejected_organisations', 'text/plain; charset=UTF-8'); - } - - public function testReadAllUsersAction(): void - { - $this->callReportingAction('/api/reports/users', 'users'); - } - - public function testReadAllOffersAction(): void - { - $this->callReportingAction('/api/reports/offers', 'offers'); - } - - public function testReadAllApprovedPitchesAction(): void - { - $this->callReportingAction('/api/reports/approved_pitches', 'approved_pitches'); - } - - public function testReadAllRejectedPitchesAction(): void - { - $this->callReportingAction('/api/reports/rejected_pitches', 'rejected_pitches', 'text/plain; charset=UTF-8'); - } - - public function testReadAllInterestsAction(): void - { - $this->callReportingAction('/api/reports/interests', 'interests'); - } - - public function testReadAllMatchesAction(): void - { - $this->callReportingAction('/api/reports/matches', 'matches'); - } - - public function testReadAllFilterRecordsAction(): void - { - $this->callReportingAction('/api/reports/filter_records', 'filter_records', 'text/plain; charset=UTF-8'); - } - - public function testReadAllOrganisationsAction(): void - { - $this->callReportingAction('/api/reports/organisations', 'organisations'); - } - - public function testReadAllPitchesAction(): void - { - $this->callReportingAction('/api/reports/pitches', 'pitches'); - } - - public function testReadAllMonitoringsAction(): void - { - $this->callReportingAction('/api/reports/monitorings', 'monitorings', 'text/plain; charset=UTF-8'); - } - - public function testReadAllProgressUpdatesAction(): void - { - $this->callReportingAction('/api/reports/progress_updates', 'progress_updates'); - } -} diff --git a/tests/Legacy/Feature/RestorationMethodMetricVersionsControllerTest.php b/tests/Legacy/Feature/RestorationMethodMetricVersionsControllerTest.php deleted file mode 100644 index 880236c10..000000000 --- a/tests/Legacy/Feature/RestorationMethodMetricVersionsControllerTest.php +++ /dev/null @@ -1,224 +0,0 @@ - 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->getJson('/api/restoration_method_metric_versions/1', $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure([ - 'data' => [ - 'id', - 'status', - 'approved_rejected_by', - 'rejected_reason', - 'rejected_reason_body', - 'data' => [ - 'id', - 'pitch_id', - 'restoration_method', - 'experience', - 'land_size', - 'price_per_hectare', - 'biomass_per_hectare', - 'carbon_impact', - 'species_impacted' => [], - ], - ], - ]); - } - - public function testApproveAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'jane@example.com', - 'password' => 'Password123', - ]); - $data = []; - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $response = $this->patchJson('/api/restoration_method_metric_versions/2/approve', $data, $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure([ - 'data' => [ - 'id', - 'status', - 'approved_rejected_by', - 'rejected_reason', - 'rejected_reason_body', - 'data' => [ - 'id', - 'pitch_id', - 'restoration_method', - 'experience', - 'land_size', - 'price_per_hectare', - 'biomass_per_hectare', - 'carbon_impact', - 'species_impacted' => [], - ], - ], - ]); - $response->assertJson([ - 'data' => [ - 'status' => 'approved', - ], - ]); - } - - public function testRejectAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'jane@example.com', - 'password' => 'Password123', - ]); - $data = [ - 'rejected_reason' => 'cannot_verify', - 'rejected_reason_body' => 'Lorem ipsum dolor sit amet', - ]; - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $response = $this->patchJson('/api/restoration_method_metric_versions/2/reject', $data, $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure([ - 'data' => [ - 'id', - 'status', - 'approved_rejected_by', - 'rejected_reason', - 'rejected_reason_body', - 'data' => [ - 'id', - 'pitch_id', - 'restoration_method', - 'experience', - 'land_size', - 'price_per_hectare', - 'biomass_per_hectare', - 'carbon_impact', - 'species_impacted' => [], - ], - ], - ]); - $response->assertJson([ - 'data' => [ - 'status' => 'rejected', - ], - ]); - } - - public function testDeleteAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->deleteJson('/api/restoration_method_metric_versions/2', $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJson([ - 'data' => [], - ]); - } - - public function testReadAllByRestorationMethodMetricAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->getJson('/api/restoration_method_metrics/1/restoration_method_metric_versions', $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure([ - 'data' => [ - [ - 'id', - 'status', - 'approved_rejected_by', - 'approved_rejected_at', - 'rejected_reason', - 'rejected_reason_body', - 'data' => [ - 'id', - 'pitch_id', - 'restoration_method', - 'experience', - 'land_size', - 'price_per_hectare', - 'biomass_per_hectare', - 'carbon_impact', - 'species_impacted' => [], - ], - ], - ], - ]); - } - - public function testReviveAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'jane@example.com', - 'password' => 'Password123', - ]); - $data = []; - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $response = $this->patchJson('/api/restoration_method_metric_versions/3/revive', $data, $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - - $response->assertJsonStructure([ - 'data' => [ - 'id', - 'status', - 'approved_rejected_by', - 'rejected_reason', - 'rejected_reason_body', - 'data' => [ - 'id', - 'pitch_id', - 'restoration_method', - 'experience', - 'land_size', - 'price_per_hectare', - 'biomass_per_hectare', - 'carbon_impact', - 'species_impacted' => [], - ], - ], - ]); - $response->assertJson([ - 'data' => [ - 'status' => 'approved', - ], - ]); - } -} diff --git a/tests/Legacy/Feature/RestorationMethodMetricsControllerTest.php b/tests/Legacy/Feature/RestorationMethodMetricsControllerTest.php deleted file mode 100644 index 6ff69f27a..000000000 --- a/tests/Legacy/Feature/RestorationMethodMetricsControllerTest.php +++ /dev/null @@ -1,204 +0,0 @@ - 'steve@example.com', - 'password' => 'Password123', - ]); - $data = [ - 'pitch_id' => 1, - 'restoration_method' => 'agroforestry', - 'experience' => 6, - 'land_size' => 10, - 'price_per_hectare' => 10, - 'biomass_per_hectare' => 1.23, - 'carbon_impact' => 1, - 'species_impacted' => [ - 'Tiger', - 'Lion', - 'Leopard', - ], - ]; - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $response = $this->postJson('/api/restoration_method_metrics', $data, $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(201); - $response->assertJsonStructure([ - 'data' => [ - 'id', - 'status', - 'approved_rejected_by', - 'rejected_reason', - 'rejected_reason_body', - 'data' => [ - 'id', - 'pitch_id', - 'restoration_method', - 'experience', - 'land_size', - 'price_per_hectare', - 'biomass_per_hectare', - 'carbon_impact', - 'species_impacted' => [], - ], - ], - ]); - } - - public function testReadAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->getJson('/api/restoration_method_metrics/1', $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure([ - 'data' => [ - 'id', - 'pitch_id', - 'restoration_method', - 'experience', - 'land_size', - 'price_per_hectare', - 'biomass_per_hectare', - 'carbon_impact', - 'species_impacted' => [], - ], - ]); - } - - public function testUpdateAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $data = [ - 'price_per_hectare' => 123, - ]; - $response = $this->patchJson('/api/restoration_method_metrics/1', $data, $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure([ - 'data' => [ - 'id', - 'status', - 'approved_rejected_by', - 'rejected_reason', - 'rejected_reason_body', - 'data' => [ - 'id', - 'pitch_id', - 'restoration_method', - 'experience', - 'land_size', - 'price_per_hectare', - 'biomass_per_hectare', - 'carbon_impact', - 'species_impacted' => [], - ], - ], - ]); - } - - public function testReadAllByPitchAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->getJson('/api/pitches/1/restoration_method_metrics', $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure([ - 'data' => [ - [ - 'id', - 'pitch_id', - 'restoration_method', - 'experience', - 'land_size', - 'price_per_hectare', - 'biomass_per_hectare', - 'carbon_impact', - 'species_impacted' => [], - ], - ], - ]); - } - - public function testInspectByPitchAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->getJson('/api/pitches/1/restoration_method_metrics/inspect', $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure([ - 'data' => [ - [ - 'id', - 'status', - 'approved_rejected_by', - 'approved_rejected_at', - 'rejected_reason', - 'rejected_reason_body', - 'data' => [ - 'id', - 'pitch_id', - 'restoration_method', - 'experience', - 'land_size', - 'price_per_hectare', - 'biomass_per_hectare', - 'carbon_impact', - 'species_impacted' => [], - ], - ], - ], - ]); - } - - public function testDeleteAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $response = $this->deleteJson('/api/restoration_method_metrics/1', $headers); - $response->assertStatus(200); - $this->assertNull(RestorationMethodMetricModel::find(1)); - } -} diff --git a/tests/Legacy/Feature/SatelliteMapsControllerTest.php b/tests/Legacy/Feature/SatelliteMapsControllerTest.php deleted file mode 100644 index 3ebc69cfc..000000000 --- a/tests/Legacy/Feature/SatelliteMapsControllerTest.php +++ /dev/null @@ -1,133 +0,0 @@ - $this->fakeMap(), - ]; - $token = Auth::attempt([ - 'email_address' => 'jane@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->post('/api/uploads', $data, $headers); - $id = json_decode($response->getContent())->data->id; - $data = [ - 'monitoring_id' => 2, - 'map' => $id, - 'alt_text' => 'Lorem ipsum dolor sit amet', - ]; - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $response = $this->postJson('/api/satellite_maps', $data, $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(201); - $response->assertJsonStructure([ - 'data' => [ - 'id', - 'monitoring_id', - 'map', - 'alt_text', - 'created_at', - 'created_by', - ], - ]); - $response->assertJson([ - 'data' => [ - 'map' => null, - ], - ]); - } - - public function testReadAllByMonitoringAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $response = $this->getJson('/api/monitorings/2/satellite_maps', $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure([ - 'data' => [ - [ - 'id', - 'monitoring_id', - 'map', - 'alt_text', - 'created_at', - 'created_by', - ], - ], - ]); - } - - public function testReadLatestByMonitoringAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $response = $this->getJson('/api/monitorings/2/satellite_maps/latest', $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure([ - 'data' => [ - 'id', - 'monitoring_id', - 'map', - 'alt_text', - 'created_at', - 'created_by', - ], - ]); - $map = json_decode($response->getContent())->data->map; - $this->assertIsString($map); - } - - public function testReadAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $response = $this->getJson('/api/satellite_maps/1', $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure([ - 'data' => [ - 'id', - 'monitoring_id', - 'map', - 'alt_text', - 'created_at', - 'created_by', - ], - ]); - $map = json_decode($response->getContent())->data->map; - $this->assertIsString($map); - } -} diff --git a/tests/Legacy/Feature/SeedDetailControllerTest.php b/tests/Legacy/Feature/SeedDetailControllerTest.php deleted file mode 100644 index 76ffaa854..000000000 --- a/tests/Legacy/Feature/SeedDetailControllerTest.php +++ /dev/null @@ -1,84 +0,0 @@ - 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $data = [ - 'name' => 'test name', - 'weight_of_sample' => 45.2001, - 'seeds_in_sample' => 63728, - ]; - - $this->postJson('/api/site/1/seeds', $data, $headers) - ->assertHeader('Content-Type', 'application/json') - ->assertStatus(201) - ->assertJsonFragment([ - 'name' => 'test name', - 'weight_of_sample' => '45.2001', - 'seeds_in_sample' => 63728, - 'seeds_per_kg' => 1409.9084, - 'site_id' => 1, - ]); - } - - public function testCreateBulkAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $data = [ - 'collection' => [ - [ - 'name' => 'unique name', - 'weight_of_sample' => 10, - 'seeds_in_sample' => 10, - ], [ - 'name' => 'non-unique name', - 'weight_of_sample' => 10, - 'seeds_in_sample' => 10, - ], [ - 'name' => 'non-unique name', - 'weight_of_sample' => 10, - 'seeds_in_sample' => 10, - ], - ], - ]; - - $this->postJson('/api/site/1/seeds/bulk', $data, $headers) - ->assertHeader('Content-Type', 'application/json') - ->assertStatus(201); - - $this->assertDatabaseHas('seed_details', [ - 'site_id' => 1, - 'name' => 'unique name', - 'weight_of_sample' => 10, - 'seeds_in_sample' => 10, - ]); - - $this->assertDatabaseHas('seed_details', [ - 'site_id' => 1, - 'name' => 'non-unique name', - 'weight_of_sample' => 20, - 'seeds_in_sample' => 20, - ]); - } -} diff --git a/tests/Legacy/Feature/SiteControllerTest.php b/tests/Legacy/Feature/SiteControllerTest.php deleted file mode 100644 index c08d8d976..000000000 --- a/tests/Legacy/Feature/SiteControllerTest.php +++ /dev/null @@ -1,466 +0,0 @@ -getHeaders('steve@example.com', 'Password123'); - $data = [ - 'programme_id' => 1, - 'site_name' => 'test site', - 'site_description' => 'test site desc', - 'site_history' => 'test site history', - 'end_date' => '2023-10-06', - 'planting_pattern' => 'some planting pattern', - 'stratification_for_heterogeneity' => 16, - ]; - - $this->postJson('/api/site', $data, $headers) - ->assertHeader('Content-Type', 'application/json') - ->assertStatus(201) - ->assertJsonFragment([ - 'continent' => 'europe', - 'country' => 'se', - 'end_date' => '2023-10-06', - 'control_site' => false, - ]); - } - - public function testCreateControlSiteAction(): void - { - $headers = $this->getHeaders('steve@example.com', 'Password123'); - $data = [ - 'programme_id' => 1, - 'control_site' => true, - 'site_name' => 'test control site', - 'site_description' => 'test control site desc', - 'site_history' => 'test site history', - 'end_date' => '2023-10-06', - 'planting_pattern' => 'some planting pattern', - 'stratification_for_heterogeneity' => 16, - ]; - - $this->postJson('/api/site', $data, $headers) - ->assertHeader('Content-Type', 'application/json') - ->assertStatus(201) - ->assertJsonFragment([ - 'continent' => 'europe', - 'country' => 'se', - 'end_date' => '2023-10-06', - 'control_site' => true, - ]); - } - - public function testControlSiteRelations(): void - { - $programme = Programme::find(1); - $this->assertCount(1, $programme->controlSites); - $this->assertCount(7, $programme->sites); - } - - public function testCreateActionUserMustBeInProgramme(): void - { - $headers = $this->getHeaders('steve@example.com', 'Password123'); - $data = [ - 'programme_id' => 4, - 'site_name' => 'test site', - 'site_description' => 'test site desc', - 'site_history' => 'test site history', - 'end_date' => '2023-10-06', - 'planting_pattern' => 'some planting pattern', - 'stratification_for_heterogeneity' => 16, - ]; - - $this->postJson('/api/site', $data, $headers) - ->assertHeader('Content-Type', 'application/json') - ->assertStatus(403); - } - - public function testUpdateAction(): void - { - $headers = $this->getHeaders('steve@example.com', 'Password123'); - $data = [ - 'name' => 'new site name', - 'description' => 'new desc', - 'history' => 'new history', - 'establishment_date' => '2019-01-01', - ]; - - $this->patchJson('/api/site/1', $data, $headers) - ->assertHeader('Content-Type', 'application/json') - ->assertStatus(200) - ->assertJsonFragment([ - 'name' => 'new site name', - 'description' => 'new desc', - 'history' => 'new history', - 'establishment_date' => '2019-01-01', - 'end_date' => '2098-04-24', - ]); - } - - public function testUpdateAdditionalTreeSpeciesAction(): void - { - $headers = $this->getHeaders('steve@example.com', 'Password123'); - - Queue::fake(); - - $uploadResponse = $this->post('/api/uploads', [ - 'upload' => $this->fakeValidCsv(), - ], $headers); - - - $data = [ - 'name' => 'new site name', - 'description' => 'new desc', - 'history' => 'new history', - 'additional_tree_species' => $uploadResponse->json('data.id'), - ]; - - $response = $this->patchJson('/api/site/1', $data, $headers) - ->assertHeader('Content-Type', 'application/json') - ->assertStatus(200) - ->assertJsonFragment([ - 'name' => 'new site name', - 'description' => 'new desc', - 'history' => 'new history', - 'end_date' => '2098-04-24', - ]); - } - - public function testReadAllAction(): void - { - $headers = $this->getHeaders('jane@example.com', 'Password123'); - - $response = $this->getJson('/api/sites', $headers); - $response->assertStatus(200); - $response->assertJsonFragment([ - 'id' => 1, - 'programme_id' => 1, - 'name' => 'Some Site', - 'name_with_id' => '#1 - Some Site', - 'description' => 'A site, somewhere', - ]); - } - - public function testReadAllForUserAction(): void - { - $headers = $this->getHeaders('steve@example.com', 'Password123'); - - $response = $this->getJson('/api/my/sites', $headers); - $response->assertStatus(200); - $response->assertJsonFragment([ - 'id' => 1, - 'programme_id' => 1, - 'name' => 'Some Site', - 'name_with_id' => '#1 - Some Site', - 'description' => 'A site, somewhere', - ]); - $response->assertJsonMissing([ - 'id' => 7, - ]); - } - - public function testReadAllActionRequiresAdmin(): void - { - $headers = $this->getHeaders('steve@example.com', 'Password123'); - - $response = $this->getJson('/api/sites', $headers); - $response->assertStatus(403); - } - - public function testReadAction(): void - { - $headers = $this->getHeaders('steve@example.com', 'Password123'); - - $response = $this->getJson('/api/site/1/overview', $headers); - $response->assertStatus(200); - $response->assertJsonFragment([ - 'id' => 1, - 'programme_id' => 1, - 'name' => 'Some Site', - 'name_with_id' => '#1 - Some Site', - 'description' => 'A site, somewhere', - 'next_due_submission_id' => 3, - 'workdays_paid' => 25, - 'workdays_volunteer' => 49, - 'total_workdays' => 74, - ]); - $response->assertJsonCount(1, 'data.media'); - $response->assertJsonPath('data.submissions.0.id', 1); - } - - public function testReadActionAllowsAdminAccess(): void - { - $headers = $this->getHeaders('jane@example.com', 'Password123'); - - $response = $this->getJson('/api/site/1/overview', $headers); - $response->assertStatus(200); - $response->assertJsonFragment([ - 'id' => 1, - 'programme_id' => 1, - 'name' => 'Some Site', - 'name_with_id' => '#1 - Some Site', - 'description' => 'A site, somewhere', - 'next_due_submission_id' => 3, - 'workdays_paid' => 25, - 'workdays_volunteer' => 49, - ]); - } - - public function testReadAllByProgrammeAction(): void - { - $headers = $this->getHeaders('steve@example.com', 'Password123'); - - $this->getJson('/api/programme/1/sites', $headers) - ->assertStatus(200) - ->assertJsonFragment([ - 'id' => 1, - 'programme_id' => 1, - 'name' => 'Some Site', - 'name_with_id' => '#1 - Some Site', - 'description' => 'A site, somewhere', - 'next_due_submission_id' => 3, - 'workdays_paid' => 25, - 'workdays_volunteer' => 49, - ]); - } - - public function testAddBoundaryToSiteAction(): void - { - $headers = $this->getHeaders('steve@example.com', 'Password123'); - $data = [ - 'site_id' => 1, - 'boundary_geojson' => '{"type":"Polygon","coordinates":[[[-1.864006519317627,50.7219083651253],[-1.8627190589904783,50.7219083651253],[-1.8627190589904783,50.72276418262861],[-1.864006519317627,50.72276418262861],[-1.864006519317627,50.7219083651253]]]}', - ]; - - $response = $this->postJson('/api/site/boundary', $data, $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - } - - public function testReadAllByProgrammeActionPaginatesAtFive(): void - { - $headers = $this->getHeaders('steve@example.com', 'Password123'); - $this->getJson('/api/programme/1/sites', $headers) - ->assertStatus(200) - ->assertJsonMissingExact([ - 'id' => 6, - 'programme_id' => 1, - 'name' => 'Some Site', - 'description' => 'A site, somewhere', - ]); - } - - public function testReadAllByProgrammeActionCanGetSecondPage(): void - { - $headers = $this->getHeaders('steve@example.com', 'Password123'); - $this->getJson('/api/programme/1/sites?page=2', $headers) - ->assertStatus(200) - ->assertJsonFragment([ - 'id' => 6, - 'programme_id' => 1, - 'name' => 'Some Site', - 'description' => 'A site, somewhere', - ]); - } - - public function testReadAllByProgrammeActionRequiresBelongingToProgramme(): void - { - $headers = $this->getHeaders('sue@example.com', 'Password123'); - $this->getJson('/api/programme/1/sites', $headers) - ->assertStatus(403); - } - - public function testAttachRestorationMethodsAction(): void - { - $headers = $this->getHeaders('steve@example.com', 'Password123'); - - $this->postJson('/api/site/1/restoration_methods', [ - 'site_restoration_method_ids' => [1], - ], $headers) - ->assertStatus(201) - ->assertJsonFragment([ - 'id' => 1, - ]) - ->assertJsonPath('data.restoration_methods.0.id', 1) - ->assertJsonPath('data.restoration_methods.0.name', 'Mangrove Tree Restoration'); - } - - public function testAttachRestorationMethodsActionRequiresRestorationMethodIDs(): void - { - $headers = $this->getHeaders('steve@example.com', 'Password123'); - - $this->postJson('/api/site/1/restoration_methods', $headers) - ->assertStatus(422); - } - - public function testAttachRestorationMethodsActionRequiresRestorationMethodIDsToExist(): void - { - $headers = $this->getHeaders('steve@example.com', 'Password123'); - - $this->postJson('/api/site/1/restoration_methods', [ - 'site_restoration_method_ids' => [10, 11, 2144], - ], $headers) - ->assertStatus(422); - } - - public function testUpdateEstablishmentDateAction(): void - { - $headers = $this->getHeaders('steve@example.com', 'Password123'); - - $this->postJson('/api/site/1/establishment_date', [ - 'establishment_date' => '2000-10-06', - ], $headers) - ->assertStatus(201) - ->assertJsonFragment([ - 'id' => 1, - 'programme_id' => 1, - 'name' => 'Some Site', - 'description' => 'A site, somewhere', - 'establishment_date' => '2000-10-06', - ]); - } - - public function testAttachLandTenureAction(): void - { - $headers = $this->getHeaders('steve@example.com', 'Password123'); - - $this->postJson('/api/site/1/land_tenure', [ - 'land_tenure_ids' => [1], - ], $headers) - ->assertStatus(201) - ->assertJsonFragment([ - 'id' => 1, - 'programme_id' => 1, - ]) - ->assertJsonPath('data.land_tenures.0.id', 1) - ->assertJsonPath('data.land_tenures.0.name', 'Public'); - } - - public function testAttachLandTenureActionRequiresLandTenureIdToExist(): void - { - $headers = $this->getHeaders('steve@example.com', 'Password123'); - - $this->postJson('/api/site/1/land_tenure', [ - 'land_tenure_ids' => [138274], - ], $headers) - ->assertStatus(422); - } - - public function testCreateNarrativeAction(): void - { - $headers = $this->getHeaders('steve@example.com', 'Password123'); - - $this->postJson('/api/site/1/narrative', [ - 'technical_narrative' => 'this is a technical narrative piece', - 'public_narrative' => 'this is a public narrative piece', - ], $headers) - ->assertStatus(201) - ->assertJsonFragment([ - 'id' => 1, - 'technical_narrative' => 'this is a technical narrative piece', - 'public_narrative' => 'this is a public narrative piece', - ]); - } - - public function testUpdateEstablishmentDateActionRequiresDate(): void - { - $headers = $this->getHeaders('steve@example.com', 'Password123'); - - $this->postJson('/api/site/1/establishment_date', [ - 'establishment_date' => 'this is not a date', - ], $headers) - ->assertStatus(422); - } - - public function testCreateNarrativeActionRequiresTechnicalNarrative(): void - { - $headers = $this->getHeaders('steve@example.com', 'Password123'); - - $this->postJson('/api/site/1/narrative', [ - 'public_narrative' => 'this is a public narrative piece', - ], $headers) - ->assertStatus(422); - } - - public function testCreateNarrativeActionRequiresPublicNarrative(): void - { - $headers = $this->getHeaders('steve@example.com', 'Password123'); - - $this->postJson('/api/site/1/narrative', [ - 'technical_narrative' => 'this is a technical narrative piece', - ], $headers) - ->assertStatus(422); - } - - public function testCreateNarrativeActionRequiresBeingJoinedToTheSitesProgramme(): void - { - $headers = $this->getHeaders('sue@example.com', 'Password123'); - - $this->postJson('/api/site/1/narrative', [ - 'technical_narrative' => 'this is a technical narrative piece', - 'public_narrative' => 'this is a public narrative piece', - ], $headers) - ->assertStatus(403); - } - - public function testCreateAimAction(): void - { - $headers = $this->getHeaders('steve@example.com', 'Password123'); - - $this->postJson('/api/site/1/aims', [ - 'aim_survival_rate' => 24, - 'aim_year_five_crown_cover' => 50, - 'aim_direct_seeding_survival_rate' => 50, - 'aim_natural_regeneration_trees_per_hectare' => 2000, - 'aim_natural_regeneration_hectares' => 137, - 'aim_soil_condition' => 'good', - 'aim_number_of_mature_trees' => 1000, - ], $headers) - ->assertStatus(201) - ->assertJsonFragment([ - 'id' => 1, - 'aim_survival_rate' => 24, - 'aim_year_five_crown_cover' => 50, - 'aim_direct_seeding_survival_rate' => 50, - 'aim_natural_regeneration_trees_per_hectare' => 2000, - 'aim_natural_regeneration_hectares' => 137, - 'aim_soil_condition' => 'good', - 'aim_number_of_mature_trees' => 1000, - ]); - } - - public function testCreateAimActionDoesNotRequireSurvivalRate(): void - { - $headers = $this->getHeaders('steve@example.com', 'Password123'); - - $this->postJson('/api/site/1/aims', [ - 'aim_year_five_crown_cover' => 50, - ], $headers) - ->assertStatus(201); - } - - public function testCreateAimActionRequiresYearFiveCrownCover(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $this->postJson('/api/site/1/aims', [ - 'aim_survival_rate' => 50, - ], $headers) - ->assertStatus(422); - } -} diff --git a/tests/Legacy/Feature/SiteRestorationMethodsControllerTest.php b/tests/Legacy/Feature/SiteRestorationMethodsControllerTest.php deleted file mode 100644 index aa36c107d..000000000 --- a/tests/Legacy/Feature/SiteRestorationMethodsControllerTest.php +++ /dev/null @@ -1,34 +0,0 @@ - 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $this->getJson('/api/site/restoration_methods', $headers) - ->assertStatus(200) - ->assertJsonFragment([ - 'id' => 1, - 'name' => 'Mangrove Tree Restoration', - 'key' => 'mangrove_tree_restoration', - ]) - ->assertJsonFragment([ - 'id' => 2, - 'name' => 'Assisted Natural Regeneration', - 'key' => 'assisted_natural_regeneration', - ]); - } -} diff --git a/tests/Legacy/Feature/SiteSubmissionControllerTest.php b/tests/Legacy/Feature/SiteSubmissionControllerTest.php deleted file mode 100644 index 492cfa97f..000000000 --- a/tests/Legacy/Feature/SiteSubmissionControllerTest.php +++ /dev/null @@ -1,185 +0,0 @@ -getHeaders('steve@example.com', 'Password123'); - - $dueSubmission = DueSubmission::factory()->create([ - 'due_submissionable_type' => Site::class, - 'due_submissionable_id' => 1, - ]); - - $data = [ - 'site_id' => 1, - 'created_by' => 'test user 3', - 'direct_seeding_kg' => 12, - 'due_submission_id' => $dueSubmission->id, - 'technical_narrative' => 'Some technical narrative', - 'workdays_paid' => 5, - 'workdays_volunteer' => 8, - ]; - - $response = $this->postJson('/api/site/submission', $data, $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(201); - $response->assertJsonFragment([ - 'site_id' => 1, - 'direct_seeding_kg' => 12, - 'workdays_paid' => 5, - 'workdays_volunteer' => 8, - 'total_workdays' => 13, - ]); - } - - public function testUpdateAction(): void - { - $headers = $this->getHeaders('steve@example.com', 'Password123'); - $data = [ - 'direct_seeding_kg' => 1232, - 'workdays_paid' => 2, - 'workdays_volunteer' => 6, - ]; - - $response = $this->patchJson('/api/site/submission/1', $data, $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - } - - public function testUpdateAdditionalTreeSpeciesAction(): void - { - $headers = $this->getHeaders('steve@example.com', 'Password123'); - - Queue::fake(); - - $uploadResponse = $this->post('/api/uploads', [ - 'upload' => $this->fakeValidCsv(), - ], $headers); - - $data = [ - 'direct_seeding_kg' => 1232, - 'workdays_paid' => 2, - 'workdays_volunteer' => 6, - 'additional_tree_species' => $uploadResponse->json('data.id'), - ]; - - $response = $this->patchJson('/api/site/submission/1', $data, $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - } - - public function testApproveAction(): void - { - $headers = $this->getHeaders('jane@example.com', 'Password123'); - - $this->getJson('/api/site/submission/1', $headers) - ->assertStatus(200) - ->assertJsonFragment([ - 'status' => SiteSubmission::STATUS_AWAITING_APPROVAL, - ]); - - $response = $this->patchJson('/api/site/submission/1/approve', $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonFragment([ - 'status' => SiteSubmission::STATUS_APPROVED, - ]); - } - - public function testApproveForbiddenAction(): void - { - $headers = $this->getHeaders('steve@example.com', 'Password123'); - - $this->getJson('/api/site/submission/1', $headers) - ->assertStatus(200) - ->assertJsonFragment([ - 'status' => SiteSubmission::STATUS_AWAITING_APPROVAL, - ]); - - $response = $this->patchJson('/api/site/submission/1/approve', $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(403); - - $this->getJson('/api/site/submission/1', $headers) - ->assertStatus(200) - ->assertJsonFragment([ - 'status' => SiteSubmission::STATUS_AWAITING_APPROVAL, - ]); - } - - public function testUpdatingCreatedByInUpdateAction(): void - { - $headers = $this->getHeaders('steve@example.com', 'Password123'); - $data = [ - 'created_by' => 'a new user', - ]; - - $response = $this->patchJson('/api/site/submission/1', $data, $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonFragment([ - 'created_by' => 'a new user', - ]); - } - - public function testCreateActionRequiresSiteId(): void - { - $headers = $this->getHeaders('steve@example.com', 'Password123'); - - $data = []; - - $this->postJson('/api/site/submission', $data, $headers) - ->assertHeader('Content-Type', 'application/json') - ->assertStatus(422); - } - - public function testCreateActionRequiresAccessToSite(): void - { - $headers = $this->getHeaders('sue@example.com', 'Password123'); - $data = [ - 'site_id' => 1, - 'created_by' => 'test user 7', - ]; - - $this->postJson('/api/site/submission', $data, $headers) - ->assertHeader('Content-Type', 'application/json') - ->assertStatus(403); - } - - public function testReadAllBySiteAction(): void - { - $headers = $this->getHeaders('steve@example.com', 'Password123'); - - $this->getJson('/api/site/1/submissions', $headers) - ->assertHeader('Content-Type', 'application/json') - ->assertStatus(200) - ->assertJsonFragment([ - 'id' => 1, - ]) - ->assertJsonFragment([ - 'id' => 2, - ]); - } - - public function testReadAction(): void - { - $headers = $this->getHeaders('steve@example.com', 'Password123'); - - $this->getJson('/api/site/submission/1', $headers) - ->assertHeader('Content-Type', 'application/json') - ->assertStatus(200) - ->assertJsonFragment([ - 'id' => 1, - 'site_id' => 1, - ]); - } -} diff --git a/tests/Legacy/Feature/SiteSubmissionDisturbanceControllerTest.php b/tests/Legacy/Feature/SiteSubmissionDisturbanceControllerTest.php deleted file mode 100644 index abe19fa38..000000000 --- a/tests/Legacy/Feature/SiteSubmissionDisturbanceControllerTest.php +++ /dev/null @@ -1,328 +0,0 @@ - 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $data = [ - 'site_submission_id' => 1, - 'disturbance_type' => 'manmade', - 'extent' => '61-80', - 'intensity' => 'high', - 'description' => 'description of disturbance', - ]; - - $this->postJson('/api/site/submission/disturbance', $data, $headers) - ->assertHeader('Content-Type', 'application/json') - ->assertStatus(201) - ->assertJsonFragment([ - 'site_submission_id' => 1, - 'disturbance_type' => 'manmade', - 'extent' => '61-80', - 'intensity' => 'high', - 'description' => 'description of disturbance', - ]); - } - - public function testCreateActionRequiresBeingPartOfSiteProgramme(): void - { - $token = Auth::attempt([ - 'email_address' => 'sue@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $data = [ - 'site_submission_id' => 1, - 'disturbance_type' => 'manmade', - 'extent' => '61-80', - 'intensity' => 'high', - 'description' => 'description of disturbance', - ]; - - $this->postJson('/api/site/submission/disturbance', $data, $headers) - ->assertStatus(403); - } - - public function testCreateActionRequiresSubmissionId(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $data = [ - 'disturbance_type' => 'manmade', - 'extent' => '61-80', - 'intensity' => 'high', - 'description' => 'description of disturbance', - ]; - - $this->postJson('/api/site/submission/disturbance', $data, $headers) - ->assertHeader('Content-Type', 'application/json') - ->assertStatus(422); - } - - public function testCreateActionRequiresDisturbanceType(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $data = [ - 'site_submission_id' => 1, - 'extent' => '61-80', - 'intensity' => 'high', - 'description' => 'description of disturbance', - ]; - - $this->postJson('/api/site/submission/disturbance', $data, $headers) - ->assertHeader('Content-Type', 'application/json') - ->assertStatus(422); - } - - public function testCreateActionRequiresIntensity(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $data = [ - 'site_submission_id' => 1, - 'disturbance_type' => 'manmade', - 'extent' => '61-80', - 'description' => 'description of disturbance', - ]; - - $this->postJson('/api/site/submission/disturbance', $data, $headers) - ->assertHeader('Content-Type', 'application/json') - ->assertStatus(422); - } - - public function testCreateActionDoesNotRequireDescription(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $data = [ - 'site_submission_id' => 1, - 'extent' => '61-80', - 'disturbance_type' => 'ecological', - 'intensity' => 'high', - ]; - - $this->postJson('/api/site/submission/disturbance', $data, $headers) - ->assertHeader('Content-Type', 'application/json') - ->assertStatus(201) - ->assertJsonFragment([ - 'site_submission_id' => 1, - 'disturbance_type' => 'ecological', - 'extent' => '61-80', - 'intensity' => 'high', - 'description' => null, - ]); - } - - public function testUpdateAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $data = [ - 'disturbance_type' => 'manmade', - 'extent' => '61-80', - 'intensity' => 'medium', - 'description' => 'new description of disturbance', - ]; - - $this->putJson('/api/site/submission/disturbance/1', $data, $headers) - ->assertHeader('Content-Type', 'application/json') - ->assertStatus(200) - ->assertJsonFragment([ - 'id' => 1, - 'site_submission_id' => 1, - 'disturbance_type' => 'manmade', - 'extent' => '61-80', - 'intensity' => 'medium', - 'description' => 'new description of disturbance', - ]); - } - - public function testDeleteAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $this->deleteJson('/api/site/submission/disturbance/1', $headers) - ->assertHeader('Content-Type', 'application/json') - ->assertStatus(200); - } - - public function testCreateDisturbanceInformationAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $data = [ - 'site_submission_id' => 1, - 'disturbance_information' => 'this is some disturbance information', - ]; - - $this->postJson('/api/site/submission/disturbance_information', $data, $headers) - ->assertHeader('Content-Type', 'application/json') - ->assertStatus(200) - ->assertJsonFragment([ - 'id' => 1, - 'disturbance_information' => 'this is some disturbance information', - ]); - } - - public function testCreateDisturbanceInformationActionRequiresBeingPartOfProgramme(): void - { - $token = Auth::attempt([ - 'email_address' => 'sue@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $data = [ - 'site_submission_id' => 1, - 'disturbance_information' => 'this is some disturbance information', - ]; - - $this->postJson('/api/site/submission/disturbance_information', $data, $headers) - ->assertHeader('Content-Type', 'application/json') - ->assertStatus(403); - } - - public function testCreateDisturbanceInformationActionRequiresSiteSubmissionId(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $data = [ - 'disturbance_information' => 'this is some disturbance information', - ]; - - $this->postJson('/api/site/submission/disturbance_information', $data, $headers) - ->assertHeader('Content-Type', 'application/json') - ->assertStatus(422); - } - - public function testCreateDisturbanceInformationActionRequiresDisturbanceInformation(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $data = [ - 'site_submission_id' => 1, - ]; - - $this->postJson('/api/site/submission/disturbance_information', $data, $headers) - ->assertHeader('Content-Type', 'application/json') - ->assertStatus(422); - } - - public function testUpdateDisturbanceInformationAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $data = [ - 'disturbance_information' => 'this is some new disturbance information', - ]; - - $this->putJson('/api/site/submission/disturbance_information/1', $data, $headers) - ->assertHeader('Content-Type', 'application/json') - ->assertStatus(200) - ->assertJsonFragment([ - 'id' => 1, - 'disturbance_information' => 'this is some new disturbance information', - ]); - } - - public function testDeleteDisturbanceInformationAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $this->deleteJson('/api/site/submission/disturbance_information/1', $headers) - ->assertHeader('Content-Type', 'application/json') - ->assertStatus(200); - - $this->assertDatabaseHas('site_submissions', [ - 'id' => 1, - 'disturbance_information' => null, - ]); - } -} diff --git a/tests/Legacy/Feature/SiteTreeSpeciesControllerTest.php b/tests/Legacy/Feature/SiteTreeSpeciesControllerTest.php deleted file mode 100644 index 96f9a4488..000000000 --- a/tests/Legacy/Feature/SiteTreeSpeciesControllerTest.php +++ /dev/null @@ -1,145 +0,0 @@ - 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $data = [ - 'site_id' => 1, - 'name' => 'test tree species name', - 'amount' => 5, - ]; - - $response = $this->postJson('/api/site/1/tree_species/manual', $data, $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure([ - 'data' => [ - 'id', - 'site_id', - 'name', - 'amount', - 'created_at', - ], - ]); - } - - public function testCreateBulkAction() - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $data = [ - 'site_submission_id' => 1, - 'tree_species' => [ - [ - 'name' => 'tree 1', - ], [ - 'name' => 'tree 2', - ], - ], - ]; - - $this->assertDatabaseCount('site_tree_species', 3); // 3 total - - $this->postJson('/api/site/1/tree_species/bulk', $data, $headers) - ->assertStatus(200); - - $this->assertDatabaseCount('site_tree_species', 4); // 2 elsewhere, 1 cleared from this submission, plus 2 from this call - } - - public function testDeleteAction() - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $this->deleteJson('/api/site/tree_species/1', $headers) - ->assertStatus(200); - } - - public function testDeleteActionRequiresBeingPartOfProgramme(): void - { - $token = Auth::attempt([ - 'email_address' => 'sue@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $this->deleteJson('/api/site/tree_species/1', $headers) - ->assertStatus(403); - } - - public function testReadAllAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $response = $this->getJson('/api/sites/tree_species', $headers); - $response->assertStatus(200); - } - - public function testReadAllBySiteAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $this->getJson('/api/site/1/tree_species', $headers) - ->assertStatus(200) - ->assertJsonCount(2, 'data'); - } - - public function testAdminReadAllBySiteAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'jane@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $this->getJson('/api/site/1/tree_species', $headers) - ->assertStatus(200) - ->assertJsonCount(2, 'data'); - } -} diff --git a/tests/Legacy/Feature/SiteTreeSpeciesCsvControllerTest.php b/tests/Legacy/Feature/SiteTreeSpeciesCsvControllerTest.php deleted file mode 100644 index bf9d8cb55..000000000 --- a/tests/Legacy/Feature/SiteTreeSpeciesCsvControllerTest.php +++ /dev/null @@ -1,133 +0,0 @@ - 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $response = $this->post('/api/uploads', [ - 'upload' => $this->fakeValidCsv(), - ], $headers); - - - $this->postJson('/api/site/1/tree_species/csv', [ - 'upload_id' => $response->json('data.id'), - ], $headers) - ->assertStatus(200); - } - - public function testCreateActionFileRequiresHeaders(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $response = $this->post('/api/uploads', [ - 'upload' => $this->fakeNoHeadersCsv(), - ], $headers); - - $this->postJson('/api/site/1/tree_species/csv', [ - 'upload_id' => $response->json('data.id'), - ], $headers) - ->assertStatus(422); - } - - public function testCreateActionFileIsRequired(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $this->postJson('/api/site/1/tree_species/csv', $headers) - ->assertStatus(422); - } - - public function testCreateActionRequiresBelongingToSiteProgramme(): void - { - $token = Auth::attempt([ - 'email_address' => 'sue@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $this->postJson('/api/site/1/tree_species/csv', $headers) - ->assertStatus(403); - } - - public function testReadAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $this->getJson('/api/site/tree_species/csv/1', $headers) - ->assertStatus(200) - ->assertJsonFragment([ - 'id' => 1, - 'site_id' => 1, - 'total_rows' => 10, - 'has_failed' => false, - ]); - } - - public function testReadTreeSpeciesAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $this->getJson('/api/site/tree_species/csv/1/trees', $headers) - ->assertStatus(200) - ->assertJsonFragment([ - 'id' => 2, - 'name' => 'A tree species', - 'site_id' => 1, - 'amount' => 500, - ]); - } - - public function testDownloadCsvTemplateAction(): void - { - $headers = [ - 'Content-Type' => 'application/json', - ]; - - $this->getJson('/api/site/tree_species/template/csv', $headers) - ->assertStatus(200); - } -} diff --git a/tests/Legacy/Feature/SocioeconomicBenefitsControllerTest.php b/tests/Legacy/Feature/SocioeconomicBenefitsControllerTest.php deleted file mode 100644 index a2e631b9d..000000000 --- a/tests/Legacy/Feature/SocioeconomicBenefitsControllerTest.php +++ /dev/null @@ -1,148 +0,0 @@ - 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $data = [ - 'upload' => 8, - 'name' => 'test benefit', - 'programme_id' => 1, - ]; - - $response = $this->postJson('/api/uploads/socioeconomic_benefits', $data, $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - } - - public function testUpdateAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $data = [ - 'upload' => 41, - 'name' => 'new test benefit', - 'site_submission_id' => 1, - 'site_id' => 1, - ]; - - $response = $this->patchJson('/api/uploads/socioeconomic_benefits', $data, $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - - $this->assertDatabaseMissing('socioeconomic_benefits', [ - 'site_submission_id' => 1, - 'name' => 'test benefit', - ]); - - $this->assertDatabaseHas('socioeconomic_benefits', [ - 'site_submission_id' => 1, - 'name' => 'new test benefit', - ]); - } - - public function testUpdateActionWhenNoFileCurrentlyExists(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $data = [ - 'upload' => 40, - 'name' => 'new test benefit', - 'site_submission_id' => 3, - 'site_id' => 1, - ]; - - $this->assertDatabaseMissing('socioeconomic_benefits', [ - 'site_submission_id' => 3, - ]); - - $response = $this->patchJson('/api/uploads/socioeconomic_benefits', $data, $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - - $this->assertDatabaseHas('socioeconomic_benefits', [ - 'site_submission_id' => 3, - 'name' => 'new test benefit', - ]); - } - - public function testDownloadTemplateAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $this->getJson('/api/uploads/socioeconomic_benefits/template', $headers) - ->assertStatus(200); - } - - public function testDownloadSiteSubmissionTemplateAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $this->getJson('/api/uploads/socioeconomic_benefits/template/site_submission', $headers) - ->assertStatus(200); - } - - public function testDownloadProgrammeSubmissionTemplateAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $this->getJson('/api/uploads/socioeconomic_benefits/template/programme_submission', $headers) - ->assertStatus(200); - } - - public function testDownloadCsvTemplateAction(): void - { - $headers = [ - 'Content-Type' => 'application/json', - ]; - - $this->getJson('/api/uploads/socioeconomic_benefits/template/csv', $headers) - ->assertStatus(200); - } -} diff --git a/tests/Legacy/Feature/StratificationControllerTest.php b/tests/Legacy/Feature/StratificationControllerTest.php deleted file mode 100644 index 640004103..000000000 --- a/tests/Legacy/Feature/StratificationControllerTest.php +++ /dev/null @@ -1,24 +0,0 @@ - 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $this->getJson('/api/uploads/stratification/example', $headers) - ->assertStatus(200); - } -} diff --git a/tests/Legacy/Feature/SubmissionControllerTest.php b/tests/Legacy/Feature/SubmissionControllerTest.php deleted file mode 100644 index d0620d46c..000000000 --- a/tests/Legacy/Feature/SubmissionControllerTest.php +++ /dev/null @@ -1,191 +0,0 @@ -getHeaders('steve@example.com', 'Password123'); - - $data = [ - 'title' => 'test title', - 'technical_narrative' => 'test tech narrative', - 'public_narrative' => 'test public narrative', - 'created_by' => 'test user', - 'workdays_paid' => 99998, - 'workdays_volunteer' => 99999, - ]; - - $response = $this->postJson('/api/programme/1/submission', $data, $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(201); - $response->assertJsonFragment([ - 'title' => 'test title', - 'technical_narrative' => 'test tech narrative', - 'public_narrative' => 'test public narrative', - 'created_by' => 'test user', - 'workdays_paid' => 99998, - 'workdays_volunteer' => 99999, - 'total_workdays' => 199997, - ]); - } - - public function testUpdateAction(): void - { - $headers = $this->getHeaders('steve@example.com', 'Password123'); - - $data = [ - 'title' => 'a new title', - 'technical_narrative' => 'a new test tech narrative', - 'workdays_paid' => 4, - 'workdays_volunteer' => 12, - ]; - - $response = $this->patchJson('/api/programme/submission/1', $data, $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - } - - public function testUpdateActionAsAdmin(): void - { - $headers = $this->getHeaders('jane@example.com', 'Password123'); - - $data = [ - 'title' => 'admin edit', - 'technical_narrative' => 'admin edit', - 'workdays_paid' => 10, - 'workdays_volunteer' => 20, - ]; - - /** - * It's important to check the admin user is not in the programme here, - * otherwise the test would pass by using the regular policy, not the - * admin one. - */ - $this->assertDatabaseMissing('programme_user', [ - 'programme_id' => 1, - 'user_id' => 2, - ]); - - $this->patchJson('/api/programme/submission/1', $data, $headers) - ->assertJsonFragment($data) - ->assertStatus(200); - } - - public function testUpdateAdditionalTreeSpeciesAction(): void - { - $headers = $this->getHeaders('steve@example.com', 'Password123'); - - Queue::fake(); - - $uploadResponse = $this->post('/api/uploads', [ - 'upload' => $this->fakeValidCsv(), - ], $headers); - - $data = [ - 'title' => 'a new title', - 'technical_narrative' => 'a new test tech narrative', - 'workdays_paid' => 4, - 'workdays_volunteer' => 12, - 'additional_tree_species' => $uploadResponse->json('data.id'), - ]; - - $response = $this->patchJson('/api/programme/submission/1', $data, $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - } - - public function testApproveAction(): void - { - $headers = $this->getHeaders('jane@example.com', 'Password123'); - - $this->getJson('/api/programme/submission/1', $headers) - ->assertStatus(200) - ->assertJsonFragment([ - 'status' => Submission::STATUS_AWAITING_APPROVAL, - ]); - - $response = $this->patchJson('/api/programme/submission/1/approve', $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonFragment([ - 'status' => Submission::STATUS_APPROVED, - ]); - } - - public function testApproveForbiddenAction(): void - { - $headers = $this->getHeaders('steve@example.com', 'Password123'); - - $this->getJson('/api/programme/submission/1', $headers) - ->assertStatus(200) - ->assertJsonFragment([ - 'status' => Submission::STATUS_AWAITING_APPROVAL, - ]); - - $response = $this->patchJson('/api/programme/submission/1/approve', $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(403); - - $this->getJson('/api/programme/submission/1', $headers) - ->assertStatus(200) - ->assertJsonFragment([ - 'status' => Submission::STATUS_AWAITING_APPROVAL, - ]); - } - - public function testUpdatingCreatedByInUpdateAction(): void - { - $headers = $this->getHeaders('steve@example.com', 'Password123'); - - $data = [ - 'created_by' => 'a new user', - ]; - - $response = $this->patchJson('/api/programme/submission/1', $data, $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonFragment([ - 'created_by' => 'a new user', - ]); - } - - public function testReadByProgrammeAction(): void - { - $headers = $this->getHeaders('steve@example.com', 'Password123'); - - $this->getJson('/api/programme/1/submissions', $headers) - ->assertStatus(200) - ->assertJsonPath('data.0.id', 1); - } - - public function testReadByProgrammeActionRequiresBelongingToProgramme(): void - { - $headers = $this->getHeaders('sue@example.com', 'Password123'); - - $this->getJson('/api/programme/1/submissions', $headers) - ->assertStatus(403); - } - - public function testReadAction(): void - { - $headers = $this->getHeaders('steve@example.com', 'Password123'); - - $this->getJson('/api/programme/submission/1', $headers) - ->assertStatus(200) - ->assertJsonPath('data.id', 1); - } - - public function testReadActionRequiresBelongingToProgramme(): void - { - $headers = $this->getHeaders('sue@example.com', 'Password123'); - - $this->getJson('/api/programme/submission/1', $headers) - ->assertStatus(403); - } -} diff --git a/tests/Legacy/Feature/SubmissionMediaUploadControllerTest.php b/tests/Legacy/Feature/SubmissionMediaUploadControllerTest.php deleted file mode 100644 index 172a0d567..000000000 --- a/tests/Legacy/Feature/SubmissionMediaUploadControllerTest.php +++ /dev/null @@ -1,61 +0,0 @@ - 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $data = [ - 'is_public' => true, - 'submission_id' => 1, - 'upload' => 1, - ]; - - $response = $this->postJson('/api/submission/upload/submission_media', $data, $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(201); - } - - public function testDeleteAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $response = $this->deleteJson('/api/submission/upload/submission_media/1', $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - } - - public function testDownloadTemplateAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $this->getJson('/api/submission/submission_questions', $headers) - ->assertStatus(200); - } -} diff --git a/tests/Legacy/Feature/TargetsControllerTest.php b/tests/Legacy/Feature/TargetsControllerTest.php deleted file mode 100644 index ba30398bc..000000000 --- a/tests/Legacy/Feature/TargetsControllerTest.php +++ /dev/null @@ -1,242 +0,0 @@ - 1, - 'start_date' => '2020-01-01', - 'finish_date' => '2021-01-01', - 'funding_amount' => 1000000, - 'land_geojson' => '{"type":"Polygon","coordinates":[[[-1.864006519317627,50.7219083651253],[-1.8627190589904783,50.7219083651253],[-1.8627190589904783,50.72276418262861],[-1.864006519317627,50.72276418262861],[-1.864006519317627,50.7219083651253]]]}', - 'data' => [ - 'trees_planted' => 123, - 'non_trees_planted' => 456, - 'survival_rate' => 75, - 'land_size_planted' => 7.5, - 'land_size_restored' => 7.5, - ], - ]; - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->postJson('/api/targets', $data, $headers); - $response->assertStatus(201); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertJsonStructure([ - 'data' => [ - 'id', - 'monitoring_id', - 'negotiator', - 'start_date', - 'finish_date', - 'funding_amount', - 'land_geojson', - 'data' => [ - 'trees_planted', - 'non_trees_planted', - 'survival_rate', - 'land_size_planted', - 'land_size_restored', - ], - 'created_at', - 'created_by', - 'updated_at', - 'accepted_at', - 'accepted_by', - ], - ]); - } - - public function testReadAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->getJson('/api/targets/1', $headers); - $response->assertStatus(200); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertJsonStructure([ - 'data' => [ - 'id', - 'monitoring_id', - 'negotiator', - 'start_date', - 'finish_date', - 'funding_amount', - 'land_geojson', - 'data' => [ - 'trees_planted', - 'non_trees_planted', - 'survival_rate', - 'land_size_planted', - 'land_size_restored', - ], - 'created_at', - 'created_by', - 'updated_at', - 'accepted_at', - 'accepted_by', - ], - ]); - } - - public function testReadAllByMonitoringAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->getJson('/api/monitorings/1/targets', $headers); - $response->assertStatus(200); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertJsonStructure([ - 'data' => [ - [ - 'id', - 'monitoring_id', - 'negotiator', - 'start_date', - 'finish_date', - 'funding_amount', - 'land_geojson', - 'data' => [ - 'trees_planted', - 'non_trees_planted', - 'survival_rate', - 'land_size_planted', - 'land_size_restored', - ], - 'created_at', - 'created_by', - 'updated_at', - 'accepted_at', - 'accepted_by', - ], - ], - ]); - } - - public function testAcceptAction(): void - { - $this->callAcceptActionAsValidUser(); - $this->callAcceptActionAsInvalidUser(); - } - - public function callAcceptActionAsValidUser() - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->patchJson('/api/targets/2/accept', $headers); - $response->assertStatus(200); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertJsonStructure([ - 'data' => [ - 'id', - 'monitoring_id', - 'negotiator', - 'start_date', - 'finish_date', - 'funding_amount', - 'land_geojson', - 'data' => [ - 'trees_planted', - 'non_trees_planted', - 'survival_rate', - 'land_size_planted', - 'land_size_restored', - ], - 'created_at', - 'created_by', - 'updated_at', - 'accepted_at', - 'accepted_by', - ], - ]); - $response = $this->getJson('/api/monitorings/1', $headers); - $response->assertStatus(200); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertJson([ - 'data' => [ - 'stage' => 'accepted_targets', - ], - ]); - } - - public function callAcceptActionAsInvalidUser() - { - $token = Auth::attempt([ - 'email_address' => 'andrew@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->patchJson('/api/targets/2/accept', $headers); - $response->assertStatus(403); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertJsonStructure([ - 'errors' => [], - ]); - } - - public function testReadAcceptedByMonitoringAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $this->patchJson('/api/targets/2/accept', $headers); - $response = $this->getJson('/api/monitorings/1/targets/accepted', $headers); - $response->assertStatus(200); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertJsonStructure([ - 'data' => [ - 'id', - 'monitoring_id', - 'negotiator', - 'start_date', - 'finish_date', - 'funding_amount', - 'land_geojson', - 'data' => [ - 'trees_planted', - 'non_trees_planted', - 'survival_rate', - 'land_size_planted', - 'land_size_restored', - ], - 'created_at', - 'created_by', - 'updated_at', - 'accepted_at', - 'accepted_by', - ], - ]); - } -} diff --git a/tests/Legacy/Feature/TasksControllerTest.php b/tests/Legacy/Feature/TasksControllerTest.php deleted file mode 100644 index d7629e04a..000000000 --- a/tests/Legacy/Feature/TasksControllerTest.php +++ /dev/null @@ -1,236 +0,0 @@ - 'jane@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $response = $this->getJson('/api/tasks/organisations', $headers); - $response->assertStatus(200); - $response->assertJsonCount(2, 'data'); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertJsonFragment([ - 'id' => 1, - ]); - $response->assertJsonFragment([ - 'id' => 4, - ]); - $response->assertJsonStructure([ - 'data' => [ - [ - 'id', - 'name', - ], - ], - ]); - } - - public function testReadAllOrganisationsActionAsTerrafundAdmin(): void - { - $token = Auth::attempt([ - 'email_address' => 'terrafund.admin@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $response = $this->getJson('/api/tasks/organisations', $headers); - $response->assertStatus(200); - $response->assertJsonCount(1, 'data'); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertJsonMissing([ - 'id' => 1, - ]); - $response->assertJsonFragment([ - 'id' => 4, - ]); - $response->assertJsonStructure([ - 'data' => [ - [ - 'id', - 'name', - ], - ], - ]); - } - - public function testReadAllPitchesAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'jane@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $response = $this->getJson('/api/tasks/pitches', $headers); - $response->assertStatus(200); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertJsonStructure([ - 'data' => [ - [ - 'id', - 'name', - ], - ], - ]); - } - - public function testReadAllMatchesAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'jane@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $response = $this->getJson('/api/tasks/matches', $headers); - $response->assertStatus(200); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertJsonStructure(['data' => [ - [ - 'id', - 'offer_id', - 'offer_name', - 'offer_interest_id', - 'offer_contacts' => [ - [ - 'first_name', - 'last_name', - 'avatar', - 'email_address', - 'phone_number', - ], - ], - 'pitch_id', - 'pitch_name', - 'pitch_interest_id', - 'pitch_contacts' => [ - [ - 'first_name', - 'last_name', - 'avatar', - 'email_address', - 'phone_number', - ], - ], - 'monitoring_id', - 'matched_at', - ], - ]]); - } - - public function testReadAllMonitoringsAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'jane@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->getJson('/api/tasks/monitorings', $headers); - $response->assertStatus(200); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertJsonStructure([ - 'data' => [ - [ - 'id', - 'match_id', - 'initiator', - 'stage', - 'negotiating', - 'created_by', - 'created_at', - 'pitch' => [ - 'id', - 'organisation_id', - 'name', - 'description', - 'land_types', - 'land_ownerships', - 'land_size', - 'land_continent', - 'land_country', - 'land_geojson', - 'restoration_methods', - 'restoration_goals', - 'funding_sources', - 'funding_amount', - 'revenue_drivers', - 'estimated_timespan', - 'long_term_engagement', - 'reporting_frequency', - 'reporting_level', - 'sustainable_development_goals', - 'avatar', - 'cover_photo', - 'video', - 'problem', - 'anticipated_outcome', - 'who_is_involved', - 'local_community_involvement', - 'training_involved', - 'training_type', - 'training_amount_people', - 'people_working_in', - 'people_amount_nearby', - 'people_amount_abroad', - 'people_amount_employees', - 'people_amount_volunteers', - 'benefited_people', - 'future_maintenance', - 'use_of_resources', - 'facebook', - 'twitter', - 'instagram', - 'successful', - 'visibility', - ], - 'offer' => [ - 'id', - 'organisation_id', - 'name', - 'description', - 'land_types', - 'land_ownerships', - 'land_size', - 'land_continent', - 'land_country', - 'restoration_methods', - 'restoration_goals', - 'funding_sources', - 'funding_amount', - 'funding_bracket', - 'price_per_tree', - 'long_term_engagement', - 'reporting_frequency', - 'reporting_level', - 'sustainable_development_goals', - 'cover_photo', - 'video', - 'created_at', - 'successful', - ], - 'updated_at', - ], - ], - ]); - } -} diff --git a/tests/Legacy/Feature/TeamMembersControllerTest.php b/tests/Legacy/Feature/TeamMembersControllerTest.php deleted file mode 100644 index 1783003aa..000000000 --- a/tests/Legacy/Feature/TeamMembersControllerTest.php +++ /dev/null @@ -1,192 +0,0 @@ - 'Oliver', - 'last_name' => 'Smith', - 'job_role' => 'Manager', - 'facebook' => null, - 'twitter' => null, - 'linkedin' => null, - 'instagram' => null, - 'avatar' => null, - 'phone_number' => null, - 'email_address' => null, - ]; - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $response = $this->postJson('/api/team_members', $data, $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(201); - $response->assertJsonStructure([ - 'data' => [ - 'id', - 'organisation_id', - 'first_name', - 'last_name', - 'job_role', - 'facebook', - 'twitter', - 'linkedin', - 'instagram', - 'avatar', - ], - 'meta' => [], - ]); - } - - public function testReadAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->getJson('/api/team_members/1', $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure([ - 'data' => [ - 'id', - 'organisation_id', - 'first_name', - 'last_name', - 'job_role', - 'facebook', - 'twitter', - 'linkedin', - 'instagram', - 'avatar', - ], - ]); - } - - public function testUpdateAction(): void - { - $data = [ - 'first_name' => 'Joe', - ]; - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $response = $this->patchJson('/api/team_members/2', $data, $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure([ - 'data' => [ - 'id', - 'organisation_id', - 'first_name', - 'last_name', - 'job_role', - 'facebook', - 'twitter', - 'linkedin', - 'instagram', - 'avatar', - ], - 'meta' => [], - ]); - } - - public function testDeleteAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $response = $this->deleteJson('/api/team_members/2', $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJson([ - 'data' => [], - ]); - } - - public function testReadAllByOrganisationAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->getJson('/api/organisations/2/team_members', $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure([ - 'data' => [ - [ - 'id', - 'organisation_id', - 'first_name', - 'last_name', - 'job_role', - 'facebook', - 'twitter', - 'instagram', - 'linkedin', - 'avatar', - ], - ], - ]); - } - - public function testInspectByOrganisationAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->getJson('/api/organisations/1/team_members/inspect', $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure([ - 'data' => [ - [ - 'id', - 'organisation_id', - 'first_name', - 'last_name', - 'email_address', - 'phone_number', - 'job_role', - 'facebook', - 'twitter', - 'instagram', - 'linkedin', - 'avatar', - ], - ], - ]); - } -} diff --git a/tests/Legacy/Feature/Terrafund/LegacyTerrafundDueSubmissionControllerTest.php b/tests/Legacy/Feature/Terrafund/LegacyTerrafundDueSubmissionControllerTest.php deleted file mode 100644 index acd8429cb..000000000 --- a/tests/Legacy/Feature/Terrafund/LegacyTerrafundDueSubmissionControllerTest.php +++ /dev/null @@ -1,183 +0,0 @@ - 'terrafund@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $this->getJson('/api/terrafund/site/submission/due', $headers) - ->assertHeader('Content-Type', 'application/json') - ->assertStatus(200) - ->assertJsonCount(2, 'data') - ->assertJsonPath('data.0.id', 1); - } - - public function testReadAllDueNurserySubmissionsForUserAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'terrafund@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $this->getJson('/api/terrafund/nursery/submission/due', $headers) - ->assertHeader('Content-Type', 'application/json') - ->assertStatus(200) - ->assertJsonCount(1, 'data'); - } - - public function testReadAllPastSiteSubmissionsForUserAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'terrafund@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $this->getJson('/api/terrafund/site/submissions/submitted', $headers) - ->assertHeader('Content-Type', 'application/json') - ->assertStatus(200) - ->assertJsonCount(1, 'data') - ->assertJsonPath('data.0.id', 5); - } - - public function testReadAllPastNurserySubmissionsForUserAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'terrafund@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $this->getJson('/api/terrafund/nursery/submissions/submitted', $headers) - ->assertHeader('Content-Type', 'application/json') - ->assertStatus(200) - ->assertJsonCount(1, 'data') - ->assertJsonPath('data.0.id', 4); - } - - public function testUnableToReportOnDueSubmissionAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'terrafund@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $data = ['reason' => 'lorem ipsum']; - $this->postJson('/api/terrafund/submission/2/unable', $data, $headers) - ->assertHeader('Content-Type', 'application/json') - ->assertStatus(200) - ->assertJsonPath('data.unable_report_reason', 'lorem ipsum') - ->assertJsonPath('data.is_submitted', 1); - - $this->assertDatabaseHas('terrafund_due_submissions', [ - 'id' => 2, - 'unable_report_reason' => 'lorem ipsum', - 'is_submitted' => true, - ]); - - $this->assertDatabaseHas('terrafund_due_submissions', [ - 'id' => 1, - 'unable_report_reason' => 'lorem ipsum', - 'is_submitted' => true, - ]); - - $this->assertDatabaseHas('terrafund_due_submissions', [ - 'id' => 3, - 'unable_report_reason' => 'lorem ipsum', - 'is_submitted' => true, - ]); - } - - public function testUnableToReportOnDueSubmissionActionOnLimit(): void - { - $token = Auth::attempt([ - 'email_address' => 'terrafund@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $data = ['reason' => Str::random(65000)]; - $this->postJson('/api/terrafund/submission/2/unable', $data, $headers) - ->assertHeader('Content-Type', 'application/json') - ->assertStatus(200) - ->assertJsonPath('data.unable_report_reason', $data['reason']) - ->assertJsonPath('data.is_submitted', 1); - } - - public function testUnableToReportOnDueSubmissionActionNotString(): void - { - $token = Auth::attempt([ - 'email_address' => 'terrafund@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $data = ['reason' => 0.00000]; - $this->postJson('/api/terrafund/submission/2/unable', $data, $headers) - ->assertHeader('Content-Type', 'application/json') - ->assertStatus(422); - } - - public function testUnableToReportOnDueSubmissionActionTooLong(): void - { - $token = Auth::attempt([ - 'email_address' => 'terrafund@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $data = ['reason' => Str::random(65001)]; - $this->postJson('/api/terrafund/submission/2/unable', $data, $headers) - ->assertHeader('Content-Type', 'application/json') - ->assertStatus(422); - } - - public function testUnableToReportOnDueSubmissionActionNotSupplied(): void - { - $token = Auth::attempt([ - 'email_address' => 'terrafund@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $data = []; - $this->postJson('/api/terrafund/submission/2/unable', $data, $headers) - ->assertHeader('Content-Type', 'application/json') - ->assertStatus(422); - } -} diff --git a/tests/Legacy/Feature/Terrafund/LegacyTerrafundFileControllerTest.php b/tests/Legacy/Feature/Terrafund/LegacyTerrafundFileControllerTest.php deleted file mode 100644 index 2be056d0f..000000000 --- a/tests/Legacy/Feature/Terrafund/LegacyTerrafundFileControllerTest.php +++ /dev/null @@ -1,263 +0,0 @@ - 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $response = $this->post('/api/uploads', [ - 'upload' => $file, - ], $headers); - - return $response->json('data.id'); - } - - public function testCreateAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'terrafund@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $uploadId = $this->uploadFile($token, $this->fakeFile()); - - $this->postJson('/api/terrafund/file', [ - 'fileable_type' => 'programme', - 'fileable_id' => 1, - 'upload' => $uploadId, - 'is_public' => false, - ], $headers) - ->assertStatus(201) - ->assertJsonFragment([ - 'fileable_type' => TerrafundProgramme::class, - 'fileable_id' => 1, - 'is_public' => false, - ]); - } - - public function testCreateActionForNursery(): void - { - $token = Auth::attempt([ - 'email_address' => 'terrafund@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $uploadId = $this->uploadFile($token, $this->fakeImage()); - - $this->postJson('/api/terrafund/file', [ - 'fileable_type' => 'nursery', - 'fileable_id' => 1, - 'upload' => $uploadId, - 'is_public' => false, - ], $headers) - ->assertStatus(201) - ->assertJsonFragment([ - 'fileable_type' => TerrafundNursery::class, - 'fileable_id' => 1, - 'is_public' => false, - ]); - } - - public function testCreateActionForSite(): void - { - $token = Auth::attempt([ - 'email_address' => 'terrafund@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $uploadId = $this->uploadFile($token, $this->fakeImage()); - - $this->postJson('/api/terrafund/file', [ - 'fileable_type' => 'site', - 'fileable_id' => 1, - 'upload' => $uploadId, - 'is_public' => false, - ], $headers) - ->assertStatus(201) - ->assertJsonFragment([ - 'fileable_type' => TerrafundSite::class, - 'fileable_id' => 1, - 'is_public' => false, - ]); - } - - public function testCreateActionProgrammeRequiresPdf(): void - { - $token = Auth::attempt([ - 'email_address' => 'terrafund@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $uploadId = $this->uploadFile($token, $this->fakeMap()); - - $this->postJson('/api/terrafund/file', [ - 'fileable_type' => 'programme', - 'fileable_id' => 1, - 'upload' => $uploadId, - 'is_public' => false, - ], $headers) - ->assertStatus(422); - } - - public function testCreateActionNurseryRequiresImage(): void - { - $token = Auth::attempt([ - 'email_address' => 'terrafund@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $uploadId = $this->uploadFile($token, $this->fakeFile()); - - $this->postJson('/api/terrafund/file', [ - 'fileable_type' => 'nursery', - 'fileable_id' => 1, - 'upload' => $uploadId, - 'is_public' => false, - ], $headers) - ->assertStatus(422); - } - - public function testCreateActionSiteRequiresImage(): void - { - $token = Auth::attempt([ - 'email_address' => 'terrafund@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $uploadId = $this->uploadFile($token, $this->fakeFile()); - - $this->postJson('/api/terrafund/file', [ - 'fileable_type' => 'site', - 'fileable_id' => 1, - 'upload' => $uploadId, - 'is_public' => false, - ], $headers) - ->assertStatus(422); - } - - public function testCreateActionRequiresBelongingToProgramme(): void - { - $token = Auth::attempt([ - 'email_address' => 'andrew@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $uploadId = $this->uploadFile($token, $this->fakeFile()); - - $this->postJson('/api/terrafund/file', [ - 'fileable_type' => 'programme', - 'fileable_id' => 1, - 'upload' => $uploadId, - 'is_public' => false, - ], $headers) - ->assertStatus(403); - } - - public function testCreateActionRequiresBelongingToNurseryProgramme(): void - { - $token = Auth::attempt([ - 'email_address' => 'andrew@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $uploadId = $this->uploadFile($token, $this->fakeFile()); - - $this->postJson('/api/terrafund/file', [ - 'fileable_type' => 'nursery', - 'fileable_id' => 1, - 'upload' => $uploadId, - 'is_public' => false, - ], $headers) - ->assertStatus(403); - } - - public function testCreateActionRequiresBelongingToSiteProgramme(): void - { - $token = Auth::attempt([ - 'email_address' => 'andrew@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $uploadId = $this->uploadFile($token, $this->fakeImage()); - - $this->postJson('/api/terrafund/file', [ - 'fileable_type' => 'site', - 'fileable_id' => 1, - 'upload' => $uploadId, - 'is_public' => false, - ], $headers) - ->assertStatus(403); - } - - public function testDeleteAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'terrafund@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $uploadId = $this->uploadFile($token, $this->fakeFile()); - - $fileId = $this->postJson('/api/terrafund/file', [ - 'fileable_type' => 'programme', - 'fileable_id' => 1, - 'upload' => $uploadId, - 'is_public' => false, - ], $headers)->json('data.id'); - - $this->deleteJson('/api/terrafund/file/' . $fileId, [], $headers) - ->assertStatus(200); - } -} diff --git a/tests/Legacy/Feature/Terrafund/LegacyTerrafundNurseryControllerTest.php b/tests/Legacy/Feature/Terrafund/LegacyTerrafundNurseryControllerTest.php deleted file mode 100644 index 79cfd1675..000000000 --- a/tests/Legacy/Feature/Terrafund/LegacyTerrafundNurseryControllerTest.php +++ /dev/null @@ -1,172 +0,0 @@ - 'test name', - 'start_date' => '2000-01-01', - 'end_date' => '2038-01-28', - 'seedling_grown' => 12345, - 'planting_contribution' => 'the planting contribution', - 'nursery_type' => 'expanding', - 'terrafund_programme_id' => 1, - ], - $overrides - ); - } - - public function testCreateAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'terrafund@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $this->postJson( - '/api/terrafund/nursery', - $this->nurseryData(), - $headers, - ) - ->assertStatus(201) - ->assertJsonFragment( - $this->nurseryData() - ); - } - - public function testCreateActionTypeHasToBeANurseryType(): void - { - $token = Auth::attempt([ - 'email_address' => 'terrafund@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $this->postJson( - '/api/terrafund/nursery', - $this->nurseryData([ - 'nursery_type' => 'not_valid', - ]), - $headers, - ) - ->assertStatus(422); - } - - public function testCreateActionUserMustBeInProgramme(): void - { - $token = Auth::attempt([ - 'email_address' => 'terrafund@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $this->postJson( - '/api/terrafund/nursery', - $this->nurseryData([ - 'terrafund_programme_id' => 2, - ]), - $headers, - ) - ->assertStatus(403); - } - - public function testCreateActionStartDateMustBeBeforeEndDate(): void - { - $token = Auth::attempt([ - 'email_address' => 'terrafund@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $this->postJson( - '/api/terrafund/nursery', - $this->nurseryData([ - 'start_date' => '2000-01-01', - 'end_date' => '1999-01-28', - ]), - $headers, - ) - ->assertStatus(422); - } - - public function testCreateActionRequiresBeingATerrafundUser(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $this->postJson( - '/api/terrafund/nursery', - $this->nurseryData(), - $headers, - ) - ->assertStatus(403); - } - - public function testReadAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'terrafund@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $this->getJson('/api/terrafund/nursery/1', $headers) - ->assertStatus(200) - ->assertJsonFragment([ - 'id' => 1, - 'name' => 'Terrafund Nursery', - 'start_date' => '2020-01-01', - 'end_date' => '2021-01-01', - 'seedling_grown' => 123, - 'planting_contribution' => 'planting contribution', - 'nursery_type' => 'existing', - 'terrafund_programme_id' => 1, - ]) - ->assertJsonPath('data.tree_species.0.id', 3) - ->assertJsonPath('data.photos.0.id', 2); - } - - public function testReadActionUserMustBeInNurseryProgramme(): void - { - $token = Auth::attempt([ - 'email_address' => 'sue@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $this->getJson('/api/terrafund/nursery/1', $headers) - ->assertStatus(403); - } -} diff --git a/tests/Legacy/Feature/Terrafund/LegacyTerrafundProgrammeControllerTest.php b/tests/Legacy/Feature/Terrafund/LegacyTerrafundProgrammeControllerTest.php deleted file mode 100644 index 56c51a05e..000000000 --- a/tests/Legacy/Feature/Terrafund/LegacyTerrafundProgrammeControllerTest.php +++ /dev/null @@ -1,386 +0,0 @@ - 'test name', - 'description' => 'test description', - 'planting_start_date' => '2000-01-01', - 'planting_end_date' => '2038-01-28', - 'budget' => 10000, - 'status' => 'existing_expansion', - 'home_country' => 'SE', - 'project_country' => 'AU', - 'boundary_geojson' => '{"type":"Polygon","coordinates":[[[-1.864006519317627,50.7219083651253],[-1.8627190589904783,50.7219083651253],[-1.8627190589904783,50.72276418262861],[-1.864006519317627,50.72276418262861],[-1.864006519317627,50.7219083651253]]]}', - 'history' => 'history', - 'objectives' => 'objectives', - 'environmental_goals' => 'environmental goals', - 'socioeconomic_goals' => 'socioeconomic goals', - 'sdgs_impacted' => 'SDGs impacted', - 'long_term_growth' => 'long term growth', - 'community_incentives' => 'community incentives', - 'total_hectares_restored' => 232323, - 'trees_planted' => 12, - 'jobs_created' => 100, - ], - $overrides - ); - } - - public function testCreateAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'terrafund@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $response = $this->postJson( - '/api/terrafund/programme', - $this->programmeData(), - $headers, - ) - ->assertStatus(201) - ->assertJsonFragment( - $this->programmeData([ - 'framework_id' => 2, - 'organisation_id' => 1, - ]) - ); - - $this->assertDatabaseHas('terrafund_programme_user', [ - 'user_id' => 12, - 'terrafund_programme_id' => $response->json('data.id'), - ]); - } - - public function testCreateActionStatusMustBeValid(): void - { - $token = Auth::attempt([ - 'email_address' => 'terrafund@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $this->postJson( - '/api/terrafund/programme', - $this->programmeData([ - 'status' => 'not valid', - ]), - $headers, - ) - ->assertStatus(422); - } - - public function testCreateActionStartDateMustBeBeforeEndDate(): void - { - $token = Auth::attempt([ - 'email_address' => 'terrafund@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $this->postJson( - '/api/terrafund/programme', - $this->programmeData([ - 'planting_start_date' => '2000-01-01', - 'planting_end_date' => '1999-01-28', - ]), - $headers, - ) - ->assertStatus(422); - } - - public function testCreateActionRequiresBeingATerrafundUser(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $this->postJson( - '/api/terrafund/programme', - $this->programmeData(), - $headers, - ) - ->assertStatus(403); - } - - public function testUpdateAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'terrafund@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $this->patchJson( - '/api/terrafund/programme/1', - $this->programmeData(), - $headers, - ) - ->assertStatus(200) - ->assertJsonFragment( - $this->programmeData([ - 'id' => 1, - 'framework_id' => 2, - 'organisation_id' => 1, - ]) - ); - } - - public function testUpdateActionRequiresAccess(): void - { - $token = Auth::attempt([ - 'email_address' => 'joe@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $this->patchJson( - '/api/terrafund/programme/1', - $this->programmeData(), - $headers, - ) - ->assertStatus(403); - } - - public function testReadAllAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'jane@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $this->getJson('/api/terrafund/programmes', $headers) - ->assertStatus(200) - ->assertJsonFragment([ - 'id' => 1, - ]); - } - - public function testReadAllActionAsTerrafundAdmin(): void - { - $token = Auth::attempt([ - 'email_address' => 'terrafund.admin@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $this->getJson('/api/terrafund/programmes', $headers) - ->assertStatus(200) - ->assertJsonFragment([ - 'id' => 1, - ]); - } - - public function testReadAllActionRequiresBeingAnAdmin(): void - { - $token = Auth::attempt([ - 'email_address' => 'joe@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $this->getJson('/api/terrafund/programmes', $headers) - ->assertStatus(403); - } - - public function testReadAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'terrafund@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $this->getJson('/api/terrafund/programme/1', $headers) - ->assertStatus(200) - ->assertJsonFragment([ - 'id' => 1, - 'name' => 'Programme name', - 'description' => 'Programme description', - 'planting_start_date' => '2000-10-06', - 'planting_end_date' => '2998-04-24', - 'budget' => 12345, - 'status' => 'new_project', - 'home_country' => 'se', - 'project_country' => 'au', - 'boundary_geojson' => '{"type":"Polygon","coordinates":[[[-1.864006519317627,50.7219083651253],[-1.8627190589904783,50.7219083651253],[-1.8627190589904783,50.72276418262861],[-1.864006519317627,50.72276418262861],[-1.864006519317627,50.7219083651253]]]}', - 'history' => 'history', - 'objectives' => 'objectives', - 'environmental_goals' => 'environmental goals', - 'socioeconomic_goals' => 'socioeconomic goals', - 'sdgs_impacted' => 'SDGs impacted', - 'long_term_growth' => 'long term growth', - 'community_incentives' => 'community incentives', - 'total_hectares_restored' => 20000, - 'trees_planted' => 12, - 'jobs_created' => 100, - 'framework_id' => 2, - ]) - ->assertJsonPath('data.tree_species.0.id', 1) - ->assertJsonPath('data.tree_species.1.id', 2) - ->assertJsonPath('data.additional_files.0.id', 1); - } - - public function testReadActionUserMustBeInProgramme(): void - { - $token = Auth::attempt([ - 'email_address' => 'sue@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $this->getJson('/api/terrafund/programme/1', $headers) - ->assertStatus(403); - } - - public function testReadAllPersonalAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'terrafund@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $this->getJson('/api/terrafund/programmes/personal', $headers) - ->assertStatus(200) - ->assertJsonFragment([ - 'id' => 1, - 'name' => 'Programme name', - 'home_country' => 'se', - 'project_country' => 'au', - ]) - ->assertJsonCount(1, 'data'); - } - - public function testReadAllPersonalActionWithOrganisationScoping(): void - { - $token = Auth::attempt([ - 'email_address' => 'terrafund@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $this->getJson('/api/terrafund/programmes/personal?organisation_id=1', $headers) - ->assertStatus(200) - ->assertJsonFragment([ - 'id' => 1, - 'name' => 'Programme name', - 'home_country' => 'se', - 'project_country' => 'au', - ]) - ->assertJsonCount(1, 'data'); - - $this->getJson('/api/terrafund/programmes/personal?organisation_id=2', $headers) - ->assertStatus(200) - ->assertJsonCount(0, 'data'); - } - - public function testReadAllPartnersAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'terrafund@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $this->getJson('/api/terrafund/programme/1/partners', $headers) - ->assertStatus(200) - ->assertJsonPath('data.0.id', 12) - ->assertJsonPath('data.1.id', 16); - } - - public function testDeletePartnerActionRequiresAccessToProgramme(): void - { - $token = Auth::attempt([ - 'email_address' => 'joe@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $this->deleteJson('/api/terrafund/programme/1/partners/16', $headers) - ->assertStatus(403); - } - - public function testDeletePartnerAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'terrafund@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $this->assertDatabaseHas('terrafund_programme_user', [ - 'user_id' => 16, - 'terrafund_programme_id' => 1, - ]); - - $this->deleteJson('/api/terrafund/programme/1/partners/16', $headers) - ->assertStatus(200); - - $this->assertDatabaseMissing('terrafund_programme_user', [ - 'user_id' => 16, - 'terrafund_programme_id' => 1, - ]); - } -} diff --git a/tests/Legacy/Feature/Terrafund/LegacyTerrafundProgrammeNurseriesControllerTest.php b/tests/Legacy/Feature/Terrafund/LegacyTerrafundProgrammeNurseriesControllerTest.php deleted file mode 100644 index 5307695bf..000000000 --- a/tests/Legacy/Feature/Terrafund/LegacyTerrafundProgrammeNurseriesControllerTest.php +++ /dev/null @@ -1,57 +0,0 @@ - 'sue@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $this->getJson('/api/terrafund/programme/1/nurseries', $headers) - ->assertStatus(403); - } - - public function testCheckHasProgrammeNurseries(): void - { - $token = Auth::attempt([ - 'email_address' => 'terrafund@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $this->getJson('/api/terrafund/programme/1/has_nurseries', $headers) - ->assertStatus(200) - ->assertJsonFragment([ - 'has_nurseries' => true, - ]); - } - - public function testCheckHasProgrammeSitesUserMustBeInProgramme(): void - { - $token = Auth::attempt([ - 'email_address' => 'sue@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $this->getJson('/api/terrafund/programme/1/has_nurseries', $headers) - ->assertStatus(403); - } -} diff --git a/tests/Legacy/Feature/Terrafund/LegacyTerrafundProgrammeSitesControllerTest.php b/tests/Legacy/Feature/Terrafund/LegacyTerrafundProgrammeSitesControllerTest.php deleted file mode 100644 index 0452bceb9..000000000 --- a/tests/Legacy/Feature/Terrafund/LegacyTerrafundProgrammeSitesControllerTest.php +++ /dev/null @@ -1,75 +0,0 @@ - 'terrafund@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $this->getJson('/api/terrafund/programme/1/sites', $headers) - ->assertStatus(200) - ->assertJsonFragment([ - 'id' => 1, - ]); - } - - public function testReadAllProgrammeSitesUserMustBeInProgramme(): void - { - $token = Auth::attempt([ - 'email_address' => 'sue@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $this->getJson('/api/terrafund/programme/1/sites', $headers) - ->assertStatus(403); - } - - public function testCheckHasProgrammeSites(): void - { - $token = Auth::attempt([ - 'email_address' => 'terrafund@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $this->getJson('/api/terrafund/programme/1/has_sites', $headers) - ->assertStatus(200) - ->assertJsonFragment([ - 'has_sites' => true, - ]); - } - - public function testCheckHasProgrammeSitesUserMustBeInProgramme(): void - { - $token = Auth::attempt([ - 'email_address' => 'sue@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $this->getJson('/api/terrafund/programme/1/has_sites', $headers) - ->assertStatus(403); - } -} diff --git a/tests/Legacy/Feature/Terrafund/LegacyTerrafundTreeSpeciesControllerTest.php b/tests/Legacy/Feature/Terrafund/LegacyTerrafundTreeSpeciesControllerTest.php deleted file mode 100644 index 64125974c..000000000 --- a/tests/Legacy/Feature/Terrafund/LegacyTerrafundTreeSpeciesControllerTest.php +++ /dev/null @@ -1,138 +0,0 @@ - 'terrafund@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $this->postJson('/api/terrafund/tree_species', [ - 'treeable_type' => 'programme', - 'treeable_id' => 1, - 'name' => 'tree species', - 'amount' => 5, - ], $headers) - ->assertHeader('Content-Type', 'application/json') - ->assertStatus(201) - ->assertJsonFragment([ - 'treeable_type' => TerrafundProgramme::class, - 'treeable_id' => 1, - 'name' => 'tree species', - 'amount' => 5, - ]); - } - - public function testCreateActionRequiresBeingPartOfProgramme(): void - { - $token = Auth::attempt([ - 'email_address' => 'sue@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $this->postJson('/api/terrafund/tree_species', [ - 'treeable_type' => 'programme', - 'treeable_id' => 1, - 'name' => 'tree species', - 'amount' => 5, - ], $headers) - ->assertHeader('Content-Type', 'application/json') - ->assertStatus(403); - } - - public function testCreateActionAsNursery(): void - { - $token = Auth::attempt([ - 'email_address' => 'terrafund@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $this->postJson('/api/terrafund/tree_species', [ - 'treeable_type' => 'nursery', - 'treeable_id' => 1, - 'name' => 'tree species', - 'amount' => 5, - ], $headers) - ->assertHeader('Content-Type', 'application/json') - ->assertStatus(201) - ->assertJsonFragment([ - 'treeable_type' => TerrafundNursery::class, - 'treeable_id' => 1, - 'name' => 'tree species', - 'amount' => 5, - ]); - } - - public function testCreateActionWithArrayRequiresBeingPartOfNursery(): void - { - $token = Auth::attempt([ - 'email_address' => 'sue@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $this->postJson('/api/terrafund/tree_species', [ - 'treeable_type' => 'nursery', - 'treeable_id' => 1, - 'name' => 'tree species', - 'amount' => 5, - ], $headers) - ->assertHeader('Content-Type', 'application/json') - ->assertStatus(403); - } - - public function testDeleteAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'terrafund@example.com', - 'password' => 'Password123', - ]); - - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $this->deleteJson('/api/terrafund/tree_species/1', $headers) - ->assertStatus(200); - } - - public function testDeleteActionRequiresBeingPartOfProgramme(): void - { - $token = Auth::attempt([ - 'email_address' => 'sue@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $this->deleteJson('/api/terrafund/tree_species/1', $headers) - ->assertStatus(403); - } -} diff --git a/tests/Legacy/Feature/Terrafund/TerrafundCsvImportControllerTest.php b/tests/Legacy/Feature/Terrafund/TerrafundCsvImportControllerTest.php deleted file mode 100644 index b5ba9d0f6..000000000 --- a/tests/Legacy/Feature/Terrafund/TerrafundCsvImportControllerTest.php +++ /dev/null @@ -1,119 +0,0 @@ - 'terrafund@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $response = $this->post('/api/uploads', [ - 'upload' => $this->fakeValidCsv(), - ], $headers); - - $this->postJson('/api/terrafund/tree_species/csv', [ - 'treeable_type' => 'programme', - 'treeable_id' => 1, - 'upload_id' => $response->json('data.id'), - ], $headers) - ->assertStatus(200); - } - - public function testCreateActionAsNursery(): void - { - $token = Auth::attempt([ - 'email_address' => 'terrafund@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $response = $this->post('/api/uploads', [ - 'upload' => $this->fakeValidCsv(), - ], $headers); - - $this->postJson('/api/terrafund/tree_species/csv', [ - 'treeable_type' => 'nursery', - 'treeable_id' => 1, - 'upload_id' => $response->json('data.id'), - ], $headers) - ->assertStatus(200); - } - - public function testCreateActionFileRequiresHeaders(): void - { - $token = Auth::attempt([ - 'email_address' => 'terrafund@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $response = $this->post('/api/uploads', [ - 'upload' => $this->fakeNoHeadersCsv(), - ], $headers); - - $this->postJson('/api/terrafund/tree_species/csv', [ - 'treeable_type' => 'programme', - 'treeable_id' => 1, - 'upload_id' => $response->json('data.id'), - ], $headers) - ->assertStatus(422); - } - - public function testCreateActionFileIsRequired(): void - { - $token = Auth::attempt([ - 'email_address' => 'terrafund@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $this->postJson('/api/terrafund/tree_species/csv', [ - 'treeable_type' => 'programme', - 'treeable_id' => 1, - ], $headers) - ->assertStatus(422); - } - - public function testCreateActionRequiresBelongingToProgramme(): void - { - $token = Auth::attempt([ - 'email_address' => 'jane@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $response = $this->post('/api/uploads', [ - 'upload' => $this->fakeValidCsv(), - ], $headers); - - $this->postJson('/api/terrafund/tree_species/csv', [ - 'treeable_type' => 'programme', - 'treeable_id' => 1, - 'upload_id' => $response->json('data.id'), - ], $headers) - ->assertStatus(200); - } -} diff --git a/tests/Legacy/Feature/Terrafund/TerrafundProgrammeInviteControllerTest.php b/tests/Legacy/Feature/Terrafund/TerrafundProgrammeInviteControllerTest.php deleted file mode 100644 index f8e41f260..000000000 --- a/tests/Legacy/Feature/Terrafund/TerrafundProgrammeInviteControllerTest.php +++ /dev/null @@ -1,159 +0,0 @@ - 'jane@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $this->postJson('/api/terrafund/programme/1/invite', [ - 'email_address' => 'sue@example.com', - 'callback_url' => 'https://testing-this.com/', - ], $headers) - ->assertStatus(201) - ->assertJsonFragment([ - 'terrafund_programme_id' => 1, - 'email_address' => 'sue@example.com', - ]); - - Mail::assertQueued(TerrafundProgrammeInviteReceived::class, function ($mail) { - return $mail->hasTo('sue@example.com'); - }); - } - - public function testCreateActionWhenUserIsAlreadyPartOfProgramme(): void - { - $token = Auth::attempt([ - 'email_address' => 'jane@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $this->postJson('/api/terrafund/programme/1/invite', [ - 'email_address' => 'terrafund@example.com', - ], $headers) - ->assertStatus(422); - } - - public function testCreateActionWithNewTerramatchUser(): void - { - Mail::fake(); - Carbon::setTestNow(Carbon::createFromDate('2021-07-23')); - - $token = Auth::attempt([ - 'email_address' => 'jane@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $this->postJson('/api/terrafund/programme/1/invite', [ - 'email_address' => 'a.new.user@email.com', - 'callback_url' => 'https://testing-this.com/', - ], $headers) - ->assertStatus(201); - - Mail::assertNotQueued(TerrafundProgrammeInviteReceived::class, function ($mail) { - return $mail->hasTo('a.new.user@email.com'); - }); - - Mail::assertQueued(UserInvited::class, function ($mail) { - return $mail->hasTo('a.new.user@email.com'); - }); - } - - public function testCreateActionEmailAddressIsRequired(): void - { - $token = Auth::attempt([ - 'email_address' => 'jane@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $this->postJson('/api/terrafund/programme/1/invite', $headers) - ->assertStatus(422); - } - - public function testCreateActionProgrammeIdHasToExist(): void - { - $token = Auth::attempt([ - 'email_address' => 'jane@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $this->postJson('/api/terrafund/programme/6102000/invite', [ - 'email_address' => 'a.new.user@email.com', - ], $headers) - ->assertStatus(404); - } - - public function testAcceptAction(): void - { - Carbon::setTestNow(Carbon::createFromDate('2021-07-23')); - $token = Auth::attempt([ - 'email_address' => 'new.terrafund@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $data = [ - 'token' => 'tlvOSFc5kpR2VqrCUiwI3gabz5OeLr7LdUmhyyF693agCu7fyW9d8p4pBtEGORmj', - ]; - - $response = $this->postJson('/api/terrafund/programme/invite/accept', $data, $headers); - $response->assertStatus(200); - - $this->assertDatabaseHas('terrafund_programme_user', [ - 'user_id' => 14, - 'terrafund_programme_id' => 1, - ]); - } - - public function testAcceptActionRequiresEmailAndTokenToMatch(): void - { - $token = Auth::attempt([ - 'email_address' => 'terrafund.orphan@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $data = [ - 'token' => 'tlvOSFc5kpR2VqrCUiwI3gabz5OeLr7LdUmhyyF693agCu7fyW9d8p4pBtEGORmj', - ]; - - $this->postJson('/api/terrafund/programme/invite/accept', $data, $headers) - ->assertStatus(404); - } -} diff --git a/tests/Legacy/Feature/Terrafund/TerrafundSiteControllerTest.php b/tests/Legacy/Feature/Terrafund/TerrafundSiteControllerTest.php deleted file mode 100644 index e315fa323..000000000 --- a/tests/Legacy/Feature/Terrafund/TerrafundSiteControllerTest.php +++ /dev/null @@ -1,234 +0,0 @@ - 'test name', - 'start_date' => '2000-01-01', - 'end_date' => '2038-01-28', - 'boundary_geojson' => '{"type":"Polygon","coordinates":[[[-1.864006519317627,50.7219083651253],[-1.8627190589904783,50.7219083651253],[-1.8627190589904783,50.72276418262861],[-1.864006519317627,50.72276418262861],[-1.864006519317627,50.7219083651253]]]}', - 'restoration_methods' => [ - 'agroforestry', - 'plantations', - ], - 'land_tenures' => [ - 'public', - 'private', - ], - 'hectares_to_restore' => 10, - 'landscape_community_contribution' => 'community contribution', - 'disturbances' => 'disturbances on the site', - ], - $overrides - ); - } - - public function testCreateAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'terrafund@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $this->postJson( - '/api/terrafund/site', - $this->siteData([ - 'terrafund_programme_id' => 1, - ]), - $headers, - ) - ->assertStatus(201) - ->assertJsonFragment( - $this->siteData([ - 'terrafund_programme_id' => 1, - ]) - ); - } - - public function testCreateActionUserMustBeInProgramme(): void - { - $token = Auth::attempt([ - 'email_address' => 'terrafund@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $this->postJson( - '/api/terrafund/site', - $this->siteData([ - 'terrafund_programme_id' => 2, - ]), - $headers, - ) - ->assertStatus(403); - } - - public function testCreateActionStartDateMustBeBeforeEndDate(): void - { - $token = Auth::attempt([ - 'email_address' => 'terrafund@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $this->postJson( - '/api/terrafund/site', - $this->siteData([ - 'terrafund_programme_id' => 1, - 'start_date' => '2000-01-01', - 'end_date' => '1999-01-28', - ]), - $headers, - ) - ->assertStatus(422); - } - - public function testCreateActionRequiresBeingATerrafundUser(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $this->postJson( - '/api/terrafund/site', - $this->siteData([ - 'terrafund_programme_id' => 1, - ]), - $headers, - ) - ->assertStatus(403); - } - - public function testUpdateAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'terrafund@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $this->patchJson( - '/api/terrafund/site/1', - $this->siteData(), - $headers, - ) - ->assertStatus(200) - ->assertJsonFragment( - $this->siteData([ - 'id' => 1, - ]) - ); - } - - public function testUpdateActionRequiresAccess(): void - { - $token = Auth::attempt([ - 'email_address' => 'joe@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $this->patchJson( - '/api/terrafund/site/1', - $this->siteData(), - $headers, - ) - ->assertStatus(403); - } - - public function testReadAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'terrafund@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $this->getJson('/api/terrafund/site/1', $headers) - ->assertStatus(200) - ->assertJsonFragment([ - 'id' => 1, - 'name' => 'Terrafund Site', - 'start_date' => '2020-01-01', - 'end_date' => '2021-01-01', - 'terrafund_programme_id' => 1, - ]) - ->assertJsonPath('data.photos.0.id', 3); - } - - public function testReadActionUserMustBeInNurseryProgramme(): void - { - $token = Auth::attempt([ - 'email_address' => 'sue@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - - $this->getJson('/api/terrafund/nursery/1', $headers) - ->assertStatus(403); - } - - public function testReadMySitesAction(): void - { - $organisation = Organisation::factory()->create(); - $terrafundProgramme = TerrafundProgramme::factory()->create(); - $terrafundSite = TerrafundSite::factory()->create([ - 'terrafund_programme_id' => $terrafundProgramme->id, - ]); - $missingSite = TerrafundSite::factory()->create(); - $user = User::factory()->create([ - 'organisation_id' => $organisation->id, - ]); - $user->frameworks()->attach(2); - $user->terrafundProgrammes()->attach($terrafundProgramme->id); - - $this->actingAs($user) - ->getJson('/api/terrafund/my/sites') - ->assertStatus(200) - ->assertJsonFragment([ - 'id' => $terrafundSite->id, - ]) - ->assertJsonMissingExact([ - 'id' => $missingSite->id, - ]); - } -} diff --git a/tests/Legacy/Feature/TreeSpeciesControllerTest.php b/tests/Legacy/Feature/TreeSpeciesControllerTest.php deleted file mode 100644 index 5adedf87c..000000000 --- a/tests/Legacy/Feature/TreeSpeciesControllerTest.php +++ /dev/null @@ -1,232 +0,0 @@ - 'steve@example.com', - 'password' => 'Password123', - ]); - $data = [ - 'pitch_id' => 1, - 'name' => 'Oak', - 'is_native' => true, - 'count' => 100, - 'price_to_plant' => 0.50, - 'price_to_maintain' => 1.25, - 'saplings' => 10.50, - 'site_prep' => 30.35, - 'survival_rate' => 75, - 'produces_food' => null, - 'produces_firewood' => null, - 'produces_timber' => null, - 'owner' => 'community', - 'season' => 'winter', - ]; - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $response = $this->postJson('/api/tree_species', $data, $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(201); - $response->assertJsonStructure([ - 'data' => [ - 'id', - 'status', - 'approved_rejected_by', - 'rejected_reason', - 'rejected_reason_body', - 'data' => [ - 'name', - 'is_native', - 'count', - 'price_to_plant', - 'price_to_maintain', - 'saplings', - 'site_prep', - 'survival_rate', - 'produces_food', - 'produces_firewood', - 'produces_timber', - 'owner', - 'season', - ], - ], - ]); - } - - public function testReadAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->getJson('/api/tree_species/1', $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure([ - 'data' => [ - 'id', - 'pitch_id', - 'name', - 'is_native', - 'count', - 'price_to_plant', - 'price_to_maintain', - 'saplings', - 'site_prep', - 'survival_rate', - 'produces_food', - 'produces_firewood', - 'produces_timber', - 'owner', - 'season', - ], - ]); - } - - public function testUpdateAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $data = [ - 'name' => 'Pine', - ]; - $response = $this->patchJson('/api/tree_species/1', $data, $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure([ - 'data' => [ - 'id', - 'status', - 'approved_rejected_by', - 'rejected_reason', - 'rejected_reason_body', - 'data' => [ - 'name', - 'is_native', - 'count', - 'price_to_plant', - 'price_to_maintain', - 'saplings', - 'site_prep', - 'survival_rate', - 'produces_food', - 'produces_firewood', - 'produces_timber', - 'owner', - 'season', - ], - ], - ]); - } - - public function testReadAllByPitchAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->getJson('/api/pitches/1/tree_species', $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure([ - 'data' => [ - [ - 'id', - 'pitch_id', - 'name', - 'is_native', - 'count', - 'price_to_plant', - 'price_to_maintain', - 'saplings', - 'site_prep', - 'survival_rate', - 'produces_food', - 'produces_firewood', - 'produces_timber', - 'owner', - 'season', - ], - ], - ]); - } - - public function testInspectByPitchAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->getJson('/api/pitches/1/tree_species/inspect', $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure([ - 'data' => [ - [ - 'id', - 'status', - 'approved_rejected_by', - 'approved_rejected_at', - 'rejected_reason', - 'rejected_reason_body', - 'data' => [ - 'id', - 'pitch_id', - 'name', - 'is_native', - 'count', - 'price_to_plant', - 'price_to_maintain', - 'saplings', - 'site_prep', - 'survival_rate', - 'produces_food', - 'produces_firewood', - 'produces_timber', - 'owner', - 'season', - ], - ], - ], - ]); - } - - public function testDeleteAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $response = $this->deleteJson('/api/tree_species/1', $headers); - $response->assertStatus(200); - $this->assertNull(TreeSpeciesModel::find(1)); - } -} diff --git a/tests/Legacy/Feature/TreeSpeciesVersionsControllerTest.php b/tests/Legacy/Feature/TreeSpeciesVersionsControllerTest.php deleted file mode 100644 index 093f2e367..000000000 --- a/tests/Legacy/Feature/TreeSpeciesVersionsControllerTest.php +++ /dev/null @@ -1,245 +0,0 @@ - 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->getJson('/api/tree_species_versions/1', $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure([ - 'data' => [ - 'id', - 'status', - 'approved_rejected_by', - 'rejected_reason', - 'rejected_reason_body', - 'data' => [ - 'name', - 'is_native', - 'count', - 'price_to_plant', - 'price_to_maintain', - 'saplings', - 'site_prep', - 'survival_rate', - 'produces_food', - 'produces_firewood', - 'produces_timber', - 'owner', - 'season', - ], - ], - ]); - } - - public function testApproveAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'jane@example.com', - 'password' => 'Password123', - ]); - $data = []; - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $response = $this->patchJson('/api/tree_species_versions/2/approve', $data, $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure([ - 'data' => [ - 'id', - 'status', - 'approved_rejected_by', - 'rejected_reason', - 'rejected_reason_body', - 'data' => [ - 'name', - 'is_native', - 'count', - 'price_to_plant', - 'price_to_maintain', - 'saplings', - 'site_prep', - 'survival_rate', - 'produces_food', - 'produces_firewood', - 'produces_timber', - 'owner', - 'season', - ], - ], - ]); - $response->assertJson([ - 'data' => [ - 'status' => 'approved', - ], - ]); - } - - public function testRejectAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'jane@example.com', - 'password' => 'Password123', - ]); - $data = [ - 'rejected_reason' => 'cannot_verify', - 'rejected_reason_body' => 'Lorem ipsum dolor sit amet', - ]; - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $response = $this->patchJson('/api/tree_species_versions/2/reject', $data, $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure([ - 'data' => [ - 'id', - 'status', - 'approved_rejected_by', - 'rejected_reason', - 'rejected_reason_body', - 'data' => [ - 'name', - 'is_native', - 'count', - 'price_to_plant', - 'price_to_maintain', - 'saplings', - 'site_prep', - 'survival_rate', - 'produces_food', - 'produces_firewood', - 'produces_timber', - 'owner', - 'season', - ], - ], - ]); - $response->assertJson([ - 'data' => [ - 'status' => 'rejected', - ], - ]); - } - - public function testDeleteAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->deleteJson('/api/tree_species_versions/2', $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJson([ - 'data' => [], - ]); - } - - public function testReadAllByTreeSpeciesAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->getJson('/api/tree_species/1/tree_species_versions', $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure([ - 'data' => [ - [ - 'id', - 'status', - 'approved_rejected_by', - 'approved_rejected_at', - 'rejected_reason', - 'rejected_reason_body', - 'data' => [ - 'id', - 'pitch_id', - 'name', - 'is_native', - 'count', - 'price_to_plant', - 'price_to_maintain', - 'saplings', - 'site_prep', - 'survival_rate', - 'produces_food', - 'produces_firewood', - 'produces_timber', - 'owner', - 'season', - ], - ], - ], - ]); - } - - public function testReviveAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'jane@example.com', - 'password' => 'Password123', - ]); - $data = []; - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $response = $this->patchJson('/api/tree_species_versions/3/revive', $data, $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure([ - 'data' => [ - 'id', - 'status', - 'approved_rejected_by', - 'rejected_reason', - 'rejected_reason_body', - 'data' => [ - 'name', - 'is_native', - 'count', - 'price_to_plant', - 'price_to_maintain', - 'saplings', - 'site_prep', - 'survival_rate', - 'produces_food', - 'produces_firewood', - 'produces_timber', - 'owner', - 'season', - ], - ], - ]); - $response->assertJson([ - 'data' => [ - 'status' => 'approved', - ], - ]); - } -} diff --git a/tests/Legacy/Feature/UploadsControllerTest.php b/tests/Legacy/Feature/UploadsControllerTest.php deleted file mode 100644 index bcf46583f..000000000 --- a/tests/Legacy/Feature/UploadsControllerTest.php +++ /dev/null @@ -1,87 +0,0 @@ - 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $data = [ - 'upload' => $this->fakeImage(), - 'title' => 'test File', - ]; - $response = $this->post('/api/uploads', $data, $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(201); - $response->assertJsonStructure([ - 'data' => [ - 'id', - 'uploaded_at', - 'title', - ], - ]); - $this->assertDatabaseHas('uploads', ['user_id' => 3]); - } - - public function testCorruptedImage(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $data = [ - 'upload' => $this->fakeCorruptedImage(), - ]; - $response = $this->post('/api/uploads', $data, $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(422); - } - - public function testUploadAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $dataA = [ - 'upload' => $this->fakeImage(), - 'title' => 'original title', - ]; - $response = $this->post('/api/uploads', $dataA, $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(201); - $response->assertJsonStructure([ - 'data' => [ - 'id', - 'uploaded_at', - 'title', - ], - ]); - - $uploadId = $response->json('data.id'); - - $dataB = [ - 'title' => 'title has been Updated', - ]; - - $response = $this->put('/api/uploads/' . $uploadId . '/update', $dataB, $headers); - $response->assertStatus(200); - $this->assertEquals($dataB['title'], $response->json('data.title')); - } -} diff --git a/tests/Legacy/Feature/UsersControllerTest.php b/tests/Legacy/Feature/UsersControllerTest.php deleted file mode 100644 index 76ffda1fd..000000000 --- a/tests/Legacy/Feature/UsersControllerTest.php +++ /dev/null @@ -1,473 +0,0 @@ - 'John', - 'last_name' => 'Doe', - 'email_address' => 'john@example.com', - 'password' => 'Password123', - 'job_role' => 'Manager', - 'twitter' => null, - 'facebook' => null, - 'instagram' => null, - 'linkedin' => null, - 'phone_number' => '0123456789', - 'whatsapp_phone' => '0123456789', - ]; - $headers = [ - 'Content-Type' => 'application/json', - ]; - $response = $this->postJson('/api/users', $data, $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(201); - $response->assertJsonStructure([ - 'data' => [ - 'id', - 'organisation_id', - 'first_name', - 'last_name', - 'email_address', - 'role', - 'email_address_verified_at', - 'last_logged_in_at', - 'twitter', - 'linkedin', - 'instagram', - 'facebook', - 'phone_number', - 'avatar', - 'whatsapp_phone', - ], - 'meta' => [], - ]); - $response->assertJson([ - 'data' => [ - 'first_name' => 'John', - 'last_name' => 'Doe', - 'email_address' => 'john@example.com', - 'role' => 'user', - 'email_address_verified_at' => null, - 'last_logged_in_at' => null, - ], - ]); - } - - /** @group slow */ - public function testInviteAction() - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $data = [ - 'email_address' => 'laura@example.com', - ]; - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $response = $this->postJson('/api/users/invite', $data, $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(201); - $response->assertJsonStructure([ - 'data' => [ - 'id', - 'organisation_id', - 'first_name', - 'last_name', - 'email_address', - 'role', - 'email_address_verified_at', - 'last_logged_in_at', - 'twitter', - 'linkedin', - 'instagram', - 'facebook', - 'phone_number', - 'avatar', - 'whatsapp_phone', - ], - ]); - $response->assertJson([ - 'data' => [ - 'first_name' => null, - 'last_name' => null, - 'email_address' => 'laura@example.com', - 'role' => 'user', - 'email_address_verified_at' => null, - 'last_logged_in_at' => null, - ], - ]); - } - - public function testInviteActionAsTerrafundAdmin(): void - { - $token = Auth::attempt([ - 'email_address' => 'jane@example.com', - 'password' => 'Password123', - ]); - $data = [ - 'email_address' => 'laura.terrafund@example.com', - 'role' => 'terrafund_admin', - ]; - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $response = $this->postJson('/api/users/invite', $data, $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(201); - $response->assertJsonStructure([ - 'data' => [ - 'id', - 'organisation_id', - 'first_name', - 'last_name', - 'email_address', - 'role', - 'email_address_verified_at', - 'last_logged_in_at', - 'twitter', - 'linkedin', - 'instagram', - 'facebook', - 'phone_number', - 'avatar', - 'whatsapp_phone', - ], - ]); - $response->assertJson([ - 'data' => [ - 'first_name' => null, - 'last_name' => null, - 'email_address' => 'laura.terrafund@example.com', - 'role' => 'terrafund_admin', - 'email_address_verified_at' => null, - 'last_logged_in_at' => null, - ], - ]); - } - - public function testAcceptAction(): void - { - $data = [ - 'first_name' => 'Sue', - 'last_name' => 'Doe', - 'email_address' => 'sue@example.com', - 'password' => 'Password123', - 'job_role' => 'Supervisor', - 'twitter' => null, - 'facebook' => null, - 'instagram' => null, - 'linkedin' => null, - 'phone_number' => '9876543210', - 'whatsapp_phone' => '9876543210', - ]; - $headers = [ - 'Content-Type' => 'application/json', - ]; - $response = $this->postJson('/api/users/accept', $data, $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(201); - $response->assertJsonStructure([ - 'data' => [ - 'id', - 'organisation_id', - 'first_name', - 'last_name', - 'email_address', - 'role', - 'email_address_verified_at', - 'last_logged_in_at', - 'twitter', - 'linkedin', - 'instagram', - 'facebook', - 'phone_number', - 'avatar', - ], - ]); - $response->assertJson([ - 'data' => [ - 'first_name' => 'Sue', - 'last_name' => 'Doe', - 'email_address' => 'sue@example.com', - ], - ]); - } - - public function testReadAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'joe@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->getJson('/api/users/1', $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure([ - 'data' => [ - 'id', - 'organisation_id', - 'first_name', - 'last_name', - 'email_address', - 'role', - 'email_address_verified_at', - 'last_logged_in_at', - 'twitter', - 'linkedin', - 'instagram', - 'facebook', - 'phone_number', - 'avatar', - 'whatsapp_phone', - ], - 'meta' => [], - ]); - } - - public function testReadAllAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'jane@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->getJson('/api/users/all', $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure([ - 'data' => [ - '*' => [ - 'id', - 'organisation_id', - 'first_name', - 'last_name', - 'email_address', - 'role', - 'email_address_verified_at', - 'last_logged_in_at', - 'twitter', - 'linkedin', - 'instagram', - 'facebook', - 'phone_number', - 'avatar', - 'whatsapp_phone', - ], - ], - 'meta' => [], - ]); - } - - public function testReadAllUnverifiedAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'jane@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $this->getJson('/api/users/unverified', $headers) - ->assertHeader('Content-Type', 'application/json') - ->assertStatus(200) - ->assertJsonStructure([ - 'data' => [ - '*' => [ - 'id', - 'organisation_id', - 'first_name', - 'last_name', - 'email_address', - 'role', - 'email_address_verified_at', - 'last_logged_in_at', - 'twitter', - 'linkedin', - 'instagram', - 'facebook', - 'phone_number', - 'avatar', - 'whatsapp_phone', - ], - ], - 'meta' => [], - ]) - ->assertJsonFragment([ - 'id' => 1, - 'email_address' => 'joe@example.com', - ]) - ->assertJsonFragment([ - 'id' => 7, - 'email_address' => 'sue@example.com', - ]) - ->assertJsonMissing([ - 'id' => 2, - 'name' => 'jane@example.com', - ]); - } - - public function testResendVerificationEmailAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'jane@example.com', - 'password' => 'Password123', - ]); - - $user = V2User::find(7); - $data = [ - 'uuid' => $user ->uuid, - ]; - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->postJson('/api/users/resend', $data, $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - - $data = [ - 'uuid' => $user ->uuid, - 'callback_url' => 'https://testing-this.com', - ]; - - $response = $this->postJson('/api/users/resend', $data, $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - } - - public function testUpdateAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $data = [ - 'first_name' => 'Stephen', - ]; - $headers = [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - $response = $this->patchJson('/api/users/3', $data, $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure([ - 'data' => [ - 'id', - 'organisation_id', - 'first_name', - 'last_name', - 'email_address', - 'role', - 'email_address_verified_at', - 'last_logged_in_at', - 'twitter', - 'linkedin', - 'instagram', - 'facebook', - 'phone_number', - 'avatar', - 'whatsapp_phone', - ], - ]); - $response->assertJson([ - 'data' => [ - 'first_name' => 'Stephen', - ], - ]); - } - - public function testReadAllByOrganisationAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->getJson('/api/organisations/2/users', $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure([ - 'data' => [ - [ - 'id', - 'organisation_id', - 'first_name', - 'last_name', - 'twitter', - 'linkedin', - 'instagram', - 'facebook', - 'avatar', - 'whatsapp_phone', - ], - ], - ]); - } - - public function testInspectByOrganisationAction(): void - { - $token = Auth::attempt([ - 'email_address' => 'steve@example.com', - 'password' => 'Password123', - ]); - $headers = [ - 'Authorization' => 'Bearer ' . $token, - ]; - $response = $this->getJson('/api/organisations/1/users/inspect', $headers); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - $response->assertJsonStructure([ - 'data' => [ - [ - 'id', - 'organisation_id', - 'first_name', - 'last_name', - 'email_address', - 'role', - 'email_address_verified_at', - 'last_logged_in_at', - 'twitter', - 'linkedin', - 'instagram', - 'facebook', - 'phone_number', - 'avatar', - 'whatsapp_phone', - ], - ], - ]); - } - - public function testUnsubscribeAction(): void - { - $encryptedId = Crypt::encryptString('2'); - $response = $this->get('/admins/' . $encryptedId . '/unsubscribe'); - $response->assertStatus(302); - $url = config('app.front_end'). '/unsubscribe'; - $response->assertHeader('Location', $url); - $admin = UserModel::findOrFail(2); - $this->assertFalse($admin->is_subscribed); - } -} diff --git a/tests/Legacy/LegacyTestCase.php b/tests/Legacy/LegacyTestCase.php deleted file mode 100644 index 10a3ba687..000000000 --- a/tests/Legacy/LegacyTestCase.php +++ /dev/null @@ -1,169 +0,0 @@ -loadEnvironmentFrom('.env.testing'); - $app->loadEnvironmentFrom('.env'); - $app->make(Kernel::class)->bootstrap(); - $this->seed(); - - self::$configurationApp = $app; - $this->app = $app; - } - } - - protected function getControllers(): array - { - $controllers = glob(__DIR__ . '/../../app/Http/Controllers/*.php'); - $controllers = array_filter($controllers, function ($controller) { - return ! in_array(basename($controller, '.php'), ['Controller']); - }); - foreach ($controllers as &$controller) { - $controller = 'App\\Http\\Controllers\\' . basename($controller, '.php'); - } - - return $controllers; - } - - protected function getCommands(): array - { - $commands = glob(__DIR__ . '/../../app/Console/Commands/*.php'); - $commands = array_filter($commands, function ($command) { - $internalCommands = ['MigrateServicesCommand', 'CreateFramesCommand', 'CreateAdminCommand', 'CheckQueueLengthCommand']; - - return ! in_array(basename($command, '.php'), $internalCommands); - }); - foreach ($commands as &$command) { - $controller = 'App\\Console\\Commands\\' . basename($command, '.php'); - } - - return $commands; - } - - protected function getActions(string $controller): array - { - $reflection = new ReflectionClass($controller); - $methods = $reflection->getMethods(ReflectionMethod::IS_PUBLIC); - - return array_filter($methods, function ($method) { - return substr($method->name, -6) == 'Action' && $method->name != 'callAction'; - }); - } - - protected function getActionBody(ReflectionMethod $action): string - { - $class = file_get_contents($action->getFileName()); - $lines = explode("\n", $class); - $start = $action->getStartLine(); - $end = $action->getEndLine(); - $body = implode("\n", array_slice($lines, $start, $end - $start)); - - return $body; - } - - protected function assertIsOneOf(array $haystack, $needle): void - { - $message = 'Failed asserting that ' . $needle . ' is one of ' . implode(', ', $haystack) . '.'; - $this->assertTrue(in_array($needle, $haystack), $message); - } - - protected function assertInArray($needle, array $haystack): void - { - $message = 'Failed asserting that ' . $needle . ' is in array ' . implode(', ', $haystack) . '.'; - $this->assertTrue(in_array($needle, $haystack), $message); - } - - protected function fakeImage() - { - return new File('image.png', fopen(__DIR__ . '/../../resources/seeds/image.png', 'r')); - } - - protected function fakeCorruptedImage() - { - return new \Illuminate\Http\UploadedFile(__DIR__ . '/../../resources/seeds/corrupted_image.png', 'pdf-as-png.png', 'image/png'); - } - - protected function fakeMap() - { - return new File('map.tiff', fopen(__DIR__ . '/../../resources/seeds/map.tiff', 'r')); - } - - protected function fakeFile() - { - return new File('file.pdf', fopen(__DIR__ . '/../../resources/seeds/file.pdf', 'r')); - } - - protected function fakeVideo() - { - return new File('video.mp4', fopen(__DIR__ . '/../../resources/seeds/video.mp4', 'r')); - } - - protected function fakeValidCsv() - { - return new File('valid-tree-species.csv', fopen(__DIR__ . '/../../resources/seeds/valid-tree-species.csv', 'r')); - } - - protected function fakeNoHeadersCsv() - { - return new File('no-headers-tree-species.csv', fopen(__DIR__ . '/../../resources/seeds/no-headers-tree-species.csv', 'r')); - } - - protected function searchCodebase(string $search, string $directory): array - { - $search = '"' . $search . '"'; - $directory = '"' . $directory . '"'; - $output = shell_exec('grep -r ' . $search . ' ' . $directory); - $lines = explode("\n", $output); - - return array_filter($lines, function ($value) { - return trim($value) != ''; - }); - } - - protected function getHeadersForUser($email) - { - $token = Auth::attempt([ - 'email_address' => $email, - 'password' => 'password', - ]); - - return [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - } - - protected function getHeaders(string $email, string $password): array - { - $token = Auth::attempt([ - 'email_address' => $email, - 'password' => $password, - ]); - - return [ - 'Authorization' => 'Bearer ' . $token, - 'Content-Type' => 'application/json', - ]; - } -} diff --git a/tests/Legacy/Other/ActionAuthorisationTest.php b/tests/Legacy/Other/ActionAuthorisationTest.php deleted file mode 100644 index c17200bd7..000000000 --- a/tests/Legacy/Other/ActionAuthorisationTest.php +++ /dev/null @@ -1,19 +0,0 @@ -getControllers() as $controller) { - $actions = $this->getActions($controller); - foreach ($actions as $action) { - $body = $this->getActionBody($action); - $this->assertStringContainsString('$this->authorize(', $body); - } - } - } -} diff --git a/tests/Legacy/Other/ActionTypeHintsTest.php b/tests/Legacy/Other/ActionTypeHintsTest.php deleted file mode 100644 index 831055abf..000000000 --- a/tests/Legacy/Other/ActionTypeHintsTest.php +++ /dev/null @@ -1,30 +0,0 @@ -getControllers() as $controller) { - $actions = $this->getActions($controller); - foreach ($actions as $action) { - $response = $action->getReturnType()->getName(); - $responses = [ - 'Illuminate\\Http\\Response', - 'Illuminate\\Http\\JsonResponse', - 'Illuminate\\Http\\RedirectResponse', - 'Illuminate\\View\\View', - 'Symfony\\Component\\HttpFoundation\\BinaryFileResponse', - 'Symfony\\Component\\HttpFoundation\\StreamedResponse', - 'App\\Http\\Resources\\V2\\User\\MeResource', - ]; - $this->assertIsOneOf($responses, $response); - $parameters = $action->getParameters(); - $this->assertTrue(count($parameters) > 0); - } - } - } -} diff --git a/tests/Legacy/Other/DraftValidatorTest.php b/tests/Legacy/Other/DraftValidatorTest.php deleted file mode 100644 index 8f620bb83..000000000 --- a/tests/Legacy/Other/DraftValidatorTest.php +++ /dev/null @@ -1,105 +0,0 @@ - null], - Arr::dot(OfferValidator::CREATE, 'offer.'), - ['offer_documents' => null, 'offer_documents.*' => null], - Arr::dot(OfferDocumentValidator::CREATE, 'offer_documents.*.'), - ['offer_contacts' => null, 'offer_contacts.*' => null], - Arr::dot(OfferContactValidator::CREATE, 'offer_contacts.*.') - ); - unset( - $frankensteinValidator['offer_documents.*.offer_id'], - $frankensteinValidator['offer_contacts.*.offer_id'] - ); - $this->assertSame(array_keys($validator), array_keys($frankensteinValidator)); - } - - public function testDraftHelperConstantsPassDraftValidator(): void - { - $valid = true; - - try { - DraftValidator::validate('UPDATE_DATA_OFFER', DraftOffer::BLUEPRINT); - DraftValidator::validate('UPDATE_DATA_PITCH', DraftPitch::BLUEPRINT); - } catch (Exception $exception) { - foreach ($exception->errors() as $source => $messages) { - foreach ($messages as $message) { - dump(json_decode($message)[3]); - } - } - $valid = false; - } - $this->assertTrue($valid); - } - - public function testDraftDataDocumentationMatchesOfferDocumentation(): void - { - $swagger = Yaml::parseFile(__DIR__ . '/../../../resources/docs/swagger.yml'); - $draftData = $swagger['definitions']['DraftDataRead']; - - $offer = $swagger['definitions']['OfferCreate']; - $offer['properties']['cover_photo']['type'] = 'string'; - $offer['properties']['video']['type'] = 'string'; - $this->assertSame($offer, $draftData['properties']['offer']); - - $offerContact = $swagger['definitions']['OfferContactCreate']; - unset($offerContact['properties']['offer_id']); - $this->assertSame($offerContact, $draftData['properties']['offer_contacts']['items']); - - $offerDocument = $swagger['definitions']['OfferDocumentCreate']; - unset($offerDocument['properties']['offer_id']); - $offerDocument['properties']['document']['type'] = 'string'; - $this->assertSame($offerDocument, $draftData['properties']['offer_documents']['items']); - } - - public function testDraftDataDocumentationMatchesPitchDocumentation(): void - { - $swagger = Yaml::parseFile(__DIR__ . '/../../../resources/docs/swagger.yml'); - $draftData = $swagger['definitions']['DraftDataRead']; - - $pitch = $swagger['definitions']['PitchCreate']; - $pitch['properties']['cover_photo']['type'] = 'string'; - $pitch['properties']['video']['type'] = 'string'; - $this->assertSame($pitch, $draftData['properties']['pitch']); - - $pitchContact = $swagger['definitions']['PitchContactCreate']; - unset($pitchContact['properties']['pitch_id']); - $this->assertSame($pitchContact, $draftData['properties']['pitch_contacts']['items']); - - $pitchDocument = $swagger['definitions']['PitchDocumentCreate']; - unset($pitchDocument['properties']['pitch_id']); - $pitchDocument['properties']['document']['type'] = 'string'; - $this->assertSame($pitchDocument, $draftData['properties']['pitch_documents']['items']); - - $carbonCertification = $swagger['definitions']['CarbonCertificationCreate']; - unset($carbonCertification['properties']['pitch_id']); - $this->assertSame($carbonCertification, $draftData['properties']['carbon_certifications']['items']); - - $restorationMethodMetric = $swagger['definitions']['RestorationMethodMetricCreate']; - unset($restorationMethodMetric['properties']['pitch_id']); - $this->assertSame($restorationMethodMetric, $draftData['properties']['restoration_method_metrics']['items']); - - $treeSpecies = $swagger['definitions']['TreeSpeciesCreate']; - unset($treeSpecies['properties']['pitch_id']); - $this->assertSame($treeSpecies, $draftData['properties']['tree_species']['items']); - } -} diff --git a/tests/Legacy/Other/NoDebuggingRemainingTest.php b/tests/Legacy/Other/NoDebuggingRemainingTest.php deleted file mode 100644 index 612430bf4..000000000 --- a/tests/Legacy/Other/NoDebuggingRemainingTest.php +++ /dev/null @@ -1,18 +0,0 @@ -searchCodebase(' dd(', __DIR__ . '/../../../app'); - $this->assertCount(0, $dds); - $varDumps = $this->searchCodebase(' var_dump(', __DIR__ . '/../../../app'); - $this->assertCount(0, $varDumps); - $dumps = $this->searchCodebase(' dump(', __DIR__ . '/../../../app'); - $this->assertCount(0, $dumps); - } -} diff --git a/tests/Legacy/Other/RoutesAndSwaggerMatchTest.php b/tests/Legacy/Other/RoutesAndSwaggerMatchTest.php deleted file mode 100644 index 66da3cfd8..000000000 --- a/tests/Legacy/Other/RoutesAndSwaggerMatchTest.php +++ /dev/null @@ -1,56 +0,0 @@ - $methods) { - foreach ($methods as $method => $details) { - $paths[$method][] = strtolower($path); - } - } - $routes = file_get_contents(__DIR__ . "/../../../routes/api.php"); - $matches = []; - preg_match_all('/\\nRoute::[a-z]{2,6}\\([^\\)]+\\);/', $routes, $matches); - foreach ($matches[0] as $match) { - $a = explode('::', trim($match)); - $b = explode('(', $a[1]); - $c = explode(', ', $b[1]); - $method = $b[0]; - $path = strtolower(trim($c[0], "'\"")); - $normalisedPath = preg_replace('/{[a-zA-Z0-9?]+}/', '{id}', $path); - $this->assertArrayHasKey($method, $paths); - $toExclude = [ - '/carbon_certification_types', - '/organisation_types', - '/land_ownerships', - '/land_sizes', - '/continents', - '/restoration_goals', - '/funding_sources', - '/reporting_frequencies', - '/reporting_levels', - '/sustainable_development_goals', - '/rejected_reasons', - ]; - if(!in_array($path, $toExclude)) { - $this->assertThat( - $paths[$method], - $this->logicalOr( - new TraversableContainsEqual($path), - new TraversableContainsEqual($normalisedPath) - ) - ); - } - } - } -} diff --git a/tests/Legacy/Other/ValidationRulesDocumentedTest.php b/tests/Legacy/Other/ValidationRulesDocumentedTest.php deleted file mode 100644 index 06895d2da..000000000 --- a/tests/Legacy/Other/ValidationRulesDocumentedTest.php +++ /dev/null @@ -1,27 +0,0 @@ -get('/documentation/raw')->getContent(); - $swagger = Yaml::parse($yaml); - $description = $swagger['info']['description']; - - $extensions = glob(__DIR__ . '/../../../app/Validators/Extensions/*.php'); - foreach ($extensions as $extension) { - $basename = basename($extension, '.php'); - if ($basename == 'Extension') { - continue; - } - $name = strtoupper(Str::snake($basename)); - $this->assertStringContainsString($name, $description); - } - } -} diff --git a/tests/Legacy/Unit/ArrayArrayExtensionTest.php b/tests/Legacy/Unit/ArrayArrayExtensionTest.php deleted file mode 100644 index d09107074..000000000 --- a/tests/Legacy/Unit/ArrayArrayExtensionTest.php +++ /dev/null @@ -1,54 +0,0 @@ - "required|array|array_array", - "foo.*" => "required|string" - ]; - } - } -HEREDOC); - } - } - - public function testArraysPass(): void - { - $this->define(); - ArrayArrayTestValidator::validate('TEST', ['foo' => ['bar', 'baz', 'qux']]); - $this->assertTrue(true); - } - - public function testOrderedStringKeysPass(): void - { - $this->define(); - ArrayArrayTestValidator::validate('TEST', ['foo' => ['0' => 'bar', '1' => 'baz', '2' => 'qux']]); - $this->assertTrue(true); - } - - public function testUnorderedKeysFail(): void - { - $this->define(); - $this->expectException('Illuminate\\Validation\\ValidationException'); - ArrayArrayTestValidator::validate('TEST', ['foo' => [0 => 'bar', 1 => 'baz', 3 => 'qux']]); - } - - public function testStringKeysFail(): void - { - $this->define(); - $this->expectException('Illuminate\\Validation\\ValidationException'); - ArrayArrayTestValidator::validate('TEST', ['foo' => ['a' => 'bar', 'b' => 'baz', 'c' => 'qux']]); - } -} diff --git a/tests/Legacy/Unit/ArrayObjectExtensionTest.php b/tests/Legacy/Unit/ArrayObjectExtensionTest.php deleted file mode 100644 index 6367cd560..000000000 --- a/tests/Legacy/Unit/ArrayObjectExtensionTest.php +++ /dev/null @@ -1,40 +0,0 @@ - "required|array|array_object", - "foo.*" => "required|string" - ]; - } - } -HEREDOC); - } - } - - public function testObjectPass(): void - { - $this->define(); - ArrayObjectTestValidator::validate('TEST', ['foo' => ['a' => 'bar', 'b' => 'baz', 'c' => 'qux']]); - $this->assertTrue(true); - } - - public function testArraysFail(): void - { - $this->define(); - $this->expectException('Illuminate\\Validation\\ValidationException'); - ArrayObjectTestValidator::validate('TEST', ['foo' => ['bar', 'baz', 'qux']]); - } -} diff --git a/tests/Legacy/Unit/Jobs/CreateProgrammeTreeSpeciesJobTest.php b/tests/Legacy/Unit/Jobs/CreateProgrammeTreeSpeciesJobTest.php deleted file mode 100644 index 76d49ea6d..000000000 --- a/tests/Legacy/Unit/Jobs/CreateProgrammeTreeSpeciesJobTest.php +++ /dev/null @@ -1,19 +0,0 @@ -assertDatabaseHas('programme_tree_species', [ - 'programme_id' => 1, - 'name' => 'tree name', - ]); - } -} diff --git a/tests/Legacy/Unit/Jobs/CreateSiteTreeSpeciesJobTest.php b/tests/Legacy/Unit/Jobs/CreateSiteTreeSpeciesJobTest.php deleted file mode 100644 index 2e7204b08..000000000 --- a/tests/Legacy/Unit/Jobs/CreateSiteTreeSpeciesJobTest.php +++ /dev/null @@ -1,31 +0,0 @@ -assertDatabaseHas('site_tree_species', [ - 'site_id' => 1, - 'name' => 'tree name', - 'amount' => 100, - ]); - } - - public function testJobCreatesSiteSpeciesTreesWithoutAmount(): void - { - CreateSiteTreeSpeciesJob::dispatchSync('tree name without amount', 1, 1); - - $this->assertDatabaseHas('site_tree_species', [ - 'site_id' => 1, - 'name' => 'tree name without amount', - 'amount' => null, - ]); - } -} diff --git a/tests/Legacy/Unit/Jobs/CreateTerrafundTreeSpeciesJobTest.php b/tests/Legacy/Unit/Jobs/CreateTerrafundTreeSpeciesJobTest.php deleted file mode 100644 index 27289520b..000000000 --- a/tests/Legacy/Unit/Jobs/CreateTerrafundTreeSpeciesJobTest.php +++ /dev/null @@ -1,23 +0,0 @@ -assertDatabaseHas('terrafund_tree_species', [ - 'treeable_type' => TerrafundProgramme::class, - 'treeable_id' => 1, - 'terrafund_csv_import_id' => 1, - 'name' => 'tree name', - 'amount' => 123, - ]); - } -} diff --git a/tests/Legacy/Unit/Jobs/RemoveProgrammeTreeSpeciesByImportJobTest.php b/tests/Legacy/Unit/Jobs/RemoveProgrammeTreeSpeciesByImportJobTest.php deleted file mode 100644 index 15af90ecf..000000000 --- a/tests/Legacy/Unit/Jobs/RemoveProgrammeTreeSpeciesByImportJobTest.php +++ /dev/null @@ -1,33 +0,0 @@ -assertDatabaseHas('programme_tree_species', [ - 'id' => 6, - 'csv_import_id' => 3, - ])->assertDatabaseHas('programme_tree_species', [ - 'id' => 7, - 'csv_import_id' => 3, - ])->assertDatabaseHas('programme_tree_species', [ - 'id' => 8, - 'csv_import_id' => 3, - ]); - - RemoveProgrammeTreeSpeciesByImportJob::dispatchSync(3); - - $this->assertDatabaseMissing('programme_tree_species', [ - 'id' => 6, - ])->assertDatabaseMissing('programme_tree_species', [ - 'id' => 7, - ])->assertDatabaseMissing('programme_tree_species', [ - 'id' => 8, - ]); - } -} diff --git a/tests/Legacy/Unit/Jobs/RemoveSiteTreeSpeciesByImportJobTest.php b/tests/Legacy/Unit/Jobs/RemoveSiteTreeSpeciesByImportJobTest.php deleted file mode 100644 index 3936ad403..000000000 --- a/tests/Legacy/Unit/Jobs/RemoveSiteTreeSpeciesByImportJobTest.php +++ /dev/null @@ -1,23 +0,0 @@ -assertDatabaseHas('site_tree_species', [ - 'id' => 2, - 'site_csv_import_id' => 1, - ]); - - RemoveSiteTreeSpeciesByImportJob::dispatchSync(1); - - $this->assertDatabaseMissing('site_tree_species', [ - 'id' => 2, - ]); - } -} diff --git a/tests/Legacy/Unit/Jobs/RemoveTerrafundTreeSpeciesByImportJobTest.php b/tests/Legacy/Unit/Jobs/RemoveTerrafundTreeSpeciesByImportJobTest.php deleted file mode 100644 index b28f61fee..000000000 --- a/tests/Legacy/Unit/Jobs/RemoveTerrafundTreeSpeciesByImportJobTest.php +++ /dev/null @@ -1,23 +0,0 @@ -assertDatabaseHas('terrafund_tree_species', [ - 'id' => 2, - 'terrafund_csv_import_id' => 1, - ]); - - RemoveTerrafundTreeSpeciesByImportJob::dispatchSync(1); - - $this->assertDatabaseMissing('terrafund_tree_species', [ - 'id' => 2, - ]); - } -} diff --git a/tests/Legacy/Unit/JsonPatchHelperTest.php b/tests/Legacy/Unit/JsonPatchHelperTest.php deleted file mode 100644 index d6ca6b860..000000000 --- a/tests/Legacy/Unit/JsonPatchHelperTest.php +++ /dev/null @@ -1,138 +0,0 @@ -assertSame(json_encode($a), json_encode($b)); - } - - public function testRemoveOpsAreReorderedCorrectly(): void - { - $before = [ - (object) ['op' => 'remove', 'path' => '/foo/1'], - (object) ['op' => 'remove', 'path' => '/foo/2'], - ]; - $after = [ - (object) ['op' => 'remove', 'path' => '/foo/2'], - (object) ['op' => 'remove', 'path' => '/foo/1'], - ]; - $this->assertIdentical($after, JsonPatchHelper::reorderRemoveOps($before)); - } - - public function testRemoveOpsAreReorderedCorrectlyAgain(): void - { - $before = [ - (object) ['op' => 'remove', 'path' => '/foo/1'], - (object) ['op' => 'remove', 'path' => '/foo/2'], - (object) ['op' => 'remove', 'path' => '/foo/3'], - ]; - $after = [ - (object) ['op' => 'remove', 'path' => '/foo/3'], - (object) ['op' => 'remove', 'path' => '/foo/2'], - (object) ['op' => 'remove', 'path' => '/foo/1'], - ]; - $this->assertIdentical($after, JsonPatchHelper::reorderRemoveOps($before)); - } - - public function testRemoveOpsAreReorderedCorrectlyAgainAgain(): void - { - $before = [ - (object) ['op' => 'remove', 'path' => '/foo/1'], - (object) ['op' => 'remove', 'path' => '/foo/2'], - (object) ['op' => 'add', 'path' => '/bar', 'value' => 'bar'], - ]; - $after = [ - (object) ['op' => 'remove', 'path' => '/foo/2'], - (object) ['op' => 'remove', 'path' => '/foo/1'], - (object) ['op' => 'add', 'path' => '/bar', 'value' => 'bar'], - ]; - $this->assertIdentical($after, JsonPatchHelper::reorderRemoveOps($before)); - } - - public function testRemoveOpsAreReorderedCorrectlyAgainAgainAgain(): void - { - $before = [ - (object) ['op' => 'add', 'path' => '/bar', 'value' => 'bar'], - (object) ['op' => 'remove', 'path' => '/foo/1'], - (object) ['op' => 'add', 'path' => '/bar', 'value' => 'bar'], - (object) ['op' => 'remove', 'path' => '/foo/2'], - (object) ['op' => 'add', 'path' => '/bar', 'value' => 'bar'], - ]; - $after = [ - (object) ['op' => 'add', 'path' => '/bar', 'value' => 'bar'], - (object) ['op' => 'remove', 'path' => '/foo/2'], - (object) ['op' => 'add', 'path' => '/bar', 'value' => 'bar'], - (object) ['op' => 'remove', 'path' => '/foo/1'], - (object) ['op' => 'add', 'path' => '/bar', 'value' => 'bar'], - ]; - $this->assertIdentical($after, JsonPatchHelper::reorderRemoveOps($before)); - } - - public function testRemoveOpsAreReorderedCorrectlyAgainAgainAgainAgain(): void - { - $before = [ - (object) ['op' => 'add', 'path' => '/bar', 'value' => 'bar'], - (object) ['op' => 'remove', 'path' => '/foo/1'], - (object) ['op' => 'add', 'path' => '/bar', 'value' => 'bar'], - (object) ['op' => 'remove', 'path' => '/foo/2'], - (object) ['op' => 'add', 'path' => '/bar', 'value' => 'bar'], - (object) ['op' => 'remove', 'path' => '/foo/3'], - (object) ['op' => 'add', 'path' => '/bar', 'value' => 'bar'], - ]; - $after = [ - (object) ['op' => 'add', 'path' => '/bar', 'value' => 'bar'], - (object) ['op' => 'remove', 'path' => '/foo/3'], - (object) ['op' => 'add', 'path' => '/bar', 'value' => 'bar'], - (object) ['op' => 'remove', 'path' => '/foo/2'], - (object) ['op' => 'add', 'path' => '/bar', 'value' => 'bar'], - (object) ['op' => 'remove', 'path' => '/foo/1'], - (object) ['op' => 'add', 'path' => '/bar', 'value' => 'bar'], - ]; - $this->assertIdentical($after, JsonPatchHelper::reorderRemoveOps($before)); - } - - public function testRemoveOpsAreReorderedCorrectlyAgainAgainAgainAgainAgain(): void - { - $before = [ - (object) ['op' => 'remove', 'path' => '/foo/1'], - ]; - $after = [ - (object) ['op' => 'remove', 'path' => '/foo/1'], - ]; - $this->assertIdentical($after, JsonPatchHelper::reorderRemoveOps($before)); - } - - public function testExistingOpsArentAffected(): void - { - $before = [ - (object) ['op' => 'add', 'path' => 'foo', 'value' => 'foo'], - (object) ['op' => 'add', 'path' => 'bar', 'value' => 'bar'], - ]; - $after = [ - (object) ['op' => 'add', 'path' => 'foo', 'value' => 'foo'], - (object) ['op' => 'add', 'path' => 'bar', 'value' => 'bar'], - ]; - $this->assertIdentical($after, JsonPatchHelper::reorderRemoveOps($before)); - } - - public function testExistingOpsArentAffectedAgain(): void - { - $before = [ - (object) ['op' => 'add', 'path' => 'foo', 'value' => 'foo'], - (object) ['op' => 'add', 'path' => 'bar', 'value' => 'bar'], - (object) ['op' => 'add', 'path' => 'baz', 'value' => 'baz'], - ]; - $after = [ - (object) ['op' => 'add', 'path' => 'foo', 'value' => 'foo'], - (object) ['op' => 'add', 'path' => 'bar', 'value' => 'bar'], - (object) ['op' => 'add', 'path' => 'baz', 'value' => 'baz'], - ]; - $this->assertIdentical($after, JsonPatchHelper::reorderRemoveOps($before)); - } -} diff --git a/tests/Legacy/Unit/Models/CarbonCertificationTest.php b/tests/Legacy/Unit/Models/CarbonCertificationTest.php deleted file mode 100644 index 179577a83..000000000 --- a/tests/Legacy/Unit/Models/CarbonCertificationTest.php +++ /dev/null @@ -1,17 +0,0 @@ -assertInstanceOf(Pitch::class, $carbonCertification->pitch); - } -} diff --git a/tests/Legacy/Unit/Models/CarbonCertificationVersionTest.php b/tests/Legacy/Unit/Models/CarbonCertificationVersionTest.php deleted file mode 100644 index 9534c23cf..000000000 --- a/tests/Legacy/Unit/Models/CarbonCertificationVersionTest.php +++ /dev/null @@ -1,17 +0,0 @@ -assertInstanceOf(CarbonCertification::class, $carbonCertificationVersion->carbonCertification); - } -} diff --git a/tests/Legacy/Unit/Models/DeviceTest.php b/tests/Legacy/Unit/Models/DeviceTest.php deleted file mode 100644 index 829a75954..000000000 --- a/tests/Legacy/Unit/Models/DeviceTest.php +++ /dev/null @@ -1,17 +0,0 @@ -assertInstanceOf(User::class, $device->user); - } -} diff --git a/tests/Legacy/Unit/Models/DraftTest.php b/tests/Legacy/Unit/Models/DraftTest.php deleted file mode 100644 index bf69ea554..000000000 --- a/tests/Legacy/Unit/Models/DraftTest.php +++ /dev/null @@ -1,17 +0,0 @@ -assertInstanceOf(Organisation::class, $draft->organisation); - } -} diff --git a/tests/Legacy/Unit/Models/ElevatorVideoTest.php b/tests/Legacy/Unit/Models/ElevatorVideoTest.php deleted file mode 100644 index 578fd4599..000000000 --- a/tests/Legacy/Unit/Models/ElevatorVideoTest.php +++ /dev/null @@ -1,25 +0,0 @@ -assertInstanceOf(Upload::class, $elevatorVideo->upload); - } - - public function testElevatorVideoBelongsToUser(): void - { - $elevatorVideo = ElevatorVideo::first(); - - $this->assertInstanceOf(User::class, $elevatorVideo->user); - } -} diff --git a/tests/Legacy/Unit/Models/FilterRecordTest.php b/tests/Legacy/Unit/Models/FilterRecordTest.php deleted file mode 100644 index b4b5993c0..000000000 --- a/tests/Legacy/Unit/Models/FilterRecordTest.php +++ /dev/null @@ -1,25 +0,0 @@ -assertInstanceOf(User::class, $filterRecord->user); - } - - public function testFilterRecordBelongsToOrganisation(): void - { - $filterRecord = FilterRecord::first(); - - $this->assertInstanceOf(Organisation::class, $filterRecord->organisation); - } -} diff --git a/tests/Legacy/Unit/Models/InterestTest.php b/tests/Legacy/Unit/Models/InterestTest.php deleted file mode 100644 index 4202c5f6e..000000000 --- a/tests/Legacy/Unit/Models/InterestTest.php +++ /dev/null @@ -1,33 +0,0 @@ -assertInstanceOf(Offer::class, $interest->offer); - } - - public function testInterestBelongsToPitch(): void - { - $interest = Interest::first(); - - $this->assertInstanceOf(Pitch::class, $interest->pitch); - } - - public function testInterestBelongsToOrganisation(): void - { - $interest = Interest::first(); - - $this->assertInstanceOf(Organisation::class, $interest->organisation); - } -} diff --git a/tests/Legacy/Unit/Models/MatchTest.php b/tests/Legacy/Unit/Models/MatchTest.php deleted file mode 100644 index 1c37c96d7..000000000 --- a/tests/Legacy/Unit/Models/MatchTest.php +++ /dev/null @@ -1,25 +0,0 @@ -assertInstanceOf(Interest::class, $matched->interest); - } - - public function testMatchBelongsToSecondaryInterest(): void - { - $matched = Matched::first(); - - $this->assertInstanceOf(Interest::class, $matched->secondaryInterest); - } -} diff --git a/tests/Legacy/Unit/Models/MonitoringTest.php b/tests/Legacy/Unit/Models/MonitoringTest.php deleted file mode 100644 index 8ff591864..000000000 --- a/tests/Legacy/Unit/Models/MonitoringTest.php +++ /dev/null @@ -1,26 +0,0 @@ -assertInstanceOf(Matched::class, $monitoring->matched); - } - - public function testMonitoringBelongsToUser(): void - { - $monitoring = Monitoring::first(); - - $this->assertInstanceOf(User::class, $monitoring->createdBy); - } -} diff --git a/tests/Legacy/Unit/Models/NotificationTest.php b/tests/Legacy/Unit/Models/NotificationTest.php deleted file mode 100644 index 248216dc9..000000000 --- a/tests/Legacy/Unit/Models/NotificationTest.php +++ /dev/null @@ -1,17 +0,0 @@ -assertInstanceOf(User::class, $notification->user); - } -} diff --git a/tests/Legacy/Unit/Models/OfferContactTest.php b/tests/Legacy/Unit/Models/OfferContactTest.php deleted file mode 100644 index 12fda25d0..000000000 --- a/tests/Legacy/Unit/Models/OfferContactTest.php +++ /dev/null @@ -1,33 +0,0 @@ -first(); - - $this->assertInstanceOf(TeamMember::class, $offerContact->team_member); - } - - public function testOfferContactBelongsToUser(): void - { - $offerContact = OfferContact::whereNotNull('user_id')->first(); - - $this->assertInstanceOf(User::class, $offerContact->user); - } - - public function testOfferContactBelongsToOffer(): void - { - $offerContact = OfferContact::first(); - - $this->assertInstanceOf(Offer::class, $offerContact->offer); - } -} diff --git a/tests/Legacy/Unit/Models/OfferDocumentTest.php b/tests/Legacy/Unit/Models/OfferDocumentTest.php deleted file mode 100644 index f704162d5..000000000 --- a/tests/Legacy/Unit/Models/OfferDocumentTest.php +++ /dev/null @@ -1,17 +0,0 @@ -assertInstanceOf(Offer::class, $offerDocument->offer); - } -} diff --git a/tests/Legacy/Unit/Models/OfferTest.php b/tests/Legacy/Unit/Models/OfferTest.php deleted file mode 100644 index 9a848ff4f..000000000 --- a/tests/Legacy/Unit/Models/OfferTest.php +++ /dev/null @@ -1,17 +0,0 @@ -assertInstanceOf(Organisation::class, $offer->organisation); - } -} diff --git a/tests/Legacy/Unit/Models/OrganisationDocumentTest.php b/tests/Legacy/Unit/Models/OrganisationDocumentTest.php deleted file mode 100644 index 23e4a5b1a..000000000 --- a/tests/Legacy/Unit/Models/OrganisationDocumentTest.php +++ /dev/null @@ -1,17 +0,0 @@ -assertInstanceOf(Organisation::class, $organisationDocument->organisation); - } -} diff --git a/tests/Legacy/Unit/Models/OrganisationDocumentVersionTest.php b/tests/Legacy/Unit/Models/OrganisationDocumentVersionTest.php deleted file mode 100644 index 5e36f92ef..000000000 --- a/tests/Legacy/Unit/Models/OrganisationDocumentVersionTest.php +++ /dev/null @@ -1,17 +0,0 @@ -assertInstanceOf(OrganisationDocument::class, $organisationDocumentVersion->organisationDocument); - } -} diff --git a/tests/Legacy/Unit/Models/OrganisationVersionTest.php b/tests/Legacy/Unit/Models/OrganisationVersionTest.php deleted file mode 100644 index febbf8c8e..000000000 --- a/tests/Legacy/Unit/Models/OrganisationVersionTest.php +++ /dev/null @@ -1,19 +0,0 @@ -assertInstanceOf(Organisation::class, $organisationVersion->organisation); - } -} diff --git a/tests/Legacy/Unit/Models/PasswordResetTest.php b/tests/Legacy/Unit/Models/PasswordResetTest.php deleted file mode 100644 index 5b465fa2c..000000000 --- a/tests/Legacy/Unit/Models/PasswordResetTest.php +++ /dev/null @@ -1,19 +0,0 @@ -assertInstanceOf(User::class, $passwordReset->user); - } -} diff --git a/tests/Legacy/Unit/Models/PitchContactTest.php b/tests/Legacy/Unit/Models/PitchContactTest.php deleted file mode 100644 index 87f44df30..000000000 --- a/tests/Legacy/Unit/Models/PitchContactTest.php +++ /dev/null @@ -1,28 +0,0 @@ -assertInstanceOf(User::class, $pitchContact->user); - } - - #[Test] - public function testPitchContactBelongsToTeamMember(): void - { - $pitchContact = PitchContact::where('id', 3)->first(); - - $this->assertInstanceOf(TeamMember::class, $pitchContact->team_member); - } -} diff --git a/tests/Legacy/Unit/Models/PitchDocumentTest.php b/tests/Legacy/Unit/Models/PitchDocumentTest.php deleted file mode 100644 index 8015b9558..000000000 --- a/tests/Legacy/Unit/Models/PitchDocumentTest.php +++ /dev/null @@ -1,19 +0,0 @@ -assertInstanceOf(Pitch::class, $pitchDocument->pitch); - } -} diff --git a/tests/Legacy/Unit/Models/PitchDocumentVersionTest.php b/tests/Legacy/Unit/Models/PitchDocumentVersionTest.php deleted file mode 100644 index 93acbfa30..000000000 --- a/tests/Legacy/Unit/Models/PitchDocumentVersionTest.php +++ /dev/null @@ -1,28 +0,0 @@ -assertInstanceOf(PitchDocument::class, $pitchDocumentVersion->pitchDocument); - } - - #[Test] - public function testPitchDocumentVersionBelongsToApprovedRejectedBy(): void - { - $pitchDocumentVersion = PitchDocumentVersion::first(); - - $this->assertInstanceOf(User::class, $pitchDocumentVersion->approvedRejectedBy); - } -} diff --git a/tests/Legacy/Unit/Models/PitchTest.php b/tests/Legacy/Unit/Models/PitchTest.php deleted file mode 100644 index 6ed6fc5ff..000000000 --- a/tests/Legacy/Unit/Models/PitchTest.php +++ /dev/null @@ -1,19 +0,0 @@ -assertInstanceOf(Organisation::class, $pitch->organisation); - } -} diff --git a/tests/Legacy/Unit/Models/PitchVersionTest.php b/tests/Legacy/Unit/Models/PitchVersionTest.php deleted file mode 100644 index 77b4ff064..000000000 --- a/tests/Legacy/Unit/Models/PitchVersionTest.php +++ /dev/null @@ -1,28 +0,0 @@ -assertInstanceOf(Pitch::class, $pitchVersion->pitch); - } - - #[Test] - public function testPitchVersionBelongsToApprovedRejectedBy(): void - { - $pitchVersion = PitchVersion::first(); - - $this->assertInstanceOf(User::class, $pitchVersion->approvedRejectedBy); - } -} diff --git a/tests/Legacy/Unit/Models/ProgressUpdateTest.php b/tests/Legacy/Unit/Models/ProgressUpdateTest.php deleted file mode 100644 index f1421d6a8..000000000 --- a/tests/Legacy/Unit/Models/ProgressUpdateTest.php +++ /dev/null @@ -1,28 +0,0 @@ -assertInstanceOf(Monitoring::class, $progressUpdate->monitoring); - } - - #[Test] - public function testProgressUpdateBelongsToUser(): void - { - $progressUpdate = ProgressUpdate::first(); - - $this->assertInstanceOf(User::class, $progressUpdate->createdBy); - } -} diff --git a/tests/Legacy/Unit/Models/RestorationMethodMetricTest.php b/tests/Legacy/Unit/Models/RestorationMethodMetricTest.php deleted file mode 100644 index d389c333c..000000000 --- a/tests/Legacy/Unit/Models/RestorationMethodMetricTest.php +++ /dev/null @@ -1,19 +0,0 @@ -assertInstanceOf(Pitch::class, $restorationMethodMetric->pitch); - } -} diff --git a/tests/Legacy/Unit/Models/RestorationMethodMetricVersionTest.php b/tests/Legacy/Unit/Models/RestorationMethodMetricVersionTest.php deleted file mode 100644 index 291f79148..000000000 --- a/tests/Legacy/Unit/Models/RestorationMethodMetricVersionTest.php +++ /dev/null @@ -1,28 +0,0 @@ -assertInstanceOf(RestorationMethodMetric::class, $restorationMethodMetricVersion->restorationMethodMetric); - } - - #[Test] - public function testRestorationMethodMetricVersionBelongsToApprovedRejectedBy(): void - { - $restorationMethodMetricVersion = RestorationMethodMetricVersion::first(); - - $this->assertInstanceOf(User::class, $restorationMethodMetricVersion->approvedRejectedBy); - } -} diff --git a/tests/Legacy/Unit/Models/SatelliteMapTest.php b/tests/Legacy/Unit/Models/SatelliteMapTest.php deleted file mode 100644 index 277774890..000000000 --- a/tests/Legacy/Unit/Models/SatelliteMapTest.php +++ /dev/null @@ -1,28 +0,0 @@ -assertInstanceOf(Monitoring::class, $satelliteMap->monitoring); - } - - #[Test] - public function testSatelliteMapBelongsToUser(): void - { - $satelliteMap = SatelliteMap::first(); - - $this->assertInstanceOf(User::class, $satelliteMap->createdBy); - } -} diff --git a/tests/Legacy/Unit/Models/TargetTest.php b/tests/Legacy/Unit/Models/TargetTest.php deleted file mode 100644 index 27a244fa6..000000000 --- a/tests/Legacy/Unit/Models/TargetTest.php +++ /dev/null @@ -1,36 +0,0 @@ -assertInstanceOf(Monitoring::class, $target->monitoring); - } - - #[Test] - public function testTargetBelongsToUser(): void - { - $target = Target::first(); - - $this->assertInstanceOf(User::class, $target->createdBy); - } - - #[Test] - public function testTargetBelongsToAcceptedByUser(): void - { - $target = Target::first(); - - $this->assertInstanceOf(User::class, $target->acceptedBy); - } -} diff --git a/tests/Legacy/Unit/Models/TeamMemberTest.php b/tests/Legacy/Unit/Models/TeamMemberTest.php deleted file mode 100644 index 4b7ca304d..000000000 --- a/tests/Legacy/Unit/Models/TeamMemberTest.php +++ /dev/null @@ -1,19 +0,0 @@ -assertInstanceOf(Organisation::class, $teamMember->organisation); - } -} diff --git a/tests/Legacy/Unit/Models/TreeSpeciesTest.php b/tests/Legacy/Unit/Models/TreeSpeciesTest.php deleted file mode 100644 index 22f220b05..000000000 --- a/tests/Legacy/Unit/Models/TreeSpeciesTest.php +++ /dev/null @@ -1,19 +0,0 @@ -assertInstanceOf(Pitch::class, $treeSpecies->pitch); - } -} diff --git a/tests/Legacy/Unit/Models/TreeSpeciesVersionTest.php b/tests/Legacy/Unit/Models/TreeSpeciesVersionTest.php deleted file mode 100644 index 545eadefa..000000000 --- a/tests/Legacy/Unit/Models/TreeSpeciesVersionTest.php +++ /dev/null @@ -1,28 +0,0 @@ -assertInstanceOf(TreeSpecies::class, $treeSpeciesVersion->treeSpecies); - } - - #[Test] - public function treeSpeciesVersionBelongsToApprovedRejectedBy(): void - { - $treeSpeciesVersion = TreeSpeciesVersion::first(); - - $this->assertInstanceOf(User::class, $treeSpeciesVersion->approvedRejectedBy); - } -} diff --git a/tests/Legacy/Unit/Models/UploadTest.php b/tests/Legacy/Unit/Models/UploadTest.php deleted file mode 100644 index 3fb2508a9..000000000 --- a/tests/Legacy/Unit/Models/UploadTest.php +++ /dev/null @@ -1,17 +0,0 @@ -assertInstanceOf(User::class, $upload->user); - } -} diff --git a/tests/Legacy/Unit/Models/UserTest.php b/tests/Legacy/Unit/Models/UserTest.php deleted file mode 100644 index 7e15eb611..000000000 --- a/tests/Legacy/Unit/Models/UserTest.php +++ /dev/null @@ -1,17 +0,0 @@ -first(); - - $this->assertInstanceOf(Organisation::class, $user->organisation); - } -} diff --git a/tests/Legacy/Unit/Models/VerificationTest.php b/tests/Legacy/Unit/Models/VerificationTest.php deleted file mode 100644 index 89893f3f0..000000000 --- a/tests/Legacy/Unit/Models/VerificationTest.php +++ /dev/null @@ -1,19 +0,0 @@ -assertInstanceOf(User::class, $verification->user); - } -} From 081c5cb5a2de56e779fe3782f553eb26b3b41c13 Mon Sep 17 00:00:00 2001 From: Nathan Curtis Date: Fri, 5 Apr 2024 14:34:57 -0700 Subject: [PATCH 05/44] [TM-785] Get the linter passing. --- app/Auth/ServiceAccountGuard.php | 8 +++--- .../Commands/CreateBackdatedReportCommand.php | 15 +++++++---- app/Console/Commands/CreateServiceAccount.php | 3 ++- .../Migration/CreateTasksMigrationCommand.php | 1 - .../OneOff/AssociateReportsTasksCommand.php | 6 +++-- .../Commands/OneOff/FixReportCompletion.php | 2 +- .../Commands/OneOff/MigrateTaskStatuses.php | 10 +++++--- .../Commands/UpdateUrlBucketCommand.php | 1 + app/Exceptions/InvalidStatusException.php | 2 +- app/Exports/V2/EntityExport.php | 16 ++++++------ app/Http/Controllers/Traits/IsAdminIndex.php | 11 ++++---- .../AdminSoftDeleteEntityController.php | 1 + .../Entities/AdminStatusEntityController.php | 2 ++ .../SubmitEntityWithFormController.php | 2 +- .../UpdateEntityWithFormController.php | 3 ++- .../V2/Entities/ViewEntityController.php | 1 + .../Entities/ViewEntityWithFormController.php | 1 + ...rojectDataAsProjectDeveloperController.php | 1 + ...jectEntityAsProjectDeveloperController.php | 1 - .../AdminIndexNurseriesController.php | 1 + .../AdminIndexNurseryReportsController.php | 1 + .../AdminIndexProjectReportsController.php | 25 ++++++++++--------- .../Projects/AdminIndexProjectsController.php | 3 +-- .../CreateBlankProjectWithFormController.php | 2 +- .../CreateProjectWithFormController.php | 2 +- .../Reports/AdminStatusReportController.php | 3 ++- .../NothingToReportReportController.php | 1 + .../AdminIndexSiteReportsController.php | 2 +- .../V2/Sites/AdminIndexSitesController.php | 1 + .../V2/Tasks/AdminIndexTasksController.php | 5 ++-- .../V2/Tasks/SubmitProjectTasksController.php | 1 + .../EntityUpdateRequestsController.php | 6 ----- .../ModelInterfaceBindingMiddleware.php | 2 +- .../ProjectReports/ProjectReportResource.php | 2 +- app/Jobs/V2/CreateTaskDueJob.php | 14 ++++++++--- .../V2/SendEntityStatusChangeEmailsJob.php | 2 +- app/Mail/EntityStatusChange.php | 6 ++--- app/Models/Traits/HasEntityResources.php | 1 + app/Models/Traits/HasEntityStatus.php | 5 ++-- .../HasEntityStatusScopesAndTransitions.php | 5 ++-- app/Models/Traits/HasReportStatus.php | 11 ++++---- app/Models/Traits/HasUpdateRequests.php | 5 ++-- app/Models/Traits/UsesLinkedFields.php | 13 +++++----- app/Models/V2/EntityModel.php | 4 +-- app/Models/V2/Projects/Project.php | 5 ++-- app/Models/V2/Projects/ProjectReport.php | 2 +- app/Models/V2/Sites/Site.php | 4 +-- app/Models/V2/Sites/SiteReport.php | 2 +- app/Models/V2/Tasks/Task.php | 19 ++++++++------ app/Models/V2/UpdateRequestableModel.php | 2 +- app/Models/V2/Workdays/Workday.php | 2 +- app/Policies/Policy.php | 2 +- app/Services/PushService.php | 2 +- .../ReportStatusStateMachine.php | 3 ++- app/Validators/ServiceAccountValidator.php | 2 +- ...023_08_16_091316_create_v2_sites_table.php | 1 - ...paid_other_activity_description_pro_re.php | 2 +- ...aid_other_activity_description_site_re.php | 2 +- ..._12_231120_add_report_task_association.php | 4 +-- ...24_02_22_224122_drop_completion_status.php | 3 +-- ...2400_seed_options_list_siting_strategy.php | 3 +-- .../2024_03_29_230737_add_api_key_to_user.php | 3 +-- ...03_29_233951_add_service_to_users_role.php | 5 +--- routes/api_v2.php | 8 +++--- 64 files changed, 158 insertions(+), 128 deletions(-) diff --git a/app/Auth/ServiceAccountGuard.php b/app/Auth/ServiceAccountGuard.php index 002b894f0..6e3f347ee 100644 --- a/app/Auth/ServiceAccountGuard.php +++ b/app/Auth/ServiceAccountGuard.php @@ -14,9 +14,9 @@ class ServiceAccountGuard implements Guard { use GuardHelpers; - const HEADER = 'authorization'; - CONST PREFIX = 'bearer'; - const API_KEY_LENGTH = 64; + public const HEADER = 'authorization'; + public const PREFIX = 'bearer'; + public const API_KEY_LENGTH = 64; protected Request $request; @@ -73,4 +73,4 @@ protected function isJwt($value): bool return false; } } -} \ No newline at end of file +} diff --git a/app/Console/Commands/CreateBackdatedReportCommand.php b/app/Console/Commands/CreateBackdatedReportCommand.php index 2532194f5..edc89da31 100644 --- a/app/Console/Commands/CreateBackdatedReportCommand.php +++ b/app/Console/Commands/CreateBackdatedReportCommand.php @@ -4,13 +4,12 @@ use App\Models\V2\Nurseries\Nursery; use App\Models\V2\Nurseries\NurseryReport; -use App\Models\V2\Sites\Site; -use App\Models\V2\Sites\SiteReport; use App\Models\V2\Projects\Project; use App\Models\V2\Projects\ProjectReport; -use App\StateMachines\TaskStatusStateMachine; +use App\Models\V2\Sites\Site; +use App\Models\V2\Sites\SiteReport; use App\Models\V2\Tasks\Task; -use Carbon\Carbon; +use App\StateMachines\TaskStatusStateMachine; use Illuminate\Console\Command; class CreateBackdatedReportCommand extends Command @@ -36,20 +35,24 @@ public function handle(): int case 'project': $entityModel = Project::class; $reportModel = ProjectReport::class; + break; case 'site': $entityModel = Site::class; $reportModel = SiteReport::class; + break; case 'nursery': $entityModel = Nursery::class; $reportModel = NurseryReport::class; + break; default: $this->error('Type must be one of "site" or "nursery"'); + return 1; } @@ -58,6 +61,7 @@ public function handle(): int $entity = $entityModel::where('uuid', $uuid)->first(); if ($entity == null) { $this->error("Entity.php not found [type=$type, uuid=$uuid]"); + return 1; } @@ -73,6 +77,7 @@ public function handle(): int if ($task == null) { $this->error("Task not found for project [$entity->project_id]"); + return 1; } @@ -97,4 +102,4 @@ public function handle(): int return 0; } -} \ No newline at end of file +} diff --git a/app/Console/Commands/CreateServiceAccount.php b/app/Console/Commands/CreateServiceAccount.php index 8044085e0..15de6e819 100644 --- a/app/Console/Commands/CreateServiceAccount.php +++ b/app/Console/Commands/CreateServiceAccount.php @@ -8,7 +8,6 @@ use DateTimeZone; use Exception; use Illuminate\Console\Command; -use Spatie\Permission\Models\Role; class CreateServiceAccount extends Command { @@ -51,11 +50,13 @@ public function handle() $user->assignRole('greenhouse-service-account'); $this->info("Created service account $email with API Key: $apiKey"); + return 0; } catch (Exception $exception) { $this->error($exception->getMessage()); $this->error('Creation failed'); + return -1; } } diff --git a/app/Console/Commands/Migration/CreateTasksMigrationCommand.php b/app/Console/Commands/Migration/CreateTasksMigrationCommand.php index 4c314edbd..4f89cb33e 100644 --- a/app/Console/Commands/Migration/CreateTasksMigrationCommand.php +++ b/app/Console/Commands/Migration/CreateTasksMigrationCommand.php @@ -5,7 +5,6 @@ use App\Models\V2\Projects\Project; use App\Models\V2\Projects\ProjectReport; use App\Models\V2\Tasks\Task; -use App\StateMachines\TaskStatusStateMachine; use Illuminate\Console\Command; class CreateTasksMigrationCommand extends Command diff --git a/app/Console/Commands/OneOff/AssociateReportsTasksCommand.php b/app/Console/Commands/OneOff/AssociateReportsTasksCommand.php index 352329a82..630d89a1d 100644 --- a/app/Console/Commands/OneOff/AssociateReportsTasksCommand.php +++ b/app/Console/Commands/OneOff/AssociateReportsTasksCommand.php @@ -41,7 +41,7 @@ public function handle() ); } - protected function addTaskIds ($class, $projectGetter = null): void + protected function addTaskIds($class, $projectGetter = null): void { if ($projectGetter == null) { $projectGetter = fn ($report) => $report->project()->withTrashed()->first(); @@ -61,12 +61,14 @@ protected function addTaskIds ($class, $projectGetter = null): void $project = $projectGetter($report); if ($project == null) { $skipped++; + continue; } $task = $this->taskForProjectAndDate($project, $report->due_at)->first(); if ($task == null) { $skipped++; + continue; } @@ -82,7 +84,7 @@ protected function addTaskIds ($class, $projectGetter = null): void $this->info("Completed $className migration [target=$target, updated=$updated, skipped=$skipped]"); } - protected function taskForProjectAndDate (Project $project, Carbon $date): Builder + protected function taskForProjectAndDate(Project $project, Carbon $date): Builder { return Task::where('project_id', $project->id) ->whereMonth('due_at', $date->month) diff --git a/app/Console/Commands/OneOff/FixReportCompletion.php b/app/Console/Commands/OneOff/FixReportCompletion.php index e26488d91..9c1699035 100644 --- a/app/Console/Commands/OneOff/FixReportCompletion.php +++ b/app/Console/Commands/OneOff/FixReportCompletion.php @@ -33,7 +33,7 @@ public function handle() $totalUpdated = 0; $totalAlreadyCorrect = 0; collect([ProjectReport::class, SiteReport::class, NurseryReport::class])->each( - function($modelClass) use (&$totalUpdated, &$totalAlreadyCorrect) { + function ($modelClass) use (&$totalUpdated, &$totalAlreadyCorrect) { $modelClass::withoutTimestamps(function () use ($modelClass, &$totalUpdated, &$totalAlreadyCorrect) { $modelClass::whereNot('status', ReportStatusStateMachine::DUE)->where('completion', '<', 100)->chunkById( 100, diff --git a/app/Console/Commands/OneOff/MigrateTaskStatuses.php b/app/Console/Commands/OneOff/MigrateTaskStatuses.php index d09510611..ec5138ea9 100644 --- a/app/Console/Commands/OneOff/MigrateTaskStatuses.php +++ b/app/Console/Commands/OneOff/MigrateTaskStatuses.php @@ -42,7 +42,7 @@ public function handle() // statuses aren't part of the updated state machine), we're re-implementing most of the logic in // Task->checkStatus Task::withoutTimestamps(function () use (&$numErrors, &$numClean) { - Task::withTrashed()->whereNotIn('status',self::VALID_STATUSES)->chunkbyId( + Task::withTrashed()->whereNotIn('status', self::VALID_STATUSES)->chunkbyId( 100, function ($tasks) use (&$numErrors, &$numClean) { foreach ($tasks as $task) { @@ -66,7 +66,8 @@ function ($tasks) use (&$numErrors, &$numClean) { } } } - }); + } + ); }); echo "Migration completed. [Tasks with errors: $numErrors, successful transitions: $numClean]"; @@ -74,10 +75,11 @@ function ($tasks) use (&$numErrors, &$numClean) { private function processException(Task $task, InvalidStatusException $exception): bool { - if (!$task->projectReport()->exists() && !$task->siteReports()->exists() && !$task->nurseryReports()->exists()) { + if (! $task->projectReport()->exists() && ! $task->siteReports()->exists() && ! $task->nurseryReports()->exists()) { echo "Task $task->id was due on $task->due_at and has no associated reports. Moving to 'approved'.\n"; $task->status = TaskStatusStateMachine::APPROVED; $task->save(); + return true; } @@ -93,11 +95,13 @@ private function processException(Task $task, InvalidStatusException $exception) echo "Task $task->id was due on $task->due_at and has reports in 'due' or 'started'. Moving to 'due'.\n"; $task->status = TaskStatusStateMachine::DUE; $task->save(); + return true; } $message = $exception->getMessage(); echo "Task $task->id: $message\n"; + return false; } } diff --git a/app/Console/Commands/UpdateUrlBucketCommand.php b/app/Console/Commands/UpdateUrlBucketCommand.php index f8502b131..13c24371f 100644 --- a/app/Console/Commands/UpdateUrlBucketCommand.php +++ b/app/Console/Commands/UpdateUrlBucketCommand.php @@ -50,6 +50,7 @@ public function handle(): int // Add more tables if needed $this->info('Update completed successfully.'); + return 0; } diff --git a/app/Exceptions/InvalidStatusException.php b/app/Exceptions/InvalidStatusException.php index de14d0dbc..1e8928b75 100644 --- a/app/Exceptions/InvalidStatusException.php +++ b/app/Exceptions/InvalidStatusException.php @@ -6,4 +6,4 @@ class InvalidStatusException extends Exception { -} \ No newline at end of file +} diff --git a/app/Exports/V2/EntityExport.php b/app/Exports/V2/EntityExport.php index 202ba9b83..d5f29a76d 100644 --- a/app/Exports/V2/EntityExport.php +++ b/app/Exports/V2/EntityExport.php @@ -73,7 +73,7 @@ protected function getAttachedMappedForEntity($entity): array $organisation->name ?? null, $entity->project->name ?? null, $entity->status ?? null, - $entity->due_at ?? null + $entity->due_at ?? null, ]; if (in_array($this->form->type, ['nursery', 'nursery-report','site', 'site-report', 'project-report'])) { @@ -83,8 +83,8 @@ protected function getAttachedMappedForEntity($entity): array if ($this->form->type === 'project-report') { $mapped[] = $entity->project->uuid ?? null; if($this->form->framework_key === 'ppc') { - $mapped[] = $entity->seedlings_grown ?? null; - } + $mapped[] = $entity->seedlings_grown ?? null; + } } if ($this->form->type === 'nursery-report') { $mapped[] = $entity->nursery->old_id ?? ($entity->nursery->id ?? null); @@ -96,9 +96,9 @@ protected function getAttachedMappedForEntity($entity): array $mapped[] = $entity->site->name ?? null; $sumTreeSPecies = $entity->treeSpecies()->sum('amount'); $mapped[] = $sumTreeSPecies > 0 ? $sumTreeSPecies : null; - $mapped[] = $entity->site->trees_planted_count ?? null; + $mapped[] = $entity->site->trees_planted_count ?? null; if($this->form->framework_key === 'ppc') { - $sumSeeding = $entity->seedings()->sum('amount'); + $sumSeeding = $entity->seedings()->sum('amount'); $mapped[] = $sumSeeding > 0 ? $sumSeeding : null; $mapped[] = $entity->site->seeds_planted_count ?? null; } @@ -116,7 +116,7 @@ protected function getAttachedHeadingsForEntity(): array 'organization-name', 'project_name', 'status', - 'due_date' + 'due_date', ]; if (in_array($this->form->type, ['nursery', 'nursery-report','site', 'site-report', 'project-report'])) { @@ -127,7 +127,7 @@ protected function getAttachedHeadingsForEntity(): array $initialHeadings[] = 'project_uuid'; if($this->form->framework_key === 'ppc') { $initialHeadings[] = 'total_seedlings_grown'; - } + } } if ($this->form->type === 'nursery-report') { @@ -139,7 +139,7 @@ protected function getAttachedHeadingsForEntity(): array if($this->form->framework_key === 'ppc') { $initialHeadings[] = 'total_seeds_planted_report'; $initialHeadings[] = 'total_seeds_planted'; - } + } } return $initialHeadings; diff --git a/app/Http/Controllers/Traits/IsAdminIndex.php b/app/Http/Controllers/Traits/IsAdminIndex.php index 266148b74..e97cfb75f 100644 --- a/app/Http/Controllers/Traits/IsAdminIndex.php +++ b/app/Http/Controllers/Traits/IsAdminIndex.php @@ -9,14 +9,14 @@ trait IsAdminIndex { - protected function sort ($query, $sortableColumns): void + protected function sort($query, $sortableColumns): void { if (in_array(request()->query('sort'), $sortableColumns)) { $query->allowedSorts($sortableColumns); } } - protected function isolateAuthorizedFrameworks (QueryBuilder $query, string $tableName): void + protected function isolateAuthorizedFrameworks(QueryBuilder $query, string $tableName): void { $user = Auth::user(); $frameworks = Framework::all(); @@ -29,7 +29,7 @@ protected function isolateAuthorizedFrameworks (QueryBuilder $query, string $tab return $framework->slug; })->toArray(); - if (!$user->hasAllPermissions($frameworkNamesWithPref)) { + if (! $user->hasAllPermissions($frameworkNamesWithPref)) { $query->where(function ($query) use ($tableName, $frameworkNames, $user) { foreach ($frameworkNames as $framework) { $frameworkPermission = 'framework-' . $framework; @@ -41,9 +41,10 @@ protected function isolateAuthorizedFrameworks (QueryBuilder $query, string $tab } } - protected function paginate (QueryBuilder $query): LengthAwarePaginator + protected function paginate(QueryBuilder $query): LengthAwarePaginator { $perPage = request()->query('per_page') ?? config('app.pagination_default', 15); + return $query->paginate($perPage)->appends(request()->query()); } -} \ No newline at end of file +} diff --git a/app/Http/Controllers/V2/Entities/AdminSoftDeleteEntityController.php b/app/Http/Controllers/V2/Entities/AdminSoftDeleteEntityController.php index 7de489d43..90a17cbb3 100644 --- a/app/Http/Controllers/V2/Entities/AdminSoftDeleteEntityController.php +++ b/app/Http/Controllers/V2/Entities/AdminSoftDeleteEntityController.php @@ -15,6 +15,7 @@ public function __invoke(Request $request, EntityModel $entity): JsonResource $this->authorize('delete', $entity); $entity->delete(); EntityDeleteEvent::dispatch($request->user(), $entity); + return $entity->createResource(); } } diff --git a/app/Http/Controllers/V2/Entities/AdminStatusEntityController.php b/app/Http/Controllers/V2/Entities/AdminStatusEntityController.php index 5d5ddde18..4470d06b1 100644 --- a/app/Http/Controllers/V2/Entities/AdminStatusEntityController.php +++ b/app/Http/Controllers/V2/Entities/AdminStatusEntityController.php @@ -17,10 +17,12 @@ public function __invoke(StatusChangeRequest $request, EntityModel $entity, stri switch($status) { case 'approve': $entity->approve(data_get($data, 'feedback')); + break; case 'moreinfo': $entity->needsMoreInformation(data_get($data, 'feedback'), data_get($data, 'feedback_fields')); + break; default: diff --git a/app/Http/Controllers/V2/Entities/SubmitEntityWithFormController.php b/app/Http/Controllers/V2/Entities/SubmitEntityWithFormController.php index 8865d1c16..2ffee728b 100644 --- a/app/Http/Controllers/V2/Entities/SubmitEntityWithFormController.php +++ b/app/Http/Controllers/V2/Entities/SubmitEntityWithFormController.php @@ -23,7 +23,7 @@ public function __invoke(EntityModel $entity, Request $request) /** @var UpdateRequest $updateRequest */ $updateRequest = $entity->updateRequests()->isUnapproved()->first(); - if (!empty($updateRequest)) { + if (! empty($updateRequest)) { $updateRequest->submitForApproval(); Action::forTarget($updateRequest)->delete(); } else { diff --git a/app/Http/Controllers/V2/Entities/UpdateEntityWithFormController.php b/app/Http/Controllers/V2/Entities/UpdateEntityWithFormController.php index de0369e16..47ab6e431 100644 --- a/app/Http/Controllers/V2/Entities/UpdateEntityWithFormController.php +++ b/app/Http/Controllers/V2/Entities/UpdateEntityWithFormController.php @@ -33,10 +33,11 @@ public function __invoke(EntityModel $entity, UpdateFormSubmissionRequest $formS if ($entity instanceof ReportModel) { $entity->updateInProgress($isAdmin); } + return $entity->createResource(); } - if (!empty($updateRequest)) { + if (! empty($updateRequest)) { $updateRequest->update([ 'content' => array_merge($updateRequest->content, $answers) ]); } else { $updateRequest = UpdateRequest::create([ diff --git a/app/Http/Controllers/V2/Entities/ViewEntityController.php b/app/Http/Controllers/V2/Entities/ViewEntityController.php index 06bae8176..09692b485 100644 --- a/app/Http/Controllers/V2/Entities/ViewEntityController.php +++ b/app/Http/Controllers/V2/Entities/ViewEntityController.php @@ -12,6 +12,7 @@ class ViewEntityController extends Controller public function __invoke(Request $request, EntityModel $entity): JsonResource { $this->authorize('read', $entity); + return $entity->createResource(); } } diff --git a/app/Http/Controllers/V2/Entities/ViewEntityWithFormController.php b/app/Http/Controllers/V2/Entities/ViewEntityWithFormController.php index eb517cb6c..dcca3e3ad 100644 --- a/app/Http/Controllers/V2/Entities/ViewEntityWithFormController.php +++ b/app/Http/Controllers/V2/Entities/ViewEntityWithFormController.php @@ -10,6 +10,7 @@ class ViewEntityWithFormController extends Controller public function __invoke(EntityModel $entity) { $this->authorize('read', $entity); + return $entity->createSchemaResource(); } } diff --git a/app/Http/Controllers/V2/Exports/ExportAllProjectDataAsProjectDeveloperController.php b/app/Http/Controllers/V2/Exports/ExportAllProjectDataAsProjectDeveloperController.php index 64900d363..ff37db5dd 100644 --- a/app/Http/Controllers/V2/Exports/ExportAllProjectDataAsProjectDeveloperController.php +++ b/app/Http/Controllers/V2/Exports/ExportAllProjectDataAsProjectDeveloperController.php @@ -79,6 +79,7 @@ private function addSiteShapefiles(Project $project, \ZipArchive $mainZip): void $mainZip->addFromString($filename, $site->boundary_geojson); } } + private function addNurseryReportsExports(Project $project, \ZipArchive $mainZip): void { $form = $this->getForm(NurseryReport::class, $project->framework_key); diff --git a/app/Http/Controllers/V2/Exports/ExportProjectEntityAsProjectDeveloperController.php b/app/Http/Controllers/V2/Exports/ExportProjectEntityAsProjectDeveloperController.php index dcef642b4..89941f52e 100644 --- a/app/Http/Controllers/V2/Exports/ExportProjectEntityAsProjectDeveloperController.php +++ b/app/Http/Controllers/V2/Exports/ExportProjectEntityAsProjectDeveloperController.php @@ -93,5 +93,4 @@ private function addSiteShapefiles(Project $project, \ZipArchive $mainZip): void $mainZip->addFromString($geojsonFilename, $site->boundary_geojson); } } - } diff --git a/app/Http/Controllers/V2/Nurseries/AdminIndexNurseriesController.php b/app/Http/Controllers/V2/Nurseries/AdminIndexNurseriesController.php index 3e7dca7b8..05a6167b9 100644 --- a/app/Http/Controllers/V2/Nurseries/AdminIndexNurseriesController.php +++ b/app/Http/Controllers/V2/Nurseries/AdminIndexNurseriesController.php @@ -52,6 +52,7 @@ public function __invoke(Request $request): NurseriesCollection } $this->isolateAuthorizedFrameworks($query, 'v2_nurseries'); + return new NurseriesCollection($this->paginate($query)); } } diff --git a/app/Http/Controllers/V2/NurseryReports/AdminIndexNurseryReportsController.php b/app/Http/Controllers/V2/NurseryReports/AdminIndexNurseryReportsController.php index 987e368a4..cb90e4b8b 100644 --- a/app/Http/Controllers/V2/NurseryReports/AdminIndexNurseryReportsController.php +++ b/app/Http/Controllers/V2/NurseryReports/AdminIndexNurseryReportsController.php @@ -56,6 +56,7 @@ public function __invoke(Request $request): NurseryReportsCollection } $this->isolateAuthorizedFrameworks($query, 'v2_nursery_reports'); + return new NurseryReportsCollection($this->paginate($query)); } } diff --git a/app/Http/Controllers/V2/ProjectReports/AdminIndexProjectReportsController.php b/app/Http/Controllers/V2/ProjectReports/AdminIndexProjectReportsController.php index 5b47f4641..75ab9d5a2 100644 --- a/app/Http/Controllers/V2/ProjectReports/AdminIndexProjectReportsController.php +++ b/app/Http/Controllers/V2/ProjectReports/AdminIndexProjectReportsController.php @@ -18,21 +18,21 @@ public function __invoke(Request $request): ProjectReportsCollection { $this->authorize('readAll', ProjectReport::class); - $query = QueryBuilder::for(ProjectReport::class) - ->join('v2_projects', function ($join) { - $join->on('v2_project_reports.project_id', '=', 'v2_projects.id'); - }) - ->selectRaw(' + $query = QueryBuilder::for(ProjectReport::class) + ->join('v2_projects', function ($join) { + $join->on('v2_project_reports.project_id', '=', 'v2_projects.id'); + }) + ->selectRaw(' v2_project_reports.*, (SELECT name FROM organisations WHERE organisations.id = v2_projects.organisation_id) as organisation_name ') - ->allowedFilters([ - AllowedFilter::scope('project_uuid', 'projectUuid'), - AllowedFilter::scope('country'), - AllowedFilter::exact('status'), - AllowedFilter::exact('update_request_status'), - AllowedFilter::exact('framework_key'), - ]); + ->allowedFilters([ + AllowedFilter::scope('project_uuid', 'projectUuid'), + AllowedFilter::scope('country'), + AllowedFilter::exact('status'), + AllowedFilter::exact('update_request_status'), + AllowedFilter::exact('framework_key'), + ]); $this->sort($query, [ 'created_at', '-created_at', @@ -51,6 +51,7 @@ public function __invoke(Request $request): ProjectReportsCollection } $this->isolateAuthorizedFrameworks($query, 'v2_project_reports'); + return new ProjectReportsCollection($this->paginate($query)); } } diff --git a/app/Http/Controllers/V2/Projects/AdminIndexProjectsController.php b/app/Http/Controllers/V2/Projects/AdminIndexProjectsController.php index 7cefd4ae3..907bc1051 100644 --- a/app/Http/Controllers/V2/Projects/AdminIndexProjectsController.php +++ b/app/Http/Controllers/V2/Projects/AdminIndexProjectsController.php @@ -5,10 +5,8 @@ use App\Http\Controllers\Controller; use App\Http\Controllers\Traits\IsAdminIndex; use App\Http\Resources\V2\Projects\ProjectsCollection; -use App\Models\Framework; use App\Models\V2\Projects\Project; use Illuminate\Http\Request; -use Illuminate\Support\Facades\Auth; use Spatie\QueryBuilder\AllowedFilter; use Spatie\QueryBuilder\QueryBuilder; @@ -49,6 +47,7 @@ public function __invoke(Request $request): ProjectsCollection } $this->isolateAuthorizedFrameworks($query, 'v2_projects'); + return new ProjectsCollection($this->paginate($query)); } } diff --git a/app/Http/Controllers/V2/Projects/CreateBlankProjectWithFormController.php b/app/Http/Controllers/V2/Projects/CreateBlankProjectWithFormController.php index ba1bf19b4..d8b5527e0 100644 --- a/app/Http/Controllers/V2/Projects/CreateBlankProjectWithFormController.php +++ b/app/Http/Controllers/V2/Projects/CreateBlankProjectWithFormController.php @@ -2,7 +2,6 @@ namespace App\Http\Controllers\V2\Projects; -use App\Events\V2\General\EntityStatusChangeEvent; use App\Http\Controllers\Controller; use App\Http\Resources\V2\Entities\EntityWithSchemaResource; use App\Models\V2\Forms\Form; @@ -26,6 +25,7 @@ public function __invoke(Request $request, Form $form): EntityWithSchemaResource $request->user()->projects()->sync([$project->id => ['is_monitoring' => false]], false); $project->dispatchStatusChangeEvent($request->user()); + return $project->createSchemaResource(); } } diff --git a/app/Http/Controllers/V2/Projects/CreateProjectWithFormController.php b/app/Http/Controllers/V2/Projects/CreateProjectWithFormController.php index 6674241da..a46a4e733 100644 --- a/app/Http/Controllers/V2/Projects/CreateProjectWithFormController.php +++ b/app/Http/Controllers/V2/Projects/CreateProjectWithFormController.php @@ -2,7 +2,6 @@ namespace App\Http\Controllers\V2\Projects; -use App\Events\V2\General\EntityStatusChangeEvent; use App\Http\Controllers\Controller; use App\Http\Resources\V2\Entities\EntityWithSchemaResource; use App\Models\V2\Forms\Application; @@ -85,6 +84,7 @@ public function __invoke(Request $request): EntityWithSchemaResource $request->user()->projects()->sync([$project->id => ['is_monitoring' => false]], false); $project->dispatchStatusChangeEvent($request->user()); + return $project->createSchemaResource(); } diff --git a/app/Http/Controllers/V2/Reports/AdminStatusReportController.php b/app/Http/Controllers/V2/Reports/AdminStatusReportController.php index 219607a73..330290afe 100644 --- a/app/Http/Controllers/V2/Reports/AdminStatusReportController.php +++ b/app/Http/Controllers/V2/Reports/AdminStatusReportController.php @@ -2,7 +2,6 @@ namespace App\Http\Controllers\V2\Reports; -use App\Events\V2\General\EntityStatusChangeEvent; use App\Http\Controllers\Controller; use App\Http\Requests\V2\UpdateRequests\StatusChangeRequest; use App\Models\V2\ReportModel; @@ -18,10 +17,12 @@ public function __invoke(StatusChangeRequest $request, ReportModel $report, stri switch($status) { case 'approve': $report->approve(data_get($data, 'feedback')); + break; case 'moreinfo': $report->needsMoreInformation(data_get($data, 'feedback'), data_get($data, 'feedback_fields')); + break; default: diff --git a/app/Http/Controllers/V2/Reports/NothingToReportReportController.php b/app/Http/Controllers/V2/Reports/NothingToReportReportController.php index 53a2c73d4..0744cbb25 100644 --- a/app/Http/Controllers/V2/Reports/NothingToReportReportController.php +++ b/app/Http/Controllers/V2/Reports/NothingToReportReportController.php @@ -12,6 +12,7 @@ public function __invoke(ReportModel $report): JsonResource { $this->authorize('update', $report); $report->nothingToReport(); + return $report->createResource(); } } diff --git a/app/Http/Controllers/V2/SiteReports/AdminIndexSiteReportsController.php b/app/Http/Controllers/V2/SiteReports/AdminIndexSiteReportsController.php index ffb0d5329..c90215d87 100644 --- a/app/Http/Controllers/V2/SiteReports/AdminIndexSiteReportsController.php +++ b/app/Http/Controllers/V2/SiteReports/AdminIndexSiteReportsController.php @@ -5,7 +5,6 @@ use App\Http\Controllers\Controller; use App\Http\Controllers\Traits\IsAdminIndex; use App\Http\Resources\V2\SiteReports\SiteReportsCollection; -use App\Models\Framework; use App\Models\V2\Sites\SiteReport; use Illuminate\Http\Request; use Spatie\QueryBuilder\AllowedFilter; @@ -55,6 +54,7 @@ public function __invoke(Request $request): SiteReportsCollection } $this->isolateAuthorizedFrameworks($query, 'v2_site_reports'); + return new SiteReportsCollection($this->paginate($query)); } } diff --git a/app/Http/Controllers/V2/Sites/AdminIndexSitesController.php b/app/Http/Controllers/V2/Sites/AdminIndexSitesController.php index eec871f7c..d4d5685d5 100644 --- a/app/Http/Controllers/V2/Sites/AdminIndexSitesController.php +++ b/app/Http/Controllers/V2/Sites/AdminIndexSitesController.php @@ -56,6 +56,7 @@ public function __invoke(Request $request): V2SitesCollection } $this->isolateAuthorizedFrameworks($query, 'v2_sites'); + return new V2SitesCollection($this->paginate($query)); } } diff --git a/app/Http/Controllers/V2/Tasks/AdminIndexTasksController.php b/app/Http/Controllers/V2/Tasks/AdminIndexTasksController.php index ea10ad830..efa211380 100644 --- a/app/Http/Controllers/V2/Tasks/AdminIndexTasksController.php +++ b/app/Http/Controllers/V2/Tasks/AdminIndexTasksController.php @@ -19,7 +19,7 @@ public function __invoke(Request $request): TasksCollection $this->authorize('readAll', Task::class); $query = QueryBuilder::for(Task::class) - ->join('v2_projects', function($join) { + ->join('v2_projects', function ($join) { $join->on('v2_tasks.project_id', '=', 'v2_projects.id'); }) ->selectRaw(' @@ -41,6 +41,7 @@ public function __invoke(Request $request): TasksCollection ]); $this->isolateAuthorizedFrameworks($query, 'v2_projects'); + return new TasksCollection($this->paginate($query)); } -} \ No newline at end of file +} diff --git a/app/Http/Controllers/V2/Tasks/SubmitProjectTasksController.php b/app/Http/Controllers/V2/Tasks/SubmitProjectTasksController.php index 2acb572b1..34ebc0d93 100644 --- a/app/Http/Controllers/V2/Tasks/SubmitProjectTasksController.php +++ b/app/Http/Controllers/V2/Tasks/SubmitProjectTasksController.php @@ -17,6 +17,7 @@ public function __invoke(Request $request, Task $task): JsonResponse { $this->authorize('update', $task); $task->submitForApproval(); + return new JsonResponse('Reports successfully submitted', 200); } } diff --git a/app/Http/Controllers/V2/UpdateRequests/EntityUpdateRequestsController.php b/app/Http/Controllers/V2/UpdateRequests/EntityUpdateRequestsController.php index 577975fc0..d07c3e80b 100644 --- a/app/Http/Controllers/V2/UpdateRequests/EntityUpdateRequestsController.php +++ b/app/Http/Controllers/V2/UpdateRequests/EntityUpdateRequestsController.php @@ -5,12 +5,6 @@ use App\Http\Controllers\Controller; use App\Http\Resources\V2\UpdateRequests\UpdateRequestResource; use App\Models\V2\EntityModel; -use App\Models\V2\Nurseries\Nursery; -use App\Models\V2\Nurseries\NurseryReport; -use App\Models\V2\Projects\Project; -use App\Models\V2\Projects\ProjectReport; -use App\Models\V2\Sites\Site; -use App\Models\V2\Sites\SiteReport; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; diff --git a/app/Http/Middleware/ModelInterfaceBindingMiddleware.php b/app/Http/Middleware/ModelInterfaceBindingMiddleware.php index c317824de..fddbf277f 100644 --- a/app/Http/Middleware/ModelInterfaceBindingMiddleware.php +++ b/app/Http/Middleware/ModelInterfaceBindingMiddleware.php @@ -42,7 +42,7 @@ public function handle(Request $request, Closure $next) { $route = $request->route(); $parameterKeys = array_keys($route->parameters); - $modelSlugIndex = array_search('modelSlug' , array_keys($route->parameters)); + $modelSlugIndex = array_search('modelSlug', array_keys($route->parameters)); if ($modelSlugIndex < 0 || count($parameterKeys) <= $modelSlugIndex) { return $next($request); } diff --git a/app/Http/Resources/V2/ProjectReports/ProjectReportResource.php b/app/Http/Resources/V2/ProjectReports/ProjectReportResource.php index 268459e52..f1e449077 100644 --- a/app/Http/Resources/V2/ProjectReports/ProjectReportResource.php +++ b/app/Http/Resources/V2/ProjectReports/ProjectReportResource.php @@ -97,7 +97,7 @@ public function toArray($request) 'equitable_opportunities' => $this->equitable_opportunities, 'local_engagement' => $this->local_engagement, 'site_addition' => $this->site_addition, - 'paid_other_activity_description' => $this->paid_other_activity_description + 'paid_other_activity_description' => $this->paid_other_activity_description, ]; return $this->appendFilesToResource($data); diff --git a/app/Jobs/V2/CreateTaskDueJob.php b/app/Jobs/V2/CreateTaskDueJob.php index 1dd3d2946..013ba48aa 100644 --- a/app/Jobs/V2/CreateTaskDueJob.php +++ b/app/Jobs/V2/CreateTaskDueJob.php @@ -81,11 +81,17 @@ public function handle() } $labels = ['Project']; - if ($hasSite) $labels[] = 'site'; - if ($hasNursery) $labels[] = 'nursery'; - $message = printf('%s %s available', + if ($hasSite) { + $labels[] = 'site'; + } + if ($hasNursery) { + $labels[] = 'nursery'; + } + $message = printf( + '%s %s available', implode(', ', $labels), - count($labels) > 1 ? 'reports' : 'report'); + count($labels) > 1 ? 'reports' : 'report' + ); Action::create([ 'status' => Action::STATUS_PENDING, diff --git a/app/Jobs/V2/SendEntityStatusChangeEmailsJob.php b/app/Jobs/V2/SendEntityStatusChangeEmailsJob.php index c5932acf0..71968922a 100644 --- a/app/Jobs/V2/SendEntityStatusChangeEmailsJob.php +++ b/app/Jobs/V2/SendEntityStatusChangeEmailsJob.php @@ -50,4 +50,4 @@ public function handle(): void Mail::to($emailAddress)->send(new EntityStatusChangeMail($this->entity)); } } -} \ No newline at end of file +} diff --git a/app/Mail/EntityStatusChange.php b/app/Mail/EntityStatusChange.php index 5d68063fa..da312f111 100644 --- a/app/Mail/EntityStatusChange.php +++ b/app/Mail/EntityStatusChange.php @@ -75,7 +75,7 @@ private function getFeedback(): ?string return null; } - return str_replace("\n", "
", $feedback); + return str_replace("\n", '
', $feedback); } private function getBodyParagraphs(): Collection @@ -100,7 +100,7 @@ private function getBodyParagraphs(): Collection ], EntityStatusStateMachine::NEEDS_MORE_INFORMATION => [ 'The information has been reviewed by your project manager and they would like to see the following updates:', - $this->getFeedback() ?? '(No feedback)' + $this->getFeedback() ?? '(No feedback)', ], default => null }); @@ -109,4 +109,4 @@ private function getBodyParagraphs(): Collection return $paragraphs->flatten()->filter(); } -} \ No newline at end of file +} diff --git a/app/Models/Traits/HasEntityResources.php b/app/Models/Traits/HasEntityResources.php index 5b09725c2..d303cb0e4 100644 --- a/app/Models/Traits/HasEntityResources.php +++ b/app/Models/Traits/HasEntityResources.php @@ -25,6 +25,7 @@ public function createResource(): JsonResource } $resourceClassName = join('\\', $resourceNamespaceParts) . '\\' . $class->getShortName() . 'Resource'; + return new $resourceClassName($this); } diff --git a/app/Models/Traits/HasEntityStatus.php b/app/Models/Traits/HasEntityStatus.php index 49759e6fe..f9d760452 100644 --- a/app/Models/Traits/HasEntityStatus.php +++ b/app/Models/Traits/HasEntityStatus.php @@ -17,7 +17,8 @@ * @property string $readable_status * @method status */ -trait HasEntityStatus { +trait HasEntityStatus +{ use HasStatus; use HasStateMachines; use HasEntityStatusScopesAndTransitions; @@ -42,4 +43,4 @@ public function getViewLinkPath(): string { return '/' . Str::lower(explode_pop('\\', get_class($this))) . '/' . $this->uuid; } -} \ No newline at end of file +} diff --git a/app/Models/Traits/HasEntityStatusScopesAndTransitions.php b/app/Models/Traits/HasEntityStatusScopesAndTransitions.php index 2fc633d77..32b693e6b 100644 --- a/app/Models/Traits/HasEntityStatusScopesAndTransitions.php +++ b/app/Models/Traits/HasEntityStatusScopesAndTransitions.php @@ -5,7 +5,8 @@ use App\StateMachines\EntityStatusStateMachine; use Illuminate\Database\Eloquent\Builder; -trait HasEntityStatusScopesAndTransitions { +trait HasEntityStatusScopesAndTransitions +{ public function scopeIsApproved(Builder $query): Builder { return $this->scopeIsStatus($query, EntityStatusStateMachine::APPROVED); @@ -41,4 +42,4 @@ public function needsMoreInformation($feedback, $feedbackFields): void $this->feedback_fields = $feedbackFields; $this->status()->transitionTo(EntityStatusStateMachine::NEEDS_MORE_INFORMATION); } -} \ No newline at end of file +} diff --git a/app/Models/Traits/HasReportStatus.php b/app/Models/Traits/HasReportStatus.php index ce55c6201..5cf3f0521 100644 --- a/app/Models/Traits/HasReportStatus.php +++ b/app/Models/Traits/HasReportStatus.php @@ -21,7 +21,8 @@ * @property int $created_by * @method status */ -trait HasReportStatus { +trait HasReportStatus +{ use HasStatus; use HasStateMachines; use HasEntityStatusScopesAndTransitions { @@ -84,7 +85,7 @@ public function isCompletable(): bool return true; } - if ($this->status == ReportStatusStateMachine::DUE && !$this->supportsNothingToReport()) { + if ($this->status == ReportStatusStateMachine::DUE && ! $this->supportsNothingToReport()) { return false; } @@ -98,7 +99,7 @@ public function hasCompleteStatus(): bool public function nothingToReport(): void { - if (!$this->supportsNothingToReport()) { + if (! $this->supportsNothingToReport()) { throw new \InvalidArgumentException( 'This report model does not support the nothing-to-report status' ); @@ -111,7 +112,7 @@ public function nothingToReport(): void public function updateInProgress(bool $isAdmin = false): void { $this->setCompletion(); - if (!$isAdmin && empty($report->created_by)) { + if (! $isAdmin && empty($report->created_by)) { $this->created_by = Auth::user()->id; } @@ -169,4 +170,4 @@ public function getViewLinkPath(): string { return '/reports/' . Str::kebab(explode_pop('\\', get_class($this))) . '/' . $this->uuid; } -} \ No newline at end of file +} diff --git a/app/Models/Traits/HasUpdateRequests.php b/app/Models/Traits/HasUpdateRequests.php index 05819873f..7ebac09e6 100644 --- a/app/Models/Traits/HasUpdateRequests.php +++ b/app/Models/Traits/HasUpdateRequests.php @@ -8,9 +8,10 @@ /** * @method morphMany(string $class, string $string) */ -trait HasUpdateRequests { +trait HasUpdateRequests +{ public function updateRequests(): MorphMany { return $this->morphMany(UpdateRequest::class, 'updaterequestable'); } -} \ No newline at end of file +} diff --git a/app/Models/Traits/UsesLinkedFields.php b/app/Models/Traits/UsesLinkedFields.php index d27ec54e1..dd6dbe7dc 100644 --- a/app/Models/Traits/UsesLinkedFields.php +++ b/app/Models/Traits/UsesLinkedFields.php @@ -72,7 +72,7 @@ public function calculateCompletion(Form $form): int $value = null; $linkedFieldInfo = $question->getLinkedFieldInfo(['model_uuid' => $this->uuid]); - if (!empty($linkedFieldInfo)) { + if (! empty($linkedFieldInfo)) { $value = $this->getEntityLinkedFieldValue($linkedFieldInfo); } else { $value = data_get($this->answers, $question->uuid); @@ -87,19 +87,19 @@ public function calculateCompletion(Form $form): int } foreach ($answers as $answer) { - if (!$answer['required']) { + if (! $answer['required']) { // don't count it if the question wasn't required continue; } - if (!empty($answer['conditionalOn']) && - !$answers[$answer['conditionalOn']]['value']) { + if (! empty($answer['conditionalOn']) && + ! $answers[$answer['conditionalOn']]['value']) { // don't count it if the question wasn't shown to the user because the parent conditional is false. continue; } $questionCount++; - if (!is_null($answer['value'])) { + if (! is_null($answer['value'])) { $answeredCount++; } } @@ -210,7 +210,7 @@ private function updateLinkedFieldValue(array $linkedFieldInfo, $answer): void public function getForm(): Form { - if (!is_null($this->form)) { + if (! is_null($this->form)) { // Some classes that use this trait have a direct database link to the form. return $this->form; } @@ -220,6 +220,7 @@ public function getForm(): Form ->where('framework_key', $this->framework_key) ->first(); } + return $this->frameworkModelForm; } diff --git a/app/Models/V2/EntityModel.php b/app/Models/V2/EntityModel.php index f1aab28db..da34e27a9 100644 --- a/app/Models/V2/EntityModel.php +++ b/app/Models/V2/EntityModel.php @@ -1,10 +1,10 @@ reports()->hasBeenSubmitted()->get($sumQueries)->first(); // The groupBy is superfluous, but required because Laravel adds "v2_sites.project_id as laravel_through_key" to // the SQL select. $siteTotals = $this->submittedSiteReports()->groupBy('v2_sites.project_id')->get($sumQueries)->first(); + return $projectTotals?->paid + $projectTotals?->volunteer + $siteTotals?->paid + $siteTotals?->volunteer; } diff --git a/app/Models/V2/Projects/ProjectReport.php b/app/Models/V2/Projects/ProjectReport.php index dbe2e24ed..5c34ce39a 100644 --- a/app/Models/V2/Projects/ProjectReport.php +++ b/app/Models/V2/Projects/ProjectReport.php @@ -140,7 +140,7 @@ class ProjectReport extends Model implements HasMedia, AuditableContract, Report 'equitable_opportunities', 'local_engagement', 'site_addition', - 'paid_other_activity_description' + 'paid_other_activity_description', ]; public $casts = [ diff --git a/app/Models/V2/Sites/Site.php b/app/Models/V2/Sites/Site.php index a5d2f7491..b82967954 100644 --- a/app/Models/V2/Sites/Site.php +++ b/app/Models/V2/Sites/Site.php @@ -293,8 +293,8 @@ public function getRegeneratedTreesCountAttribute(): int public function getWorkdayCountAttribute(): int { $totals = $this->reports()->hasBeenSubmitted()->get([ - DB::raw("sum(`workdays_volunteer`) as volunteer"), - DB::raw("sum(`workdays_paid`) as paid"), + DB::raw('sum(`workdays_volunteer`) as volunteer'), + DB::raw('sum(`workdays_paid`) as paid'), ])->first(); return $totals?->paid + $totals?->volunteer; diff --git a/app/Models/V2/Sites/SiteReport.php b/app/Models/V2/Sites/SiteReport.php index 7ca16a376..c6b628c60 100644 --- a/app/Models/V2/Sites/SiteReport.php +++ b/app/Models/V2/Sites/SiteReport.php @@ -90,7 +90,7 @@ class SiteReport extends Model implements HasMedia, AuditableContract, ReportMod 'feedback_fields', 'polygon_status', 'answers', - 'paid_other_activity_description' + 'paid_other_activity_description', ]; public $fileConfiguration = [ diff --git a/app/Models/V2/Tasks/Task.php b/app/Models/V2/Tasks/Task.php index 54b779a22..40603f1e7 100644 --- a/app/Models/V2/Tasks/Task.php +++ b/app/Models/V2/Tasks/Task.php @@ -47,7 +47,7 @@ class Task extends Model public const COMPLETE_STATUSES = [ TaskStatusStateMachine::AWAITING_APPROVAL, - TaskStatusStateMachine::APPROVED + TaskStatusStateMachine::APPROVED, ]; protected $fillable = [ @@ -115,9 +115,9 @@ public function scopeFrameworkKey(Builder $query, string $frameworkKey): Builder /** * @throws InvalidStatusException */ - public function submitForApproval () + public function submitForApproval() { - if (!$this->status()->canBe(TaskStatusStateMachine::AWAITING_APPROVAL)) { + if (! $this->status()->canBe(TaskStatusStateMachine::AWAITING_APPROVAL)) { throw new InvalidStatusException( 'Task is not in a state that can be moved to awaiting approval' ); @@ -125,8 +125,8 @@ public function submitForApproval () // First, make sure all reports are either complete, or completable $reports = collect([$this->projectReport])->concat($this->siteReports)->concat($this->nurseryReports); - $hasIncomplete = $reports->reduce(function($hasIncomplete, $report) { - return $hasIncomplete || !$report->isCompletable(); + $hasIncomplete = $reports->reduce(function ($hasIncomplete, $report) { + return $hasIncomplete || ! $report->isCompletable(); }); if ($hasIncomplete) { throw new InvalidStatusException('Task is not submittable due to incomplete reports'); @@ -167,6 +167,7 @@ public function checkStatus(): void })->flatten()->unique(); if ($reportStatuses->containsOneItem() && $reportStatuses[0] == ReportStatusStateMachine::APPROVED) { $this->status()->transitionTo(TaskStatusStateMachine::APPROVED); + return; } elseif ( $reportStatuses @@ -182,7 +183,8 @@ public function checkStatus(): void return $relation ->whereIn( 'status', - [ReportStatusStateMachine::NEEDS_MORE_INFORMATION, ReportStatusStateMachine::AWAITING_APPROVAL]) + [ReportStatusStateMachine::NEEDS_MORE_INFORMATION, ReportStatusStateMachine::AWAITING_APPROVAL] + ) ->select('id', 'status') ->get(); })->flatten(); @@ -207,11 +209,13 @@ public function checkStatus(): void // A report in needs-more-information causes the task to go to needs-more-information $this->status()->transitionTo(TaskStatusStateMachine::NEEDS_MORE_INFORMATION); + return; } elseif ($report->updateRequests()->isStatus(UpdateRequestStatusStateMachine::NEEDS_MORE_INFORMATION)->exists()) { // an awaiting-approval report with a needs-more-information update request causes the task to go to // needs-more-information $this->status()->transitionTo(TaskStatusStateMachine::NEEDS_MORE_INFORMATION); + return; } } @@ -230,10 +234,11 @@ public function getCompletionStatusAttribute(): string $hasStartedReport = $this->getReportRelations()->reduce(function ($hasStarted, $relation) { return $hasStarted || $relation->where('completion', '>', '0')->exists(); }); + return $hasStartedReport ? 'started' : 'not-started'; } - private function getReportRelations (): Collection + private function getReportRelations(): Collection { return collect([$this->projectReport(), $this->siteReports(), $this->nurseryReports()]); } diff --git a/app/Models/V2/UpdateRequestableModel.php b/app/Models/V2/UpdateRequestableModel.php index 5cd1ad018..fe7bf2e07 100644 --- a/app/Models/V2/UpdateRequestableModel.php +++ b/app/Models/V2/UpdateRequestableModel.php @@ -7,4 +7,4 @@ interface UpdateRequestableModel { public function updateRequests(): MorphMany; -} \ No newline at end of file +} diff --git a/app/Models/V2/Workdays/Workday.php b/app/Models/V2/Workdays/Workday.php index 74f938fa5..80850212f 100644 --- a/app/Models/V2/Workdays/Workday.php +++ b/app/Models/V2/Workdays/Workday.php @@ -30,7 +30,7 @@ class Workday extends Model 'gender', 'age', 'ethnicity', - 'indigeneity' + 'indigeneity', ]; public const COLLECTION_PROJECT_PAID_PROJECT_ESTABLISHMENT = 'paid-project-establishment'; diff --git a/app/Policies/Policy.php b/app/Policies/Policy.php index 26f5df35b..fef9fcdff 100644 --- a/app/Policies/Policy.php +++ b/app/Policies/Policy.php @@ -39,7 +39,7 @@ protected function isAdmin(?UserModel $user): bool protected function isServiceAccount(?UserModel $user): bool { - return !$this->isGuest($user) && $user->role == 'service'; + return ! $this->isGuest($user) && $user->role == 'service'; } protected function isOrphanedUser(?UserModel $user): bool diff --git a/app/Services/PushService.php b/app/Services/PushService.php index dc33e3126..7691a5bec 100644 --- a/app/Services/PushService.php +++ b/app/Services/PushService.php @@ -20,7 +20,7 @@ public function __construct() public function fetchEndpointArn(string $os, string $pushToken): ?string { - if (!config('app.sns.enabled')) { + if (! config('app.sns.enabled')) { return null; } diff --git a/app/StateMachines/ReportStatusStateMachine.php b/app/StateMachines/ReportStatusStateMachine.php index 4ef3619bf..b942fce82 100644 --- a/app/StateMachines/ReportStatusStateMachine.php +++ b/app/StateMachines/ReportStatusStateMachine.php @@ -14,6 +14,7 @@ public function transitions(): array $parentTransitions = parent::transitions(); // Reports can go from awaiting approval to started if the nothing_to_report flag is true (see validations below) $parentTransitions[self::AWAITING_APPROVAL][] = self::STARTED; + return array_merge( [ self::DUE => [self::STARTED, self::AWAITING_APPROVAL], @@ -55,7 +56,7 @@ public function afterTransitionHooks(): array return $hooks; } - private function addHook ($hooks, $status, $hook) + private function addHook($hooks, $status, $hook) { $hooks[$status] = [$hook]; } diff --git a/app/Validators/ServiceAccountValidator.php b/app/Validators/ServiceAccountValidator.php index b4d9aecb8..00500e597 100644 --- a/app/Validators/ServiceAccountValidator.php +++ b/app/Validators/ServiceAccountValidator.php @@ -8,4 +8,4 @@ class ServiceAccountValidator extends Validator 'email_address' => 'required|string|email|between:1,255|unique:users,email_address', 'api_key' => 'required|string|size:64|unique:users,api_key', ]; -} \ No newline at end of file +} diff --git a/database/migrations/2023_08_16_091316_create_v2_sites_table.php b/database/migrations/2023_08_16_091316_create_v2_sites_table.php index 5db7c15c8..85c7fe4be 100644 --- a/database/migrations/2023_08_16_091316_create_v2_sites_table.php +++ b/database/migrations/2023_08_16_091316_create_v2_sites_table.php @@ -1,7 +1,6 @@ whereIn('modelSlug', ModelInterfaceBindingMiddleware::ENTITY_TYPES_PLURAL) ->middleware('modelInterface') - ->group(function() { + ->group(function () { Route::put('/{entity}/{status}', AdminStatusEntityController::class); Route::delete('/{entity}', AdminSoftDeleteEntityController::class); }); @@ -411,7 +411,7 @@ Route::prefix('{modelSlug}') ->whereIn('modelSlug', ModelInterfaceBindingMiddleware::ENTITY_TYPES_PLURAL) ->middleware('modelInterface') - ->group(function() { + ->group(function () { Route::get('/{entity}', ViewEntityWithFormController::class)->middleware('i18n'); Route::put('/{entity}', UpdateEntityWithFormController::class); Route::put('/{entity}/submit', SubmitEntityWithFormController::class); @@ -547,14 +547,14 @@ Route::prefix('{modelSlug}') ->whereIn('modelSlug', ['site-reports', 'nursery-reports']) ->middleware('modelInterface') - ->group(function() { + ->group(function () { Route::put('/{report}/nothing-to-report', NothingToReportReportController::class); }); Route::prefix('{modelSlug}') ->whereIn('modelSlug', ModelInterfaceBindingMiddleware::ENTITY_TYPES_PLURAL) ->middleware('modelInterface') - ->group(function() { + ->group(function () { Route::get('/{entity}', ViewEntityController::class); }); From 22ac48d9cb3434370a6fa6a7678414d6db41a155 Mon Sep 17 00:00:00 2001 From: Nathan Curtis Date: Fri, 5 Apr 2024 16:08:06 -0700 Subject: [PATCH 06/44] [TM-785] Get the UpdateRequests tests passing. --- .../AdminIndexUpdateRequestControllerTest.php | 7 +++-- ...AdminStatusUpdateRequestControllerTest.php | 31 +++++++++---------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/tests/V2/UpdateRequests/AdminIndexUpdateRequestControllerTest.php b/tests/V2/UpdateRequests/AdminIndexUpdateRequestControllerTest.php index 6a15249b5..7bf324a0e 100644 --- a/tests/V2/UpdateRequests/AdminIndexUpdateRequestControllerTest.php +++ b/tests/V2/UpdateRequests/AdminIndexUpdateRequestControllerTest.php @@ -2,9 +2,10 @@ namespace Tests\V2\UpdateRequests; +use App\Models\Framework; use App\Models\User; use App\Models\V2\UpdateRequests\UpdateRequest; -//use Illuminate\Support\Facades\Artisan; +use Illuminate\Support\Facades\Artisan; use Illuminate\Foundation\Testing\RefreshDatabase; use Tests\TestCase; @@ -14,14 +15,16 @@ class AdminIndexUpdateRequestControllerTest extends TestCase public function test_invoke_action(): void { - // Artisan::call('v2migration:roles'); + Artisan::call('v2migration:roles'); UpdateRequest::truncate(); $user = User::factory()->create(); $user->givePermissionTo('manage-own'); + Framework::factory()->create(['slug' => 'terrafund']); $tfAdmin = User::factory()->admin()->create(); $tfAdmin->givePermissionTo('framework-terrafund'); + Framework::factory()->create(['slug' => 'ppc']); $ppcAdmin = User::factory()->admin()->create(); $ppcAdmin->givePermissionTo('framework-ppc'); diff --git a/tests/V2/UpdateRequests/AdminStatusUpdateRequestControllerTest.php b/tests/V2/UpdateRequests/AdminStatusUpdateRequestControllerTest.php index 5b1233631..23821cccb 100644 --- a/tests/V2/UpdateRequests/AdminStatusUpdateRequestControllerTest.php +++ b/tests/V2/UpdateRequests/AdminStatusUpdateRequestControllerTest.php @@ -8,7 +8,9 @@ use App\Models\V2\Projects\Project; use App\Models\V2\Sites\Site; use App\Models\V2\UpdateRequests\UpdateRequest; -//use Illuminate\Support\Facades\Artisan; +use App\StateMachines\EntityStatusStateMachine; +use Illuminate\Support\Facades\Artisan; +use App\StateMachines\UpdateRequestStatusStateMachine; use Illuminate\Foundation\Testing\RefreshDatabase; use Tests\TestCase; @@ -18,7 +20,7 @@ class AdminStatusUpdateRequestControllerTest extends TestCase public function test_invoke_action_permissions(): void { - // Artisan::call('v2migration:roles'); + Artisan::call('v2migration:roles'); $organisation = Organisation::factory()->create(); $project = Project::factory()->create([ 'framework_key' => 'ppc', @@ -36,7 +38,7 @@ public function test_invoke_action_permissions(): void 'project_id' => $project->id, 'updaterequestable_type' => Site::class, 'updaterequestable_id' => $site->id, - 'status' => UpdateRequest::STATUS_REQUESTED, + 'status' => UpdateRequestStatusStateMachine::AWAITING_APPROVAL, ]); $owner = User::factory()->create(['organisation_id' => $organisation->id]); @@ -51,8 +53,8 @@ public function test_invoke_action_permissions(): void $ppcAdmin = User::factory()->admin()->create(); $ppcAdmin->givePermissionTo('framework-ppc'); - $payload = ['comments' => 'testing rejection']; - $uri = '/api/v2/admin/update-requests/' . $updateRequest->uuid . '/reject'; + $payload = ['comments' => 'testing more information']; + $uri = '/api/v2/admin/update-requests/' . $updateRequest->uuid . '/moreinfo'; $this->actingAs($random) ->putJson($uri, $payload) @@ -73,7 +75,7 @@ public function test_invoke_action_permissions(): void public function test_flow(): void { - // Artisan::call('v2migration:roles'); + Artisan::call('v2migration:roles'); $organisation = Organisation::factory()->create(); $project = Project::factory()->create([ 'framework_key' => 'ppc', @@ -91,7 +93,7 @@ public function test_flow(): void 'project_id' => $project->id, 'updaterequestable_type' => Site::class, 'updaterequestable_id' => $site->id, - 'status' => UpdateRequest::STATUS_REQUESTED, + 'status' => UpdateRequestStatusStateMachine::AWAITING_APPROVAL, ]); $ppcAdmin = User::factory()->admin()->create(); @@ -99,20 +101,15 @@ public function test_flow(): void $uri = '/api/v2/admin/update-requests/' . $updateRequest->uuid; - $this->actingAs($ppcAdmin) - ->putJson($uri . '/reject', ['comments' => 'testing rejection']) - ->assertSuccessful() - ->assertJsonFragment(['status' => UpdateRequest::STATUS_REJECTED]); - $this->actingAs($ppcAdmin) ->putJson($uri . '/moreinfo', ['comments' => 'blah blah blah']) ->assertSuccessful() - ->assertJsonFragment(['status' => UpdateRequest::STATUS_NEEDS_MORE_INFORMATION]); + ->assertJsonFragment(['status' => UpdateRequestStatusStateMachine::NEEDS_MORE_INFORMATION]); } public function test_approve_updates(): void { - // Artisan::call('v2migration:roles'); + Artisan::call('v2migration:roles'); $organisation = Organisation::factory()->create(); $owner = User::factory()->create(['organisation_id' => $organisation->id]); $owner->givePermissionTo('manage-own'); @@ -128,7 +125,7 @@ public function test_approve_updates(): void $site = Site::factory()->create([ 'project_id' => $project->id, 'framework_key' => 'ppc', - 'status' => Site::STATUS_APPROVED, + 'status' => EntityStatusStateMachine::APPROVED, ]); $form = CustomFormHelper::generateFakeForm('site', 'ppc'); @@ -147,14 +144,14 @@ public function test_approve_updates(): void 'project_id' => $project->id, 'updaterequestable_type' => Site::class, 'updaterequestable_id' => $site->id, - 'status' => UpdateRequest::STATUS_REQUESTED, + 'status' => UpdateRequestStatusStateMachine::AWAITING_APPROVAL, 'content' => $answers, ]); $this->actingAs($ppcAdmin) ->putJson('/api/v2/admin/update-requests/' . $updateRequest->uuid . '/approve', []) ->assertSuccessful() - ->assertJsonFragment(['status' => UpdateRequest::STATUS_APPROVED]); + ->assertJsonFragment(['status' => UpdateRequestStatusStateMachine::APPROVED]); // $updated = Site::find($site->id); // $this->assertEquals('* testing name updated *', $updated->name); From 1b39e58f2416a13c2dfece1fe779d2df0eeb3728 Mon Sep 17 00:00:00 2001 From: Nathan Curtis Date: Fri, 5 Apr 2024 16:30:14 -0700 Subject: [PATCH 07/44] [TM-785] Stages tests passing. --- tests/V2/Stages/IndexStageControllerTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/V2/Stages/IndexStageControllerTest.php b/tests/V2/Stages/IndexStageControllerTest.php index 46851d31d..ed7087fcf 100644 --- a/tests/V2/Stages/IndexStageControllerTest.php +++ b/tests/V2/Stages/IndexStageControllerTest.php @@ -14,12 +14,12 @@ final class IndexStageControllerTest extends TestCase public function test_users_can_view_stage_index(): void { $user = User::factory()->create(); - $count = Stage::count(); Stage::factory()->count(5)->create(); + $count = Stage::count(); // it's paginated to 100 - if ($count + 5 > 100) { + if ($count > 100) { $count = 100; } From 8a254d86d51e434fb15a8f67affc7a7d967174fc Mon Sep 17 00:00:00 2001 From: Nathan Curtis Date: Mon, 8 Apr 2024 13:26:53 -0700 Subject: [PATCH 08/44] [TM-785] Don't let faker create random statuses; it leads to flaky tests. --- database/factories/V2/Nurseries/NurseryFactory.php | 2 +- database/factories/V2/Nurseries/NurseryReportFactory.php | 2 +- database/factories/V2/Projects/ProjectFactory.php | 2 +- database/factories/V2/Projects/ProjectReportFactory.php | 2 +- database/factories/V2/Sites/SiteFactory.php | 2 +- database/factories/V2/Sites/SiteReportFactory.php | 2 +- database/factories/V2/Tasks/TaskFactory.php | 2 +- database/factories/V2/UpdateRequests/UpdateRequestFactory.php | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/database/factories/V2/Nurseries/NurseryFactory.php b/database/factories/V2/Nurseries/NurseryFactory.php index f5e8776e9..a588035ba 100644 --- a/database/factories/V2/Nurseries/NurseryFactory.php +++ b/database/factories/V2/Nurseries/NurseryFactory.php @@ -22,7 +22,7 @@ public function definition() return [ 'framework_key' => $frameworkKey, 'project_id' => Project::factory()->create(['framework_key' => $frameworkKey])->id, - 'status' => $this->faker->randomElement(array_keys(Nursery::$statuses)), + 'status' => array_keys(Nursery::$statuses)[0], 'type' => $this->faker->randomElement($types), 'name' => $this->faker->word(), 'start_date' => $this->faker->date(), diff --git a/database/factories/V2/Nurseries/NurseryReportFactory.php b/database/factories/V2/Nurseries/NurseryReportFactory.php index 068c8ab3e..6d4cfbbe8 100644 --- a/database/factories/V2/Nurseries/NurseryReportFactory.php +++ b/database/factories/V2/Nurseries/NurseryReportFactory.php @@ -20,7 +20,7 @@ public function definition() return [ 'framework_key' => $this->faker->randomElement($frameworks), 'nursery_id' => Nursery::factory()->create()->id, - 'status' => $this->faker->randomElement(array_keys(NurseryReport::$statuses)), + 'status' => array_keys(NurseryReport::$statuses)[0], 'title' => $this->faker->text(30), 'seedlings_young_trees' => $this->faker->numberBetween(0, 9999999), 'interesting_facts' => $this->faker->text(500), diff --git a/database/factories/V2/Projects/ProjectFactory.php b/database/factories/V2/Projects/ProjectFactory.php index 3dc4c8a42..51047ac93 100644 --- a/database/factories/V2/Projects/ProjectFactory.php +++ b/database/factories/V2/Projects/ProjectFactory.php @@ -31,7 +31,7 @@ public function definition() return [ 'framework_key' => $this->faker->randomElement($frameworks), 'name' => $this->faker->words(3, true), - 'status' => $this->faker->randomElement(array_keys(Project::$statuses)), + 'status' => array_keys(Project::$statuses)[0], 'project_status' => $this->faker->randomElement($projStatus), 'organisation_id' => Organisation::factory()->create()->id, 'boundary_geojson' => $geojson, diff --git a/database/factories/V2/Projects/ProjectReportFactory.php b/database/factories/V2/Projects/ProjectReportFactory.php index 50480c224..b4b5cec85 100644 --- a/database/factories/V2/Projects/ProjectReportFactory.php +++ b/database/factories/V2/Projects/ProjectReportFactory.php @@ -22,7 +22,7 @@ public function definition() 'project_id' => Project::factory()->create(), 'due_at' => $this->faker->dateTime, 'title' => $this->faker->text(30), - 'status' => $this->faker->randomElement(array_keys(ProjectReport::$statuses)), + 'status' => array_keys(ProjectReport::$statuses)[0], 'completion' => $this->faker->numberBetween(0, 100), ]; } diff --git a/database/factories/V2/Sites/SiteFactory.php b/database/factories/V2/Sites/SiteFactory.php index e2ccd45ee..94d0cd0da 100644 --- a/database/factories/V2/Sites/SiteFactory.php +++ b/database/factories/V2/Sites/SiteFactory.php @@ -52,7 +52,7 @@ public function definition() 'framework_key' => $this->faker->randomElement($frameworks), 'project_id' => Project::factory()->create()->id, 'name' => $this->faker->words(3, true), - 'status' => $this->faker->randomElement(array_keys(Site::$statuses)), + 'status' => array_keys(Site::$statuses)[0], 'control_site' => $this->faker->boolean(15), 'boundary_geojson' => '{"type":"Polygon","coordinates":[[[-1.864006519317627,50.7219083651253],[-1.8627190589904783,50.7219083651253],[-1.8627190589904783,50.72276418262861],[-1.864006519317627,50.72276418262861],[-1.864006519317627,50.7219083651253]]]}', 'land_use_types' => $this->faker->randomElements( diff --git a/database/factories/V2/Sites/SiteReportFactory.php b/database/factories/V2/Sites/SiteReportFactory.php index 35e70b066..412788e49 100644 --- a/database/factories/V2/Sites/SiteReportFactory.php +++ b/database/factories/V2/Sites/SiteReportFactory.php @@ -22,7 +22,7 @@ public function definition() 'site_id' => Site::factory()->create(), 'due_at' => $this->faker->dateTime, 'title' => $this->faker->text(30), - 'status' => $this->faker->randomElement(array_keys(SiteReport::$statuses)), + 'status' => array_keys(SiteReport::$statuses)[0], 'completion' => $this->faker->numberBetween(0, 100), ]; } diff --git a/database/factories/V2/Tasks/TaskFactory.php b/database/factories/V2/Tasks/TaskFactory.php index 6adb2c4c9..475b4aabf 100644 --- a/database/factories/V2/Tasks/TaskFactory.php +++ b/database/factories/V2/Tasks/TaskFactory.php @@ -20,7 +20,7 @@ public function definition() $date = Carbon::create($fakedDate); return [ - 'status' => $this->faker->randomElement(Task::$statuses), + 'status' => array_keys(Task::$statuses)[0], 'organisation_id' => (Organisation::factory()->create())->id, 'project_id' => (Organisation::factory()->create())->id, 'period_key' => $date->year . '-' . $date->month, diff --git a/database/factories/V2/UpdateRequests/UpdateRequestFactory.php b/database/factories/V2/UpdateRequests/UpdateRequestFactory.php index 0c9d9a581..90bdaa9c1 100644 --- a/database/factories/V2/UpdateRequests/UpdateRequestFactory.php +++ b/database/factories/V2/UpdateRequests/UpdateRequestFactory.php @@ -28,7 +28,7 @@ public function definition() 'framework_key' => $frameworkKey, 'organisation_id' => $organisation->id, 'project_id' => $project->id, - 'status' => $this->faker->randomElement(array_keys(UpdateRequest::$statuses)), + 'status' => array_keys(UpdateRequest::$statuses)[0], 'updaterequestable_type' => Project::class, 'updaterequestable_id' => $project->id, 'content' => json_encode(['name' => 'test project']), From 446244b61602f05d5e5a354ab228b5d69435d6b7 Mon Sep 17 00:00:00 2001 From: Nathan Curtis Date: Mon, 8 Apr 2024 13:47:39 -0700 Subject: [PATCH 09/44] [TM-785] Avoid generating multiple forms for the same framework/entity in a single test run. --- app/Helpers/CustomFormHelper.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/Helpers/CustomFormHelper.php b/app/Helpers/CustomFormHelper.php index 4c533735b..1622a0ae9 100644 --- a/app/Helpers/CustomFormHelper.php +++ b/app/Helpers/CustomFormHelper.php @@ -50,10 +50,17 @@ public static function generateFakeForm(string $type, string $framework): Form break; } + $form = Form::where(['framework_key' => $framework, 'model' => $model])->first(); + if ($form != null) { + // If we've already generated a fake form for this combo, use it because otherwise the form the + // controller gets from the DB will be different from the form in use by the test. + return $form; + } + $form = Form::factory()->create(['framework_key' => $framework, 'model' => $model]); $section = FormSection::factory()->create(['form_id' => $form->uuid]); foreach (config('wri.linked-fields.models.' . $type . '.fields') as $key => $fieldCfg) { - $questions = FormQuestion::factory()->create( + FormQuestion::factory()->create( [ 'input_type' => data_get($fieldCfg, 'input_type'), 'label' => data_get($fieldCfg, 'label'), From 9d60eb5e05468c7afd69ed7de73217a2ea8d3c63 Mon Sep 17 00:00:00 2001 From: Nathan Curtis Date: Mon, 8 Apr 2024 13:49:42 -0700 Subject: [PATCH 10/44] [TM-785] Sites tests all passing. --- tests/V2/Sites/AdminIndexSitesControllerTest.php | 6 +++++- tests/V2/Sites/AdminSitesMultiControllerTest.php | 4 ++-- tests/V2/Sites/AdminSoftDeleteSiteControllerTest.php | 4 ++-- .../Sites/AdminSoftDeleteSiteReportControllerTest.php | 4 ++-- tests/V2/Sites/AdminStatusSiteControllerTest.php | 9 +++++---- tests/V2/Sites/CreateSiteControllerWithFormTest.php | 4 ++-- .../AdminSoftDeleteSiteMonitoringControllerTest.php | 4 ++-- .../AdminUpdateSiteMonitoringControllerTest.php | 4 ++-- .../Monitoring/ViewSiteMonitoringControllerTest.php | 4 ++-- tests/V2/Sites/SoftDeleteSiteControllerTest.php | 4 ++-- tests/V2/Sites/SubmitSiteControllerTest.php | 4 ++-- tests/V2/Sites/UpdateSiteWithFormControllerTest.php | 11 ++++++----- .../V2/Sites/ViewASitesMonitoringsControllerTest.php | 4 ++-- tests/V2/Sites/ViewSiteControllerTest.php | 4 ++-- tests/V2/Sites/ViewSiteWithFormControllerTest.php | 4 ++-- 15 files changed, 40 insertions(+), 34 deletions(-) diff --git a/tests/V2/Sites/AdminIndexSitesControllerTest.php b/tests/V2/Sites/AdminIndexSitesControllerTest.php index 4f2b4c58c..3a975f845 100644 --- a/tests/V2/Sites/AdminIndexSitesControllerTest.php +++ b/tests/V2/Sites/AdminIndexSitesControllerTest.php @@ -2,9 +2,11 @@ namespace Tests\V2\Sites; +use App\Models\Framework; use App\Models\User; use App\Models\V2\Sites\Site; use Illuminate\Foundation\Testing\RefreshDatabase; +use Illuminate\Support\Facades\Artisan; use Tests\TestCase; class AdminIndexSitesControllerTest extends TestCase @@ -16,8 +18,10 @@ class AdminIndexSitesControllerTest extends TestCase public function setUp(): void { parent::setUp(); - // Artisan::call('v2migration:roles'); + Artisan::call('v2migration:roles'); $this->user = User::factory()->admin()->create(); + Framework::factory()->create(['slug' => 'terrafund']); + Framework::factory()->create(['slug' => 'ppc']); $this->user->givePermissionTo('framework-terrafund'); Site::query()->delete(); diff --git a/tests/V2/Sites/AdminSitesMultiControllerTest.php b/tests/V2/Sites/AdminSitesMultiControllerTest.php index d25d962dc..8b4243c65 100644 --- a/tests/V2/Sites/AdminSitesMultiControllerTest.php +++ b/tests/V2/Sites/AdminSitesMultiControllerTest.php @@ -6,7 +6,7 @@ use App\Models\V2\Sites\Site; use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\WithFaker; -// use Illuminate\Support\Facades\Artisan; +use Illuminate\Support\Facades\Artisan; use Tests\TestCase; class AdminSitesMultiControllerTest extends TestCase @@ -16,7 +16,7 @@ class AdminSitesMultiControllerTest extends TestCase public function test_invoke_action() { - // Artisan::call('v2migration:roles --fresh'); + Artisan::call('v2migration:roles --fresh'); $admin = User::factory()->admin()->create(); $admin->givePermissionTo('framework-terrafund'); $admin->givePermissionTo('framework-ppc'); diff --git a/tests/V2/Sites/AdminSoftDeleteSiteControllerTest.php b/tests/V2/Sites/AdminSoftDeleteSiteControllerTest.php index 572991dea..2ae96710e 100644 --- a/tests/V2/Sites/AdminSoftDeleteSiteControllerTest.php +++ b/tests/V2/Sites/AdminSoftDeleteSiteControllerTest.php @@ -1,6 +1,6 @@ admin()->create(); $user->givePermissionTo($permission); diff --git a/tests/V2/Sites/AdminSoftDeleteSiteReportControllerTest.php b/tests/V2/Sites/AdminSoftDeleteSiteReportControllerTest.php index 75d845f70..0e854abc3 100644 --- a/tests/V2/Sites/AdminSoftDeleteSiteReportControllerTest.php +++ b/tests/V2/Sites/AdminSoftDeleteSiteReportControllerTest.php @@ -1,6 +1,6 @@ admin()->create(); $user->givePermissionTo($permission); diff --git a/tests/V2/Sites/AdminStatusSiteControllerTest.php b/tests/V2/Sites/AdminStatusSiteControllerTest.php index ea2a5e436..049dba79a 100644 --- a/tests/V2/Sites/AdminStatusSiteControllerTest.php +++ b/tests/V2/Sites/AdminStatusSiteControllerTest.php @@ -5,7 +5,8 @@ use App\Models\User; use App\Models\V2\Organisation; use App\Models\V2\Projects\Project; -//use Illuminate\Support\Facades\Artisan; +use App\StateMachines\EntityStatusStateMachine; +use Illuminate\Support\Facades\Artisan; use App\Models\V2\Sites\Site; use Illuminate\Foundation\Testing\RefreshDatabase; use Tests\TestCase; @@ -16,7 +17,7 @@ class AdminStatusSiteControllerTest extends TestCase public function test_invoke_action(): void { - // Artisan::call('v2migration:roles'); + Artisan::call('v2migration:roles'); $organisation = Organisation::factory()->create(); $project = Project::factory()->create([ 'framework_key' => 'ppc', @@ -26,7 +27,7 @@ public function test_invoke_action(): void $site = Site::factory()->create([ 'framework_key' => 'ppc', 'project_id' => $project->id, - 'status' => Site::STATUS_AWAITING_APPROVAL, + 'status' => EntityStatusStateMachine::AWAITING_APPROVAL, ]); $owner = User::factory()->create(['organisation_id' => $organisation->id]); @@ -59,6 +60,6 @@ public function test_invoke_action(): void $this->actingAs($ppcAdmin) ->putJson($uri, $payload) ->assertSuccessful() - ->assertJsonFragment(['status' => Site::STATUS_NEEDS_MORE_INFORMATION]); + ->assertJsonFragment(['status' => EntityStatusStateMachine::NEEDS_MORE_INFORMATION]); } } diff --git a/tests/V2/Sites/CreateSiteControllerWithFormTest.php b/tests/V2/Sites/CreateSiteControllerWithFormTest.php index c6f9dd2dd..2e091c57b 100644 --- a/tests/V2/Sites/CreateSiteControllerWithFormTest.php +++ b/tests/V2/Sites/CreateSiteControllerWithFormTest.php @@ -8,7 +8,7 @@ use App\Models\V2\Projects\Project; use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\WithFaker; -//use Illuminate\Support\Facades\Artisan; +use Illuminate\Support\Facades\Artisan; use Tests\TestCase; class CreateSiteControllerWithFormTest extends TestCase @@ -18,7 +18,7 @@ class CreateSiteControllerWithFormTest extends TestCase public function test_invoke_action() { - // Artisan::call('v2migration:roles --fresh'); + Artisan::call('v2migration:roles --fresh'); $tfAdmin = User::factory()->admin()->create(); $tfAdmin->givePermissionTo('framework-terrafund'); diff --git a/tests/V2/Sites/Monitoring/AdminSoftDeleteSiteMonitoringControllerTest.php b/tests/V2/Sites/Monitoring/AdminSoftDeleteSiteMonitoringControllerTest.php index cbad26a7c..d5dd08174 100644 --- a/tests/V2/Sites/Monitoring/AdminSoftDeleteSiteMonitoringControllerTest.php +++ b/tests/V2/Sites/Monitoring/AdminSoftDeleteSiteMonitoringControllerTest.php @@ -7,7 +7,7 @@ use App\Models\V2\Projects\Project; use App\Models\V2\Sites\Site; use App\Models\V2\Sites\SiteMonitoring; -//use Illuminate\Support\Facades\Artisan; +use Illuminate\Support\Facades\Artisan; use Illuminate\Foundation\Testing\RefreshDatabase; use Tests\TestCase; @@ -26,7 +26,7 @@ public function setUp(): void $organisation = Organisation::factory()->create(); -// Artisan::call('v2migration:roles --fresh'); + Artisan::call('v2migration:roles'); $this->owner = User::factory()->admin()->create(['organisation_id' => $organisation->id]); $this->owner->givePermissionTo('manage-own'); diff --git a/tests/V2/Sites/Monitoring/AdminUpdateSiteMonitoringControllerTest.php b/tests/V2/Sites/Monitoring/AdminUpdateSiteMonitoringControllerTest.php index 6e0a8e37d..3e3b2424a 100644 --- a/tests/V2/Sites/Monitoring/AdminUpdateSiteMonitoringControllerTest.php +++ b/tests/V2/Sites/Monitoring/AdminUpdateSiteMonitoringControllerTest.php @@ -7,7 +7,7 @@ use App\Models\V2\Projects\Project; use App\Models\V2\Sites\Site; use App\Models\V2\Sites\SiteMonitoring; -//use Illuminate\Support\Facades\Artisan; +use Illuminate\Support\Facades\Artisan; use Illuminate\Foundation\Testing\RefreshDatabase; use Tests\TestCase; @@ -27,7 +27,7 @@ public function setUp(): void $organisation = Organisation::factory()->create(); -// Artisan::call('v2migration:roles --fresh'); + Artisan::call('v2migration:roles'); $this->owner = User::factory()->admin()->create(['organisation_id' => $organisation->id]); $this->owner->givePermissionTo('manage-own'); diff --git a/tests/V2/Sites/Monitoring/ViewSiteMonitoringControllerTest.php b/tests/V2/Sites/Monitoring/ViewSiteMonitoringControllerTest.php index 212cfc5a1..1a63c3d9b 100644 --- a/tests/V2/Sites/Monitoring/ViewSiteMonitoringControllerTest.php +++ b/tests/V2/Sites/Monitoring/ViewSiteMonitoringControllerTest.php @@ -7,7 +7,7 @@ use App\Models\V2\Projects\Project; use App\Models\V2\Sites\Site; use App\Models\V2\Sites\SiteMonitoring; -//use Illuminate\Support\Facades\Artisan; +use Illuminate\Support\Facades\Artisan; use Illuminate\Foundation\Testing\RefreshDatabase; use Tests\TestCase; @@ -17,7 +17,7 @@ class ViewSiteMonitoringControllerTest extends TestCase public function test_invoke_action() { -// Artisan::call('v2migration:roles --fresh'); + Artisan::call('v2migration:roles'); $tfAdmin = User::factory()->admin()->create(); $tfAdmin->givePermissionTo('framework-terrafund'); diff --git a/tests/V2/Sites/SoftDeleteSiteControllerTest.php b/tests/V2/Sites/SoftDeleteSiteControllerTest.php index a39db5698..110fd8ee5 100644 --- a/tests/V2/Sites/SoftDeleteSiteControllerTest.php +++ b/tests/V2/Sites/SoftDeleteSiteControllerTest.php @@ -1,6 +1,6 @@ create(['framework_key' => $fmKey]); $site = Site::factory()->{$fmKey}()->create([ diff --git a/tests/V2/Sites/SubmitSiteControllerTest.php b/tests/V2/Sites/SubmitSiteControllerTest.php index a26f082a2..c415cfa1b 100644 --- a/tests/V2/Sites/SubmitSiteControllerTest.php +++ b/tests/V2/Sites/SubmitSiteControllerTest.php @@ -9,7 +9,7 @@ use App\Models\V2\Sites\Site; use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\WithFaker; -//use Illuminate\Support\Facades\Artisan; +use Illuminate\Support\Facades\Artisan; use Tests\TestCase; class SubmitSiteControllerTest extends TestCase @@ -19,7 +19,7 @@ class SubmitSiteControllerTest extends TestCase public function test_invoke_action() { - // Artisan::call('v2migration:roles --fresh'); + Artisan::call('v2migration:roles'); $organisation = Organisation::factory()->create(); $owner = User::factory()->create(['organisation_id' => $organisation->id]); $owner->givePermissionTo('manage-own'); diff --git a/tests/V2/Sites/UpdateSiteWithFormControllerTest.php b/tests/V2/Sites/UpdateSiteWithFormControllerTest.php index 102496369..0202a0d31 100644 --- a/tests/V2/Sites/UpdateSiteWithFormControllerTest.php +++ b/tests/V2/Sites/UpdateSiteWithFormControllerTest.php @@ -7,9 +7,10 @@ use App\Models\V2\Organisation; use App\Models\V2\Projects\Project; use App\Models\V2\Sites\Site; +use App\StateMachines\EntityStatusStateMachine; use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\WithFaker; -//use Illuminate\Support\Facades\Artisan; +use Illuminate\Support\Facades\Artisan; use Tests\TestCase; class UpdateSiteWithFormControllerTest extends TestCase @@ -19,7 +20,7 @@ class UpdateSiteWithFormControllerTest extends TestCase public function test_invoke_action() { - // Artisan::call('v2migration:roles --fresh'); + Artisan::call('v2migration:roles'); $tfAdmin = User::factory()->admin()->create(); $tfAdmin->givePermissionTo('framework-terrafund'); @@ -40,7 +41,7 @@ public function test_invoke_action() $site = Site::factory()->create([ 'project_id' => $project->id, 'framework_key' => 'ppc', - 'status' => Site::STATUS_STARTED, + 'status' => EntityStatusStateMachine::STARTED, ]); $form = CustomFormHelper::generateFakeForm('site', 'ppc'); @@ -86,7 +87,7 @@ public function test_invoke_action() public function test_update_request() { - // Artisan::call('v2migration:roles --fresh'); + Artisan::call('v2migration:roles'); $organisation = Organisation::factory()->create(); $owner = User::factory()->create(['organisation_id' => $organisation->id]); $owner->givePermissionTo('manage-own'); @@ -99,7 +100,7 @@ public function test_update_request() $site = Site::factory()->create([ 'project_id' => $project->id, 'framework_key' => 'ppc', - 'status' => Site::STATUS_APPROVED, + 'status' => EntityStatusStateMachine::APPROVED, ]); $form = CustomFormHelper::generateFakeForm('site', 'ppc'); diff --git a/tests/V2/Sites/ViewASitesMonitoringsControllerTest.php b/tests/V2/Sites/ViewASitesMonitoringsControllerTest.php index f26864985..6721b8f4e 100644 --- a/tests/V2/Sites/ViewASitesMonitoringsControllerTest.php +++ b/tests/V2/Sites/ViewASitesMonitoringsControllerTest.php @@ -7,7 +7,7 @@ use App\Models\V2\Projects\Project; use App\Models\V2\Sites\Site; use App\Models\V2\Sites\SiteMonitoring; -//use Illuminate\Support\Facades\Artisan; +use Illuminate\Support\Facades\Artisan; use Illuminate\Foundation\Testing\RefreshDatabase; use Tests\TestCase; @@ -27,7 +27,7 @@ public function setUp(): void $organisation = Organisation::factory()->create(); -// Artisan::call('v2migration:roles --fresh'); + Artisan::call('v2migration:roles'); $this->owner = User::factory()->admin()->create(['organisation_id' => $organisation->id]); $this->owner->givePermissionTo('manage-own'); diff --git a/tests/V2/Sites/ViewSiteControllerTest.php b/tests/V2/Sites/ViewSiteControllerTest.php index 32272ca9b..6bd8c027a 100644 --- a/tests/V2/Sites/ViewSiteControllerTest.php +++ b/tests/V2/Sites/ViewSiteControllerTest.php @@ -9,7 +9,7 @@ use App\Models\V2\Sites\Site; use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\WithFaker; -//use Illuminate\Support\Facades\Artisan; +use Illuminate\Support\Facades\Artisan; use Tests\TestCase; class ViewSiteControllerTest extends TestCase @@ -19,7 +19,7 @@ class ViewSiteControllerTest extends TestCase public function test_invoke_action() { - // Artisan::call('v2migration:roles --fresh'); + Artisan::call('v2migration:roles'); $tfAdmin = User::factory()->admin()->create(); $tfAdmin->givePermissionTo('framework-terrafund'); diff --git a/tests/V2/Sites/ViewSiteWithFormControllerTest.php b/tests/V2/Sites/ViewSiteWithFormControllerTest.php index 61897bbfd..ee6daaf62 100644 --- a/tests/V2/Sites/ViewSiteWithFormControllerTest.php +++ b/tests/V2/Sites/ViewSiteWithFormControllerTest.php @@ -9,7 +9,7 @@ use App\Models\V2\Sites\Site; use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\WithFaker; -//use Illuminate\Support\Facades\Artisan; +use Illuminate\Support\Facades\Artisan; use Tests\TestCase; class ViewSiteWithFormControllerTest extends TestCase @@ -19,7 +19,7 @@ class ViewSiteWithFormControllerTest extends TestCase public function test_invoke_action() { - // Artisan::call('v2migration:roles --fresh'); + Artisan::call('v2migration:roles'); $tfAdmin = User::factory()->admin()->create(); $tfAdmin->givePermissionTo('framework-terrafund'); From da0904836939d956dc3959242deb38756409a8f4 Mon Sep 17 00:00:00 2001 From: Nathan Curtis Date: Mon, 8 Apr 2024 14:37:57 -0700 Subject: [PATCH 11/44] [TM-785] Projects tests all passing. --- .../Projects/AdminIndexProjectsControllerTest.php | 4 ++-- .../Projects/AdminProjectMultiControllerTest.php | 4 ++-- .../AdminSoftDeleteProjectControllerTest.php | 6 +++--- .../Projects/AdminStatusProjectControllerTest.php | 9 +++++---- .../CreateBlankProjectWithFormControllerTest.php | 7 ++++--- .../CreateProjectInviteControllerTest.php | 15 ++++++--------- .../CreateProjectWithFormControllerTest.php | 11 ++++++----- .../IndexSitePolygonsForProjectControllerTest.php | 2 +- ...nSoftDeleteProjectMonitoringControllerTest.php | 4 ++-- ...AdminUpdateProjectMonitoringControllerTest.php | 2 +- .../ProjectInviteAcceptControllerTest.php | 4 ++-- .../Projects/SoftDeleteProjectControllerTest.php | 11 ++++++----- tests/V2/Projects/SubmitProjectControllerTest.php | 4 ++-- .../UpdateProjectWithFormControllerTest.php | 11 ++++++----- .../ViewAProjectsMonitoringsControllerTest.php | 4 ++-- .../V2/Projects/ViewMyProjectsControllerTest.php | 8 ++++---- tests/V2/Projects/ViewProjectControllerTest.php | 6 +++--- ...iewProjectMonitoringPartnersControllerTest.php | 4 +--- .../ViewProjectNurseriesControllerTest.php | 2 +- .../Projects/ViewProjectSitesControllerTest.php | 4 ++-- .../ViewProjectWithFormControllerTest.php | 4 ++-- 21 files changed, 63 insertions(+), 63 deletions(-) diff --git a/tests/V2/Projects/AdminIndexProjectsControllerTest.php b/tests/V2/Projects/AdminIndexProjectsControllerTest.php index a7c4867fa..fbae1dc14 100644 --- a/tests/V2/Projects/AdminIndexProjectsControllerTest.php +++ b/tests/V2/Projects/AdminIndexProjectsControllerTest.php @@ -6,7 +6,7 @@ use App\Models\V2\Projects\Project; use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\WithFaker; -//use Illuminate\Support\Facades\Artisan; +use Illuminate\Support\Facades\Artisan; use Tests\TestCase; class AdminIndexProjectsControllerTest extends TestCase @@ -17,7 +17,7 @@ class AdminIndexProjectsControllerTest extends TestCase public function test_invoke_action() { - // Artisan::call('v2migration:roles'); + Artisan::call('v2migration:roles'); $tfAdmin = User::factory()->admin()->create(); $ppcAdmin = User::factory()->admin()->create(); $tfAdmin->givePermissionTo('framework-terrafund'); diff --git a/tests/V2/Projects/AdminProjectMultiControllerTest.php b/tests/V2/Projects/AdminProjectMultiControllerTest.php index 01f5794b3..7a1f3d5fe 100644 --- a/tests/V2/Projects/AdminProjectMultiControllerTest.php +++ b/tests/V2/Projects/AdminProjectMultiControllerTest.php @@ -6,7 +6,7 @@ use App\Models\V2\Projects\Project; use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\WithFaker; -// use Illuminate\Support\Facades\Artisan; +use Illuminate\Support\Facades\Artisan; use Tests\TestCase; class AdminProjectMultiControllerTest extends TestCase @@ -16,7 +16,7 @@ class AdminProjectMultiControllerTest extends TestCase public function test_invoke_action() { - // Artisan::call('v2migration:roles'); + Artisan::call('v2migration:roles'); $admin = User::factory()->admin()->create(); $admin->givePermissionTo('framework-terrafund'); $admin->givePermissionTo('framework-ppc'); diff --git a/tests/V2/Projects/AdminSoftDeleteProjectControllerTest.php b/tests/V2/Projects/AdminSoftDeleteProjectControllerTest.php index 74ef9528c..71840f27d 100644 --- a/tests/V2/Projects/AdminSoftDeleteProjectControllerTest.php +++ b/tests/V2/Projects/AdminSoftDeleteProjectControllerTest.php @@ -1,12 +1,12 @@ admin()->create(); $user->givePermissionTo($permission); diff --git a/tests/V2/Projects/AdminStatusProjectControllerTest.php b/tests/V2/Projects/AdminStatusProjectControllerTest.php index 8b14be864..0c0376f5f 100644 --- a/tests/V2/Projects/AdminStatusProjectControllerTest.php +++ b/tests/V2/Projects/AdminStatusProjectControllerTest.php @@ -5,7 +5,8 @@ use App\Models\User; use App\Models\V2\Organisation; use App\Models\V2\Projects\Project; -//use Illuminate\Support\Facades\Artisan; +use App\StateMachines\EntityStatusStateMachine; +use Illuminate\Support\Facades\Artisan; use Illuminate\Foundation\Testing\RefreshDatabase; use Tests\TestCase; @@ -15,12 +16,12 @@ class AdminStatusProjectControllerTest extends TestCase public function test_invoke_action(): void { - // Artisan::call('v2migration:roles'); + Artisan::call('v2migration:roles'); $organisation = Organisation::factory()->create(); $project = Project::factory()->create([ 'framework_key' => 'ppc', 'organisation_id' => $organisation->id, - 'status' => Project::STATUS_AWAITING_APPROVAL, + 'status' => EntityStatusStateMachine::AWAITING_APPROVAL, ]); $owner = User::factory()->create(['organisation_id' => $organisation->id]); @@ -53,6 +54,6 @@ public function test_invoke_action(): void $this->actingAs($ppcAdmin) ->putJson($uri, $payload) ->assertSuccessful() - ->assertJsonFragment(['status' => Project::STATUS_NEEDS_MORE_INFORMATION]); + ->assertJsonFragment(['status' => EntityStatusStateMachine::NEEDS_MORE_INFORMATION]); } } diff --git a/tests/V2/Projects/CreateBlankProjectWithFormControllerTest.php b/tests/V2/Projects/CreateBlankProjectWithFormControllerTest.php index 94bda0eb1..885f52880 100644 --- a/tests/V2/Projects/CreateBlankProjectWithFormControllerTest.php +++ b/tests/V2/Projects/CreateBlankProjectWithFormControllerTest.php @@ -1,6 +1,6 @@ prepareData($fmKey); @@ -48,7 +49,7 @@ public function test_a_project_developer_can_create_a_blank_project_from_a_given 'framework_key' => $form->framework_key, 'organisation_id' => $organisation->id, 'application_id' => null, - 'status' => Project::STATUS_STARTED, + 'status' => EntityStatusStateMachine::STARTED, 'project_status' => null, 'name' => null, 'boundary_geojson' => null, diff --git a/tests/V2/Projects/CreateProjectInviteControllerTest.php b/tests/V2/Projects/CreateProjectInviteControllerTest.php index 3cb40b50c..727972d55 100644 --- a/tests/V2/Projects/CreateProjectInviteControllerTest.php +++ b/tests/V2/Projects/CreateProjectInviteControllerTest.php @@ -8,7 +8,6 @@ use App\Models\V2\Projects\Project; use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\WithFaker; -//use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Mail; @@ -25,13 +24,13 @@ public function setUp(): void Mail::fake(); - // Artisan::call('v2migration:roles --fresh'); + Artisan::call('v2migration:roles'); } /** * @dataProvider permissionsDataProvider */ - public function test_it_creates_project_invitations_for_existing_users(string $permission, string $fmKey, bool $useUserEmail) + public function test_it_creates_project_invitations_for_existing_users(string $permission, string $fmKey) { DB::table('v2_project_invites')->truncate(); @@ -48,10 +47,11 @@ public function test_it_creates_project_invitations_for_existing_users(string $p $project = Project::factory()->{$fmKey}()->create(['organisation_id' => $organisation->id]); - $email_address = $useUserEmail ? $user->email_address : $this->faker->email; + $email_address = $this->faker->email; $payload = [ 'email_address' => $email_address, + 'callback_url' => 'https://test.terramatch.org/foo', ]; $this->actingAs($user) @@ -65,7 +65,6 @@ public function test_it_creates_project_invitations_for_existing_users(string $p ->assertJsonFragment([ 'project_id' => $project->id, 'email_address' => $payload['email_address'], - 'accepted_at' => null, ]); } @@ -101,10 +100,8 @@ function (V2ProjectInviteReceived $projectInviteReceived) use ($email_address, $ public static function permissionsDataProvider() { return [ - ['framework-terrafund', 'terrafund', true], - ['framework-terrafund', 'terrafund', false], - ['framework-ppc', 'ppc', true], - ['framework-ppc', 'ppc', false], + ['framework-terrafund', 'terrafund'], + ['framework-ppc', 'ppc'], ]; } } diff --git a/tests/V2/Projects/CreateProjectWithFormControllerTest.php b/tests/V2/Projects/CreateProjectWithFormControllerTest.php index 99b1604b2..4da0c1436 100644 --- a/tests/V2/Projects/CreateProjectWithFormControllerTest.php +++ b/tests/V2/Projects/CreateProjectWithFormControllerTest.php @@ -1,6 +1,6 @@ prepareData($fmKey); @@ -37,6 +37,7 @@ public function test_a_project_developer_can_create_a_project_from_a_given_form( $payload = [ 'parent_entity' => 'application', 'parent_uuid' => $application->uuid, + 'form_uuid' => $form->uuid, ]; $uri = '/api/v2/forms/projects'; @@ -53,7 +54,7 @@ public function test_a_project_developer_can_create_a_project_from_a_given_form( 'framework_key' => $form->framework_key, 'organisation_id' => $application->organisation->id, 'application_id' => $application->id, - 'status' => Project::STATUS_STARTED, + 'status' => EntityStatusStateMachine::STARTED, 'project_status' => null, 'name' => $projectPitch->project_name, 'boundary_geojson' => $projectPitch->proj_boundary, @@ -90,7 +91,7 @@ public function test_a_project_developer_can_create_a_project_from_a_given_form( */ public function test_an_unauthorized_user_cant_create_a_project_from_a_given_form(string $permission, string $fmKey) { - // Artisan::call('v2migration:roles --fresh'); + Artisan::call('v2migration:roles'); list($fundingProgramme, $application, $organisation, $projectPitch, $formSubmissions, $form) = $this->prepareData($fmKey); diff --git a/tests/V2/Projects/IndexSitePolygonsForProjectControllerTest.php b/tests/V2/Projects/IndexSitePolygonsForProjectControllerTest.php index b2a312210..2fdd084e6 100644 --- a/tests/V2/Projects/IndexSitePolygonsForProjectControllerTest.php +++ b/tests/V2/Projects/IndexSitePolygonsForProjectControllerTest.php @@ -18,7 +18,7 @@ class IndexSitePolygonsForProjectControllerTest extends TestCase public function test_invoke_action() { - Artisan::call('v2migration:roles --fresh'); + Artisan::call('v2migration:roles'); $tfAdmin = User::factory()->admin()->create(); $tfAdmin->givePermissionTo('framework-terrafund'); diff --git a/tests/V2/Projects/Monitoring/AdminSoftDeleteProjectMonitoringControllerTest.php b/tests/V2/Projects/Monitoring/AdminSoftDeleteProjectMonitoringControllerTest.php index a142a0447..8be7b7ce7 100644 --- a/tests/V2/Projects/Monitoring/AdminSoftDeleteProjectMonitoringControllerTest.php +++ b/tests/V2/Projects/Monitoring/AdminSoftDeleteProjectMonitoringControllerTest.php @@ -6,7 +6,7 @@ use App\Models\V2\Organisation; use App\Models\V2\Projects\Project; use App\Models\V2\Projects\ProjectMonitoring; -//use Illuminate\Support\Facades\Artisan; +use Illuminate\Support\Facades\Artisan; use Illuminate\Foundation\Testing\RefreshDatabase; use Tests\TestCase; @@ -24,7 +24,7 @@ public function setUp(): void $organisation = Organisation::factory()->create(); -// Artisan::call('v2migration:roles --fresh'); + Artisan::call('v2migration:roles'); $this->owner = User::factory()->admin()->create(['organisation_id' => $organisation->id]); $this->owner->givePermissionTo('manage-own'); diff --git a/tests/V2/Projects/Monitoring/AdminUpdateProjectMonitoringControllerTest.php b/tests/V2/Projects/Monitoring/AdminUpdateProjectMonitoringControllerTest.php index 46feb858a..524616e80 100644 --- a/tests/V2/Projects/Monitoring/AdminUpdateProjectMonitoringControllerTest.php +++ b/tests/V2/Projects/Monitoring/AdminUpdateProjectMonitoringControllerTest.php @@ -26,7 +26,7 @@ public function setUp(): void $organisation = Organisation::factory()->create(); - Artisan::call('v2migration:roles --fresh'); + Artisan::call('v2migration:roles'); $this->owner = User::factory()->admin()->create(['organisation_id' => $organisation->id]); $this->owner->givePermissionTo('manage-own'); diff --git a/tests/V2/Projects/ProjectInviteAcceptControllerTest.php b/tests/V2/Projects/ProjectInviteAcceptControllerTest.php index 3969deda6..ecba36670 100644 --- a/tests/V2/Projects/ProjectInviteAcceptControllerTest.php +++ b/tests/V2/Projects/ProjectInviteAcceptControllerTest.php @@ -8,7 +8,7 @@ use App\Models\V2\Projects\ProjectInvite; use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\WithFaker; -//use Illuminate\Support\Facades\Artisan; +use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\Mail; use Tests\TestCase; @@ -20,7 +20,7 @@ class ProjectInviteAcceptControllerTest extends TestCase public function test_invoke_action() { Mail::fake(); - // Artisan::call('v2migration:roles --fresh'); + Artisan::call('v2migration:roles'); $organisation = Organisation::factory()->create(); $project = Project::factory()->create([ diff --git a/tests/V2/Projects/SoftDeleteProjectControllerTest.php b/tests/V2/Projects/SoftDeleteProjectControllerTest.php index b1de3c4dc..e64134b45 100644 --- a/tests/V2/Projects/SoftDeleteProjectControllerTest.php +++ b/tests/V2/Projects/SoftDeleteProjectControllerTest.php @@ -1,13 +1,14 @@ create(); $organisation = Organisation::factory()->create(); @@ -27,13 +28,13 @@ public function test_invoke_action() $project1 = Project::factory()->create([ 'organisation_id' => $organisation->id, 'framework_key' => 'terrafund', - 'status' => Project::STATUS_AWAITING_APPROVAL, + 'status' => EntityStatusStateMachine::AWAITING_APPROVAL, ]); $project2 = Project::factory()->create([ 'organisation_id' => $organisation->id, 'framework_key' => 'terrafund', - 'status' => Project::STATUS_STARTED, + 'status' => EntityStatusStateMachine::STARTED, ]); $uri1 = '/api/v2/projects/' . $project1->uuid; diff --git a/tests/V2/Projects/SubmitProjectControllerTest.php b/tests/V2/Projects/SubmitProjectControllerTest.php index eab0817d2..baf685a38 100644 --- a/tests/V2/Projects/SubmitProjectControllerTest.php +++ b/tests/V2/Projects/SubmitProjectControllerTest.php @@ -8,7 +8,7 @@ use App\Models\V2\Projects\Project; use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\WithFaker; -//use Illuminate\Support\Facades\Artisan; +use Illuminate\Support\Facades\Artisan; use Tests\TestCase; class SubmitProjectControllerTest extends TestCase @@ -18,7 +18,7 @@ class SubmitProjectControllerTest extends TestCase public function test_invoke_action() { - // Artisan::call('v2migration:roles --fresh'); + Artisan::call('v2migration:roles'); $organisation = Organisation::factory()->create(); $owner = User::factory()->create(['organisation_id' => $organisation->id]); $owner->givePermissionTo('manage-own'); diff --git a/tests/V2/Projects/UpdateProjectWithFormControllerTest.php b/tests/V2/Projects/UpdateProjectWithFormControllerTest.php index ce72ef7ff..56ed4d289 100644 --- a/tests/V2/Projects/UpdateProjectWithFormControllerTest.php +++ b/tests/V2/Projects/UpdateProjectWithFormControllerTest.php @@ -6,9 +6,10 @@ use App\Models\User; use App\Models\V2\Organisation; use App\Models\V2\Projects\Project; +use App\StateMachines\EntityStatusStateMachine; use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\WithFaker; -//use Illuminate\Support\Facades\Artisan; +use Illuminate\Support\Facades\Artisan; use Tests\TestCase; class UpdateProjectWithFormControllerTest extends TestCase @@ -18,7 +19,7 @@ class UpdateProjectWithFormControllerTest extends TestCase public function test_invoke_action() { - // Artisan::call('v2migration:roles --fresh'); + Artisan::call('v2migration:roles'); $tfAdmin = User::factory()->admin()->create(); $tfAdmin->givePermissionTo('framework-terrafund'); @@ -34,7 +35,7 @@ public function test_invoke_action() $project = Project::factory()->create([ 'organisation_id' => $organisation->id, 'framework_key' => 'ppc', - 'status' => Project::STATUS_STARTED, + 'status' => EntityStatusStateMachine::STARTED, ]); $form = CustomFormHelper::generateFakeForm('project', 'ppc'); @@ -79,7 +80,7 @@ public function test_invoke_action() public function test_update_request() { - // Artisan::call('v2migration:roles --fresh'); + Artisan::call('v2migration:roles'); $organisation = Organisation::factory()->create(); $owner = User::factory()->create(['organisation_id' => $organisation->id]); $owner->givePermissionTo('manage-own'); @@ -87,7 +88,7 @@ public function test_update_request() $project = Project::factory()->create([ 'organisation_id' => $organisation->id, 'framework_key' => 'ppc', - 'status' => Project::STATUS_APPROVED, + 'status' => EntityStatusStateMachine::APPROVED, ]); $form = CustomFormHelper::generateFakeForm('project', 'ppc'); diff --git a/tests/V2/Projects/ViewAProjectsMonitoringsControllerTest.php b/tests/V2/Projects/ViewAProjectsMonitoringsControllerTest.php index 615ea372f..910d52b36 100644 --- a/tests/V2/Projects/ViewAProjectsMonitoringsControllerTest.php +++ b/tests/V2/Projects/ViewAProjectsMonitoringsControllerTest.php @@ -6,7 +6,7 @@ use App\Models\V2\Organisation; use App\Models\V2\Projects\Project; use App\Models\V2\Projects\ProjectMonitoring; -//use Illuminate\Support\Facades\Artisan; +use Illuminate\Support\Facades\Artisan; use Illuminate\Foundation\Testing\RefreshDatabase; use Tests\TestCase; @@ -25,7 +25,7 @@ public function setUp(): void $organisation = Organisation::factory()->create(); -// Artisan::call('v2migration:roles --fresh'); + Artisan::call('v2migration:roles'); $this->owner = User::factory()->admin()->create(['organisation_id' => $organisation->id]); $this->owner->givePermissionTo('manage-own'); diff --git a/tests/V2/Projects/ViewMyProjectsControllerTest.php b/tests/V2/Projects/ViewMyProjectsControllerTest.php index 40fe8b1eb..011193e0c 100644 --- a/tests/V2/Projects/ViewMyProjectsControllerTest.php +++ b/tests/V2/Projects/ViewMyProjectsControllerTest.php @@ -7,7 +7,7 @@ use App\Models\V2\Projects\Project; use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\WithFaker; -// use Illuminate\Support\Facades\Artisan; + use Illuminate\Support\Facades\Artisan; use Tests\TestCase; class ViewMyProjectsControllerTest extends TestCase @@ -17,7 +17,7 @@ class ViewMyProjectsControllerTest extends TestCase public function test_invoke_action() { - // Artisan::call('v2migration:roles --fresh'); + Artisan::call('v2migration:roles'); $organisation = Organisation::factory()->create(); $user = User::factory()->create(['organisation_id' => $organisation->id]); $user->givePermissionTo('manage-own'); @@ -48,8 +48,8 @@ public function test_invoke_action() $this->actingAs($user) ->getJson($uri) ->assertSuccessful() - ->assertJsonCount(3, 'data') - ->assertJsonFragment([ + ->assertJsonCount(2, 'data') + ->assertJsonMissing([ 'uuid' => $organisationProject->uuid, ]) ->assertJsonFragment([ diff --git a/tests/V2/Projects/ViewProjectControllerTest.php b/tests/V2/Projects/ViewProjectControllerTest.php index 74aeb1b47..03306c437 100644 --- a/tests/V2/Projects/ViewProjectControllerTest.php +++ b/tests/V2/Projects/ViewProjectControllerTest.php @@ -8,7 +8,7 @@ use App\Models\V2\Projects\Project; use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\WithFaker; -//use Illuminate\Support\Facades\Artisan; +use Illuminate\Support\Facades\Artisan; use Tests\TestCase; class ViewProjectControllerTest extends TestCase @@ -18,7 +18,7 @@ class ViewProjectControllerTest extends TestCase public function test_invoke_action() { - // Artisan::call('v2migration:roles --fresh'); + Artisan::call('v2migration:roles'); $tfAdmin = User::factory()->admin()->create(); $tfAdmin->givePermissionTo('framework-terrafund'); @@ -53,7 +53,7 @@ public function test_invoke_action() public function test_it_does_not_return_soft_deleted_projects() { - // Artisan::call('v2migration:roles --fresh'); + Artisan::call('v2migration:roles'); $organisation = Organisation::factory()->create(); $user = User::factory()->create(); $owner = User::factory()->create(['organisation_id' => $organisation->id]); diff --git a/tests/V2/Projects/ViewProjectMonitoringPartnersControllerTest.php b/tests/V2/Projects/ViewProjectMonitoringPartnersControllerTest.php index 7576fdf80..6b176fa99 100644 --- a/tests/V2/Projects/ViewProjectMonitoringPartnersControllerTest.php +++ b/tests/V2/Projects/ViewProjectMonitoringPartnersControllerTest.php @@ -8,9 +8,7 @@ use App\Models\V2\Projects\ProjectInvite; use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\WithFaker; -// use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\Artisan; -use Illuminate\Support\Str; use Tests\TestCase; class ViewProjectMonitoringPartnersControllerTest extends TestCase @@ -20,7 +18,7 @@ class ViewProjectMonitoringPartnersControllerTest extends TestCase public function test_it_returns_project_partners() { -// Artisan::call('v2migration:roles --fresh'); + Artisan::call('v2migration:roles'); $organisation = Organisation::factory()->create(); $user = User::factory()->create(['organisation_id' => $organisation->id]); diff --git a/tests/V2/Projects/ViewProjectNurseriesControllerTest.php b/tests/V2/Projects/ViewProjectNurseriesControllerTest.php index 6d6b9ede4..ec65c472f 100644 --- a/tests/V2/Projects/ViewProjectNurseriesControllerTest.php +++ b/tests/V2/Projects/ViewProjectNurseriesControllerTest.php @@ -32,7 +32,7 @@ public function setUp(): void { parent::setUp(); - Artisan::call('v2migration:roles --fresh'); + Artisan::call('v2migration:roles'); $this->ppcAdmin = User::factory()->admin()->create(); $this->ppcAdmin->givePermissionTo('framework-ppc'); diff --git a/tests/V2/Projects/ViewProjectSitesControllerTest.php b/tests/V2/Projects/ViewProjectSitesControllerTest.php index 61d87907e..061f27e5c 100644 --- a/tests/V2/Projects/ViewProjectSitesControllerTest.php +++ b/tests/V2/Projects/ViewProjectSitesControllerTest.php @@ -10,7 +10,7 @@ use Illuminate\Database\Eloquent\Factories\Sequence; use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\WithFaker; -//use Illuminate\Support\Facades\Artisan; +use Illuminate\Support\Facades\Artisan; use Tests\TestCase; class ViewProjectSitesControllerTest extends TestCase @@ -32,7 +32,7 @@ public function setUp(): void { parent::setUp(); - // Artisan::call('v2migration:roles --fresh'); + Artisan::call('v2migration:roles'); $this->ppcAdmin = User::factory()->admin()->create(); $this->ppcAdmin->givePermissionTo('framework-ppc'); diff --git a/tests/V2/Projects/ViewProjectWithFormControllerTest.php b/tests/V2/Projects/ViewProjectWithFormControllerTest.php index dd4efd4e0..80d46c383 100644 --- a/tests/V2/Projects/ViewProjectWithFormControllerTest.php +++ b/tests/V2/Projects/ViewProjectWithFormControllerTest.php @@ -8,7 +8,7 @@ use App\Models\V2\Projects\Project; use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\WithFaker; -//use Illuminate\Support\Facades\Artisan; +use Illuminate\Support\Facades\Artisan; use Tests\TestCase; class ViewProjectWithFormControllerTest extends TestCase @@ -18,7 +18,7 @@ class ViewProjectWithFormControllerTest extends TestCase public function test_invoke_action() { - // Artisan::call('v2migration:roles --fresh'); + Artisan::call('v2migration:roles'); $tfAdmin = User::factory()->admin()->create(); $tfAdmin->givePermissionTo('framework-terrafund'); From be83f11ba7bbe81673820e584868fd5d58a40b54 Mon Sep 17 00:00:00 2001 From: Nathan Curtis Date: Mon, 8 Apr 2024 14:43:09 -0700 Subject: [PATCH 12/44] [TM-785] Nursery tests all passing. --- .../Nurseries/AdminIndexNurseriesControllerTest.php | 2 +- .../AdminSoftDeleteNurseryControllerTest.php | 4 ++-- .../V2/Nurseries/AdminStatusNurseryControllerTest.php | 9 +++++---- .../Nurseries/CreateNurseryControllerWithFormTest.php | 4 ++-- .../V2/Nurseries/SoftDeleteNurseryControllerTest.php | 11 ++++++----- tests/V2/Nurseries/SubmitNurseryControllerTest.php | 4 ++-- .../Nurseries/UpdateNurseryWithFormControllerTest.php | 10 +++++----- tests/V2/Nurseries/ViewNurseryControllerTest.php | 4 ++-- .../Nurseries/ViewNurseryWithFormControllerTest.php | 2 +- .../AdminNurseriesMultiControllerTest.php | 4 ++-- 10 files changed, 28 insertions(+), 26 deletions(-) rename tests/V2/{Nurseries => Projects}/AdminNurseriesMultiControllerTest.php (92%) diff --git a/tests/V2/Nurseries/AdminIndexNurseriesControllerTest.php b/tests/V2/Nurseries/AdminIndexNurseriesControllerTest.php index ec2a5ab2f..b24bf9f5d 100644 --- a/tests/V2/Nurseries/AdminIndexNurseriesControllerTest.php +++ b/tests/V2/Nurseries/AdminIndexNurseriesControllerTest.php @@ -17,7 +17,7 @@ class AdminIndexNurseriesControllerTest extends TestCase public function setUp(): void { parent::setUp(); - // Artisan::call('v2migration:roles'); + Artisan::call('v2migration:roles'); $this->user = User::factory()->admin()->create(); $this->user->givePermissionTo('framework-terrafund'); $this->user->givePermissionTo('framework-ppc'); diff --git a/tests/V2/Nurseries/AdminSoftDeleteNurseryControllerTest.php b/tests/V2/Nurseries/AdminSoftDeleteNurseryControllerTest.php index cb51153ac..3e8b2f684 100644 --- a/tests/V2/Nurseries/AdminSoftDeleteNurseryControllerTest.php +++ b/tests/V2/Nurseries/AdminSoftDeleteNurseryControllerTest.php @@ -1,6 +1,6 @@ admin()->create(); $user->givePermissionTo($permission); diff --git a/tests/V2/Nurseries/AdminStatusNurseryControllerTest.php b/tests/V2/Nurseries/AdminStatusNurseryControllerTest.php index 9e5bcf908..68265b3c1 100644 --- a/tests/V2/Nurseries/AdminStatusNurseryControllerTest.php +++ b/tests/V2/Nurseries/AdminStatusNurseryControllerTest.php @@ -6,7 +6,8 @@ use App\Models\V2\Nurseries\Nursery; use App\Models\V2\Organisation; use App\Models\V2\Projects\Project; -//use Illuminate\Support\Facades\Artisan; +use App\StateMachines\EntityStatusStateMachine; +use Illuminate\Support\Facades\Artisan; use Illuminate\Foundation\Testing\RefreshDatabase; use Tests\TestCase; @@ -16,7 +17,7 @@ class AdminStatusNurseryControllerTest extends TestCase public function test_invoke_action(): void { - // Artisan::call('v2migration:roles'); + Artisan::call('v2migration:roles'); $organisation = Organisation::factory()->create(); $project = Project::factory()->create([ 'framework_key' => 'ppc', @@ -26,7 +27,7 @@ public function test_invoke_action(): void $nursery = Nursery::factory()->create([ 'framework_key' => 'ppc', 'project_id' => $project->id, - 'status' => Nursery::STATUS_AWAITING_APPROVAL, + 'status' => EntityStatusStateMachine::AWAITING_APPROVAL, ]); $owner = User::factory()->create(['organisation_id' => $organisation->id]); @@ -59,6 +60,6 @@ public function test_invoke_action(): void $this->actingAs($ppcAdmin) ->putJson($uri, $payload) ->assertSuccessful() - ->assertJsonFragment(['status' => Nursery::STATUS_NEEDS_MORE_INFORMATION]); + ->assertJsonFragment(['status' => EntityStatusStateMachine::NEEDS_MORE_INFORMATION]); } } diff --git a/tests/V2/Nurseries/CreateNurseryControllerWithFormTest.php b/tests/V2/Nurseries/CreateNurseryControllerWithFormTest.php index 3cb7173f9..3bae6c8ce 100644 --- a/tests/V2/Nurseries/CreateNurseryControllerWithFormTest.php +++ b/tests/V2/Nurseries/CreateNurseryControllerWithFormTest.php @@ -8,7 +8,7 @@ use App\Models\V2\Projects\Project; use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\WithFaker; -//use Illuminate\Support\Facades\Artisan; +use Illuminate\Support\Facades\Artisan; use Tests\TestCase; class CreateNurseryControllerWithFormTest extends TestCase @@ -18,7 +18,7 @@ class CreateNurseryControllerWithFormTest extends TestCase public function test_a_pd_can_create_a_nursery_with_form() { - // Artisan::call('v2migration:roles --fresh'); + Artisan::call('v2migration:roles'); $tfAdmin = User::factory()->admin()->create(); $tfAdmin->givePermissionTo('framework-terrafund'); diff --git a/tests/V2/Nurseries/SoftDeleteNurseryControllerTest.php b/tests/V2/Nurseries/SoftDeleteNurseryControllerTest.php index 6f99a83e1..1f0d55026 100644 --- a/tests/V2/Nurseries/SoftDeleteNurseryControllerTest.php +++ b/tests/V2/Nurseries/SoftDeleteNurseryControllerTest.php @@ -1,15 +1,16 @@ create(['framework_key' => $fmKey]); $nursery = Nursery::factory()->{$fmKey}()->create([ @@ -49,10 +50,10 @@ public function test_project_developer_can_soft_delete_nurseries_without_reports */ public function test_project_developer_cant_soft_delete_nurseries_with_reports(string $permission, string $fmKey) { - // Artisan::call('v2migration:roles'); + Artisan::call('v2migration:roles'); $statuses = [ - Site::STATUS_APPROVED, + EntityStatusStateMachine::APPROVED, ]; $project = Project::factory()->create(['framework_key' => $fmKey]); diff --git a/tests/V2/Nurseries/SubmitNurseryControllerTest.php b/tests/V2/Nurseries/SubmitNurseryControllerTest.php index 153a73cb2..3c4029258 100644 --- a/tests/V2/Nurseries/SubmitNurseryControllerTest.php +++ b/tests/V2/Nurseries/SubmitNurseryControllerTest.php @@ -9,7 +9,7 @@ use App\Models\V2\Projects\Project; use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\WithFaker; -//use Illuminate\Support\Facades\Artisan; +use Illuminate\Support\Facades\Artisan; use Tests\TestCase; class SubmitNurseryControllerTest extends TestCase @@ -19,7 +19,7 @@ class SubmitNurseryControllerTest extends TestCase public function test_invoke_action() { - // Artisan::call('v2migration:roles --fresh'); + Artisan::call('v2migration:roles'); $organisation = Organisation::factory()->create(); $owner = User::factory()->create(['organisation_id' => $organisation->id]); $owner->givePermissionTo('manage-own'); diff --git a/tests/V2/Nurseries/UpdateNurseryWithFormControllerTest.php b/tests/V2/Nurseries/UpdateNurseryWithFormControllerTest.php index 9a2afa30f..480bb42bf 100644 --- a/tests/V2/Nurseries/UpdateNurseryWithFormControllerTest.php +++ b/tests/V2/Nurseries/UpdateNurseryWithFormControllerTest.php @@ -7,9 +7,9 @@ use App\Models\V2\Nurseries\Nursery; use App\Models\V2\Organisation; use App\Models\V2\Projects\Project; +use App\StateMachines\EntityStatusStateMachine; use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\WithFaker; -//use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\Artisan; use Tests\TestCase; @@ -20,7 +20,7 @@ class UpdateNurseryWithFormControllerTest extends TestCase public function test_invoke_action() { - // Artisan::call('v2migration:roles --fresh'); + Artisan::call('v2migration:roles'); $tfAdmin = User::factory()->admin()->create(); $tfAdmin->givePermissionTo('framework-terrafund'); @@ -41,7 +41,7 @@ public function test_invoke_action() $nursery = Nursery::factory()->create([ 'project_id' => $project->id, 'framework_key' => 'ppc', - 'status' => Nursery::STATUS_STARTED, + 'status' => EntityStatusStateMachine::STARTED, ]); $form = CustomFormHelper::generateFakeForm('nursery', 'ppc'); @@ -87,7 +87,7 @@ public function test_invoke_action() public function test_nursery_update_request() { - // Artisan::call('v2migration:roles --fresh'); + Artisan::call('v2migration:roles'); $organisation = Organisation::factory()->create(); $owner = User::factory()->create(['organisation_id' => $organisation->id]); @@ -101,7 +101,7 @@ public function test_nursery_update_request() $nursery = Nursery::factory()->create([ 'project_id' => $project->id, 'framework_key' => 'ppc', - 'status' => Nursery::STATUS_APPROVED, + 'status' => EntityStatusStateMachine::APPROVED, ]); $form = CustomFormHelper::generateFakeForm('nursery', 'ppc'); diff --git a/tests/V2/Nurseries/ViewNurseryControllerTest.php b/tests/V2/Nurseries/ViewNurseryControllerTest.php index 15e4386b1..a525a8830 100644 --- a/tests/V2/Nurseries/ViewNurseryControllerTest.php +++ b/tests/V2/Nurseries/ViewNurseryControllerTest.php @@ -9,7 +9,7 @@ use App\Models\V2\Projects\Project; use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\WithFaker; -//use Illuminate\Support\Facades\Artisan; +use Illuminate\Support\Facades\Artisan; use Tests\TestCase; class ViewNurseryControllerTest extends TestCase @@ -19,7 +19,7 @@ class ViewNurseryControllerTest extends TestCase public function test_invoke_action() { - // Artisan::call('v2migration:roles --fresh'); + Artisan::call('v2migration:roles'); $tfAdmin = User::factory()->admin()->create(); $tfAdmin->givePermissionTo('framework-terrafund'); diff --git a/tests/V2/Nurseries/ViewNurseryWithFormControllerTest.php b/tests/V2/Nurseries/ViewNurseryWithFormControllerTest.php index eae9670d0..09ce82588 100644 --- a/tests/V2/Nurseries/ViewNurseryWithFormControllerTest.php +++ b/tests/V2/Nurseries/ViewNurseryWithFormControllerTest.php @@ -19,7 +19,7 @@ class ViewNurseryWithFormControllerTest extends TestCase public function test_invoke_action() { - Artisan::call('v2migration:roles --fresh'); + Artisan::call('v2migration:roles'); $tfAdmin = User::factory()->admin()->create(); $tfAdmin->givePermissionTo('framework-terrafund'); diff --git a/tests/V2/Nurseries/AdminNurseriesMultiControllerTest.php b/tests/V2/Projects/AdminNurseriesMultiControllerTest.php similarity index 92% rename from tests/V2/Nurseries/AdminNurseriesMultiControllerTest.php rename to tests/V2/Projects/AdminNurseriesMultiControllerTest.php index 885883448..62652d4da 100644 --- a/tests/V2/Nurseries/AdminNurseriesMultiControllerTest.php +++ b/tests/V2/Projects/AdminNurseriesMultiControllerTest.php @@ -6,7 +6,7 @@ use App\Models\V2\Nurseries\Nursery; use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\WithFaker; -// use Illuminate\Support\Facades\Artisan; +use Illuminate\Support\Facades\Artisan; use Tests\TestCase; class AdminNurseriesMultiControllerTest extends TestCase @@ -16,7 +16,7 @@ class AdminNurseriesMultiControllerTest extends TestCase public function test_invoke_action() { - // Artisan::call('v2migration:roles --fresh'); + Artisan::call('v2migration:roles'); $admin = User::factory()->admin()->create(); $admin->givePermissionTo('framework-terrafund'); $admin->givePermissionTo('framework-ppc'); From fc602d4b98afc3dc017277fc3bab461aad6e3fcd Mon Sep 17 00:00:00 2001 From: Nathan Curtis Date: Mon, 8 Apr 2024 14:56:29 -0700 Subject: [PATCH 13/44] [TM-785] Task tests passing. --- tests/V2/Tasks/CreateTaskDueJobTest.php | 7 ++-- .../IndexOrganisationsTasksControllerTest.php | 2 +- tests/V2/Tasks/IndexTaskControllerTest.php | 5 +-- .../Tasks/SubmitTaskReportsControllerTest.php | 34 ++++++++++--------- ...ViewProjectsTasksReportsControllerTest.php | 2 +- tests/V2/Tasks/ViewTaskControllerTest.php | 2 +- 6 files changed, 28 insertions(+), 24 deletions(-) diff --git a/tests/V2/Tasks/CreateTaskDueJobTest.php b/tests/V2/Tasks/CreateTaskDueJobTest.php index 0daaa195e..ffcd9c1fc 100644 --- a/tests/V2/Tasks/CreateTaskDueJobTest.php +++ b/tests/V2/Tasks/CreateTaskDueJobTest.php @@ -6,6 +6,8 @@ use App\Models\V2\Projects\Project; use App\Models\V2\Projects\ProjectReport; use App\Models\V2\Tasks\Task; +use App\StateMachines\ReportStatusStateMachine; +use App\StateMachines\TaskStatusStateMachine; use Carbon\Carbon; use Illuminate\Foundation\Testing\RefreshDatabase; use Tests\TestCase; @@ -25,15 +27,14 @@ public function testCreateTaskDueSubmissions() $this->assertDatabaseHas(Task::class, [ 'project_id' => $project->id, 'due_at' => $dueAt, - 'framework_key' => 'terrafund', - 'status' => Task::STATUS_DUE, + 'status' => TaskStatusStateMachine::DUE, ]); $this->assertDatabaseHas(ProjectReport::class, [ 'project_id' => $project->id, 'due_at' => $dueAt, 'framework_key' => 'terrafund', - 'status' => ProjectReport::STATUS_DUE, + 'status' => ReportStatusStateMachine::DUE, ]); } diff --git a/tests/V2/Tasks/IndexOrganisationsTasksControllerTest.php b/tests/V2/Tasks/IndexOrganisationsTasksControllerTest.php index 1a3f865c9..80fbf5a15 100644 --- a/tests/V2/Tasks/IndexOrganisationsTasksControllerTest.php +++ b/tests/V2/Tasks/IndexOrganisationsTasksControllerTest.php @@ -19,7 +19,7 @@ class IndexOrganisationsTasksControllerTest extends TestCase public function test_invoke_action() { - Artisan::call('v2migration:roles --fresh'); + Artisan::call('v2migration:roles'); $organisation = Organisation::factory()->create(); $owner = User::factory()->create(['organisation_id' => $organisation->id]); diff --git a/tests/V2/Tasks/IndexTaskControllerTest.php b/tests/V2/Tasks/IndexTaskControllerTest.php index 0b6e5036e..926f2eb23 100644 --- a/tests/V2/Tasks/IndexTaskControllerTest.php +++ b/tests/V2/Tasks/IndexTaskControllerTest.php @@ -7,6 +7,7 @@ use App\Models\V2\Organisation; use App\Models\V2\Projects\Project; use App\Models\V2\Tasks\Task; +use App\StateMachines\TaskStatusStateMachine; use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\WithFaker; use Illuminate\Support\Facades\Artisan; @@ -19,7 +20,7 @@ class IndexTaskControllerTest extends TestCase public function test_invoke_action() { - Artisan::call('v2migration:roles --fresh'); + Artisan::call('v2migration:roles'); $organisation = Organisation::factory()->create(); $owner = User::factory()->create(['organisation_id' => $organisation->id]); @@ -35,7 +36,7 @@ public function test_invoke_action() Task::factory()->count(3)->create([ 'organisation_id' => $organisation->id, 'project_id' => $project->id, - 'status' => Task::STATUS_DUE, + 'status' => TaskStatusStateMachine::DUE, ]); CustomFormHelper::generateFakeForm('site', 'ppc'); diff --git a/tests/V2/Tasks/SubmitTaskReportsControllerTest.php b/tests/V2/Tasks/SubmitTaskReportsControllerTest.php index d6281fbbe..4195c710b 100644 --- a/tests/V2/Tasks/SubmitTaskReportsControllerTest.php +++ b/tests/V2/Tasks/SubmitTaskReportsControllerTest.php @@ -12,10 +12,13 @@ use App\Models\V2\Sites\Site; use App\Models\V2\Sites\SiteReport; use App\Models\V2\Tasks\Task; +use App\StateMachines\EntityStatusStateMachine; +use App\StateMachines\ReportStatusStateMachine; +use App\StateMachines\TaskStatusStateMachine; use Carbon\Carbon; use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\WithFaker; -//use Illuminate\Support\Facades\Artisan; +use Illuminate\Support\Facades\Artisan; use Tests\TestCase; class SubmitTaskReportsControllerTest extends TestCase @@ -25,7 +28,7 @@ class SubmitTaskReportsControllerTest extends TestCase public function test_invoke_action() { - // Artisan::call('v2migration:roles --fresh'); + Artisan::call('v2migration:roles'); $organisation = Organisation::factory()->create(); $owner = User::factory()->create(['organisation_id' => $organisation->id]); @@ -60,23 +63,28 @@ public function test_invoke_action() $projectReport = ProjectReport::factory()->create([ 'project_id' => $project->id, + 'task_id' => $task->id, 'framework_key' => 'ppc', 'due_at' => $date, - 'status' => ProjectReport::STATUS_DUE, + 'status' => EntityStatusStateMachine::AWAITING_APPROVAL, ]); $siteReport = SiteReport::factory()->create([ 'site_id' => $site->id, + 'task_id' => $task->id, 'framework_key' => 'ppc', 'due_at' => $date, - 'status' => SiteReport::STATUS_DUE, + 'nothing_to_report' => true, + 'status' => ReportStatusStateMachine::DUE, ]); $nurseryReport = NurseryReport::factory()->create([ 'nursery_id' => $nursery->id, + 'task_id' => $task->id, 'framework_key' => 'ppc', 'due_at' => $date, - 'status' => NurseryReport::STATUS_DUE, + 'completion' => 100, + 'status' => EntityStatusStateMachine::STARTED, ]); CustomFormHelper::generateFakeForm('site', 'ppc'); @@ -92,21 +100,15 @@ public function test_invoke_action() ->assertSuccessful(); $projectReport->refresh(); - $this->assertEquals(ProjectReport::STATUS_AWAITING_APPROVAL, $projectReport->status); - $this->assertEquals(ProjectReport::COMPLETION_STATUS_COMPLETE, $projectReport->completion_status); - $this->assertEquals(100, $projectReport->completion); + $this->assertEquals(EntityStatusStateMachine::AWAITING_APPROVAL, $projectReport->status); $siteReport->refresh(); - $this->assertEquals(SiteReport::STATUS_AWAITING_APPROVAL, $siteReport->status); - $this->assertEquals(SiteReport::COMPLETION_STATUS_COMPLETE, $siteReport->completion_status); - $this->assertEquals(100, $siteReport->completion); + $this->assertEquals(EntityStatusStateMachine::AWAITING_APPROVAL, $siteReport->status); $nurseryReport->refresh(); - $this->assertEquals(NurseryReport::STATUS_AWAITING_APPROVAL, $nurseryReport->status); - $this->assertEquals(NurseryReport::COMPLETION_STATUS_COMPLETE, $nurseryReport->completion_status); - $this->assertEquals(100, $nurseryReport->completion); + $this->assertEquals(EntityStatusStateMachine::AWAITING_APPROVAL, $nurseryReport->status); - $updatedTask = Task::find($task->id) ; - $this->assertEquals(Task::STATUS_COMPLETE, $updatedTask->status); + $updatedTask = Task::find($task->id); + $this->assertEquals(TaskStatusStateMachine::AWAITING_APPROVAL, $updatedTask->status); } } diff --git a/tests/V2/Tasks/ViewProjectsTasksReportsControllerTest.php b/tests/V2/Tasks/ViewProjectsTasksReportsControllerTest.php index d8606ad02..e50270bb0 100644 --- a/tests/V2/Tasks/ViewProjectsTasksReportsControllerTest.php +++ b/tests/V2/Tasks/ViewProjectsTasksReportsControllerTest.php @@ -24,7 +24,7 @@ class ViewProjectsTasksReportsControllerTest extends TestCase public function test_invoke_action() { - Artisan::call('v2migration:roles --fresh'); + Artisan::call('v2migration:roles'); $organisation = Organisation::factory()->create(); $owner = User::factory()->create(['organisation_id' => $organisation->id]); diff --git a/tests/V2/Tasks/ViewTaskControllerTest.php b/tests/V2/Tasks/ViewTaskControllerTest.php index e14d766ee..efa2cedfb 100644 --- a/tests/V2/Tasks/ViewTaskControllerTest.php +++ b/tests/V2/Tasks/ViewTaskControllerTest.php @@ -19,7 +19,7 @@ class ViewTaskControllerTest extends TestCase public function test_invoke_action() { - Artisan::call('v2migration:roles --fresh'); + Artisan::call('v2migration:roles'); $organisation = Organisation::factory()->create(); $owner = User::factory()->create(['organisation_id' => $organisation->id]); From b51534be7219af666543432959264fd53513dccf Mon Sep 17 00:00:00 2001 From: Nathan Curtis Date: Mon, 8 Apr 2024 15:24:28 -0700 Subject: [PATCH 14/44] [TM-785] Report tests passing. --- ...AdminIndexNurseryReportsControllerTest.php | 7 +- ...nSoftDeleteNurseryReportControllerTest.php | 4 +- ...AdminStatusNurseryReportControllerTest.php | 9 +-- ...ateNurseryReportControllerWithFormTest.php | 70 ------------------- ...ateProjectReportControllerWithFormTest.php | 64 ----------------- ...ingToReportNurseryReportControllerTest.php | 9 +-- ...NurseryReportsViaNurseryControllerTest.php | 11 ++- .../SubmitNurseryReportControllerTest.php | 6 +- ...ateNurseryReportWithFormControllerTest.php | 11 +-- .../ViewNurseryReportControllerTest.php | 4 +- ...iewNurseryReportWithFormControllerTest.php | 4 +- ...AdminIndexProjectReportsControllerTest.php | 9 ++- ...AdminStatusProjectReportControllerTest.php | 9 +-- ...ProjectReportsViaProjectControllerTest.php | 11 ++- .../SubmitProjectReportControllerTest.php | 6 +- ...ateProjectReportWithFormControllerTest.php | 9 +-- .../ViewProjectReportControllerTest.php | 2 +- ...iewProjectReportWithFormControllerTest.php | 5 +- .../AdminIndexSiteReportsControllerTest.php | 7 +- ...nSoftDeleteProjectReportControllerTest.php | 4 +- .../AdminStatusSiteReportControllerTest.php | 9 +-- ...CreateSiteReportControllerWithFormTest.php | 70 ------------------- ...othingToReportSiteReportControllerTest.php | 9 +-- .../SiteReportsViaSiteControllerTest.php | 11 ++- .../SubmitSiteReportControllerTest.php | 6 +- ...UpdateSiteReportWithFormControllerTest.php | 11 +-- .../ViewSiteReportControllerTest.php | 2 +- .../ViewSiteReportWithFormControllerTest.php | 4 +- 28 files changed, 109 insertions(+), 274 deletions(-) delete mode 100644 tests/V2/NurseryReports/CreateNurseryReportControllerWithFormTest.php delete mode 100644 tests/V2/NurseryReports/CreateProjectReportControllerWithFormTest.php delete mode 100644 tests/V2/SiteReports/CreateSiteReportControllerWithFormTest.php diff --git a/tests/V2/NurseryReports/AdminIndexNurseryReportsControllerTest.php b/tests/V2/NurseryReports/AdminIndexNurseryReportsControllerTest.php index 01aa0cca5..3d9339a6f 100644 --- a/tests/V2/NurseryReports/AdminIndexNurseryReportsControllerTest.php +++ b/tests/V2/NurseryReports/AdminIndexNurseryReportsControllerTest.php @@ -2,11 +2,12 @@ namespace Tests\V2\NurseryReports; +use App\Models\Framework; use App\Models\User; use App\Models\V2\Nurseries\NurseryReport; use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\WithFaker; -// use Illuminate\Support\Facades\Artisan; + use Illuminate\Support\Facades\Artisan; use Tests\TestCase; class AdminIndexNurseryReportsControllerTest extends TestCase @@ -16,9 +17,11 @@ class AdminIndexNurseryReportsControllerTest extends TestCase public function test_invoke_action() { - // Artisan::call('v2migration:roles'); + Artisan::call('v2migration:roles'); $tfAdmin = User::factory()->admin()->create(); $ppcAdmin = User::factory()->admin()->create(); + Framework::factory()->create(['slug' => 'terrafund']); + Framework::factory()->create(['slug' => 'ppc']); $tfAdmin->givePermissionTo('framework-terrafund'); $ppcAdmin->givePermissionTo('framework-ppc'); $user = User::factory()->create(); diff --git a/tests/V2/NurseryReports/AdminSoftDeleteNurseryReportControllerTest.php b/tests/V2/NurseryReports/AdminSoftDeleteNurseryReportControllerTest.php index 2f1e55dd1..5dea3a4b2 100644 --- a/tests/V2/NurseryReports/AdminSoftDeleteNurseryReportControllerTest.php +++ b/tests/V2/NurseryReports/AdminSoftDeleteNurseryReportControllerTest.php @@ -1,6 +1,6 @@ admin()->create(); $user->givePermissionTo($permission); diff --git a/tests/V2/NurseryReports/AdminStatusNurseryReportControllerTest.php b/tests/V2/NurseryReports/AdminStatusNurseryReportControllerTest.php index edfa727cd..1ef026b80 100644 --- a/tests/V2/NurseryReports/AdminStatusNurseryReportControllerTest.php +++ b/tests/V2/NurseryReports/AdminStatusNurseryReportControllerTest.php @@ -7,7 +7,8 @@ use App\Models\V2\Nurseries\NurseryReport; use App\Models\V2\Organisation; use App\Models\V2\Projects\Project; -//use Illuminate\Support\Facades\Artisan; +use App\StateMachines\EntityStatusStateMachine; +use Illuminate\Support\Facades\Artisan; use Illuminate\Foundation\Testing\RefreshDatabase; use Tests\TestCase; @@ -17,7 +18,7 @@ class AdminStatusNurseryReportControllerTest extends TestCase public function test_invoke_action(): void { - // Artisan::call('v2migration:roles'); + Artisan::call('v2migration:roles'); $organisation = Organisation::factory()->create(); $project = Project::factory()->create([ 'framework_key' => 'ppc', @@ -32,7 +33,7 @@ public function test_invoke_action(): void $report = NurseryReport::factory()->create([ 'nursery_id' => $nursery->id, 'framework_key' => 'ppc', - 'status' => NurseryReport::STATUS_AWAITING_APPROVAL, + 'status' => EntityStatusStateMachine::AWAITING_APPROVAL, ]); $owner = User::factory()->create(['organisation_id' => $organisation->id]); @@ -65,6 +66,6 @@ public function test_invoke_action(): void $this->actingAs($ppcAdmin) ->putJson($uri, $payload) ->assertSuccessful() - ->assertJsonFragment(['status' => NurseryReport::STATUS_NEEDS_MORE_INFORMATION]); + ->assertJsonFragment(['status' => EntityStatusStateMachine::NEEDS_MORE_INFORMATION]); } } diff --git a/tests/V2/NurseryReports/CreateNurseryReportControllerWithFormTest.php b/tests/V2/NurseryReports/CreateNurseryReportControllerWithFormTest.php deleted file mode 100644 index 69d1bb51d..000000000 --- a/tests/V2/NurseryReports/CreateNurseryReportControllerWithFormTest.php +++ /dev/null @@ -1,70 +0,0 @@ -admin()->create(); - $tfAdmin->givePermissionTo('framework-terrafund'); - - $ppcAdmin = User::factory()->admin()->create(); - $ppcAdmin->givePermissionTo('framework-ppc'); - - $organisation = Organisation::factory()->create(); - $owner = User::factory()->create(['organisation_id' => $organisation->id]); - $owner->givePermissionTo('manage-own'); - - $user = User::factory()->create(); - - $project = Project::factory()->create([ - 'organisation_id' => $organisation->id, - 'framework_key' => 'ppc', - ]); - - $nursery = Nursery::factory()->create([ - 'project_id' => $project->id, - 'framework_key' => 'ppc', - ]); - - $form = CustomFormHelper::generateFakeForm('nursery-report', 'ppc'); - - $payload = [ - 'parent_entity' => 'nursery', - 'parent_uuid' => $nursery->uuid, - ]; - - $uri = '/api/v2/forms/nursery-reports'; - - $this->actingAs($user) - ->postJson($uri, $payload) - ->assertStatus(403); - - $this->actingAs($tfAdmin) - ->postJson($uri, $payload) - ->assertStatus(403); - - $this->actingAs($ppcAdmin) - ->postJson($uri, $payload) - ->assertStatus(403); - - $this->actingAs($owner) - ->postJson($uri, $payload) - ->assertSuccessful(); - } -} diff --git a/tests/V2/NurseryReports/CreateProjectReportControllerWithFormTest.php b/tests/V2/NurseryReports/CreateProjectReportControllerWithFormTest.php deleted file mode 100644 index b3db9402f..000000000 --- a/tests/V2/NurseryReports/CreateProjectReportControllerWithFormTest.php +++ /dev/null @@ -1,64 +0,0 @@ -admin()->create(); - $tfAdmin->givePermissionTo('framework-terrafund'); - - $ppcAdmin = User::factory()->admin()->create(); - $ppcAdmin->givePermissionTo('framework-ppc'); - - $organisation = Organisation::factory()->create(); - $owner = User::factory()->create(['organisation_id' => $organisation->id]); - $owner->givePermissionTo('manage-own'); - - $user = User::factory()->create(); - - $project = Project::factory()->create([ - 'organisation_id' => $organisation->id, - 'framework_key' => 'ppc', - ]); - - $form = CustomFormHelper::generateFakeForm('project-report', 'ppc'); - - $payload = [ - 'parent_entity' => 'project', - 'parent_uuid' => $project->uuid, - ]; - - $uri = '/api/v2/forms/project-reports'; - - $this->actingAs($user) - ->postJson($uri, $payload) - ->assertStatus(403); - - $this->actingAs($tfAdmin) - ->postJson($uri, $payload) - ->assertStatus(403); - - $this->actingAs($ppcAdmin) - ->postJson($uri, $payload) - ->assertStatus(403); - - $this->actingAs($owner) - ->postJson($uri, $payload) - ->assertSuccessful(); - } -} diff --git a/tests/V2/NurseryReports/NothingToReportNurseryReportControllerTest.php b/tests/V2/NurseryReports/NothingToReportNurseryReportControllerTest.php index 7330148e8..ab9d106a1 100644 --- a/tests/V2/NurseryReports/NothingToReportNurseryReportControllerTest.php +++ b/tests/V2/NurseryReports/NothingToReportNurseryReportControllerTest.php @@ -7,9 +7,10 @@ use App\Models\V2\Nurseries\NurseryReport; use App\Models\V2\Organisation; use App\Models\V2\Projects\Project; +use App\StateMachines\EntityStatusStateMachine; use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\WithFaker; -// use Illuminate\Support\Facades\Artisan; +use Illuminate\Support\Facades\Artisan; use Tests\TestCase; class NothingToReportNurseryReportControllerTest extends TestCase @@ -19,7 +20,7 @@ class NothingToReportNurseryReportControllerTest extends TestCase public function test_invoke_action() { - // Artisan::call('v2migration:roles --fresh'); + Artisan::call('v2migration:roles'); $tfAdmin = User::factory()->admin()->create(); $tfAdmin->givePermissionTo('framework-terrafund'); @@ -62,7 +63,7 @@ public function test_invoke_action() ->putJson($uri) ->assertSuccessful() ->assertJsonFragment([ - 'status' => NurseryReport::STATUS_AWAITING_APPROVAL, + 'status' => EntityStatusStateMachine::AWAITING_APPROVAL, 'nothing_to_report' => true, ]); @@ -70,7 +71,7 @@ public function test_invoke_action() ->putJson($uri) ->assertSuccessful() ->assertJsonFragment([ - 'status' => NurseryReport::STATUS_AWAITING_APPROVAL, + 'status' => EntityStatusStateMachine::AWAITING_APPROVAL, 'nothing_to_report' => true, ]); } diff --git a/tests/V2/NurseryReports/NurseryReportsViaNurseryControllerTest.php b/tests/V2/NurseryReports/NurseryReportsViaNurseryControllerTest.php index ed70a69e8..3ba7182c6 100644 --- a/tests/V2/NurseryReports/NurseryReportsViaNurseryControllerTest.php +++ b/tests/V2/NurseryReports/NurseryReportsViaNurseryControllerTest.php @@ -7,9 +7,10 @@ use App\Models\V2\Nurseries\Nursery; use App\Models\V2\Nurseries\NurseryReport; use App\Models\V2\Projects\Project; +use App\StateMachines\EntityStatusStateMachine; use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\WithFaker; -// use Illuminate\Support\Facades\Artisan; +use Illuminate\Support\Facades\Artisan; use Tests\TestCase; class NurseryReportsViaNurseryControllerTest extends TestCase @@ -19,7 +20,7 @@ class NurseryReportsViaNurseryControllerTest extends TestCase public function test_invoke_action() { - // Artisan::call('v2migration:roles'); + Artisan::call('v2migration:roles'); $tfAdmin = User::factory()->admin()->create(); $tfAdmin->givePermissionTo('framework-terrafund'); @@ -37,7 +38,11 @@ public function test_invoke_action() $nursery = Nursery::factory()->create(['project_id' => $project->id, 'framework_key' => 'ppc']); NurseryReport::query()->delete(); - NurseryReport::factory()->count(4)->create(['nursery_id' => $nursery->id, 'framework_key' => 'ppc', 'status' => NurseryReport::STATUS_APPROVED]); + NurseryReport::factory()->count(4)->create([ + 'nursery_id' => $nursery->id, + 'framework_key' => 'ppc', + 'status' => EntityStatusStateMachine::APPROVED, + ]); NurseryReport::factory()->count(2)->create(['framework_key' => 'ppc']); $uri = '/api/v2/nurseries/' . $nursery->uuid . '/reports'; diff --git a/tests/V2/NurseryReports/SubmitNurseryReportControllerTest.php b/tests/V2/NurseryReports/SubmitNurseryReportControllerTest.php index e04645056..bb3e9f63e 100644 --- a/tests/V2/NurseryReports/SubmitNurseryReportControllerTest.php +++ b/tests/V2/NurseryReports/SubmitNurseryReportControllerTest.php @@ -8,9 +8,10 @@ use App\Models\V2\Nurseries\NurseryReport; use App\Models\V2\Organisation; use App\Models\V2\Projects\Project; +use App\StateMachines\EntityStatusStateMachine; use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\WithFaker; -//use Illuminate\Support\Facades\Artisan; +use Illuminate\Support\Facades\Artisan; use Tests\TestCase; class SubmitNurseryReportControllerTest extends TestCase @@ -20,7 +21,7 @@ class SubmitNurseryReportControllerTest extends TestCase public function test_invoke_action() { - // Artisan::call('v2migration:roles --fresh'); + Artisan::call('v2migration:roles'); $organisation = Organisation::factory()->create(); $owner = User::factory()->create(['organisation_id' => $organisation->id]); $owner->givePermissionTo('manage-own'); @@ -40,6 +41,7 @@ public function test_invoke_action() $report = NurseryReport::factory()->create([ 'nursery_id' => $nursery->id, 'framework_key' => 'ppc', + 'status' => EntityStatusStateMachine::STARTED, ]); CustomFormHelper::generateFakeForm('nursery-report', 'ppc'); diff --git a/tests/V2/NurseryReports/UpdateNurseryReportWithFormControllerTest.php b/tests/V2/NurseryReports/UpdateNurseryReportWithFormControllerTest.php index a9663ba2b..8a7a41713 100644 --- a/tests/V2/NurseryReports/UpdateNurseryReportWithFormControllerTest.php +++ b/tests/V2/NurseryReports/UpdateNurseryReportWithFormControllerTest.php @@ -8,9 +8,10 @@ use App\Models\V2\Nurseries\NurseryReport; use App\Models\V2\Organisation; use App\Models\V2\Projects\Project; +use App\StateMachines\EntityStatusStateMachine; use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\WithFaker; -//use Illuminate\Support\Facades\Artisan; +use Illuminate\Support\Facades\Artisan; use Tests\TestCase; class UpdateNurseryReportWithFormControllerTest extends TestCase @@ -20,7 +21,7 @@ class UpdateNurseryReportWithFormControllerTest extends TestCase public function test_invoke_action() { - // Artisan::call('v2migration:roles --fresh'); + Artisan::call('v2migration:roles'); $tfAdmin = User::factory()->admin()->create(); $tfAdmin->givePermissionTo('framework-terrafund'); @@ -46,7 +47,7 @@ public function test_invoke_action() $report = NurseryReport::factory()->create([ 'nursery_id' => $nursery->id, 'framework_key' => 'ppc', - 'status' => NurseryReport::STATUS_STARTED, + 'status' => EntityStatusStateMachine::STARTED, ]); $form = CustomFormHelper::generateFakeForm('nursery-report', 'ppc'); @@ -92,7 +93,7 @@ public function test_invoke_action() public function test_update_request() { - // Artisan::call('v2migration:roles --fresh'); + Artisan::call('v2migration:roles'); $organisation = Organisation::factory()->create(); $owner = User::factory()->create(['organisation_id' => $organisation->id]); $owner->givePermissionTo('manage-own'); @@ -110,7 +111,7 @@ public function test_update_request() $report = NurseryReport::factory()->create([ 'nursery_id' => $nursery->id, 'framework_key' => 'ppc', - 'status' => NurseryReport::STATUS_APPROVED, + 'status' => EntityStatusStateMachine::APPROVED, ]); $form = CustomFormHelper::generateFakeForm('nursery-report', 'ppc'); diff --git a/tests/V2/NurseryReports/ViewNurseryReportControllerTest.php b/tests/V2/NurseryReports/ViewNurseryReportControllerTest.php index 7b574d4c2..4cd2dcf94 100644 --- a/tests/V2/NurseryReports/ViewNurseryReportControllerTest.php +++ b/tests/V2/NurseryReports/ViewNurseryReportControllerTest.php @@ -10,7 +10,7 @@ use App\Models\V2\Projects\Project; use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\WithFaker; -//use Illuminate\Support\Facades\Artisan; +use Illuminate\Support\Facades\Artisan; use Tests\TestCase; class ViewNurseryReportControllerTest extends TestCase @@ -20,7 +20,7 @@ class ViewNurseryReportControllerTest extends TestCase public function test_invoke_action() { - // Artisan::call('v2migration:roles --fresh'); + Artisan::call('v2migration:roles'); $tfAdmin = User::factory()->admin()->create(); $tfAdmin->givePermissionTo('framework-terrafund'); diff --git a/tests/V2/NurseryReports/ViewNurseryReportWithFormControllerTest.php b/tests/V2/NurseryReports/ViewNurseryReportWithFormControllerTest.php index f0ad8f393..fcd6526de 100644 --- a/tests/V2/NurseryReports/ViewNurseryReportWithFormControllerTest.php +++ b/tests/V2/NurseryReports/ViewNurseryReportWithFormControllerTest.php @@ -10,7 +10,7 @@ use App\Models\V2\Projects\Project; use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\WithFaker; -//use Illuminate\Support\Facades\Artisan; +use Illuminate\Support\Facades\Artisan; use Tests\TestCase; class ViewNurseryReportWithFormControllerTest extends TestCase @@ -20,7 +20,7 @@ class ViewNurseryReportWithFormControllerTest extends TestCase public function test_invoke_action() { - // Artisan::call('v2migration:roles --fresh'); + Artisan::call('v2migration:roles'); $tfAdmin = User::factory()->admin()->create(); $tfAdmin->givePermissionTo('framework-terrafund'); diff --git a/tests/V2/ProjectReports/AdminIndexProjectReportsControllerTest.php b/tests/V2/ProjectReports/AdminIndexProjectReportsControllerTest.php index 0d025da95..7d5ed3801 100644 --- a/tests/V2/ProjectReports/AdminIndexProjectReportsControllerTest.php +++ b/tests/V2/ProjectReports/AdminIndexProjectReportsControllerTest.php @@ -2,12 +2,13 @@ namespace Tests\V2\ProjectReports; +use App\Models\Framework; use App\Models\User; use App\Models\V2\Projects\Project; use App\Models\V2\Projects\ProjectReport; use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\WithFaker; -// use Illuminate\Support\Facades\Artisan; +use Illuminate\Support\Facades\Artisan; use Tests\TestCase; class AdminIndexProjectReportsControllerTest extends TestCase @@ -17,9 +18,11 @@ class AdminIndexProjectReportsControllerTest extends TestCase public function test_invoke_action() { - // Artisan::call('v2migration:roles'); + Artisan::call('v2migration:roles'); $tfAdmin = User::factory()->admin()->create(); $ppcAdmin = User::factory()->admin()->create(); + Framework::factory()->create(['slug' => 'terrafund']); + Framework::factory()->create(['slug' => 'ppc']); $tfAdmin->givePermissionTo('framework-terrafund'); $ppcAdmin->givePermissionTo('framework-ppc'); $user = User::factory()->create(); @@ -55,7 +58,7 @@ public function test_invoke_action() public function test_searching_on_project_name() { - // Artisan::call('v2migration:roles'); + Artisan::call('v2migration:roles'); $tfAdmin = User::factory()->admin()->create(); $tfAdmin->givePermissionTo('framework-terrafund'); diff --git a/tests/V2/ProjectReports/AdminStatusProjectReportControllerTest.php b/tests/V2/ProjectReports/AdminStatusProjectReportControllerTest.php index 6f3965858..b74fd4f4b 100644 --- a/tests/V2/ProjectReports/AdminStatusProjectReportControllerTest.php +++ b/tests/V2/ProjectReports/AdminStatusProjectReportControllerTest.php @@ -6,7 +6,8 @@ use App\Models\V2\Organisation; use App\Models\V2\Projects\Project; use App\Models\V2\Projects\ProjectReport; -//use Illuminate\Support\Facades\Artisan; +use App\StateMachines\EntityStatusStateMachine; +use Illuminate\Support\Facades\Artisan; use Illuminate\Foundation\Testing\RefreshDatabase; use Tests\TestCase; @@ -16,7 +17,7 @@ class AdminStatusProjectReportControllerTest extends TestCase public function test_invoke_action(): void { - // Artisan::call('v2migration:roles'); + Artisan::call('v2migration:roles'); $organisation = Organisation::factory()->create(); $project = Project::factory()->create([ 'framework_key' => 'ppc', @@ -26,7 +27,7 @@ public function test_invoke_action(): void $report = ProjectReport::factory()->create([ 'project_id' => $project->id, 'framework_key' => 'ppc', - 'status' => ProjectReport::STATUS_AWAITING_APPROVAL, + 'status' => EntityStatusStateMachine::AWAITING_APPROVAL, ]); $owner = User::factory()->create(['organisation_id' => $organisation->id]); @@ -59,6 +60,6 @@ public function test_invoke_action(): void $this->actingAs($ppcAdmin) ->putJson($uri, $payload) ->assertSuccessful() - ->assertJsonFragment(['status' => ProjectReport::STATUS_NEEDS_MORE_INFORMATION]); + ->assertJsonFragment(['status' => EntityStatusStateMachine::NEEDS_MORE_INFORMATION]); } } diff --git a/tests/V2/ProjectReports/ProjectReportsViaProjectControllerTest.php b/tests/V2/ProjectReports/ProjectReportsViaProjectControllerTest.php index 5b8dfe6fc..94e5c886e 100644 --- a/tests/V2/ProjectReports/ProjectReportsViaProjectControllerTest.php +++ b/tests/V2/ProjectReports/ProjectReportsViaProjectControllerTest.php @@ -6,9 +6,10 @@ use App\Models\User; use App\Models\V2\Projects\Project; use App\Models\V2\Projects\ProjectReport; +use App\StateMachines\EntityStatusStateMachine; use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\WithFaker; -// use Illuminate\Support\Facades\Artisan; +use Illuminate\Support\Facades\Artisan; use Tests\TestCase; class ProjectReportsViaProjectControllerTest extends TestCase @@ -18,7 +19,7 @@ class ProjectReportsViaProjectControllerTest extends TestCase public function test_invoke_action() { - // Artisan::call('v2migration:roles'); + Artisan::call('v2migration:roles'); $tfAdmin = User::factory()->admin()->create(); $tfAdmin->givePermissionTo('framework-terrafund'); @@ -33,7 +34,11 @@ public function test_invoke_action() ProjectReport::query()->delete(); $project = Project::factory()->create(['organisation_id' => $organisation->id, 'framework_key' => 'ppc']); - ProjectReport::factory()->count(4)->create(['project_id' => $project->id, 'framework_key' => 'ppc', 'status' => ProjectReport::STATUS_APPROVED]); + ProjectReport::factory()->count(4)->create([ + 'project_id' => $project->id, + 'framework_key' => 'ppc', + 'status' => EntityStatusStateMachine::APPROVED, + ]); ProjectReport::factory()->count(2)->create(['framework_key' => 'ppc']); $uri = '/api/v2/projects/' . $project->uuid . '/reports'; diff --git a/tests/V2/ProjectReports/SubmitProjectReportControllerTest.php b/tests/V2/ProjectReports/SubmitProjectReportControllerTest.php index 384fe2078..69a3bcfa0 100644 --- a/tests/V2/ProjectReports/SubmitProjectReportControllerTest.php +++ b/tests/V2/ProjectReports/SubmitProjectReportControllerTest.php @@ -7,9 +7,10 @@ use App\Models\V2\Organisation; use App\Models\V2\Projects\Project; use App\Models\V2\Projects\ProjectReport; +use App\StateMachines\EntityStatusStateMachine; use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\WithFaker; -//use Illuminate\Support\Facades\Artisan; +use Illuminate\Support\Facades\Artisan; use Tests\TestCase; class SubmitProjectReportControllerTest extends TestCase @@ -19,7 +20,7 @@ class SubmitProjectReportControllerTest extends TestCase public function test_invoke_action() { - // Artisan::call('v2migration:roles --fresh'); + Artisan::call('v2migration:roles'); $organisation = Organisation::factory()->create(); $owner = User::factory()->create(['organisation_id' => $organisation->id]); $owner->givePermissionTo('manage-own'); @@ -34,6 +35,7 @@ public function test_invoke_action() $report = ProjectReport::factory()->create([ 'project_id' => $project->id, 'framework_key' => 'ppc', + 'status' => EntityStatusStateMachine::STARTED, ]); CustomFormHelper::generateFakeForm('project-report', 'ppc'); diff --git a/tests/V2/ProjectReports/UpdateProjectReportWithFormControllerTest.php b/tests/V2/ProjectReports/UpdateProjectReportWithFormControllerTest.php index 60e3d08d0..18e139e50 100644 --- a/tests/V2/ProjectReports/UpdateProjectReportWithFormControllerTest.php +++ b/tests/V2/ProjectReports/UpdateProjectReportWithFormControllerTest.php @@ -7,6 +7,7 @@ use App\Models\V2\Organisation; use App\Models\V2\Projects\Project; use App\Models\V2\Projects\ProjectReport; +use App\StateMachines\EntityStatusStateMachine; use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\WithFaker; use Illuminate\Support\Facades\Artisan; @@ -19,7 +20,7 @@ class UpdateProjectReportWithFormControllerTest extends TestCase public function test_invoke_action() { - Artisan::call('v2migration:roles --fresh'); + Artisan::call('v2migration:roles'); $tfAdmin = User::factory()->admin()->create(); $tfAdmin->givePermissionTo('framework-terrafund'); @@ -40,7 +41,7 @@ public function test_invoke_action() $report = ProjectReport::factory()->create([ 'project_id' => $project->id, 'framework_key' => 'ppc', - 'status' => ProjectReport::STATUS_STARTED, + 'status' => EntityStatusStateMachine::STARTED, ]); $form = CustomFormHelper::generateFakeForm('project-report', 'ppc'); @@ -90,7 +91,7 @@ public function test_invoke_action() public function test_update_request() { - // Artisan::call('v2migration:roles --fresh'); + Artisan::call('v2migration:roles'); $organisation = Organisation::factory()->create(); $owner = User::factory()->create(['organisation_id' => $organisation->id]); $owner->givePermissionTo('manage-own'); @@ -103,7 +104,7 @@ public function test_update_request() $report = ProjectReport::factory()->create([ 'project_id' => $project->id, 'framework_key' => 'ppc', - 'status' => ProjectReport::STATUS_APPROVED, + 'status' => EntityStatusStateMachine::APPROVED, ]); $form = CustomFormHelper::generateFakeForm('project-report', 'ppc'); diff --git a/tests/V2/ProjectReports/ViewProjectReportControllerTest.php b/tests/V2/ProjectReports/ViewProjectReportControllerTest.php index 12a294d9a..b9365ea0c 100644 --- a/tests/V2/ProjectReports/ViewProjectReportControllerTest.php +++ b/tests/V2/ProjectReports/ViewProjectReportControllerTest.php @@ -19,7 +19,7 @@ class ViewProjectReportControllerTest extends TestCase public function test_invoke_action() { - Artisan::call('v2migration:roles --fresh'); + Artisan::call('v2migration:roles'); $tfAdmin = User::factory()->admin()->create(); $tfAdmin->givePermissionTo('framework-terrafund'); diff --git a/tests/V2/ProjectReports/ViewProjectReportWithFormControllerTest.php b/tests/V2/ProjectReports/ViewProjectReportWithFormControllerTest.php index 5ae9b5ff9..dee461325 100644 --- a/tests/V2/ProjectReports/ViewProjectReportWithFormControllerTest.php +++ b/tests/V2/ProjectReports/ViewProjectReportWithFormControllerTest.php @@ -7,9 +7,10 @@ use App\Models\V2\Organisation; use App\Models\V2\Projects\Project; use App\Models\V2\Projects\ProjectReport; +use App\StateMachines\EntityStatusStateMachine; use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\WithFaker; -//use Illuminate\Support\Facades\Artisan; +use Illuminate\Support\Facades\Artisan; use Tests\TestCase; class ViewProjectReportWithFormControllerTest extends TestCase @@ -19,7 +20,7 @@ class ViewProjectReportWithFormControllerTest extends TestCase public function test_invoke_action() { - // Artisan::call('v2migration:roles --fresh'); + Artisan::call('v2migration:roles'); $tfAdmin = User::factory()->admin()->create(); $tfAdmin->givePermissionTo('framework-terrafund'); diff --git a/tests/V2/SiteReports/AdminIndexSiteReportsControllerTest.php b/tests/V2/SiteReports/AdminIndexSiteReportsControllerTest.php index 4c16862ba..5c97f63f1 100644 --- a/tests/V2/SiteReports/AdminIndexSiteReportsControllerTest.php +++ b/tests/V2/SiteReports/AdminIndexSiteReportsControllerTest.php @@ -2,11 +2,12 @@ namespace Tests\V2\SiteReports; +use App\Models\Framework; use App\Models\User; use App\Models\V2\sites\SiteReport; use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\WithFaker; -// use Illuminate\Support\Facades\Artisan; +use Illuminate\Support\Facades\Artisan; use Tests\TestCase; class AdminIndexSiteReportsControllerTest extends TestCase @@ -16,7 +17,9 @@ class AdminIndexSiteReportsControllerTest extends TestCase public function test_invoke_action() { - // Artisan::call('v2migration:roles'); + Artisan::call('v2migration:roles'); + Framework::factory()->create(['slug' => 'terrafund']); + Framework::factory()->create(['slug' => 'ppc']); $tfAdmin = User::factory()->admin()->create(); $ppcAdmin = User::factory()->admin()->create(); $tfAdmin->givePermissionTo('framework-terrafund'); diff --git a/tests/V2/SiteReports/AdminSoftDeleteProjectReportControllerTest.php b/tests/V2/SiteReports/AdminSoftDeleteProjectReportControllerTest.php index 6218edea0..57b805bd0 100644 --- a/tests/V2/SiteReports/AdminSoftDeleteProjectReportControllerTest.php +++ b/tests/V2/SiteReports/AdminSoftDeleteProjectReportControllerTest.php @@ -1,6 +1,6 @@ admin()->create(); $user->givePermissionTo($permission); diff --git a/tests/V2/SiteReports/AdminStatusSiteReportControllerTest.php b/tests/V2/SiteReports/AdminStatusSiteReportControllerTest.php index c8a3fba4a..a58d74d48 100644 --- a/tests/V2/SiteReports/AdminStatusSiteReportControllerTest.php +++ b/tests/V2/SiteReports/AdminStatusSiteReportControllerTest.php @@ -6,7 +6,8 @@ use App\Models\V2\Organisation; use App\Models\V2\Projects\Project; use App\Models\V2\Sites\Site; -//use Illuminate\Support\Facades\Artisan; +use App\StateMachines\EntityStatusStateMachine; +use Illuminate\Support\Facades\Artisan; use App\Models\V2\Sites\SiteReport; use Illuminate\Foundation\Testing\RefreshDatabase; use Tests\TestCase; @@ -17,7 +18,7 @@ class AdminStatusSiteReportControllerTest extends TestCase public function test_invoke_action(): void { - // Artisan::call('v2migration:roles'); + Artisan::call('v2migration:roles'); $organisation = Organisation::factory()->create(); $project = Project::factory()->create([ 'framework_key' => 'ppc', @@ -32,7 +33,7 @@ public function test_invoke_action(): void $report = SiteReport::factory()->create([ 'site_id' => $site->id, 'framework_key' => 'ppc', - 'status' => SiteReport::STATUS_AWAITING_APPROVAL, + 'status' => EntityStatusStateMachine::AWAITING_APPROVAL, ]); $owner = User::factory()->create(['organisation_id' => $organisation->id]); @@ -65,6 +66,6 @@ public function test_invoke_action(): void $this->actingAs($ppcAdmin) ->putJson($uri, $payload) ->assertSuccessful() - ->assertJsonFragment(['status' => SiteReport::STATUS_NEEDS_MORE_INFORMATION]); + ->assertJsonFragment(['status' => EntityStatusStateMachine::NEEDS_MORE_INFORMATION]); } } diff --git a/tests/V2/SiteReports/CreateSiteReportControllerWithFormTest.php b/tests/V2/SiteReports/CreateSiteReportControllerWithFormTest.php deleted file mode 100644 index 62e9dc177..000000000 --- a/tests/V2/SiteReports/CreateSiteReportControllerWithFormTest.php +++ /dev/null @@ -1,70 +0,0 @@ -admin()->create(); - $tfAdmin->givePermissionTo('framework-terrafund'); - - $ppcAdmin = User::factory()->admin()->create(); - $ppcAdmin->givePermissionTo('framework-ppc'); - - $organisation = Organisation::factory()->create(); - $owner = User::factory()->create(['organisation_id' => $organisation->id]); - $owner->givePermissionTo('manage-own'); - - $user = User::factory()->create(); - - $project = Project::factory()->create([ - 'organisation_id' => $organisation->id, - 'framework_key' => 'ppc', - ]); - - $site = Site::factory()->create([ - 'project_id' => $project->id, - 'framework_key' => 'ppc', - ]); - - $form = CustomFormHelper::generateFakeForm('site-report', 'ppc'); - - $payload = [ - 'parent_entity' => 'site', - 'parent_uuid' => $site->uuid, - ]; - - $uri = '/api/v2/forms/site-reports/'; - - $this->actingAs($user) - ->postJson($uri, $payload) - ->assertStatus(403); - - $this->actingAs($tfAdmin) - ->postJson($uri, $payload) - ->assertStatus(403); - - $this->actingAs($ppcAdmin) - ->postJson($uri, $payload) - ->assertStatus(403); - - $this->actingAs($owner) - ->postJson($uri, $payload) - ->assertSuccessful(); - } -} diff --git a/tests/V2/SiteReports/NothingToReportSiteReportControllerTest.php b/tests/V2/SiteReports/NothingToReportSiteReportControllerTest.php index cd748e5bb..2e2d1f647 100644 --- a/tests/V2/SiteReports/NothingToReportSiteReportControllerTest.php +++ b/tests/V2/SiteReports/NothingToReportSiteReportControllerTest.php @@ -7,9 +7,10 @@ use App\Models\V2\Projects\Project; use App\Models\V2\Sites\Site; use App\Models\V2\Sites\SiteReport; +use App\StateMachines\EntityStatusStateMachine; use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\WithFaker; -// use Illuminate\Support\Facades\Artisan; +use Illuminate\Support\Facades\Artisan; use Tests\TestCase; class NothingToReportSiteReportControllerTest extends TestCase @@ -19,7 +20,7 @@ class NothingToReportSiteReportControllerTest extends TestCase public function test_invoke_action() { - // Artisan::call('v2migration:roles --fresh'); + Artisan::call('v2migration:roles'); $tfAdmin = User::factory()->admin()->create(); $tfAdmin->givePermissionTo('framework-terrafund'); @@ -61,7 +62,7 @@ public function test_invoke_action() ->putJson($uri) ->assertSuccessful() ->assertJsonFragment([ - 'status' => SiteReport::STATUS_AWAITING_APPROVAL, + 'status' => EntityStatusStateMachine::AWAITING_APPROVAL, 'nothing_to_report' => true, ]); @@ -69,7 +70,7 @@ public function test_invoke_action() ->putJson($uri) ->assertSuccessful() ->assertJsonFragment([ - 'status' => SiteReport::STATUS_AWAITING_APPROVAL, + 'status' => EntityStatusStateMachine::AWAITING_APPROVAL, 'nothing_to_report' => true, ]); } diff --git a/tests/V2/SiteReports/SiteReportsViaSiteControllerTest.php b/tests/V2/SiteReports/SiteReportsViaSiteControllerTest.php index 96221e24e..220a4c7d6 100644 --- a/tests/V2/SiteReports/SiteReportsViaSiteControllerTest.php +++ b/tests/V2/SiteReports/SiteReportsViaSiteControllerTest.php @@ -7,9 +7,10 @@ use App\Models\V2\Projects\Project; use App\Models\V2\Sites\Site; use App\Models\V2\Sites\SiteReport; +use App\StateMachines\EntityStatusStateMachine; use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\WithFaker; -// use Illuminate\Support\Facades\Artisan; +use Illuminate\Support\Facades\Artisan; use Tests\TestCase; class SiteReportsViaSiteControllerTest extends TestCase @@ -19,7 +20,7 @@ class SiteReportsViaSiteControllerTest extends TestCase public function test_invoke_action() { - // Artisan::call('v2migration:roles'); + Artisan::call('v2migration:roles'); $tfAdmin = User::factory()->admin()->create(); $tfAdmin->givePermissionTo('framework-terrafund'); @@ -37,7 +38,11 @@ public function test_invoke_action() $site = Site::factory()->create(['project_id' => $project->id, 'framework_key' => 'ppc']); SiteReport::query()->delete(); - SiteReport::factory()->count(4)->create(['site_id' => $site->id, 'framework_key' => 'ppc', 'status' => SiteReport::STATUS_APPROVED]); + SiteReport::factory()->count(4)->create([ + 'site_id' => $site->id, + 'framework_key' => 'ppc', + 'status' => EntityStatusStateMachine::APPROVED, + ]); SiteReport::factory()->count(2)->create(['framework_key' => 'ppc']); $uri = '/api/v2/sites/' . $site->uuid . '/reports'; diff --git a/tests/V2/SiteReports/SubmitSiteReportControllerTest.php b/tests/V2/SiteReports/SubmitSiteReportControllerTest.php index 44b5a339c..3d1046a32 100644 --- a/tests/V2/SiteReports/SubmitSiteReportControllerTest.php +++ b/tests/V2/SiteReports/SubmitSiteReportControllerTest.php @@ -8,9 +8,10 @@ use App\Models\V2\Projects\Project; use App\Models\V2\Sites\Site; use App\Models\V2\Sites\SiteReport; +use App\StateMachines\EntityStatusStateMachine; use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\WithFaker; -//use Illuminate\Support\Facades\Artisan; +use Illuminate\Support\Facades\Artisan; use Tests\TestCase; class SubmitSiteReportControllerTest extends TestCase @@ -20,7 +21,7 @@ class SubmitSiteReportControllerTest extends TestCase public function test_invoke_action() { - // Artisan::call('v2migration:roles --fresh'); + Artisan::call('v2migration:roles --fresh'); $organisation = Organisation::factory()->create(); $owner = User::factory()->create(['organisation_id' => $organisation->id]); $owner->givePermissionTo('manage-own'); @@ -40,6 +41,7 @@ public function test_invoke_action() $report = SiteReport::factory()->create([ 'site_id' => $site->id, 'framework_key' => 'ppc', + 'status' => EntityStatusStateMachine::STARTED, ]); CustomFormHelper::generateFakeForm('site-report', 'ppc'); diff --git a/tests/V2/SiteReports/UpdateSiteReportWithFormControllerTest.php b/tests/V2/SiteReports/UpdateSiteReportWithFormControllerTest.php index f6a5623e2..2ddf49349 100644 --- a/tests/V2/SiteReports/UpdateSiteReportWithFormControllerTest.php +++ b/tests/V2/SiteReports/UpdateSiteReportWithFormControllerTest.php @@ -8,9 +8,10 @@ use App\Models\V2\Projects\Project; use App\Models\V2\Sites\Site; use App\Models\V2\Sites\SiteReport; +use App\StateMachines\EntityStatusStateMachine; use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\WithFaker; -//use Illuminate\Support\Facades\Artisan; +use Illuminate\Support\Facades\Artisan; use Tests\TestCase; class UpdateSiteReportWithFormControllerTest extends TestCase @@ -20,7 +21,7 @@ class UpdateSiteReportWithFormControllerTest extends TestCase public function test_invoke_action() { - // Artisan::call('v2migration:roles --fresh'); + Artisan::call('v2migration:roles'); $tfAdmin = User::factory()->admin()->create(); $tfAdmin->givePermissionTo('framework-terrafund'); @@ -46,7 +47,7 @@ public function test_invoke_action() $report = SiteReport::factory()->create([ 'site_id' => $site->id, 'framework_key' => 'ppc', - 'status' => SiteReport::STATUS_STARTED, + 'status' => EntityStatusStateMachine::STARTED, ]); $form = CustomFormHelper::generateFakeForm('site-report', 'ppc'); @@ -92,7 +93,7 @@ public function test_invoke_action() public function test_update_request() { - // Artisan::call('v2migration:roles --fresh'); + Artisan::call('v2migration:roles'); $organisation = Organisation::factory()->create(); $owner = User::factory()->create(['organisation_id' => $organisation->id]); $owner->givePermissionTo('manage-own'); @@ -110,7 +111,7 @@ public function test_update_request() $report = SiteReport::factory()->create([ 'site_id' => $site->id, 'framework_key' => 'ppc', - 'status' => SiteReport::STATUS_APPROVED, + 'status' => EntityStatusStateMachine::APPROVED, ]); $form = CustomFormHelper::generateFakeForm('site-report', 'ppc'); diff --git a/tests/V2/SiteReports/ViewSiteReportControllerTest.php b/tests/V2/SiteReports/ViewSiteReportControllerTest.php index 42886786f..6b485ac3c 100644 --- a/tests/V2/SiteReports/ViewSiteReportControllerTest.php +++ b/tests/V2/SiteReports/ViewSiteReportControllerTest.php @@ -20,7 +20,7 @@ class ViewSiteReportControllerTest extends TestCase public function test_invoke_action() { - Artisan::call('v2migration:roles --fresh'); + Artisan::call('v2migration:roles'); $tfAdmin = User::factory()->admin()->create(); $tfAdmin->givePermissionTo('framework-terrafund'); diff --git a/tests/V2/SiteReports/ViewSiteReportWithFormControllerTest.php b/tests/V2/SiteReports/ViewSiteReportWithFormControllerTest.php index 861af2339..7c948907b 100644 --- a/tests/V2/SiteReports/ViewSiteReportWithFormControllerTest.php +++ b/tests/V2/SiteReports/ViewSiteReportWithFormControllerTest.php @@ -10,7 +10,7 @@ use App\Models\V2\Sites\SiteReport; use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\WithFaker; -//use Illuminate\Support\Facades\Artisan; +use Illuminate\Support\Facades\Artisan; use Tests\TestCase; class ViewSiteReportWithFormControllerTest extends TestCase @@ -20,7 +20,7 @@ class ViewSiteReportWithFormControllerTest extends TestCase public function test_invoke_action() { - // Artisan::call('v2migration:roles --fresh'); + Artisan::call('v2migration:roles'); $tfAdmin = User::factory()->admin()->create(); $tfAdmin->givePermissionTo('framework-terrafund'); From 999eabe5aab1bf4a9126639e30fa215179d5c28a Mon Sep 17 00:00:00 2001 From: Nathan Curtis Date: Mon, 8 Apr 2024 15:43:45 -0700 Subject: [PATCH 15/44] [TM-785] Get use of the roles migration consistent. I'm torn on this approach for setting up the roles, but it's what we're using and leaving it commented out in tests is making the tests fail when run in isolation. The --fresh flag should never be needed, and without it the artisan command is quick and idempotent. --- tests/Feature/UsersControllerTest.php | 3 +-- .../DeleteDisturbanceControllerTest.php | 7 ++++--- ...GetDisturbancesForEntityControllerTest.php | 7 ++++--- .../StoreDisturbanceControllerTest.php | 7 ++++--- .../UpdateDisturbanceControllerTest.php | 7 ++++--- ...portAllMonitoredEntitiesControllerTest.php | 4 ++-- ...titiesAsProjectDeveloperControllerTest.php | 19 +++++++++---------- ...EntityAsProjectDeveloperControllerTest.php | 4 +--- .../ViewNurseryGalleryControllerTest.php | 4 ++-- ...ViewNurseryReportGalleryControllerTest.php | 4 ++-- .../ViewProjectGalleryControllerTest.php | 4 ++-- ...ProjectMonitoringGalleryControllerTest.php | 4 ++-- ...ViewProjectReportGalleryControllerTest.php | 4 ++-- .../Gallery/ViewSiteGalleryControllerTest.php | 4 ++-- ...iewSiteMonitoringGalleryControllerTest.php | 4 ++-- .../ViewSiteReportGalleryControllerTest.php | 3 ++- .../NurseryImageLocationsControllerTest.php | 4 ++-- ...seryReportImageLocationsControllerTest.php | 4 ++-- .../ProjectImageLocationsControllerTest.php | 4 ++-- ...jectReportImageLocationsControllerTest.php | 4 ++-- .../SiteImageLocationsControllerTest.php | 4 ++-- ...SiteReportImageLocationsControllerTest.php | 4 ++-- .../DeleteInvasiveControllerTest.php | 7 ++++--- .../GetInvasivesForEntityControllerTest.php | 7 ++++--- .../Invasives/StoreInvasiveControllerTest.php | 7 ++++--- .../UpdateInvasiveControllerTest.php | 7 ++++--- ...nIndexReportingFrameworkControllerTest.php | 4 ++-- ...UpdateReportingFrameworkControllerTest.php | 6 +++--- .../Seedings/DeleteSeedingControllerTest.php | 10 ++++++---- .../GetSeedingsForEntityControllerTest.php | 12 +++++++----- .../Seedings/StoreSeedingControllerTest.php | 11 ++++++----- .../Seedings/UpdateSeedingControllerTest.php | 8 +++++--- .../SubmitSiteReportControllerTest.php | 2 +- .../Sites/AdminSitesMultiControllerTest.php | 2 +- .../CreateSiteControllerWithFormTest.php | 2 +- .../V2/Sites/SoftDeleteSiteControllerTest.php | 2 +- .../V2/Stratas/DeleteStrataControllerTest.php | 7 ++++--- .../GetStratasForEntityControllerTest.php | 7 ++++--- .../V2/Stratas/StoreStrataControllerTest.php | 7 ++++--- .../V2/Stratas/UpdateStrataControllerTest.php | 7 ++++--- .../GetTreeSpeciesForEntityControllerTest.php | 6 +++--- ...nSoftDeleteUpdateRequestControllerTest.php | 4 ++-- .../AdminViewUpdateRequestControllerTest.php | 4 ++-- .../EntityUpdateRequestControllerTest.php | 4 ++-- .../V2/User/CompleteActionControllerTest.php | 4 ++-- tests/V2/Users/AdminUserControllerTest.php | 4 ++-- .../Workdays/DeleteWorkdayControllerTest.php | 7 ++++--- .../GetWorkdaysForEntityControllerTest.php | 9 +++++---- .../Workdays/StoreWorkdayControllerTest.php | 9 +++++---- .../Workdays/UpdateWorkdayControllerTest.php | 9 +++++---- 50 files changed, 154 insertions(+), 134 deletions(-) diff --git a/tests/Feature/UsersControllerTest.php b/tests/Feature/UsersControllerTest.php index 5ca8086af..29dc17f16 100644 --- a/tests/Feature/UsersControllerTest.php +++ b/tests/Feature/UsersControllerTest.php @@ -5,7 +5,6 @@ use App\Models\User; use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Support\Facades\Artisan; -//use Illuminate\Support\Facades\Artisan; use Tests\TestCase; final class UsersControllerTest extends TestCase @@ -14,7 +13,7 @@ final class UsersControllerTest extends TestCase public function testUpdateRoleAction(): void { - Artisan::call('v2migration:roles --fresh'); + Artisan::call('v2migration:roles'); $admin = User::factory()->admin()->create(); $user = User::factory()->create(); diff --git a/tests/V2/Disturbances/DeleteDisturbanceControllerTest.php b/tests/V2/Disturbances/DeleteDisturbanceControllerTest.php index 7bae7424e..07571214e 100644 --- a/tests/V2/Disturbances/DeleteDisturbanceControllerTest.php +++ b/tests/V2/Disturbances/DeleteDisturbanceControllerTest.php @@ -7,8 +7,9 @@ use App\Models\V2\Organisation; use App\Models\V2\Projects\Project; use App\Models\V2\Sites\Site; +use App\StateMachines\EntityStatusStateMachine; use Illuminate\Foundation\Testing\RefreshDatabase; -//use Illuminate\Support\Facades\Artisan; +use Illuminate\Support\Facades\Artisan; use Tests\TestCase; class DeleteDisturbanceControllerTest extends TestCase @@ -17,7 +18,7 @@ class DeleteDisturbanceControllerTest extends TestCase public function test_invoke_action() { - // Artisan::call('v2migration:roles --fresh'); + Artisan::call('v2migration:roles'); $organisation = Organisation::factory()->create(); $owner = User::factory()->create(['organisation_id' => $organisation->id]); $owner->givePermissionTo('manage-own'); @@ -32,7 +33,7 @@ public function test_invoke_action() $site = Site::factory()->create([ 'project_id' => $project->id, 'framework_key' => 'ppc', - 'status' => Site::STATUS_STARTED, + 'status' => EntityStatusStateMachine::STARTED, ]); $disturbanceable = Disturbance::factory()->create([ diff --git a/tests/V2/Disturbances/GetDisturbancesForEntityControllerTest.php b/tests/V2/Disturbances/GetDisturbancesForEntityControllerTest.php index 9646d5152..d7d341632 100644 --- a/tests/V2/Disturbances/GetDisturbancesForEntityControllerTest.php +++ b/tests/V2/Disturbances/GetDisturbancesForEntityControllerTest.php @@ -7,7 +7,8 @@ use App\Models\V2\Organisation; use App\Models\V2\Projects\Project; use App\Models\V2\Sites\Site; -// use Illuminate\Support\Facades\Artisan; +use App\StateMachines\EntityStatusStateMachine; +use Illuminate\Support\Facades\Artisan; use Illuminate\Foundation\Testing\RefreshDatabase; use Tests\TestCase; @@ -17,7 +18,7 @@ class GetDisturbancesForEntityControllerTest extends TestCase public function test_invoke_action() { - // Artisan::call('v2migration:roles --fresh'); + Artisan::call('v2migration:roles'); $organisation = Organisation::factory()->create(); $owner = User::factory()->create(['organisation_id' => $organisation->id]); $owner->givePermissionTo('manage-own'); @@ -32,7 +33,7 @@ public function test_invoke_action() $site = Site::factory()->create([ 'project_id' => $project->id, 'framework_key' => 'ppc', - 'status' => Site::STATUS_STARTED, + 'status' => EntityStatusStateMachine::STARTED, ]); $disturbance = Disturbance::factory()->create([ diff --git a/tests/V2/Disturbances/StoreDisturbanceControllerTest.php b/tests/V2/Disturbances/StoreDisturbanceControllerTest.php index 41c3fdf05..86ca6bbad 100644 --- a/tests/V2/Disturbances/StoreDisturbanceControllerTest.php +++ b/tests/V2/Disturbances/StoreDisturbanceControllerTest.php @@ -6,7 +6,8 @@ use App\Models\V2\Organisation; use App\Models\V2\Projects\Project; use App\Models\V2\Sites\Site; -//use Illuminate\Support\Facades\Artisan; +use App\StateMachines\EntityStatusStateMachine; +use Illuminate\Support\Facades\Artisan; use Illuminate\Foundation\Testing\RefreshDatabase; use Tests\TestCase; @@ -16,7 +17,7 @@ class StoreDisturbanceControllerTest extends TestCase public function test_user_can_create_stratas() { - // Artisan::call('v2migration:roles --fresh'); + Artisan::call('v2migration:roles'); $organisation = Organisation::factory()->create(); $owner = User::factory()->create(['organisation_id' => $organisation->id]); $owner->givePermissionTo('manage-own'); @@ -31,7 +32,7 @@ public function test_user_can_create_stratas() $site = Site::factory()->create([ 'project_id' => $project->id, 'framework_key' => 'ppc', - 'status' => Site::STATUS_STARTED, + 'status' => EntityStatusStateMachine::STARTED, ]); $payload = [ diff --git a/tests/V2/Disturbances/UpdateDisturbanceControllerTest.php b/tests/V2/Disturbances/UpdateDisturbanceControllerTest.php index be6d80683..49614b70a 100644 --- a/tests/V2/Disturbances/UpdateDisturbanceControllerTest.php +++ b/tests/V2/Disturbances/UpdateDisturbanceControllerTest.php @@ -7,7 +7,8 @@ use App\Models\V2\Organisation; use App\Models\V2\Projects\Project; use App\Models\V2\Sites\Site; -//use Illuminate\Support\Facades\Artisan; +use App\StateMachines\EntityStatusStateMachine; +use Illuminate\Support\Facades\Artisan; use Illuminate\Foundation\Testing\RefreshDatabase; use Tests\TestCase; @@ -17,7 +18,7 @@ class UpdateDisturbanceControllerTest extends TestCase public function test_user_can_update_strata() { - // Artisan::call('v2migration:roles --fresh'); + Artisan::call('v2migration:roles'); $organisation = Organisation::factory()->create(); $owner = User::factory()->create(['organisation_id' => $organisation->id]); $owner->givePermissionTo('manage-own'); @@ -32,7 +33,7 @@ public function test_user_can_update_strata() $site = Site::factory()->create([ 'project_id' => $project->id, 'framework_key' => 'ppc', - 'status' => Site::STATUS_STARTED, + 'status' => EntityStatusStateMachine::STARTED, ]); $disturbance = Disturbance::factory()->create([ diff --git a/tests/V2/Exports/ExportAllMonitoredEntitiesControllerTest.php b/tests/V2/Exports/ExportAllMonitoredEntitiesControllerTest.php index ceb7c0381..e1bdbb19e 100644 --- a/tests/V2/Exports/ExportAllMonitoredEntitiesControllerTest.php +++ b/tests/V2/Exports/ExportAllMonitoredEntitiesControllerTest.php @@ -1,6 +1,6 @@ admin()->create(); $user->givePermissionTo($permission); diff --git a/tests/V2/Exports/ExportEntitiesAsProjectDeveloperControllerTest.php b/tests/V2/Exports/ExportEntitiesAsProjectDeveloperControllerTest.php index bb1bb8941..e298ff0b8 100644 --- a/tests/V2/Exports/ExportEntitiesAsProjectDeveloperControllerTest.php +++ b/tests/V2/Exports/ExportEntitiesAsProjectDeveloperControllerTest.php @@ -1,6 +1,6 @@ create(); $owner = User::factory()->create(['organisation_id' => $organisation->id]); @@ -59,7 +58,7 @@ public function test_an_user_can_export_all_sites_data_for_a_given_project(strin */ public function test_an_user_can_export_all_nurseries_data_for_a_given_project(string $permission, string $fmKey) { - // Artisan::call('v2migration:roles'); + Artisan::call('v2migration:roles'); $organisation = Organisation::factory()->create(); $owner = User::factory()->create(['organisation_id' => $organisation->id]); @@ -89,7 +88,7 @@ public function test_an_user_can_export_all_nurseries_data_for_a_given_project(s */ public function test_an_user_can_export_nursery_reports_data(string $permission, string $fmKey) { - // Artisan::call('v2migration:roles'); + Artisan::call('v2migration:roles'); $organisation = Organisation::factory()->create(); $owner = User::factory()->create(['organisation_id' => $organisation->id]); @@ -124,7 +123,7 @@ public function test_an_user_can_export_nursery_reports_data(string $permission, */ public function test_an_user_can_export_site_reports_data(string $permission, string $fmKey) { - // Artisan::call('v2migration:roles'); + Artisan::call('v2migration:roles'); $organisation = Organisation::factory()->create(); $owner = User::factory()->create(['organisation_id' => $organisation->id]); @@ -159,7 +158,7 @@ public function test_an_user_can_export_site_reports_data(string $permission, st */ public function test_an_user_can_export_project_reports_data(string $permission, string $fmKey) { - // Artisan::call('v2migration:roles'); + Artisan::call('v2migration:roles'); $organisation = Organisation::factory()->create(); $owner = User::factory()->create(['organisation_id' => $organisation->id]); @@ -189,7 +188,7 @@ public function test_an_user_can_export_project_reports_data(string $permission, */ public function test_an_user_can_export_all_project_data(string $permission, string $fmKey) { - // Artisan::call('v2migration:roles'); + Artisan::call('v2migration:roles'); Carbon::setTestNow(now()); @@ -251,7 +250,7 @@ public function test_an_user_can_export_all_project_data(string $permission, str */ public function test_an_user_can_export_all_site_data(string $permission, string $fmKey) { - // Artisan::call('v2migration:roles'); + Artisan::call('v2migration:roles'); Carbon::setTestNow(now()); @@ -291,7 +290,7 @@ public function test_an_user_can_export_all_site_data(string $permission, string */ public function test_an_user_can_export_all_nursey_data(string $permission, string $fmKey) { - // Artisan::call('v2migration:roles'); + Artisan::call('v2migration:roles'); Carbon::setTestNow(now()); diff --git a/tests/V2/Exports/ExportProjectEntityAsProjectDeveloperControllerTest.php b/tests/V2/Exports/ExportProjectEntityAsProjectDeveloperControllerTest.php index 66f2fc8e3..a61172411 100644 --- a/tests/V2/Exports/ExportProjectEntityAsProjectDeveloperControllerTest.php +++ b/tests/V2/Exports/ExportProjectEntityAsProjectDeveloperControllerTest.php @@ -1,6 +1,6 @@ create(); $owner = User::factory()->create(['organisation_id' => $organisation->id]); $owner->givePermissionTo('manage-own'); diff --git a/tests/V2/Files/Gallery/ViewNurseryGalleryControllerTest.php b/tests/V2/Files/Gallery/ViewNurseryGalleryControllerTest.php index 776f6ff1a..e90a2cfd2 100644 --- a/tests/V2/Files/Gallery/ViewNurseryGalleryControllerTest.php +++ b/tests/V2/Files/Gallery/ViewNurseryGalleryControllerTest.php @@ -8,7 +8,7 @@ use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\WithFaker; use Illuminate\Http\UploadedFile; -//use Illuminate\Support\Facades\Artisan; +use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\Storage; use Tests\TestCase; @@ -33,7 +33,7 @@ public function setUp(): void { parent::setUp(); - // Artisan::call('v2migration:roles --fresh'); + Artisan::call('v2migration:roles'); $this->admin = User::factory()->admin()->create(); $this->admin->givePermissionTo('framework-ppc'); diff --git a/tests/V2/Files/Gallery/ViewNurseryReportGalleryControllerTest.php b/tests/V2/Files/Gallery/ViewNurseryReportGalleryControllerTest.php index 061ac266b..28027183c 100644 --- a/tests/V2/Files/Gallery/ViewNurseryReportGalleryControllerTest.php +++ b/tests/V2/Files/Gallery/ViewNurseryReportGalleryControllerTest.php @@ -7,7 +7,7 @@ use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\WithFaker; use Illuminate\Http\UploadedFile; -//use Illuminate\Support\Facades\Artisan; +use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\Storage; use Tests\TestCase; @@ -28,7 +28,7 @@ public function setUp(): void { parent::setUp(); - // Artisan::call('v2migration:roles --fresh'); + Artisan::call('v2migration:roles'); $this->admin = User::factory()->admin()->create(); $this->admin->givePermissionTo('framework-ppc'); diff --git a/tests/V2/Files/Gallery/ViewProjectGalleryControllerTest.php b/tests/V2/Files/Gallery/ViewProjectGalleryControllerTest.php index fc2c1dd07..62023a42e 100644 --- a/tests/V2/Files/Gallery/ViewProjectGalleryControllerTest.php +++ b/tests/V2/Files/Gallery/ViewProjectGalleryControllerTest.php @@ -12,7 +12,7 @@ use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\WithFaker; use Illuminate\Http\UploadedFile; -//use Illuminate\Support\Facades\Artisan; +use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\Storage; use Tests\TestCase; @@ -53,7 +53,7 @@ public function setUp(): void { parent::setUp(); - // Artisan::call('v2migration:roles --fresh'); + Artisan::call('v2migration:roles'); $this->admin = User::factory()->admin()->create(); $this->admin->givePermissionTo('framework-ppc'); diff --git a/tests/V2/Files/Gallery/ViewProjectMonitoringGalleryControllerTest.php b/tests/V2/Files/Gallery/ViewProjectMonitoringGalleryControllerTest.php index c784dac03..f3eb975e9 100644 --- a/tests/V2/Files/Gallery/ViewProjectMonitoringGalleryControllerTest.php +++ b/tests/V2/Files/Gallery/ViewProjectMonitoringGalleryControllerTest.php @@ -7,7 +7,7 @@ use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\WithFaker; use Illuminate\Http\UploadedFile; -//use Illuminate\Support\Facades\Artisan; +use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\Storage; use Tests\TestCase; @@ -28,7 +28,7 @@ public function setUp(): void { parent::setUp(); -// Artisan::call('v2migration:roles --fresh'); + Artisan::call('v2migration:roles'); $this->admin = User::factory()->admin()->create(); $this->admin->givePermissionTo('framework-ppc'); diff --git a/tests/V2/Files/Gallery/ViewProjectReportGalleryControllerTest.php b/tests/V2/Files/Gallery/ViewProjectReportGalleryControllerTest.php index cb3204989..3aaab8082 100644 --- a/tests/V2/Files/Gallery/ViewProjectReportGalleryControllerTest.php +++ b/tests/V2/Files/Gallery/ViewProjectReportGalleryControllerTest.php @@ -7,7 +7,7 @@ use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\WithFaker; use Illuminate\Http\UploadedFile; -//use Illuminate\Support\Facades\Artisan; +use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\Storage; use Tests\TestCase; @@ -28,7 +28,7 @@ public function setUp(): void { parent::setUp(); - // Artisan::call('v2migration:roles --fresh'); + Artisan::call('v2migration:roles'); $this->admin = User::factory()->admin()->create(); $this->admin->givePermissionTo('framework-ppc'); diff --git a/tests/V2/Files/Gallery/ViewSiteGalleryControllerTest.php b/tests/V2/Files/Gallery/ViewSiteGalleryControllerTest.php index e5d7edb6b..0a3e6c291 100644 --- a/tests/V2/Files/Gallery/ViewSiteGalleryControllerTest.php +++ b/tests/V2/Files/Gallery/ViewSiteGalleryControllerTest.php @@ -8,7 +8,7 @@ use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\WithFaker; use Illuminate\Http\UploadedFile; -//use Illuminate\Support\Facades\Artisan; +use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\Storage; use Tests\TestCase; @@ -33,7 +33,7 @@ public function setUp(): void { parent::setUp(); - // Artisan::call('v2migration:roles --fresh'); + Artisan::call('v2migration:roles'); $this->admin = User::factory()->admin()->create(); $this->admin->givePermissionTo('framework-ppc'); diff --git a/tests/V2/Files/Gallery/ViewSiteMonitoringGalleryControllerTest.php b/tests/V2/Files/Gallery/ViewSiteMonitoringGalleryControllerTest.php index e13e38e3a..16895fe24 100644 --- a/tests/V2/Files/Gallery/ViewSiteMonitoringGalleryControllerTest.php +++ b/tests/V2/Files/Gallery/ViewSiteMonitoringGalleryControllerTest.php @@ -7,7 +7,7 @@ use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\WithFaker; use Illuminate\Http\UploadedFile; -//use Illuminate\Support\Facades\Artisan; +use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\Storage; use Tests\TestCase; @@ -28,7 +28,7 @@ public function setUp(): void { parent::setUp(); -// Artisan::call('v2migration:roles --fresh'); + Artisan::call('v2migration:roles'); $this->admin = User::factory()->admin()->create(); $this->admin->givePermissionTo('framework-ppc'); diff --git a/tests/V2/Files/Gallery/ViewSiteReportGalleryControllerTest.php b/tests/V2/Files/Gallery/ViewSiteReportGalleryControllerTest.php index fe0ed84d3..0175b7dad 100644 --- a/tests/V2/Files/Gallery/ViewSiteReportGalleryControllerTest.php +++ b/tests/V2/Files/Gallery/ViewSiteReportGalleryControllerTest.php @@ -7,6 +7,7 @@ use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\WithFaker; use Illuminate\Http\UploadedFile; +use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\Storage; use Tests\TestCase; @@ -27,7 +28,7 @@ public function setUp(): void { parent::setUp(); - // Artisan::call('v2migration:roles --fresh'); + Artisan::call('v2migration:roles'); $this->admin = User::factory()->admin()->create(); $this->admin->givePermissionTo('framework-ppc'); diff --git a/tests/V2/Files/Location/NurseryImageLocationsControllerTest.php b/tests/V2/Files/Location/NurseryImageLocationsControllerTest.php index 6d86825a9..2f58c56ac 100644 --- a/tests/V2/Files/Location/NurseryImageLocationsControllerTest.php +++ b/tests/V2/Files/Location/NurseryImageLocationsControllerTest.php @@ -8,7 +8,7 @@ use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\WithFaker; use Illuminate\Http\UploadedFile; -//use Illuminate\Support\Facades\Artisan; +use Illuminate\Support\Facades\Artisan; use Tests\TestCase; class NurseryImageLocationsControllerTest extends TestCase @@ -36,7 +36,7 @@ public function setUp(): void { parent::setUp(); - // Artisan::call('v2migration:roles --fresh'); + Artisan::call('v2migration:roles'); $this->admin = User::factory()->admin()->create(); $this->admin->givePermissionTo('framework-ppc'); diff --git a/tests/V2/Files/Location/NurseryReportImageLocationsControllerTest.php b/tests/V2/Files/Location/NurseryReportImageLocationsControllerTest.php index 4d8ed1e13..d3f501f68 100644 --- a/tests/V2/Files/Location/NurseryReportImageLocationsControllerTest.php +++ b/tests/V2/Files/Location/NurseryReportImageLocationsControllerTest.php @@ -7,7 +7,7 @@ use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\WithFaker; use Illuminate\Http\UploadedFile; -//use Illuminate\Support\Facades\Artisan; +use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\Storage; use Tests\TestCase; @@ -30,7 +30,7 @@ public function setUp(): void { parent::setUp(); - // Artisan::call('v2migration:roles --fresh'); + Artisan::call('v2migration:roles'); $this->admin = User::factory()->admin()->create(); $this->admin->givePermissionTo('framework-ppc'); diff --git a/tests/V2/Files/Location/ProjectImageLocationsControllerTest.php b/tests/V2/Files/Location/ProjectImageLocationsControllerTest.php index a7255bf64..e85a532ca 100644 --- a/tests/V2/Files/Location/ProjectImageLocationsControllerTest.php +++ b/tests/V2/Files/Location/ProjectImageLocationsControllerTest.php @@ -12,7 +12,7 @@ use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\WithFaker; use Illuminate\Http\UploadedFile; -//use Illuminate\Support\Facades\Artisan; +use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\Storage; use Tests\TestCase; @@ -65,7 +65,7 @@ public function setUp(): void { parent::setUp(); - // Artisan::call('v2migration:roles --fresh'); + Artisan::call('v2migration:roles'); $this->admin = User::factory()->admin()->create(); $this->admin->givePermissionTo('framework-ppc'); diff --git a/tests/V2/Files/Location/ProjectReportImageLocationsControllerTest.php b/tests/V2/Files/Location/ProjectReportImageLocationsControllerTest.php index d9b16cab7..4ba84db4b 100644 --- a/tests/V2/Files/Location/ProjectReportImageLocationsControllerTest.php +++ b/tests/V2/Files/Location/ProjectReportImageLocationsControllerTest.php @@ -7,7 +7,7 @@ use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\WithFaker; use Illuminate\Http\UploadedFile; -//use Illuminate\Support\Facades\Artisan; +use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\Storage; use Tests\TestCase; @@ -30,7 +30,7 @@ public function setUp(): void { parent::setUp(); - // Artisan::call('v2migration:roles --fresh'); + Artisan::call('v2migration:roles'); $this->admin = User::factory()->admin()->create(); $this->admin->givePermissionTo('framework-ppc'); diff --git a/tests/V2/Files/Location/SiteImageLocationsControllerTest.php b/tests/V2/Files/Location/SiteImageLocationsControllerTest.php index 58c65eaba..42277a001 100644 --- a/tests/V2/Files/Location/SiteImageLocationsControllerTest.php +++ b/tests/V2/Files/Location/SiteImageLocationsControllerTest.php @@ -8,7 +8,7 @@ use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\WithFaker; use Illuminate\Http\UploadedFile; -//use Illuminate\Support\Facades\Artisan; +use Illuminate\Support\Facades\Artisan; use Tests\TestCase; class SiteImageLocationsControllerTest extends TestCase @@ -36,7 +36,7 @@ public function setUp(): void { parent::setUp(); - // Artisan::call('v2migration:roles --fresh'); + Artisan::call('v2migration:roles'); $this->admin = User::factory()->admin()->create(); $this->admin->givePermissionTo('framework-ppc'); diff --git a/tests/V2/Files/Location/SiteReportImageLocationsControllerTest.php b/tests/V2/Files/Location/SiteReportImageLocationsControllerTest.php index 0531bf7a3..760d88f61 100644 --- a/tests/V2/Files/Location/SiteReportImageLocationsControllerTest.php +++ b/tests/V2/Files/Location/SiteReportImageLocationsControllerTest.php @@ -7,7 +7,7 @@ use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\WithFaker; use Illuminate\Http\UploadedFile; -//use Illuminate\Support\Facades\Artisan; +use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\Storage; use Tests\TestCase; @@ -30,7 +30,7 @@ public function setUp(): void { parent::setUp(); - // Artisan::call('v2migration:roles --fresh'); + Artisan::call('v2migration:roles'); $this->admin = User::factory()->admin()->create(); $this->admin->givePermissionTo('framework-ppc'); diff --git a/tests/V2/Invasives/DeleteInvasiveControllerTest.php b/tests/V2/Invasives/DeleteInvasiveControllerTest.php index 3e5861428..a1d8c4534 100644 --- a/tests/V2/Invasives/DeleteInvasiveControllerTest.php +++ b/tests/V2/Invasives/DeleteInvasiveControllerTest.php @@ -7,8 +7,9 @@ use App\Models\V2\Organisation; use App\Models\V2\Projects\Project; use App\Models\V2\Sites\Site; +use App\StateMachines\EntityStatusStateMachine; use Illuminate\Foundation\Testing\RefreshDatabase; -//use Illuminate\Support\Facades\Artisan; +use Illuminate\Support\Facades\Artisan; use Tests\TestCase; class DeleteInvasiveControllerTest extends TestCase @@ -17,7 +18,7 @@ class DeleteInvasiveControllerTest extends TestCase public function test_invoke_action() { - // Artisan::call('v2migration:roles --fresh'); + Artisan::call('v2migration:roles'); $organisation = Organisation::factory()->create(); $owner = User::factory()->create(['organisation_id' => $organisation->id]); $owner->givePermissionTo('manage-own'); @@ -32,7 +33,7 @@ public function test_invoke_action() $site = Site::factory()->create([ 'project_id' => $project->id, 'framework_key' => 'ppc', - 'status' => Site::STATUS_STARTED, + 'status' => EntityStatusStateMachine::STARTED, ]); $invasive = Invasive::factory()->create([ diff --git a/tests/V2/Invasives/GetInvasivesForEntityControllerTest.php b/tests/V2/Invasives/GetInvasivesForEntityControllerTest.php index 3b326c688..1bdf515a3 100644 --- a/tests/V2/Invasives/GetInvasivesForEntityControllerTest.php +++ b/tests/V2/Invasives/GetInvasivesForEntityControllerTest.php @@ -7,7 +7,8 @@ use App\Models\V2\Organisation; use App\Models\V2\Projects\Project; use App\Models\V2\Sites\Site; -// use Illuminate\Support\Facades\Artisan; +use App\StateMachines\EntityStatusStateMachine; +use Illuminate\Support\Facades\Artisan; use Illuminate\Foundation\Testing\RefreshDatabase; use Tests\TestCase; @@ -17,7 +18,7 @@ class GetInvasivesForEntityControllerTest extends TestCase public function test_invoke_action() { - // Artisan::call('v2migration:roles --fresh'); + Artisan::call('v2migration:roles'); $organisation = Organisation::factory()->create(); $owner = User::factory()->create(['organisation_id' => $organisation->id]); $owner->givePermissionTo('manage-own'); @@ -32,7 +33,7 @@ public function test_invoke_action() $site = Site::factory()->create([ 'project_id' => $project->id, 'framework_key' => 'ppc', - 'status' => Site::STATUS_STARTED, + 'status' => EntityStatusStateMachine::STARTED, ]); Invasive::factory()->create([ diff --git a/tests/V2/Invasives/StoreInvasiveControllerTest.php b/tests/V2/Invasives/StoreInvasiveControllerTest.php index 1f740e5d9..179d0c364 100644 --- a/tests/V2/Invasives/StoreInvasiveControllerTest.php +++ b/tests/V2/Invasives/StoreInvasiveControllerTest.php @@ -6,7 +6,8 @@ use App\Models\V2\Organisation; use App\Models\V2\Projects\Project; use App\Models\V2\Sites\Site; -//use Illuminate\Support\Facades\Artisan; +use App\StateMachines\EntityStatusStateMachine; +use Illuminate\Support\Facades\Artisan; use Illuminate\Foundation\Testing\RefreshDatabase; use Tests\TestCase; @@ -16,7 +17,7 @@ class StoreInvasiveControllerTest extends TestCase public function test_invoke_action() { - // Artisan::call('v2migration:roles --fresh'); + Artisan::call('v2migration:roles'); $organisation = Organisation::factory()->create(); $owner = User::factory()->create(['organisation_id' => $organisation->id]); $owner->givePermissionTo('manage-own'); @@ -31,7 +32,7 @@ public function test_invoke_action() $site = Site::factory()->create([ 'project_id' => $project->id, 'framework_key' => 'ppc', - 'status' => Site::STATUS_STARTED, + 'status' => EntityStatusStateMachine::STARTED, ]); $payload = [ diff --git a/tests/V2/Invasives/UpdateInvasiveControllerTest.php b/tests/V2/Invasives/UpdateInvasiveControllerTest.php index e67819c29..0e999d850 100644 --- a/tests/V2/Invasives/UpdateInvasiveControllerTest.php +++ b/tests/V2/Invasives/UpdateInvasiveControllerTest.php @@ -7,7 +7,8 @@ use App\Models\V2\Organisation; use App\Models\V2\Projects\Project; use App\Models\V2\Sites\Site; -//use Illuminate\Support\Facades\Artisan; +use App\StateMachines\EntityStatusStateMachine; +use Illuminate\Support\Facades\Artisan; use Illuminate\Foundation\Testing\RefreshDatabase; use Tests\TestCase; @@ -17,7 +18,7 @@ class UpdateInvasiveControllerTest extends TestCase public function test_invoke_action() { - // Artisan::call('v2migration:roles --fresh'); + Artisan::call('v2migration:roles'); $organisation = Organisation::factory()->create(); $owner = User::factory()->create(['organisation_id' => $organisation->id]); $owner->givePermissionTo('manage-own'); @@ -32,7 +33,7 @@ public function test_invoke_action() $site = Site::factory()->create([ 'project_id' => $project->id, 'framework_key' => 'ppc', - 'status' => Site::STATUS_STARTED, + 'status' => EntityStatusStateMachine::STARTED, ]); $invasive = Invasive::factory()->create([ diff --git a/tests/V2/ReportingFrameworks/AdminIndexReportingFrameworkControllerTest.php b/tests/V2/ReportingFrameworks/AdminIndexReportingFrameworkControllerTest.php index fc96da73e..28d318960 100644 --- a/tests/V2/ReportingFrameworks/AdminIndexReportingFrameworkControllerTest.php +++ b/tests/V2/ReportingFrameworks/AdminIndexReportingFrameworkControllerTest.php @@ -4,7 +4,7 @@ use App\Models\Framework; use App\Models\User; -//use Illuminate\Support\Facades\Artisan; +use Illuminate\Support\Facades\Artisan; use Illuminate\Foundation\Testing\RefreshDatabase; use Tests\TestCase; @@ -14,7 +14,7 @@ class AdminIndexReportingFrameworkControllerTest extends TestCase public function test_invoke_action() { - // Artisan::call('v2migration:roles'); + Artisan::call('v2migration:roles'); $count = Framework::count(); $user = User::factory()->create(); $admin = User::factory()->admin()->create(); diff --git a/tests/V2/ReportingFrameworks/UpdateReportingFrameworkControllerTest.php b/tests/V2/ReportingFrameworks/UpdateReportingFrameworkControllerTest.php index dc3230cd9..52515b717 100644 --- a/tests/V2/ReportingFrameworks/UpdateReportingFrameworkControllerTest.php +++ b/tests/V2/ReportingFrameworks/UpdateReportingFrameworkControllerTest.php @@ -8,7 +8,7 @@ use App\Models\V2\Forms\Form; use App\Models\V2\Projects\Project; use App\Models\V2\Projects\ProjectReport; -//use Illuminate\Support\Facades\Artisan; +use Illuminate\Support\Facades\Artisan; use Illuminate\Foundation\Testing\RefreshDatabase; use Tests\TestCase; @@ -18,7 +18,7 @@ class UpdateReportingFrameworkControllerTest extends TestCase public function test_invoke_action() { - // Artisan::call('v2migration:roles'); + Artisan::call('v2migration:roles'); $user = User::factory()->create(); $admin = User::factory()->admin()->create(); $admin->givePermissionTo(['framework-ppc', 'framework-terrafund']); @@ -41,7 +41,7 @@ public function test_invoke_action() public function test_clean_up_action() { $admin = User::factory()->admin()->create(); - // Artisan::call('v2migration:roles'); + Artisan::call('v2migration:roles'); $admin->givePermissionTo(['framework-ppc', 'framework-terrafund']); $formP1 = CustomFormHelper::generateFakeForm('project', 'ppc'); diff --git a/tests/V2/Seedings/DeleteSeedingControllerTest.php b/tests/V2/Seedings/DeleteSeedingControllerTest.php index 88f732777..09f7f4392 100644 --- a/tests/V2/Seedings/DeleteSeedingControllerTest.php +++ b/tests/V2/Seedings/DeleteSeedingControllerTest.php @@ -8,7 +8,9 @@ use App\Models\V2\Seeding; use App\Models\V2\Sites\Site; use App\Models\V2\Sites\SiteReport; +use App\StateMachines\EntityStatusStateMachine; use Illuminate\Foundation\Testing\RefreshDatabase; +use Illuminate\Support\Facades\Artisan; use Tests\TestCase; class DeleteSeedingControllerTest extends TestCase @@ -18,7 +20,7 @@ class DeleteSeedingControllerTest extends TestCase public function setUp(): void { parent::setUp(); - // Artisan::call('v2migration:roles --fresh'); + Artisan::call('v2migration:roles'); } /** @@ -41,7 +43,7 @@ public function test_it_can_delete_a_seeding_for_a_site(string $fmKey) $site = Site::factory()->create([ 'project_id' => $project->id, 'framework_key' => $fmKey, - 'status' => Site::STATUS_STARTED, + 'status' => EntityStatusStateMachine::STARTED, ]); $seeding = Seeding::factory()->create([ @@ -82,13 +84,13 @@ public function test_it_can_delete_a_seeding_for_a_site_report(string $fmKey) $site = Site::factory()->create([ 'project_id' => $project->id, 'framework_key' => $fmKey, - 'status' => Site::STATUS_STARTED, + 'status' => EntityStatusStateMachine::STARTED, ]); $siteReport = SiteReport::factory()->create([ 'site_id' => $site->id, 'framework_key' => $fmKey, - 'status' => SiteReport::STATUS_STARTED, + 'status' => EntityStatusStateMachine::STARTED, ]); $seeding = Seeding::factory()->create([ diff --git a/tests/V2/Seedings/GetSeedingsForEntityControllerTest.php b/tests/V2/Seedings/GetSeedingsForEntityControllerTest.php index 27a4a46d9..554555689 100644 --- a/tests/V2/Seedings/GetSeedingsForEntityControllerTest.php +++ b/tests/V2/Seedings/GetSeedingsForEntityControllerTest.php @@ -1,6 +1,6 @@ create([ 'project_id' => $project->id, 'framework_key' => $fmKey, - 'status' => Site::STATUS_STARTED, + 'status' => EntityStatusStateMachine::STARTED, ]); Seeding::factory()->count(3)->create([ @@ -78,13 +80,13 @@ public function test_it_can_list_seedings_for_a_site_report(string $fmKey) $site = Site::factory()->create([ 'project_id' => $project->id, 'framework_key' => $fmKey, - 'status' => Site::STATUS_STARTED, + 'status' => EntityStatusStateMachine::STARTED, ]); $siteReport = SiteReport::factory()->create([ 'site_id' => $site->id, 'framework_key' => $fmKey, - 'status' => SiteReport::STATUS_STARTED, + 'status' => EntityStatusStateMachine::STARTED, ]); Seeding::factory()->create([ diff --git a/tests/V2/Seedings/StoreSeedingControllerTest.php b/tests/V2/Seedings/StoreSeedingControllerTest.php index 1b6839074..31fb4b8c5 100644 --- a/tests/V2/Seedings/StoreSeedingControllerTest.php +++ b/tests/V2/Seedings/StoreSeedingControllerTest.php @@ -1,12 +1,13 @@ create([ 'project_id' => $project->id, 'framework_key' => 'ppc', - 'status' => Site::STATUS_STARTED, + 'status' => EntityStatusStateMachine::STARTED, ]); $payload = [ @@ -86,13 +87,13 @@ public function test_user_can_create_seedings_for_site_reports(string $fmKey) $site = Site::factory()->create([ 'project_id' => $project->id, 'framework_key' => 'ppc', - 'status' => Site::STATUS_STARTED, + 'status' => EntityStatusStateMachine::STARTED, ]); $siteReport = SiteReport::factory()->create([ 'site_id' => $site->id, 'framework_key' => $fmKey, - 'status' => SiteReport::STATUS_STARTED, + 'status' => EntityStatusStateMachine::STARTED, ]); $payload = [ diff --git a/tests/V2/Seedings/UpdateSeedingControllerTest.php b/tests/V2/Seedings/UpdateSeedingControllerTest.php index 3d37e6355..b624d1044 100644 --- a/tests/V2/Seedings/UpdateSeedingControllerTest.php +++ b/tests/V2/Seedings/UpdateSeedingControllerTest.php @@ -1,13 +1,15 @@ create([ 'project_id' => $project->id, 'framework_key' => $fmKey, - 'status' => Site::STATUS_STARTED, + 'status' => EntityStatusStateMachine::STARTED, ]); $seeding = Seeding::factory()->create([ diff --git a/tests/V2/SiteReports/SubmitSiteReportControllerTest.php b/tests/V2/SiteReports/SubmitSiteReportControllerTest.php index 3d1046a32..a09f064f4 100644 --- a/tests/V2/SiteReports/SubmitSiteReportControllerTest.php +++ b/tests/V2/SiteReports/SubmitSiteReportControllerTest.php @@ -21,7 +21,7 @@ class SubmitSiteReportControllerTest extends TestCase public function test_invoke_action() { - Artisan::call('v2migration:roles --fresh'); + Artisan::call('v2migration:roles'); $organisation = Organisation::factory()->create(); $owner = User::factory()->create(['organisation_id' => $organisation->id]); $owner->givePermissionTo('manage-own'); diff --git a/tests/V2/Sites/AdminSitesMultiControllerTest.php b/tests/V2/Sites/AdminSitesMultiControllerTest.php index 8b4243c65..ecca6e720 100644 --- a/tests/V2/Sites/AdminSitesMultiControllerTest.php +++ b/tests/V2/Sites/AdminSitesMultiControllerTest.php @@ -16,7 +16,7 @@ class AdminSitesMultiControllerTest extends TestCase public function test_invoke_action() { - Artisan::call('v2migration:roles --fresh'); + Artisan::call('v2migration:roles'); $admin = User::factory()->admin()->create(); $admin->givePermissionTo('framework-terrafund'); $admin->givePermissionTo('framework-ppc'); diff --git a/tests/V2/Sites/CreateSiteControllerWithFormTest.php b/tests/V2/Sites/CreateSiteControllerWithFormTest.php index 2e091c57b..cf39dd87a 100644 --- a/tests/V2/Sites/CreateSiteControllerWithFormTest.php +++ b/tests/V2/Sites/CreateSiteControllerWithFormTest.php @@ -18,7 +18,7 @@ class CreateSiteControllerWithFormTest extends TestCase public function test_invoke_action() { - Artisan::call('v2migration:roles --fresh'); + Artisan::call('v2migration:roles'); $tfAdmin = User::factory()->admin()->create(); $tfAdmin->givePermissionTo('framework-terrafund'); diff --git a/tests/V2/Sites/SoftDeleteSiteControllerTest.php b/tests/V2/Sites/SoftDeleteSiteControllerTest.php index 110fd8ee5..9c31c989e 100644 --- a/tests/V2/Sites/SoftDeleteSiteControllerTest.php +++ b/tests/V2/Sites/SoftDeleteSiteControllerTest.php @@ -48,7 +48,7 @@ public function test_project_developer_can_soft_delete_sites_without_reports(str */ public function test_project_developer_cant_soft_delete_sites_with_reports(string $permission, string $fmKey) { - // Artisan::call('v2migration:roles'); + Artisan::call('v2migration:roles'); $project = Project::factory()->create(['framework_key' => $fmKey]); $site = Site::factory()->{$fmKey}()->create([ diff --git a/tests/V2/Stratas/DeleteStrataControllerTest.php b/tests/V2/Stratas/DeleteStrataControllerTest.php index 54694b922..29fae603d 100644 --- a/tests/V2/Stratas/DeleteStrataControllerTest.php +++ b/tests/V2/Stratas/DeleteStrataControllerTest.php @@ -7,7 +7,8 @@ use App\Models\V2\Projects\Project; use App\Models\V2\Sites\Site; use App\Models\V2\Stratas\Strata; -//use Illuminate\Support\Facades\Artisan; +use App\StateMachines\EntityStatusStateMachine; +use Illuminate\Support\Facades\Artisan; use Illuminate\Foundation\Testing\RefreshDatabase; use Tests\TestCase; @@ -17,7 +18,7 @@ class DeleteStrataControllerTest extends TestCase public function test_invoke_action() { - // Artisan::call('v2migration:roles --fresh'); + Artisan::call('v2migration:roles'); $organisation = Organisation::factory()->create(); $owner = User::factory()->create(['organisation_id' => $organisation->id]); $owner->givePermissionTo('manage-own'); @@ -32,7 +33,7 @@ public function test_invoke_action() $site = Site::factory()->create([ 'project_id' => $project->id, 'framework_key' => 'ppc', - 'status' => Site::STATUS_STARTED, + 'status' => EntityStatusStateMachine::STARTED, ]); $strata = Strata::factory()->create([ diff --git a/tests/V2/Stratas/GetStratasForEntityControllerTest.php b/tests/V2/Stratas/GetStratasForEntityControllerTest.php index 9e8bbb7ea..395fd2608 100644 --- a/tests/V2/Stratas/GetStratasForEntityControllerTest.php +++ b/tests/V2/Stratas/GetStratasForEntityControllerTest.php @@ -7,7 +7,8 @@ use App\Models\V2\Projects\Project; use App\Models\V2\Sites\Site; use App\Models\V2\Stratas\Strata; -// use Illuminate\Support\Facades\Artisan; +use App\StateMachines\EntityStatusStateMachine; +use Illuminate\Support\Facades\Artisan; use Illuminate\Foundation\Testing\RefreshDatabase; use Tests\TestCase; @@ -17,7 +18,7 @@ class GetStratasForEntityControllerTest extends TestCase public function test_invoke_action() { - // Artisan::call('v2migration:roles --fresh'); + Artisan::call('v2migration:roles'); $organisation = Organisation::factory()->create(); $owner = User::factory()->create(['organisation_id' => $organisation->id]); $owner->givePermissionTo('manage-own'); @@ -32,7 +33,7 @@ public function test_invoke_action() $site = Site::factory()->create([ 'project_id' => $project->id, 'framework_key' => 'ppc', - 'status' => Site::STATUS_STARTED, + 'status' => EntityStatusStateMachine::STARTED, ]); Strata::factory()->create([ diff --git a/tests/V2/Stratas/StoreStrataControllerTest.php b/tests/V2/Stratas/StoreStrataControllerTest.php index 13e0ff759..b826f0e94 100644 --- a/tests/V2/Stratas/StoreStrataControllerTest.php +++ b/tests/V2/Stratas/StoreStrataControllerTest.php @@ -6,7 +6,8 @@ use App\Models\V2\Organisation; use App\Models\V2\Projects\Project; use App\Models\V2\Sites\Site; -//use Illuminate\Support\Facades\Artisan; +use App\StateMachines\EntityStatusStateMachine; +use Illuminate\Support\Facades\Artisan; use Illuminate\Foundation\Testing\RefreshDatabase; use Tests\TestCase; @@ -16,7 +17,7 @@ class StoreStrataControllerTest extends TestCase public function test_user_can_create_stratas() { - // Artisan::call('v2migration:roles --fresh'); + Artisan::call('v2migration:roles'); $organisation = Organisation::factory()->create(); $owner = User::factory()->create(['organisation_id' => $organisation->id]); $owner->givePermissionTo('manage-own'); @@ -31,7 +32,7 @@ public function test_user_can_create_stratas() $site = Site::factory()->create([ 'project_id' => $project->id, 'framework_key' => 'ppc', - 'status' => Site::STATUS_STARTED, + 'status' => EntityStatusStateMachine::STARTED, ]); $payload = [ diff --git a/tests/V2/Stratas/UpdateStrataControllerTest.php b/tests/V2/Stratas/UpdateStrataControllerTest.php index 9fac5c0e7..c54f6fc43 100644 --- a/tests/V2/Stratas/UpdateStrataControllerTest.php +++ b/tests/V2/Stratas/UpdateStrataControllerTest.php @@ -7,7 +7,8 @@ use App\Models\V2\Projects\Project; use App\Models\V2\Sites\Site; use App\Models\V2\Stratas\Strata; -//use Illuminate\Support\Facades\Artisan; +use App\StateMachines\EntityStatusStateMachine; +use Illuminate\Support\Facades\Artisan; use Illuminate\Foundation\Testing\RefreshDatabase; use Tests\TestCase; @@ -17,7 +18,7 @@ class UpdateStrataControllerTest extends TestCase public function test_user_can_update_strata() { - // Artisan::call('v2migration:roles --fresh'); + Artisan::call('v2migration:roles'); $organisation = Organisation::factory()->create(); $owner = User::factory()->create(['organisation_id' => $organisation->id]); $owner->givePermissionTo('manage-own'); @@ -32,7 +33,7 @@ public function test_user_can_update_strata() $site = Site::factory()->create([ 'project_id' => $project->id, 'framework_key' => 'ppc', - 'status' => Site::STATUS_STARTED, + 'status' => EntityStatusStateMachine::STARTED, ]); $strata = Strata::factory()->create([ diff --git a/tests/V2/TreeSpecies/GetTreeSpeciesForEntityControllerTest.php b/tests/V2/TreeSpecies/GetTreeSpeciesForEntityControllerTest.php index 1f2d2d744..a34dcb04c 100644 --- a/tests/V2/TreeSpecies/GetTreeSpeciesForEntityControllerTest.php +++ b/tests/V2/TreeSpecies/GetTreeSpeciesForEntityControllerTest.php @@ -1,6 +1,6 @@ admin()->create(); $user->givePermissionTo($permission); diff --git a/tests/V2/UpdateRequests/AdminSoftDeleteUpdateRequestControllerTest.php b/tests/V2/UpdateRequests/AdminSoftDeleteUpdateRequestControllerTest.php index fbe806816..050059da8 100644 --- a/tests/V2/UpdateRequests/AdminSoftDeleteUpdateRequestControllerTest.php +++ b/tests/V2/UpdateRequests/AdminSoftDeleteUpdateRequestControllerTest.php @@ -7,7 +7,7 @@ use App\Models\V2\Projects\Project; use App\Models\V2\Sites\Site; use App\Models\V2\UpdateRequests\UpdateRequest; -//use Illuminate\Support\Facades\Artisan; +use Illuminate\Support\Facades\Artisan; use Illuminate\Foundation\Testing\RefreshDatabase; use Tests\TestCase; @@ -17,7 +17,7 @@ class AdminSoftDeleteUpdateRequestControllerTest extends TestCase public function test_invoke_action(): void { - // Artisan::call('v2migration:roles'); + Artisan::call('v2migration:roles'); $organisation = Organisation::factory()->create(); $project = Project::factory()->create([ 'framework_key' => 'ppc', diff --git a/tests/V2/UpdateRequests/AdminViewUpdateRequestControllerTest.php b/tests/V2/UpdateRequests/AdminViewUpdateRequestControllerTest.php index f88f7350d..00c705630 100644 --- a/tests/V2/UpdateRequests/AdminViewUpdateRequestControllerTest.php +++ b/tests/V2/UpdateRequests/AdminViewUpdateRequestControllerTest.php @@ -7,7 +7,7 @@ use App\Models\V2\Projects\Project; use App\Models\V2\Sites\Site; use App\Models\V2\UpdateRequests\UpdateRequest; -//use Illuminate\Support\Facades\Artisan; +use Illuminate\Support\Facades\Artisan; use Illuminate\Foundation\Testing\RefreshDatabase; use Tests\TestCase; @@ -17,7 +17,7 @@ class AdminViewUpdateRequestControllerTest extends TestCase public function test_invoke_action(): void { - // Artisan::call('v2migration:roles'); + Artisan::call('v2migration:roles'); $organisation = Organisation::factory()->create(); $project = Project::factory()->create([ 'framework_key' => 'ppc', diff --git a/tests/V2/UpdateRequests/EntityUpdateRequestControllerTest.php b/tests/V2/UpdateRequests/EntityUpdateRequestControllerTest.php index d4f606047..c4a2e5094 100644 --- a/tests/V2/UpdateRequests/EntityUpdateRequestControllerTest.php +++ b/tests/V2/UpdateRequests/EntityUpdateRequestControllerTest.php @@ -7,7 +7,7 @@ use App\Models\V2\Projects\Project; use App\Models\V2\Sites\Site; use App\Models\V2\UpdateRequests\UpdateRequest; -//use Illuminate\Support\Facades\Artisan; +use Illuminate\Support\Facades\Artisan; use Illuminate\Foundation\Testing\RefreshDatabase; use Tests\TestCase; @@ -17,7 +17,7 @@ class EntityUpdateRequestControllerTest extends TestCase public function test_invoke_action(): void { - // Artisan::call('v2migration:roles'); + Artisan::call('v2migration:roles'); $organisation = Organisation::factory()->create(); $project = Project::factory()->create([ 'framework_key' => 'ppc', diff --git a/tests/V2/User/CompleteActionControllerTest.php b/tests/V2/User/CompleteActionControllerTest.php index 394c0def9..88d66debe 100644 --- a/tests/V2/User/CompleteActionControllerTest.php +++ b/tests/V2/User/CompleteActionControllerTest.php @@ -4,7 +4,7 @@ use App\Models\User; use App\Models\V2\Action; -// use Illuminate\Support\Facades\Artisan; +use Illuminate\Support\Facades\Artisan; use Illuminate\Foundation\Testing\RefreshDatabase; use Tests\TestCase; @@ -14,7 +14,7 @@ class CompleteActionControllerTest extends TestCase public function test_users_can_complete_their_actions() { - // Artisan::call('v2migration:roles'); + Artisan::call('v2migration:roles'); $user = User::factory()->admin()->create(); $user->givePermissionTo('manage-own'); diff --git a/tests/V2/Users/AdminUserControllerTest.php b/tests/V2/Users/AdminUserControllerTest.php index 7483b3316..acb0f8be2 100644 --- a/tests/V2/Users/AdminUserControllerTest.php +++ b/tests/V2/Users/AdminUserControllerTest.php @@ -111,7 +111,7 @@ public function test_show_action(): void public function test_create_action(): void { - // Artisan::call('v2migration:roles --fresh'); + Artisan::call('v2migration:roles'); $user = User::factory()->create(); $admin = User::factory()->admin()->create(); @@ -155,7 +155,7 @@ public function test_an_user_can_be_updated() */ public function test_an_user_can_have_been_assigned_with_a_role(string $primaryRole, string $expectedUserType) { - // Artisan::call('v2migration:roles --fresh'); + Artisan::call('v2migration:roles'); $user = User::factory()->create(); $admin = User::factory()->admin()->create(); diff --git a/tests/V2/Workdays/DeleteWorkdayControllerTest.php b/tests/V2/Workdays/DeleteWorkdayControllerTest.php index e2965462d..a8ee600ed 100644 --- a/tests/V2/Workdays/DeleteWorkdayControllerTest.php +++ b/tests/V2/Workdays/DeleteWorkdayControllerTest.php @@ -7,8 +7,9 @@ use App\Models\V2\Projects\Project; use App\Models\V2\Sites\Site; use App\Models\V2\Workdays\Workday; +use App\StateMachines\EntityStatusStateMachine; use Illuminate\Foundation\Testing\RefreshDatabase; -//use Illuminate\Support\Facades\Artisan; +use Illuminate\Support\Facades\Artisan; use Tests\TestCase; class DeleteWorkdayControllerTest extends TestCase @@ -17,7 +18,7 @@ class DeleteWorkdayControllerTest extends TestCase public function test_invoke_action() { - // Artisan::call('v2migration:roles --fresh'); + Artisan::call('v2migration:roles'); $organisation = Organisation::factory()->create(); $owner = User::factory()->create(['organisation_id' => $organisation->id]); $owner->givePermissionTo('manage-own'); @@ -32,7 +33,7 @@ public function test_invoke_action() $site = Site::factory()->create([ 'project_id' => $project->id, 'framework_key' => 'ppc', - 'status' => Site::STATUS_STARTED, + 'status' => EntityStatusStateMachine::STARTED, ]); $workday = Workday::factory()->create([ diff --git a/tests/V2/Workdays/GetWorkdaysForEntityControllerTest.php b/tests/V2/Workdays/GetWorkdaysForEntityControllerTest.php index e5924b4ba..f57b562f3 100644 --- a/tests/V2/Workdays/GetWorkdaysForEntityControllerTest.php +++ b/tests/V2/Workdays/GetWorkdaysForEntityControllerTest.php @@ -8,7 +8,8 @@ use App\Models\V2\Sites\Site; use App\Models\V2\Sites\SiteReport; use App\Models\V2\Workdays\Workday; -//use Illuminate\Support\Facades\Artisan; +use App\StateMachines\EntityStatusStateMachine; +use Illuminate\Support\Facades\Artisan; use Illuminate\Foundation\Testing\RefreshDatabase; use Tests\TestCase; @@ -18,7 +19,7 @@ class GetWorkdaysForEntityControllerTest extends TestCase public function test_invoke_action() { - // Artisan::call('v2migration:roles --fresh'); + Artisan::call('v2migration:roles'); $organisation = Organisation::factory()->create(); $owner = User::factory()->create(['organisation_id' => $organisation->id]); $owner->givePermissionTo('manage-own'); @@ -33,13 +34,13 @@ public function test_invoke_action() $site = Site::factory()->create([ 'project_id' => $project->id, 'framework_key' => 'ppc', - 'status' => Site::STATUS_STARTED, + 'status' => EntityStatusStateMachine::STARTED, ]); $report = SiteReport::factory()->create([ 'site_id' => $site->id, 'framework_key' => 'ppc', - 'status' => SiteReport::STATUS_STARTED, + 'status' => EntityStatusStateMachine::STARTED, ]); $workday = Workday::factory()->create([ diff --git a/tests/V2/Workdays/StoreWorkdayControllerTest.php b/tests/V2/Workdays/StoreWorkdayControllerTest.php index 4afb58fbf..c49570f05 100644 --- a/tests/V2/Workdays/StoreWorkdayControllerTest.php +++ b/tests/V2/Workdays/StoreWorkdayControllerTest.php @@ -7,7 +7,8 @@ use App\Models\V2\Projects\Project; use App\Models\V2\Sites\Site; use App\Models\V2\Sites\SiteReport; -//use Illuminate\Support\Facades\Artisan; +use App\StateMachines\EntityStatusStateMachine; +use Illuminate\Support\Facades\Artisan; use App\Models\V2\Workdays\Workday; use Illuminate\Foundation\Testing\RefreshDatabase; use Tests\TestCase; @@ -18,7 +19,7 @@ class StoreWorkdayControllerTest extends TestCase public function test_invoke_action() { - // Artisan::call('v2migration:roles --fresh'); + Artisan::call('v2migration:roles'); $organisation = Organisation::factory()->create(); $owner = User::factory()->create(['organisation_id' => $organisation->id]); $owner->givePermissionTo('manage-own'); @@ -33,13 +34,13 @@ public function test_invoke_action() $site = Site::factory()->create([ 'project_id' => $project->id, 'framework_key' => 'ppc', - 'status' => Site::STATUS_STARTED, + 'status' => EntityStatusStateMachine::STARTED, ]); $report = SiteReport::factory()->create([ 'site_id' => $site->id, 'framework_key' => 'ppc', - 'status' => SiteReport::STATUS_STARTED, + 'status' => EntityStatusStateMachine::STARTED, ]); $payload = [ diff --git a/tests/V2/Workdays/UpdateWorkdayControllerTest.php b/tests/V2/Workdays/UpdateWorkdayControllerTest.php index 348609c56..51f94f2a7 100644 --- a/tests/V2/Workdays/UpdateWorkdayControllerTest.php +++ b/tests/V2/Workdays/UpdateWorkdayControllerTest.php @@ -8,7 +8,8 @@ use App\Models\V2\Sites\Site; use App\Models\V2\Sites\SiteReport; use App\Models\V2\Workdays\Workday; -//use Illuminate\Support\Facades\Artisan; +use App\StateMachines\EntityStatusStateMachine; +use Illuminate\Support\Facades\Artisan; use Illuminate\Foundation\Testing\RefreshDatabase; use Tests\TestCase; @@ -18,7 +19,7 @@ class UpdateWorkdayControllerTest extends TestCase public function test_invoke_action() { - // Artisan::call('v2migration:roles --fresh'); + Artisan::call('v2migration:roles'); $organisation = Organisation::factory()->create(); $owner = User::factory()->create(['organisation_id' => $organisation->id]); $owner->givePermissionTo('manage-own'); @@ -33,13 +34,13 @@ public function test_invoke_action() $site = Site::factory()->create([ 'project_id' => $project->id, 'framework_key' => 'ppc', - 'status' => Site::STATUS_STARTED, + 'status' => EntityStatusStateMachine::STARTED, ]); $report = SiteReport::factory()->create([ 'site_id' => $site->id, 'framework_key' => 'ppc', - 'status' => SiteReport::STATUS_STARTED, + 'status' => EntityStatusStateMachine::STARTED, ]); $workday = Workday::factory()->create([ From 81db14510c3cbea6ac87a1d238e0f82d8526b2ec Mon Sep 17 00:00:00 2001 From: Nathan Curtis Date: Mon, 8 Apr 2024 15:45:43 -0700 Subject: [PATCH 16/44] [TM-785] Clean up some warnings in tests found by PhpStorm --- tests/Other/SwaggerTest.php | 1 - tests/Unit/Models/V2/Nurseries/NurseryTest.php | 2 +- tests/Unit/Models/V2/Projects/ProjectTest.php | 2 +- tests/Unit/Models/V2/Sites/SiteTest.php | 2 +- tests/V2/Audits/AdminIndexAuditsControllerTest.php | 2 +- tests/V2/Projects/UpdateProjectWithFormControllerTest.php | 3 --- 6 files changed, 4 insertions(+), 8 deletions(-) diff --git a/tests/Other/SwaggerTest.php b/tests/Other/SwaggerTest.php index 46e7bd1e8..d1230ef2e 100644 --- a/tests/Other/SwaggerTest.php +++ b/tests/Other/SwaggerTest.php @@ -102,7 +102,6 @@ public function test_v2_valid_swagger(): void } if (property_exists($results, 'messages')) { dd($results->messages); - $this->assertEmpty($results->messages); } File::delete('swagger-v2.json'); } diff --git a/tests/Unit/Models/V2/Nurseries/NurseryTest.php b/tests/Unit/Models/V2/Nurseries/NurseryTest.php index a0cfcae14..7601726f9 100644 --- a/tests/Unit/Models/V2/Nurseries/NurseryTest.php +++ b/tests/Unit/Models/V2/Nurseries/NurseryTest.php @@ -1,6 +1,6 @@ actingAs($owner) ->putJson($uri, $payload) ->assertSuccessful(); - - // $updated = $project->fresh(); - // $this->assertEquals($updated->name, '* testing name updated *'); } public function test_update_request() From 973d987a6a802e800d5cad50137ea7e98a978122 Mon Sep 17 00:00:00 2001 From: Nathan Curtis Date: Mon, 8 Apr 2024 16:47:48 -0700 Subject: [PATCH 17/44] [TM-785] All V2 tests passing. --- .../Requests/V2/Forms/StoreFormRequest.php | 2 +- routes/api_v2.php | 2 +- .../AdminExportApplicationControllerTest.php | 21 ++++++------------- 3 files changed, 8 insertions(+), 17 deletions(-) diff --git a/app/Http/Requests/V2/Forms/StoreFormRequest.php b/app/Http/Requests/V2/Forms/StoreFormRequest.php index a4ea9fc4d..586bdaf53 100644 --- a/app/Http/Requests/V2/Forms/StoreFormRequest.php +++ b/app/Http/Requests/V2/Forms/StoreFormRequest.php @@ -33,7 +33,7 @@ public function rules() 'form_sections.*.description' => ['sometimes', 'nullable', 'max:65000'], 'form_sections.*.form_questions' => ['sometimes', 'array'], - 'form_sections.*.form_questions.*.linked_field_key' => ['required', 'nullable', 'string'], + 'form_sections.*.form_questions.*.linked_field_key' => ['sometimes', 'nullable', 'string'], 'form_sections.*.form_questions.*.label' => ['required', 'string'], 'form_sections.*.form_questions.*.input_type' => ['sometimes', 'nullable'], 'form_sections.*.form_questions.*.name' => ['sometimes', 'nullable'], diff --git a/routes/api_v2.php b/routes/api_v2.php index 9e4d1d83f..d9db5bfd0 100644 --- a/routes/api_v2.php +++ b/routes/api_v2.php @@ -390,7 +390,7 @@ Route::get('/projects', ViewMyProjectsController::class); }); -Route::post('/users/resend', [AuthController::class, 'resendByEmail']); +Route::post('/users/resend', [AuthController::class, 'resendByEmail'])->withoutMiddleware('auth:service-api-key,api'); Route::prefix('forms')->group(function () { Route::get('/my/submissions', ViewMyFormSubmissionsController::class)->middleware('i18n'); diff --git a/tests/V2/Applications/AdminExportApplicationControllerTest.php b/tests/V2/Applications/AdminExportApplicationControllerTest.php index afb649c95..b8b352e36 100644 --- a/tests/V2/Applications/AdminExportApplicationControllerTest.php +++ b/tests/V2/Applications/AdminExportApplicationControllerTest.php @@ -24,27 +24,18 @@ class AdminExportApplicationControllerTest extends TestCase use WithFaker; use RefreshDatabase; + protected $fundingNames = ['TerraFund for AFR100: Landscapes - Expression of Interest (Non Profits)', 'TerraFund for AFR100: Landscapes - Expression of Interest (Enterprises)']; + public function test_invoke_action() { - $forms = Form::whereIn('title', [ - 'TerraFund for AFR100: Landscapes - Request for Proposals (Non Profits)', - 'TerraFund for AFR100: Landscapes - Request for Proposals (Enterprise)', - ])->get(); - - if ($forms->count() == 0) { - Artisan::call('v2-custom-form-update-data'); - Artisan::call('v2-custom-form-prep-phase2'); - Artisan::call('v2-custom-form-rfp-update-data'); - $forms = Form::whereIn('title', [ - 'TerraFund for AFR100: Landscapes - Request for Proposals (Non Profits)', - 'TerraFund for AFR100: Landscapes - Request for Proposals (Enterprise)', - ])->get(); - } + Artisan::call('v2-custom-form-update-data'); + Artisan::call('v2-custom-form-prep-phase2'); + Artisan::call('v2-custom-form-rfp-update-data'); $admin = User::factory()->admin()->create(); $user = User::factory()->create(); - $fundingProgrammes = FundingProgramme::whereIn('id', [1,2])->get(); + $fundingProgrammes = FundingProgramme::whereIn('name', $this->fundingNames)->get(); foreach ($fundingProgrammes as $fundingProgramme) { $organisations = Organisation::factory()->count($this->faker->numberBetween(1, 5))->create(); From 5a8deaaf759ae3136f1f68180369c4e1b916040c Mon Sep 17 00:00:00 2001 From: Nathan Curtis Date: Tue, 9 Apr 2024 09:28:29 -0700 Subject: [PATCH 18/44] [TM-785] Another lint pass after fixing the tests. --- .../V2/Applications/AdminExportApplicationControllerTest.php | 1 - .../Disturbances/GetDisturbancesForEntityControllerTest.php | 2 +- tests/V2/Disturbances/StoreDisturbanceControllerTest.php | 2 +- tests/V2/Disturbances/UpdateDisturbanceControllerTest.php | 2 +- tests/V2/Invasives/GetInvasivesForEntityControllerTest.php | 2 +- tests/V2/Invasives/StoreInvasiveControllerTest.php | 2 +- tests/V2/Invasives/UpdateInvasiveControllerTest.php | 2 +- tests/V2/Nurseries/AdminStatusNurseryControllerTest.php | 2 +- tests/V2/Nurseries/SoftDeleteNurseryControllerTest.php | 1 - .../NurseryReports/AdminIndexNurseryReportsControllerTest.php | 2 +- .../NurseryReports/AdminStatusNurseryReportControllerTest.php | 2 +- .../ProjectReports/AdminStatusProjectReportControllerTest.php | 2 +- .../ViewProjectReportWithFormControllerTest.php | 1 - tests/V2/Projects/AdminStatusProjectControllerTest.php | 2 +- tests/V2/Projects/ViewMyProjectsControllerTest.php | 2 +- .../AdminIndexReportingFrameworkControllerTest.php | 2 +- .../UpdateReportingFrameworkControllerTest.php | 2 +- tests/V2/SiteReports/AdminStatusSiteReportControllerTest.php | 4 ++-- tests/V2/Sites/AdminStatusSiteControllerTest.php | 4 ++-- tests/V2/Stratas/DeleteStrataControllerTest.php | 2 +- tests/V2/Stratas/GetStratasForEntityControllerTest.php | 2 +- tests/V2/Stratas/StoreStrataControllerTest.php | 2 +- tests/V2/Stratas/UpdateStrataControllerTest.php | 2 +- .../V2/TreeSpecies/GetTreeSpeciesForEntityControllerTest.php | 2 +- .../UpdateRequests/AdminIndexUpdateRequestControllerTest.php | 2 +- .../AdminSoftDeleteUpdateRequestControllerTest.php | 2 +- .../UpdateRequests/AdminStatusUpdateRequestControllerTest.php | 2 +- .../UpdateRequests/AdminViewUpdateRequestControllerTest.php | 2 +- tests/V2/UpdateRequests/EntityUpdateRequestControllerTest.php | 2 +- tests/V2/User/CompleteActionControllerTest.php | 2 +- tests/V2/Workdays/GetWorkdaysForEntityControllerTest.php | 2 +- tests/V2/Workdays/StoreWorkdayControllerTest.php | 4 ++-- tests/V2/Workdays/UpdateWorkdayControllerTest.php | 2 +- 33 files changed, 33 insertions(+), 36 deletions(-) diff --git a/tests/V2/Applications/AdminExportApplicationControllerTest.php b/tests/V2/Applications/AdminExportApplicationControllerTest.php index b8b352e36..8d7313c27 100644 --- a/tests/V2/Applications/AdminExportApplicationControllerTest.php +++ b/tests/V2/Applications/AdminExportApplicationControllerTest.php @@ -4,7 +4,6 @@ use App\Models\User; use App\Models\V2\Forms\Application; -use App\Models\V2\Forms\Form; use App\Models\V2\Forms\FormSubmission; use App\Models\V2\FundingProgramme; use App\Models\V2\FundingType; diff --git a/tests/V2/Disturbances/GetDisturbancesForEntityControllerTest.php b/tests/V2/Disturbances/GetDisturbancesForEntityControllerTest.php index d7d341632..c3344c70a 100644 --- a/tests/V2/Disturbances/GetDisturbancesForEntityControllerTest.php +++ b/tests/V2/Disturbances/GetDisturbancesForEntityControllerTest.php @@ -8,8 +8,8 @@ use App\Models\V2\Projects\Project; use App\Models\V2\Sites\Site; use App\StateMachines\EntityStatusStateMachine; -use Illuminate\Support\Facades\Artisan; use Illuminate\Foundation\Testing\RefreshDatabase; +use Illuminate\Support\Facades\Artisan; use Tests\TestCase; class GetDisturbancesForEntityControllerTest extends TestCase diff --git a/tests/V2/Disturbances/StoreDisturbanceControllerTest.php b/tests/V2/Disturbances/StoreDisturbanceControllerTest.php index 86ca6bbad..a9420603b 100644 --- a/tests/V2/Disturbances/StoreDisturbanceControllerTest.php +++ b/tests/V2/Disturbances/StoreDisturbanceControllerTest.php @@ -7,8 +7,8 @@ use App\Models\V2\Projects\Project; use App\Models\V2\Sites\Site; use App\StateMachines\EntityStatusStateMachine; -use Illuminate\Support\Facades\Artisan; use Illuminate\Foundation\Testing\RefreshDatabase; +use Illuminate\Support\Facades\Artisan; use Tests\TestCase; class StoreDisturbanceControllerTest extends TestCase diff --git a/tests/V2/Disturbances/UpdateDisturbanceControllerTest.php b/tests/V2/Disturbances/UpdateDisturbanceControllerTest.php index 49614b70a..5bffd1d65 100644 --- a/tests/V2/Disturbances/UpdateDisturbanceControllerTest.php +++ b/tests/V2/Disturbances/UpdateDisturbanceControllerTest.php @@ -8,8 +8,8 @@ use App\Models\V2\Projects\Project; use App\Models\V2\Sites\Site; use App\StateMachines\EntityStatusStateMachine; -use Illuminate\Support\Facades\Artisan; use Illuminate\Foundation\Testing\RefreshDatabase; +use Illuminate\Support\Facades\Artisan; use Tests\TestCase; class UpdateDisturbanceControllerTest extends TestCase diff --git a/tests/V2/Invasives/GetInvasivesForEntityControllerTest.php b/tests/V2/Invasives/GetInvasivesForEntityControllerTest.php index 1bdf515a3..81a4e68fa 100644 --- a/tests/V2/Invasives/GetInvasivesForEntityControllerTest.php +++ b/tests/V2/Invasives/GetInvasivesForEntityControllerTest.php @@ -8,8 +8,8 @@ use App\Models\V2\Projects\Project; use App\Models\V2\Sites\Site; use App\StateMachines\EntityStatusStateMachine; -use Illuminate\Support\Facades\Artisan; use Illuminate\Foundation\Testing\RefreshDatabase; +use Illuminate\Support\Facades\Artisan; use Tests\TestCase; class GetInvasivesForEntityControllerTest extends TestCase diff --git a/tests/V2/Invasives/StoreInvasiveControllerTest.php b/tests/V2/Invasives/StoreInvasiveControllerTest.php index 179d0c364..d0c858ec7 100644 --- a/tests/V2/Invasives/StoreInvasiveControllerTest.php +++ b/tests/V2/Invasives/StoreInvasiveControllerTest.php @@ -7,8 +7,8 @@ use App\Models\V2\Projects\Project; use App\Models\V2\Sites\Site; use App\StateMachines\EntityStatusStateMachine; -use Illuminate\Support\Facades\Artisan; use Illuminate\Foundation\Testing\RefreshDatabase; +use Illuminate\Support\Facades\Artisan; use Tests\TestCase; class StoreInvasiveControllerTest extends TestCase diff --git a/tests/V2/Invasives/UpdateInvasiveControllerTest.php b/tests/V2/Invasives/UpdateInvasiveControllerTest.php index 0e999d850..bc3b75b23 100644 --- a/tests/V2/Invasives/UpdateInvasiveControllerTest.php +++ b/tests/V2/Invasives/UpdateInvasiveControllerTest.php @@ -8,8 +8,8 @@ use App\Models\V2\Projects\Project; use App\Models\V2\Sites\Site; use App\StateMachines\EntityStatusStateMachine; -use Illuminate\Support\Facades\Artisan; use Illuminate\Foundation\Testing\RefreshDatabase; +use Illuminate\Support\Facades\Artisan; use Tests\TestCase; class UpdateInvasiveControllerTest extends TestCase diff --git a/tests/V2/Nurseries/AdminStatusNurseryControllerTest.php b/tests/V2/Nurseries/AdminStatusNurseryControllerTest.php index 68265b3c1..41ec3bc6a 100644 --- a/tests/V2/Nurseries/AdminStatusNurseryControllerTest.php +++ b/tests/V2/Nurseries/AdminStatusNurseryControllerTest.php @@ -7,8 +7,8 @@ use App\Models\V2\Organisation; use App\Models\V2\Projects\Project; use App\StateMachines\EntityStatusStateMachine; -use Illuminate\Support\Facades\Artisan; use Illuminate\Foundation\Testing\RefreshDatabase; +use Illuminate\Support\Facades\Artisan; use Tests\TestCase; class AdminStatusNurseryControllerTest extends TestCase diff --git a/tests/V2/Nurseries/SoftDeleteNurseryControllerTest.php b/tests/V2/Nurseries/SoftDeleteNurseryControllerTest.php index 1f0d55026..45e56b8be 100644 --- a/tests/V2/Nurseries/SoftDeleteNurseryControllerTest.php +++ b/tests/V2/Nurseries/SoftDeleteNurseryControllerTest.php @@ -6,7 +6,6 @@ use App\Models\V2\Nurseries\Nursery; use App\Models\V2\Nurseries\NurseryReport; use App\Models\V2\Projects\Project; -use App\Models\V2\Sites\Site; use App\StateMachines\EntityStatusStateMachine; use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\WithFaker; diff --git a/tests/V2/NurseryReports/AdminIndexNurseryReportsControllerTest.php b/tests/V2/NurseryReports/AdminIndexNurseryReportsControllerTest.php index 3d9339a6f..039c1175f 100644 --- a/tests/V2/NurseryReports/AdminIndexNurseryReportsControllerTest.php +++ b/tests/V2/NurseryReports/AdminIndexNurseryReportsControllerTest.php @@ -7,7 +7,7 @@ use App\Models\V2\Nurseries\NurseryReport; use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\WithFaker; - use Illuminate\Support\Facades\Artisan; +use Illuminate\Support\Facades\Artisan; use Tests\TestCase; class AdminIndexNurseryReportsControllerTest extends TestCase diff --git a/tests/V2/NurseryReports/AdminStatusNurseryReportControllerTest.php b/tests/V2/NurseryReports/AdminStatusNurseryReportControllerTest.php index 1ef026b80..a9727dc91 100644 --- a/tests/V2/NurseryReports/AdminStatusNurseryReportControllerTest.php +++ b/tests/V2/NurseryReports/AdminStatusNurseryReportControllerTest.php @@ -8,8 +8,8 @@ use App\Models\V2\Organisation; use App\Models\V2\Projects\Project; use App\StateMachines\EntityStatusStateMachine; -use Illuminate\Support\Facades\Artisan; use Illuminate\Foundation\Testing\RefreshDatabase; +use Illuminate\Support\Facades\Artisan; use Tests\TestCase; class AdminStatusNurseryReportControllerTest extends TestCase diff --git a/tests/V2/ProjectReports/AdminStatusProjectReportControllerTest.php b/tests/V2/ProjectReports/AdminStatusProjectReportControllerTest.php index b74fd4f4b..ab8734975 100644 --- a/tests/V2/ProjectReports/AdminStatusProjectReportControllerTest.php +++ b/tests/V2/ProjectReports/AdminStatusProjectReportControllerTest.php @@ -7,8 +7,8 @@ use App\Models\V2\Projects\Project; use App\Models\V2\Projects\ProjectReport; use App\StateMachines\EntityStatusStateMachine; -use Illuminate\Support\Facades\Artisan; use Illuminate\Foundation\Testing\RefreshDatabase; +use Illuminate\Support\Facades\Artisan; use Tests\TestCase; class AdminStatusProjectReportControllerTest extends TestCase diff --git a/tests/V2/ProjectReports/ViewProjectReportWithFormControllerTest.php b/tests/V2/ProjectReports/ViewProjectReportWithFormControllerTest.php index dee461325..1849ef59b 100644 --- a/tests/V2/ProjectReports/ViewProjectReportWithFormControllerTest.php +++ b/tests/V2/ProjectReports/ViewProjectReportWithFormControllerTest.php @@ -7,7 +7,6 @@ use App\Models\V2\Organisation; use App\Models\V2\Projects\Project; use App\Models\V2\Projects\ProjectReport; -use App\StateMachines\EntityStatusStateMachine; use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\WithFaker; use Illuminate\Support\Facades\Artisan; diff --git a/tests/V2/Projects/AdminStatusProjectControllerTest.php b/tests/V2/Projects/AdminStatusProjectControllerTest.php index 0c0376f5f..b79e85d0a 100644 --- a/tests/V2/Projects/AdminStatusProjectControllerTest.php +++ b/tests/V2/Projects/AdminStatusProjectControllerTest.php @@ -6,8 +6,8 @@ use App\Models\V2\Organisation; use App\Models\V2\Projects\Project; use App\StateMachines\EntityStatusStateMachine; -use Illuminate\Support\Facades\Artisan; use Illuminate\Foundation\Testing\RefreshDatabase; +use Illuminate\Support\Facades\Artisan; use Tests\TestCase; class AdminStatusProjectControllerTest extends TestCase diff --git a/tests/V2/Projects/ViewMyProjectsControllerTest.php b/tests/V2/Projects/ViewMyProjectsControllerTest.php index 011193e0c..35b215215 100644 --- a/tests/V2/Projects/ViewMyProjectsControllerTest.php +++ b/tests/V2/Projects/ViewMyProjectsControllerTest.php @@ -7,7 +7,7 @@ use App\Models\V2\Projects\Project; use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\WithFaker; - use Illuminate\Support\Facades\Artisan; +use Illuminate\Support\Facades\Artisan; use Tests\TestCase; class ViewMyProjectsControllerTest extends TestCase diff --git a/tests/V2/ReportingFrameworks/AdminIndexReportingFrameworkControllerTest.php b/tests/V2/ReportingFrameworks/AdminIndexReportingFrameworkControllerTest.php index 28d318960..ac5452c40 100644 --- a/tests/V2/ReportingFrameworks/AdminIndexReportingFrameworkControllerTest.php +++ b/tests/V2/ReportingFrameworks/AdminIndexReportingFrameworkControllerTest.php @@ -4,8 +4,8 @@ use App\Models\Framework; use App\Models\User; -use Illuminate\Support\Facades\Artisan; use Illuminate\Foundation\Testing\RefreshDatabase; +use Illuminate\Support\Facades\Artisan; use Tests\TestCase; class AdminIndexReportingFrameworkControllerTest extends TestCase diff --git a/tests/V2/ReportingFrameworks/UpdateReportingFrameworkControllerTest.php b/tests/V2/ReportingFrameworks/UpdateReportingFrameworkControllerTest.php index 52515b717..4fe00a885 100644 --- a/tests/V2/ReportingFrameworks/UpdateReportingFrameworkControllerTest.php +++ b/tests/V2/ReportingFrameworks/UpdateReportingFrameworkControllerTest.php @@ -8,8 +8,8 @@ use App\Models\V2\Forms\Form; use App\Models\V2\Projects\Project; use App\Models\V2\Projects\ProjectReport; -use Illuminate\Support\Facades\Artisan; use Illuminate\Foundation\Testing\RefreshDatabase; +use Illuminate\Support\Facades\Artisan; use Tests\TestCase; class UpdateReportingFrameworkControllerTest extends TestCase diff --git a/tests/V2/SiteReports/AdminStatusSiteReportControllerTest.php b/tests/V2/SiteReports/AdminStatusSiteReportControllerTest.php index a58d74d48..5d3f4e70d 100644 --- a/tests/V2/SiteReports/AdminStatusSiteReportControllerTest.php +++ b/tests/V2/SiteReports/AdminStatusSiteReportControllerTest.php @@ -6,10 +6,10 @@ use App\Models\V2\Organisation; use App\Models\V2\Projects\Project; use App\Models\V2\Sites\Site; -use App\StateMachines\EntityStatusStateMachine; -use Illuminate\Support\Facades\Artisan; use App\Models\V2\Sites\SiteReport; +use App\StateMachines\EntityStatusStateMachine; use Illuminate\Foundation\Testing\RefreshDatabase; +use Illuminate\Support\Facades\Artisan; use Tests\TestCase; class AdminStatusSiteReportControllerTest extends TestCase diff --git a/tests/V2/Sites/AdminStatusSiteControllerTest.php b/tests/V2/Sites/AdminStatusSiteControllerTest.php index 049dba79a..214df0522 100644 --- a/tests/V2/Sites/AdminStatusSiteControllerTest.php +++ b/tests/V2/Sites/AdminStatusSiteControllerTest.php @@ -5,10 +5,10 @@ use App\Models\User; use App\Models\V2\Organisation; use App\Models\V2\Projects\Project; -use App\StateMachines\EntityStatusStateMachine; -use Illuminate\Support\Facades\Artisan; use App\Models\V2\Sites\Site; +use App\StateMachines\EntityStatusStateMachine; use Illuminate\Foundation\Testing\RefreshDatabase; +use Illuminate\Support\Facades\Artisan; use Tests\TestCase; class AdminStatusSiteControllerTest extends TestCase diff --git a/tests/V2/Stratas/DeleteStrataControllerTest.php b/tests/V2/Stratas/DeleteStrataControllerTest.php index 29fae603d..bfe10012d 100644 --- a/tests/V2/Stratas/DeleteStrataControllerTest.php +++ b/tests/V2/Stratas/DeleteStrataControllerTest.php @@ -8,8 +8,8 @@ use App\Models\V2\Sites\Site; use App\Models\V2\Stratas\Strata; use App\StateMachines\EntityStatusStateMachine; -use Illuminate\Support\Facades\Artisan; use Illuminate\Foundation\Testing\RefreshDatabase; +use Illuminate\Support\Facades\Artisan; use Tests\TestCase; class DeleteStrataControllerTest extends TestCase diff --git a/tests/V2/Stratas/GetStratasForEntityControllerTest.php b/tests/V2/Stratas/GetStratasForEntityControllerTest.php index 395fd2608..f7a52729d 100644 --- a/tests/V2/Stratas/GetStratasForEntityControllerTest.php +++ b/tests/V2/Stratas/GetStratasForEntityControllerTest.php @@ -8,8 +8,8 @@ use App\Models\V2\Sites\Site; use App\Models\V2\Stratas\Strata; use App\StateMachines\EntityStatusStateMachine; -use Illuminate\Support\Facades\Artisan; use Illuminate\Foundation\Testing\RefreshDatabase; +use Illuminate\Support\Facades\Artisan; use Tests\TestCase; class GetStratasForEntityControllerTest extends TestCase diff --git a/tests/V2/Stratas/StoreStrataControllerTest.php b/tests/V2/Stratas/StoreStrataControllerTest.php index b826f0e94..a777a4d3d 100644 --- a/tests/V2/Stratas/StoreStrataControllerTest.php +++ b/tests/V2/Stratas/StoreStrataControllerTest.php @@ -7,8 +7,8 @@ use App\Models\V2\Projects\Project; use App\Models\V2\Sites\Site; use App\StateMachines\EntityStatusStateMachine; -use Illuminate\Support\Facades\Artisan; use Illuminate\Foundation\Testing\RefreshDatabase; +use Illuminate\Support\Facades\Artisan; use Tests\TestCase; class StoreStrataControllerTest extends TestCase diff --git a/tests/V2/Stratas/UpdateStrataControllerTest.php b/tests/V2/Stratas/UpdateStrataControllerTest.php index c54f6fc43..523a6ad65 100644 --- a/tests/V2/Stratas/UpdateStrataControllerTest.php +++ b/tests/V2/Stratas/UpdateStrataControllerTest.php @@ -8,8 +8,8 @@ use App\Models\V2\Sites\Site; use App\Models\V2\Stratas\Strata; use App\StateMachines\EntityStatusStateMachine; -use Illuminate\Support\Facades\Artisan; use Illuminate\Foundation\Testing\RefreshDatabase; +use Illuminate\Support\Facades\Artisan; use Tests\TestCase; class UpdateStrataControllerTest extends TestCase diff --git a/tests/V2/TreeSpecies/GetTreeSpeciesForEntityControllerTest.php b/tests/V2/TreeSpecies/GetTreeSpeciesForEntityControllerTest.php index a34dcb04c..9f4548a53 100644 --- a/tests/V2/TreeSpecies/GetTreeSpeciesForEntityControllerTest.php +++ b/tests/V2/TreeSpecies/GetTreeSpeciesForEntityControllerTest.php @@ -10,8 +10,8 @@ use App\Models\V2\Sites\Site; use App\Models\V2\Sites\SiteReport; use App\Models\V2\TreeSpecies\TreeSpecies; -use Illuminate\Support\Facades\Artisan; use Illuminate\Foundation\Testing\RefreshDatabase; +use Illuminate\Support\Facades\Artisan; use Tests\TestCase; class GetTreeSpeciesForEntityControllerTest extends TestCase diff --git a/tests/V2/UpdateRequests/AdminIndexUpdateRequestControllerTest.php b/tests/V2/UpdateRequests/AdminIndexUpdateRequestControllerTest.php index 7bf324a0e..c2bf87f7d 100644 --- a/tests/V2/UpdateRequests/AdminIndexUpdateRequestControllerTest.php +++ b/tests/V2/UpdateRequests/AdminIndexUpdateRequestControllerTest.php @@ -5,8 +5,8 @@ use App\Models\Framework; use App\Models\User; use App\Models\V2\UpdateRequests\UpdateRequest; -use Illuminate\Support\Facades\Artisan; use Illuminate\Foundation\Testing\RefreshDatabase; +use Illuminate\Support\Facades\Artisan; use Tests\TestCase; class AdminIndexUpdateRequestControllerTest extends TestCase diff --git a/tests/V2/UpdateRequests/AdminSoftDeleteUpdateRequestControllerTest.php b/tests/V2/UpdateRequests/AdminSoftDeleteUpdateRequestControllerTest.php index 050059da8..d7ec69a54 100644 --- a/tests/V2/UpdateRequests/AdminSoftDeleteUpdateRequestControllerTest.php +++ b/tests/V2/UpdateRequests/AdminSoftDeleteUpdateRequestControllerTest.php @@ -7,8 +7,8 @@ use App\Models\V2\Projects\Project; use App\Models\V2\Sites\Site; use App\Models\V2\UpdateRequests\UpdateRequest; -use Illuminate\Support\Facades\Artisan; use Illuminate\Foundation\Testing\RefreshDatabase; +use Illuminate\Support\Facades\Artisan; use Tests\TestCase; class AdminSoftDeleteUpdateRequestControllerTest extends TestCase diff --git a/tests/V2/UpdateRequests/AdminStatusUpdateRequestControllerTest.php b/tests/V2/UpdateRequests/AdminStatusUpdateRequestControllerTest.php index 23821cccb..6c8955acc 100644 --- a/tests/V2/UpdateRequests/AdminStatusUpdateRequestControllerTest.php +++ b/tests/V2/UpdateRequests/AdminStatusUpdateRequestControllerTest.php @@ -9,9 +9,9 @@ use App\Models\V2\Sites\Site; use App\Models\V2\UpdateRequests\UpdateRequest; use App\StateMachines\EntityStatusStateMachine; -use Illuminate\Support\Facades\Artisan; use App\StateMachines\UpdateRequestStatusStateMachine; use Illuminate\Foundation\Testing\RefreshDatabase; +use Illuminate\Support\Facades\Artisan; use Tests\TestCase; class AdminStatusUpdateRequestControllerTest extends TestCase diff --git a/tests/V2/UpdateRequests/AdminViewUpdateRequestControllerTest.php b/tests/V2/UpdateRequests/AdminViewUpdateRequestControllerTest.php index 00c705630..a329458e2 100644 --- a/tests/V2/UpdateRequests/AdminViewUpdateRequestControllerTest.php +++ b/tests/V2/UpdateRequests/AdminViewUpdateRequestControllerTest.php @@ -7,8 +7,8 @@ use App\Models\V2\Projects\Project; use App\Models\V2\Sites\Site; use App\Models\V2\UpdateRequests\UpdateRequest; -use Illuminate\Support\Facades\Artisan; use Illuminate\Foundation\Testing\RefreshDatabase; +use Illuminate\Support\Facades\Artisan; use Tests\TestCase; class AdminViewUpdateRequestControllerTest extends TestCase diff --git a/tests/V2/UpdateRequests/EntityUpdateRequestControllerTest.php b/tests/V2/UpdateRequests/EntityUpdateRequestControllerTest.php index c4a2e5094..8fe8e8573 100644 --- a/tests/V2/UpdateRequests/EntityUpdateRequestControllerTest.php +++ b/tests/V2/UpdateRequests/EntityUpdateRequestControllerTest.php @@ -7,8 +7,8 @@ use App\Models\V2\Projects\Project; use App\Models\V2\Sites\Site; use App\Models\V2\UpdateRequests\UpdateRequest; -use Illuminate\Support\Facades\Artisan; use Illuminate\Foundation\Testing\RefreshDatabase; +use Illuminate\Support\Facades\Artisan; use Tests\TestCase; class EntityUpdateRequestControllerTest extends TestCase diff --git a/tests/V2/User/CompleteActionControllerTest.php b/tests/V2/User/CompleteActionControllerTest.php index 88d66debe..4a51f00c1 100644 --- a/tests/V2/User/CompleteActionControllerTest.php +++ b/tests/V2/User/CompleteActionControllerTest.php @@ -4,8 +4,8 @@ use App\Models\User; use App\Models\V2\Action; -use Illuminate\Support\Facades\Artisan; use Illuminate\Foundation\Testing\RefreshDatabase; +use Illuminate\Support\Facades\Artisan; use Tests\TestCase; class CompleteActionControllerTest extends TestCase diff --git a/tests/V2/Workdays/GetWorkdaysForEntityControllerTest.php b/tests/V2/Workdays/GetWorkdaysForEntityControllerTest.php index f57b562f3..f6d94db26 100644 --- a/tests/V2/Workdays/GetWorkdaysForEntityControllerTest.php +++ b/tests/V2/Workdays/GetWorkdaysForEntityControllerTest.php @@ -9,8 +9,8 @@ use App\Models\V2\Sites\SiteReport; use App\Models\V2\Workdays\Workday; use App\StateMachines\EntityStatusStateMachine; -use Illuminate\Support\Facades\Artisan; use Illuminate\Foundation\Testing\RefreshDatabase; +use Illuminate\Support\Facades\Artisan; use Tests\TestCase; class GetWorkdaysForEntityControllerTest extends TestCase diff --git a/tests/V2/Workdays/StoreWorkdayControllerTest.php b/tests/V2/Workdays/StoreWorkdayControllerTest.php index c49570f05..2702018d7 100644 --- a/tests/V2/Workdays/StoreWorkdayControllerTest.php +++ b/tests/V2/Workdays/StoreWorkdayControllerTest.php @@ -7,10 +7,10 @@ use App\Models\V2\Projects\Project; use App\Models\V2\Sites\Site; use App\Models\V2\Sites\SiteReport; -use App\StateMachines\EntityStatusStateMachine; -use Illuminate\Support\Facades\Artisan; use App\Models\V2\Workdays\Workday; +use App\StateMachines\EntityStatusStateMachine; use Illuminate\Foundation\Testing\RefreshDatabase; +use Illuminate\Support\Facades\Artisan; use Tests\TestCase; class StoreWorkdayControllerTest extends TestCase diff --git a/tests/V2/Workdays/UpdateWorkdayControllerTest.php b/tests/V2/Workdays/UpdateWorkdayControllerTest.php index 51f94f2a7..2ae663330 100644 --- a/tests/V2/Workdays/UpdateWorkdayControllerTest.php +++ b/tests/V2/Workdays/UpdateWorkdayControllerTest.php @@ -9,8 +9,8 @@ use App\Models\V2\Sites\SiteReport; use App\Models\V2\Workdays\Workday; use App\StateMachines\EntityStatusStateMachine; -use Illuminate\Support\Facades\Artisan; use Illuminate\Foundation\Testing\RefreshDatabase; +use Illuminate\Support\Facades\Artisan; use Tests\TestCase; class UpdateWorkdayControllerTest extends TestCase From 3af2e8a563026414b9bad5f6bf06a1cdf13c4cf2 Mon Sep 17 00:00:00 2001 From: Nathan Curtis Date: Tue, 9 Apr 2024 10:47:24 -0700 Subject: [PATCH 19/44] [TM-785] `make test` now runs locally without overwriting the local dev db. --- .env.testing | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++ Makefile | 16 +++++++++--- 2 files changed, 82 insertions(+), 4 deletions(-) create mode 100644 .env.testing diff --git a/.env.testing b/.env.testing new file mode 100644 index 000000000..57154b920 --- /dev/null +++ b/.env.testing @@ -0,0 +1,70 @@ +APP_NAME=Laravel +APP_ENV=local +APP_KEY=base64:dGJr4Cs1jvRm98V15YvJhtrkkDiU4aXPK/0LAZhjSFA= +APP_DEBUG=true +APP_URL=http://127.0.0.1:8080 +APP_FRONT_END=http://localhost:3000 + +LOG_CHANNEL=stack + +DB_CONNECTION=mysql +DB_HOST=mariadb +DB_PORT=3306 +DB_DATABASE=terramatch_test +DB_USERNAME=wri +DB_PASSWORD=wri + +BROADCAST_DRIVER=log +CACHE_DRIVER=redis +QUEUE_CONNECTION=redis +SESSION_DRIVER=redis +SESSION_CONNECTION=default +SESSION_LIFETIME=120 + +SNS_PLATFORM_ARN_IOS=arn:aws:sns:us-west-2:123456789012:app/APNS/wri_rm_ios +SNS_PLATFORM_ARN_ANDROID=arn:aws:sns:us-west-2:123456789012:app/FCM/wri_rm_android +SNS_PREFIX=http://motocker:9911 +SNS_ENABLED=false + +REDIS_HOST=redis +REDIS_PASSWORD= +REDIS_PORT=6379 +REDIS_QUEUE_NAME=wri_test +REDIS_DB=0 +REDIS_CACHE_DB=1 + +MAIL_MAILER=smtp +MAIL_HOST=mailcatcher +MAIL_PORT=1025 +MAIL_USERNAME= +MAIL_PASSWORD= +MAIL_ENCRYPTION=null +MAIL_FROM_ADDRESS=noreply@terramatch.org +MAIL_FROM_NAME="WRI TerraMatch" + +AWS_ACCESS_KEY_ID=AKIABUVWH1HUD7YQZQAR +AWS_SECRET_ACCESS_KEY=PVMlDMep3/jLSz9GxPV3mTvH4JZynkf2BFeTu+i8 +AWS_DEFAULT_REGION=us-west-2 +AWS_BUCKET=wri +S3_PREFIX=http://minio:9000 +S3_BUCKET=wri + +PUSHER_APP_ID= +PUSHER_APP_KEY= +PUSHER_APP_SECRET= +PUSHER_APP_CLUSTER= + +MIX_PUSHER_APP_KEY= +MIX_PUSHER_APP_CLUSTER= + +JWT_SECRET=qu3sep4GKdbg6PiVPCKLKljHukXALorq6nLHDBOCSwvs6BrgE6zb8gPmZfrNspKt + +ELASTIC_TRANSCODER_PREFIX=http://elastictranscoder:2323 +ELASTIC_TRANSCODER_PIPELINE_ID=1111111111111-abcde1 +ELASTIC_TRANSCODER_PRESET_ID=1351620000001-000001 + +LOG_SLACK_WEBHOOK_URL= + +SENTRY_LARAVEL_DSN= + +TREE_SEARCH_API_URL= diff --git a/Makefile b/Makefile index 9a60c3bd5..16c33bf88 100644 --- a/Makefile +++ b/Makefile @@ -24,8 +24,14 @@ migrate-seed: docker-compose exec php php ./artisan migrate-services docker-compose exec php php ./artisan db:seed -test: migrate-seed - docker-compose exec php ./vendor/bin/php-cs-fixer fix -v --dry-run --stop-on-violation --using-cache=no +migrate-seed-test: + echo "create database if not exists terramatch_test;" | docker-compose exec -T mariadb mysql -h localhost -u root -proot + echo "grant all on terramatch_test.* to 'wri'@'%';" | docker-compose exec -T mariadb mysql -h localhost -u root -proot + docker-compose exec php php artisan --env=testing migrate:fresh + docker-compose exec php php artisan --env=testing migrate-services + docker-compose exec php php artisan --env=testing db:seed + +test: lint migrate-seed-test docker-compose exec php ./vendor/bin/phpunit test-single: @@ -33,11 +39,13 @@ test-single: ts: test-single -quick-test: migrate-seed - docker-compose exec php ./vendor/bin/php-cs-fixer fix -v --dry-run --stop-on-violation --using-cache=no +quick-test: lint migrate-seed-test docker-compose exec php ./vendor/bin/phpunit --exclude=skipPipeline,slow lint: + docker-compose exec php ./vendor/bin/php-cs-fixer fix -v --dry-run --stop-on-violation --using-cache=no + +lint-fix: docker-compose exec php ./vendor/bin/php-cs-fixer fix -v lint-test: From d78ba0584d3d076bd4b805866b85f6c7e8f509b9 Mon Sep 17 00:00:00 2001 From: Nathan Curtis Date: Tue, 9 Apr 2024 11:09:01 -0700 Subject: [PATCH 20/44] [TM-785] Experiment with initial workflow structure. --- .github/workflows/pr.yml | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 .github/workflows/pr.yml diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml new file mode 100644 index 000000000..69269f31e --- /dev/null +++ b/.github/workflows/pr.yml @@ -0,0 +1,9 @@ +name: lin-test-on-pull-request +on: workflow_dispatch +jobs: + lint-test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Build + run: make rebuild-with-composer From 5a4cb69d5c5dfa8b155920b871c630887d7d5d8c Mon Sep 17 00:00:00 2001 From: Nathan Curtis Date: Tue, 9 Apr 2024 11:42:16 -0700 Subject: [PATCH 21/44] [TM-785] Try a different command. --- .github/workflows/pr.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 69269f31e..f86bb0168 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -1,4 +1,4 @@ -name: lin-test-on-pull-request +name: lint-test-on-pull-request on: workflow_dispatch jobs: lint-test: @@ -6,4 +6,4 @@ jobs: steps: - uses: actions/checkout@v4 - name: Build - run: make rebuild-with-composer + run: make up From 7e8a968b91a4803f113a4a08e042544433180de0 Mon Sep 17 00:00:00 2001 From: Nathan Curtis Date: Tue, 9 Apr 2024 11:49:42 -0700 Subject: [PATCH 22/44] [TM-785] See if the simplest workflow will work --- .github/workflows/pr.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index f86bb0168..a0c7213c6 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -4,6 +4,5 @@ jobs: lint-test: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - - name: Build - run: make up + - name: Checkout + uses: actions/checkout@v4 From f1db14c82119ee20adb80abd28665950ebe942ec Mon Sep 17 00:00:00 2001 From: Nathan Curtis Date: Tue, 9 Apr 2024 11:58:50 -0700 Subject: [PATCH 23/44] [TM-785] See if I can get a default workflow from Github to work --- .github/workflows/docker-image.yml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 .github/workflows/docker-image.yml diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml new file mode 100644 index 000000000..4a79ebd56 --- /dev/null +++ b/.github/workflows/docker-image.yml @@ -0,0 +1,14 @@ +name: Docker Image CI + +on: workflow_dispatch + +jobs: + + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: Build the Docker image + run: docker build . --file Dockerfile --tag my-image-name:$(date +%s) From 6dca35d8155a59069ca467c7d60d34b07f524c60 Mon Sep 17 00:00:00 2001 From: Nathan Curtis Date: Tue, 9 Apr 2024 12:14:09 -0700 Subject: [PATCH 24/44] [TM-785] Delete .github/workflows directory --- .github/workflows/docker-image.yml | 14 -------------- .github/workflows/pr.yml | 8 -------- 2 files changed, 22 deletions(-) delete mode 100644 .github/workflows/docker-image.yml delete mode 100644 .github/workflows/pr.yml diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml deleted file mode 100644 index 4a79ebd56..000000000 --- a/.github/workflows/docker-image.yml +++ /dev/null @@ -1,14 +0,0 @@ -name: Docker Image CI - -on: workflow_dispatch - -jobs: - - build: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - - name: Build the Docker image - run: docker build . --file Dockerfile --tag my-image-name:$(date +%s) diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml deleted file mode 100644 index a0c7213c6..000000000 --- a/.github/workflows/pr.yml +++ /dev/null @@ -1,8 +0,0 @@ -name: lint-test-on-pull-request -on: workflow_dispatch -jobs: - lint-test: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v4 From 5818748007b2169543e128f5222d3650d9dfc05a Mon Sep 17 00:00:00 2001 From: Nathan Curtis Date: Tue, 9 Apr 2024 11:03:38 -0700 Subject: [PATCH 25/44] [TM-785] Github workflow to run tests. --- .github/workflows/pull-request.yml | 15 +++++++++++++++ Makefile | 10 +++++----- 2 files changed, 20 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/pull-request.yml diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml new file mode 100644 index 000000000..d7b52b16e --- /dev/null +++ b/.github/workflows/pull-request.yml @@ -0,0 +1,15 @@ +name: pull-request +on: + pull_request: + branches: [main, staging, release/**] +jobs: + lintTest: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Install deps + run: make composer + - name: Bring up Docker + run: make up + - name: Lint & Test + run: make test diff --git a/Makefile b/Makefile index 16c33bf88..0fdfff1ff 100644 --- a/Makefile +++ b/Makefile @@ -27,12 +27,12 @@ migrate-seed: migrate-seed-test: echo "create database if not exists terramatch_test;" | docker-compose exec -T mariadb mysql -h localhost -u root -proot echo "grant all on terramatch_test.* to 'wri'@'%';" | docker-compose exec -T mariadb mysql -h localhost -u root -proot - docker-compose exec php php artisan --env=testing migrate:fresh - docker-compose exec php php artisan --env=testing migrate-services - docker-compose exec php php artisan --env=testing db:seed + docker-compose exec -T php php artisan --env=testing migrate:fresh + docker-compose exec -T php php artisan --env=testing migrate-services + docker-compose exec -T php php artisan --env=testing db:seed test: lint migrate-seed-test - docker-compose exec php ./vendor/bin/phpunit + docker-compose exec -T php ./vendor/bin/phpunit test-single: docker-compose exec php ./vendor/bin/phpunit --filter $(t) @@ -43,7 +43,7 @@ quick-test: lint migrate-seed-test docker-compose exec php ./vendor/bin/phpunit --exclude=skipPipeline,slow lint: - docker-compose exec php ./vendor/bin/php-cs-fixer fix -v --dry-run --stop-on-violation --using-cache=no + docker-compose exec -T php ./vendor/bin/php-cs-fixer fix -v --dry-run --stop-on-violation --using-cache=no lint-fix: docker-compose exec php ./vendor/bin/php-cs-fixer fix -v From 2c171926d21414e32b9d91ddc5d2dcf82f889139 Mon Sep 17 00:00:00 2001 From: Nathan Curtis Date: Tue, 9 Apr 2024 15:38:55 -0700 Subject: [PATCH 26/44] Fix linting problem with new code from staging --- .../2024_01_08_160230_seed_options_list_siting_strategy.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/database/migrations/2024_01_08_160230_seed_options_list_siting_strategy.php b/database/migrations/2024_01_08_160230_seed_options_list_siting_strategy.php index f80af3230..fe732a261 100644 --- a/database/migrations/2024_01_08_160230_seed_options_list_siting_strategy.php +++ b/database/migrations/2024_01_08_160230_seed_options_list_siting_strategy.php @@ -7,8 +7,7 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Support\Str; -return new class extends Migration -{ +return new class extends Migration { /** * This migration seeds the default options * From b7e704ef74495af44578d7c64675c6c33cd061c2 Mon Sep 17 00:00:00 2001 From: Nathan Curtis Date: Wed, 10 Apr 2024 13:43:22 -0700 Subject: [PATCH 27/44] [TM-812] Streamline the process of updating from form values. --- .../UpdateEntityWithFormController.php | 3 +- .../AdminStatusUpdateRequestController.php | 3 +- app/Models/Traits/UsesLinkedFields.php | 49 ++++++++++--------- app/Models/V2/EntityModel.php | 2 +- 4 files changed, 29 insertions(+), 28 deletions(-) diff --git a/app/Http/Controllers/V2/Entities/UpdateEntityWithFormController.php b/app/Http/Controllers/V2/Entities/UpdateEntityWithFormController.php index 47ab6e431..cdaf5c3c6 100644 --- a/app/Http/Controllers/V2/Entities/UpdateEntityWithFormController.php +++ b/app/Http/Controllers/V2/Entities/UpdateEntityWithFormController.php @@ -28,8 +28,7 @@ public function __invoke(EntityModel $entity, UpdateFormSubmissionRequest $formS $updateRequest = $entity->updateRequests()->isUnapproved()->first(); $isAdmin = Auth::user()->can("framework-$entity->framework_key"); if ($entity->isEditable() || ($isAdmin && empty($updateRequest))) { - $config = data_get($entity->getFormConfig(), 'fields', []); - $entity->update($entity->mapEntityAnswers($answers, $form, $config)); + $entity->updateFromForm($answers); if ($entity instanceof ReportModel) { $entity->updateInProgress($isAdmin); } diff --git a/app/Http/Controllers/V2/UpdateRequests/AdminStatusUpdateRequestController.php b/app/Http/Controllers/V2/UpdateRequests/AdminStatusUpdateRequestController.php index c26483e28..e51e9faca 100644 --- a/app/Http/Controllers/V2/UpdateRequests/AdminStatusUpdateRequestController.php +++ b/app/Http/Controllers/V2/UpdateRequests/AdminStatusUpdateRequestController.php @@ -73,8 +73,7 @@ private function applyUpdates(UpdateRequest $updateRequest) { /** @var EntityModel $entity */ $entity = $updateRequest->updaterequestable; - $entityProps = $entity->mapEntityAnswers($updateRequest->content, $entity->getForm(), data_get($entity->getFormConfig(), 'fields', [])); - $entity->update($entityProps); + $entity->updateFromForm($updateRequest->content); } private function handleAction(StatusChangeRequest $request, UpdateRequest $updateRequest) diff --git a/app/Models/Traits/UsesLinkedFields.php b/app/Models/Traits/UsesLinkedFields.php index dd6dbe7dc..8bb520fb5 100644 --- a/app/Models/Traits/UsesLinkedFields.php +++ b/app/Models/Traits/UsesLinkedFields.php @@ -8,6 +8,27 @@ trait UsesLinkedFields { private ?Form $frameworkModelForm = null; + public function getForm(): Form + { + if (! is_null($this->form)) { + // Some classes that use this trait have a direct database link to the form. + return $this->form; + } + + if (is_null($this->frameworkModelForm)) { + $this->frameworkModelForm = Form::where('model', get_class($this)) + ->where('framework_key', $this->framework_key) + ->first(); + } + + return $this->frameworkModelForm; + } + + public function getFormConfig(): ?array + { + return config('wri.linked-fields.models.' . $this->shortName); + } + public function updateAllAnswers(array $input): array { $localAnswers = []; @@ -29,14 +50,16 @@ public function updateAllAnswers(array $input): array return $localAnswers; } - public function mapEntityAnswers(array $input, Form $form, array $cfg): array + public function updateFromForm(array $input): void { + $form = $this->getForm(); + $fieldsConfig = data_get($this->getFormConfig(), 'fields', []); $localAnswers = []; $entityProps = []; foreach ($form->sections as $section) { foreach ($section->questions as $question) { if ($question->input_type !== 'conditional') { - $fieldConfig = data_get($cfg, $question->linked_field_key); + $fieldConfig = data_get($fieldsConfig, $question->linked_field_key); $property = data_get($fieldConfig, 'property', null); $value = data_get($input, $question->uuid, null); @@ -54,7 +77,7 @@ public function mapEntityAnswers(array $input, Form $form, array $cfg): array } } - return $entityProps; + $this->update($entityProps); } public function calculateCompletion(Form $form): int @@ -208,24 +231,4 @@ private function updateLinkedFieldValue(array $linkedFieldInfo, $answer): void } } - public function getForm(): Form - { - if (! is_null($this->form)) { - // Some classes that use this trait have a direct database link to the form. - return $this->form; - } - - if (is_null($this->frameworkModelForm)) { - $this->frameworkModelForm = Form::where('model', get_class($this)) - ->where('framework_key', $this->framework_key) - ->first(); - } - - return $this->frameworkModelForm; - } - - public function getFormConfig(): ?array - { - return config('wri.linked-fields.models.' . $this->shortName); - } } diff --git a/app/Models/V2/EntityModel.php b/app/Models/V2/EntityModel.php index da34e27a9..eb4957056 100644 --- a/app/Models/V2/EntityModel.php +++ b/app/Models/V2/EntityModel.php @@ -19,7 +19,7 @@ public function getForm(): ?Form; public function getFormConfig(): ?array; - public function mapEntityAnswers(array $input, Form $form, array $cfg): array; + public function updateFromForm(array $formValues): array; public function createResource(): JsonResource; From f2fb2b674811b281629fbcdfc25e6d684ecf28cf Mon Sep 17 00:00:00 2001 From: Nathan Curtis Date: Thu, 11 Apr 2024 08:50:46 -0700 Subject: [PATCH 28/44] [TM-812] Include the form title on the form data so the entity edit page doesn't need to load the entity too. --- app/Http/Resources/V2/Entities/EntityWithSchemaResource.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/Http/Resources/V2/Entities/EntityWithSchemaResource.php b/app/Http/Resources/V2/Entities/EntityWithSchemaResource.php index 8414df20e..dbe1d9780 100644 --- a/app/Http/Resources/V2/Entities/EntityWithSchemaResource.php +++ b/app/Http/Resources/V2/Entities/EntityWithSchemaResource.php @@ -30,6 +30,7 @@ public function toArray($request) 'form' => (new FormResource($this->schema))->params($params), 'answers' => $this->getEntityAnswers($this->schema), 'status' => $this->status, + 'form_title' => $this->report_title ?? $this->title ?? $this->name, ]; } } From 337974d9f4f2f511cb10c2e51a0d2020147b74ad Mon Sep 17 00:00:00 2001 From: Nathan Curtis Date: Thu, 11 Apr 2024 09:38:25 -0700 Subject: [PATCH 29/44] [TM-812] Include update request data in the entity schema response for FE efficiency. --- app/Http/Resources/V2/Entities/EntityWithSchemaResource.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/Http/Resources/V2/Entities/EntityWithSchemaResource.php b/app/Http/Resources/V2/Entities/EntityWithSchemaResource.php index dbe1d9780..bff2e97c7 100644 --- a/app/Http/Resources/V2/Entities/EntityWithSchemaResource.php +++ b/app/Http/Resources/V2/Entities/EntityWithSchemaResource.php @@ -24,6 +24,7 @@ public function toArray($request) 'model' => $this, ]; + $updateRequest = $this->updateRequests()->isUnapproved()->select('uuid', 'content')->first(); return [ 'uuid' => $this->uuid, 'name' => $this->name, @@ -31,6 +32,11 @@ public function toArray($request) 'answers' => $this->getEntityAnswers($this->schema), 'status' => $this->status, 'form_title' => $this->report_title ?? $this->title ?? $this->name, + 'update_request' => [ + 'uuid' => $updateRequest?->uuid, + 'status' => $updateRequest?->status, + 'content' => $updateRequest?->content, + ] ]; } } From 792eef9fe6f48df77727612cb2a1898c9b217338 Mon Sep 17 00:00:00 2001 From: Nathan Curtis Date: Thu, 11 Apr 2024 09:43:18 -0700 Subject: [PATCH 30/44] [TM-812] Update docs --- openapi-src/V2/definitions/EntityFormRead.yml | 13 +++- resources/docs/swagger-v2.yml | 66 +++++++++++++++++++ 2 files changed, 78 insertions(+), 1 deletion(-) diff --git a/openapi-src/V2/definitions/EntityFormRead.yml b/openapi-src/V2/definitions/EntityFormRead.yml index ed58ac6fe..48b408bb9 100644 --- a/openapi-src/V2/definitions/EntityFormRead.yml +++ b/openapi-src/V2/definitions/EntityFormRead.yml @@ -10,4 +10,15 @@ properties: form: type: object answers: - type: object \ No newline at end of file + type: object + form_title: + type: string + update_request: + type: object + properties: + uuid: + type: string + status: + type: string + content: + type: object \ No newline at end of file diff --git a/resources/docs/swagger-v2.yml b/resources/docs/swagger-v2.yml index f5920a4ad..7b48511b9 100644 --- a/resources/docs/swagger-v2.yml +++ b/resources/docs/swagger-v2.yml @@ -160,6 +160,17 @@ definitions: type: object answers: type: object + form_title: + type: string + update_request: + type: object + properties: + uuid: + type: string + status: + type: string + content: + type: object UserRead: type: object properties: @@ -56871,6 +56882,17 @@ paths: type: object answers: type: object + form_title: + type: string + update_request: + type: object + properties: + uuid: + type: string + status: + type: string + content: + type: object put: operationId: put-v2-forms-entity-form-uuid summary: Update a specific entity using a form schema @@ -56922,6 +56944,17 @@ paths: type: object answers: type: object + form_title: + type: string + update_request: + type: object + properties: + uuid: + type: string + status: + type: string + content: + type: object '/v2/forms/{ENTITY}/{UUID}/submit': put: operationId: put-v2-forms-entity-form-uuid-submit @@ -56961,6 +56994,17 @@ paths: type: object answers: type: object + form_title: + type: string + update_request: + type: object + properties: + uuid: + type: string + status: + type: string + content: + type: object '/v2/forms/{ENTITY}': post: summary: Create an entity with a custom form @@ -57014,6 +57058,17 @@ paths: type: object answers: type: object + form_title: + type: string + update_request: + type: object + properties: + uuid: + type: string + status: + type: string + content: + type: object '/v2/forms/projects/{UUID}': post: summary: Create a project with a custom form @@ -57057,6 +57112,17 @@ paths: type: object answers: type: object + form_title: + type: string + update_request: + type: object + properties: + uuid: + type: string + status: + type: string + content: + type: object '/v2/projects/{UUID}/site-polygons': get: summary: Get the polygons (geojson) from all sites belonging to a specific project From cf92c77113a080ee9979839456bd0aa7f640902d Mon Sep 17 00:00:00 2001 From: Nathan Curtis Date: Thu, 11 Apr 2024 15:57:03 -0700 Subject: [PATCH 31/44] [TM-812] Implement tree species sync in form updates. --- .../UpdateEntityWithFormController.php | 7 +- .../V2/Entities/EntityWithSchemaResource.php | 24 +++---- app/Models/Traits/UsesLinkedFields.php | 58 ++++++++++++--- app/Models/V2/EntityModel.php | 2 +- openapi-src/V2/definitions/EntityFormRead.yml | 14 +++- resources/docs/swagger-v2.yml | 72 +++++++++++++++++++ 6 files changed, 147 insertions(+), 30 deletions(-) diff --git a/app/Http/Controllers/V2/Entities/UpdateEntityWithFormController.php b/app/Http/Controllers/V2/Entities/UpdateEntityWithFormController.php index cdaf5c3c6..6366dd2f3 100644 --- a/app/Http/Controllers/V2/Entities/UpdateEntityWithFormController.php +++ b/app/Http/Controllers/V2/Entities/UpdateEntityWithFormController.php @@ -4,7 +4,6 @@ use App\Http\Controllers\Controller; use App\Http\Requests\V2\Forms\UpdateFormSubmissionRequest; -use App\Http\Resources\V2\UpdateRequests\UpdateRequestResource; use App\Models\V2\EntityModel; use App\Models\V2\ReportModel; use App\Models\V2\UpdateRequests\UpdateRequest; @@ -33,13 +32,13 @@ public function __invoke(EntityModel $entity, UpdateFormSubmissionRequest $formS $entity->updateInProgress($isAdmin); } - return $entity->createResource(); + return $entity->createSchemaResource(); } if (! empty($updateRequest)) { $updateRequest->update([ 'content' => array_merge($updateRequest->content, $answers) ]); } else { - $updateRequest = UpdateRequest::create([ + UpdateRequest::create([ 'organisation_id' => $entity->organisation ? $entity->organisation->id : $entity->project->organisation_id, 'project_id' => $entity->project ? $entity->project->id : $entity->id, 'created_by_id' => Auth::user()->id, @@ -52,6 +51,6 @@ public function __invoke(EntityModel $entity, UpdateFormSubmissionRequest $formS $entity->update(['update_request_status' => UpdateRequestStatusStateMachine::DRAFT]); } - return new UpdateRequestResource($updateRequest); + return $entity->createSchemaResource(); } } diff --git a/app/Http/Resources/V2/Entities/EntityWithSchemaResource.php b/app/Http/Resources/V2/Entities/EntityWithSchemaResource.php index bff2e97c7..824cb1bee 100644 --- a/app/Http/Resources/V2/Entities/EntityWithSchemaResource.php +++ b/app/Http/Resources/V2/Entities/EntityWithSchemaResource.php @@ -9,14 +9,6 @@ class EntityWithSchemaResource extends JsonResource { - protected Form $schema; - - public function __construct(EntityModel $resource) - { - parent::__construct($resource); - $this->schema = $resource->getForm(); - } - public function toArray($request) { $params = [ @@ -28,14 +20,18 @@ public function toArray($request) return [ 'uuid' => $this->uuid, 'name' => $this->name, - 'form' => (new FormResource($this->schema))->params($params), - 'answers' => $this->getEntityAnswers($this->schema), + 'form' => (new FormResource($this->getForm()))->params($params), + 'answers' => $this->getEntityAnswers($this->getForm()), 'status' => $this->status, 'form_title' => $this->report_title ?? $this->title ?? $this->name, - 'update_request' => [ - 'uuid' => $updateRequest?->uuid, - 'status' => $updateRequest?->status, - 'content' => $updateRequest?->content, + 'feedback' => $this->feedback, + 'feedback_fields' => $this->feedback_fields, + 'update_request' => $updateRequest == null ? null : [ + 'uuid' => $updateRequest->uuid, + 'status' => $updateRequest->status, + 'content' => $updateRequest->content, + 'feedback' => $updateRequest->feedback, + 'feedback_fields' => $updateRequest->feedback_fields, ] ]; } diff --git a/app/Models/Traits/UsesLinkedFields.php b/app/Models/Traits/UsesLinkedFields.php index 8bb520fb5..b35a07012 100644 --- a/app/Models/Traits/UsesLinkedFields.php +++ b/app/Models/Traits/UsesLinkedFields.php @@ -50,28 +50,39 @@ public function updateAllAnswers(array $input): array return $localAnswers; } - public function updateFromForm(array $input): void + public function updateFromForm(array $formData): void { $form = $this->getForm(); - $fieldsConfig = data_get($this->getFormConfig(), 'fields', []); + $formConfig = $this->getFormConfig(); + $fieldsConfig = data_get($formConfig, 'fields', []); + $relationsConfig = data_get($formConfig, 'relations', []); $localAnswers = []; $entityProps = []; + foreach ($form->sections as $section) { foreach ($section->questions as $question) { if ($question->input_type !== 'conditional') { $fieldConfig = data_get($fieldsConfig, $question->linked_field_key); - $property = data_get($fieldConfig, 'property', null); - $value = data_get($input, $question->uuid, null); + if ($fieldConfig != null) { + $property = data_get($fieldConfig, 'property', null); + $value = data_get($formData, $question->uuid, null); - if (! is_null($value)) { - if (empty($property)) { - $localAnswers[$question->uuid] = data_get($input, $question->uuid); - } + if (! is_null($value)) { + if (empty($property)) { + $localAnswers[$question->uuid] = data_get($formData, $question->uuid); + } - $entityProps[$property] = $value; + $entityProps[$property] = $value; + } + } else { + $property = data_get($relationsConfig, "$question->linked_field_key.property"); + if (! empty($property)) { + $this->syncRelation($property, collect(data_get($formData, $question->uuid))); + } } + } else { - $localAnswers[$question->uuid] = data_get($input, $question->uuid, null); + $localAnswers[$question->uuid] = data_get($formData, $question->uuid, null); $entityProps['answers'] = $localAnswers; } } @@ -231,4 +242,31 @@ private function updateLinkedFieldValue(array $linkedFieldInfo, $answer): void } } + private function syncRelation(string $property, $data): void + { + // This will expand as we complete more tickets in TM-747, until eventually we support all form relations. + if ($property != 'treeSpecies') { + return; + } + + $this->$property()->whereNotIn('uuid', $data->pluck('uuid')->filter())->delete(); + + // This would be better as a bulk operation, but too much processing is required to make that feasible + // in Eloquent (upsert isn't supported on MorphMany, for instance), and these sets will always be small + // so doing them one at a time is OK. + $entries = $this->$property()->get(); + foreach ($data as $entry) { + $model = null; + if (! empty($entry['uuid'])) { + $model = $entries->firstWhere('uuid', $entry['uuid']); + } + if ($model != null) { + $model->update($entry); + } else { + // protection against updating a deleted entry + unset($entry['uuid']); + $this->$property()->create($entry); + } + } + } } diff --git a/app/Models/V2/EntityModel.php b/app/Models/V2/EntityModel.php index eb4957056..48c8092e2 100644 --- a/app/Models/V2/EntityModel.php +++ b/app/Models/V2/EntityModel.php @@ -19,7 +19,7 @@ public function getForm(): ?Form; public function getFormConfig(): ?array; - public function updateFromForm(array $formValues): array; + public function updateFromForm(array $formValues): void; public function createResource(): JsonResource; diff --git a/openapi-src/V2/definitions/EntityFormRead.yml b/openapi-src/V2/definitions/EntityFormRead.yml index 48b408bb9..781df1f7d 100644 --- a/openapi-src/V2/definitions/EntityFormRead.yml +++ b/openapi-src/V2/definitions/EntityFormRead.yml @@ -13,6 +13,12 @@ properties: type: object form_title: type: string + feedback: + type: string + feedback_fields: + type: array + items: + type: string update_request: type: object properties: @@ -21,4 +27,10 @@ properties: status: type: string content: - type: object \ No newline at end of file + type: object + feedback: + type: string + feedback_fields: + type: array + items: + type: string \ No newline at end of file diff --git a/resources/docs/swagger-v2.yml b/resources/docs/swagger-v2.yml index 7b48511b9..787fdfa04 100644 --- a/resources/docs/swagger-v2.yml +++ b/resources/docs/swagger-v2.yml @@ -162,6 +162,12 @@ definitions: type: object form_title: type: string + feedback: + type: string + feedback_fields: + type: array + items: + type: string update_request: type: object properties: @@ -171,6 +177,12 @@ definitions: type: string content: type: object + feedback: + type: string + feedback_fields: + type: array + items: + type: string UserRead: type: object properties: @@ -56884,6 +56896,12 @@ paths: type: object form_title: type: string + feedback: + type: string + feedback_fields: + type: array + items: + type: string update_request: type: object properties: @@ -56893,6 +56911,12 @@ paths: type: string content: type: object + feedback: + type: string + feedback_fields: + type: array + items: + type: string put: operationId: put-v2-forms-entity-form-uuid summary: Update a specific entity using a form schema @@ -56946,6 +56970,12 @@ paths: type: object form_title: type: string + feedback: + type: string + feedback_fields: + type: array + items: + type: string update_request: type: object properties: @@ -56955,6 +56985,12 @@ paths: type: string content: type: object + feedback: + type: string + feedback_fields: + type: array + items: + type: string '/v2/forms/{ENTITY}/{UUID}/submit': put: operationId: put-v2-forms-entity-form-uuid-submit @@ -56996,6 +57032,12 @@ paths: type: object form_title: type: string + feedback: + type: string + feedback_fields: + type: array + items: + type: string update_request: type: object properties: @@ -57005,6 +57047,12 @@ paths: type: string content: type: object + feedback: + type: string + feedback_fields: + type: array + items: + type: string '/v2/forms/{ENTITY}': post: summary: Create an entity with a custom form @@ -57060,6 +57108,12 @@ paths: type: object form_title: type: string + feedback: + type: string + feedback_fields: + type: array + items: + type: string update_request: type: object properties: @@ -57069,6 +57123,12 @@ paths: type: string content: type: object + feedback: + type: string + feedback_fields: + type: array + items: + type: string '/v2/forms/projects/{UUID}': post: summary: Create a project with a custom form @@ -57114,6 +57174,12 @@ paths: type: object form_title: type: string + feedback: + type: string + feedback_fields: + type: array + items: + type: string update_request: type: object properties: @@ -57123,6 +57189,12 @@ paths: type: string content: type: object + feedback: + type: string + feedback_fields: + type: array + items: + type: string '/v2/projects/{UUID}/site-polygons': get: summary: Get the polygons (geojson) from all sites belonging to a specific project From 4223664fc55d1ea3a2336d8267b45cef1b8c4b69 Mon Sep 17 00:00:00 2001 From: Nathan Curtis Date: Fri, 12 Apr 2024 10:26:09 -0700 Subject: [PATCH 32/44] [TM-812] Remove the tree species mutation endpoints. --- .../DeleteTreeSpeciesController.php | 19 --- .../StoreTreeSpeciesController.php | 61 ------- .../UpdateTreeSpeciesController.php | 20 --- .../Requests/UpdateTreeSpeciesRequest.php | 96 ----------- .../TreeSpecies/StoreTreeSpeciesRequest.php | 24 --- .../TreeSpecies/UpdateTreeSpeciesRequest.php | 22 --- .../V2/Entities/EntityWithSchemaResource.php | 5 +- .../V2/definitions/V2TreeSpeciesCreate.yml | 17 -- .../V2/definitions/V2TreeSpeciesUpdate.yml | 13 -- openapi-src/V2/definitions/_index.yml | 4 - openapi-src/V2/paths/_index.yml | 51 ------ resources/docs/swagger-v2.yml | 155 ------------------ routes/api_v2.php | 6 - .../DeleteTreeSpeciesControllerTest.php | 41 ----- .../StoreTreeSpeciesControllerTest.php | 50 ------ .../UpdateTreeSpeciesControllerTest.php | 55 ------- 16 files changed, 2 insertions(+), 637 deletions(-) delete mode 100644 app/Http/Controllers/V2/TreeSpecies/DeleteTreeSpeciesController.php delete mode 100644 app/Http/Controllers/V2/TreeSpecies/StoreTreeSpeciesController.php delete mode 100644 app/Http/Controllers/V2/TreeSpecies/UpdateTreeSpeciesController.php delete mode 100644 app/Http/Requests/UpdateTreeSpeciesRequest.php delete mode 100644 app/Http/Requests/V2/TreeSpecies/StoreTreeSpeciesRequest.php delete mode 100644 app/Http/Requests/V2/TreeSpecies/UpdateTreeSpeciesRequest.php delete mode 100644 openapi-src/V2/definitions/V2TreeSpeciesCreate.yml delete mode 100644 openapi-src/V2/definitions/V2TreeSpeciesUpdate.yml delete mode 100644 tests/V2/TreeSpecies/DeleteTreeSpeciesControllerTest.php delete mode 100644 tests/V2/TreeSpecies/StoreTreeSpeciesControllerTest.php delete mode 100644 tests/V2/TreeSpecies/UpdateTreeSpeciesControllerTest.php diff --git a/app/Http/Controllers/V2/TreeSpecies/DeleteTreeSpeciesController.php b/app/Http/Controllers/V2/TreeSpecies/DeleteTreeSpeciesController.php deleted file mode 100644 index 2298c9052..000000000 --- a/app/Http/Controllers/V2/TreeSpecies/DeleteTreeSpeciesController.php +++ /dev/null @@ -1,19 +0,0 @@ -authorize('update', $treeSpecies->speciesable); - $treeSpecies->delete(); - $treeSpecies->save(); - - return new TreeSpeciesResource($treeSpecies); - } -} diff --git a/app/Http/Controllers/V2/TreeSpecies/StoreTreeSpeciesController.php b/app/Http/Controllers/V2/TreeSpecies/StoreTreeSpeciesController.php deleted file mode 100644 index 649bff579..000000000 --- a/app/Http/Controllers/V2/TreeSpecies/StoreTreeSpeciesController.php +++ /dev/null @@ -1,61 +0,0 @@ -getEntityFromRequest($storeTreeSpeciesRequest); - $this->authorize('read', $model); - - $storeTreeSpeciesRequest->merge([ - 'speciesable_type' => get_class($model), - 'speciesable_id' => $model->id, - ]); - - $treeSpecies = TreeSpecies::create($storeTreeSpeciesRequest->all()); - - return new TreeSpeciesResource($treeSpecies); - } - - private function getEntityFromRequest(StoreTreeSpeciesRequest $request) - { - switch ($request->get('model_type')) { - case 'organisation': - return Organisation::isUuid($request->get('model_uuid'))->firstOrFail(); - case 'project-pitch': - return ProjectPitch::isUuid($request->get('model_uuid'))->firstOrFail(); - case 'project': - return Project::isUuid($request->get('model_uuid'))->firstOrFail(); - case 'project-report': - return ProjectReport::isUuid($request->get('model_uuid'))->firstOrFail(); - case 'site': - return Site::isUuid($request->get('model_uuid'))->firstOrFail(); - case 'site-report': - return SiteReport::isUuid($request->get('model_uuid'))->firstOrFail(); - case 'nursery': - return Nursery::isUuid($request->get('model_uuid'))->firstOrFail(); - case 'nursery-report': - return NurseryReport::isUuid($request->get('model_uuid'))->firstOrFail(); - default: - throw new InvalidMorphableModelException(); - } - - return $request; - } -} diff --git a/app/Http/Controllers/V2/TreeSpecies/UpdateTreeSpeciesController.php b/app/Http/Controllers/V2/TreeSpecies/UpdateTreeSpeciesController.php deleted file mode 100644 index 2600aff77..000000000 --- a/app/Http/Controllers/V2/TreeSpecies/UpdateTreeSpeciesController.php +++ /dev/null @@ -1,20 +0,0 @@ -authorize('read', $treeSpecies->speciesable); - $treeSpecies->update($updateTreeSpeciesRequest->validated()); - $treeSpecies->save(); - - return new TreeSpeciesResource($treeSpecies); - } -} diff --git a/app/Http/Requests/UpdateTreeSpeciesRequest.php b/app/Http/Requests/UpdateTreeSpeciesRequest.php deleted file mode 100644 index f9cee1536..000000000 --- a/app/Http/Requests/UpdateTreeSpeciesRequest.php +++ /dev/null @@ -1,96 +0,0 @@ - [ - 'sometimes', - 'required', - 'string', - 'between:1,255', - ], - 'is_native' => [ - 'sometimes', - 'required', - 'boolean', - ], - 'count' => [ - 'sometimes', - 'required', - 'integer', - 'between:0,2147483647', - ], - 'price_to_plant' => [ - 'sometimes', - 'required', - 'numeric', - 'between:0,999999', - ], - 'price_to_maintain' => [ - 'sometimes', - 'required', - 'numeric', - 'between:0,999999', - ], - 'saplings' => [ - 'sometimes', - 'required', - 'numeric', - 'between:0,999999', - ], - 'site_prep' => [ - 'sometimes', - 'required', - 'numeric', - 'between:0,999999', - ], - 'survival_rate' => [ - 'sometimes', - 'present', - 'nullable', - 'integer', - 'between:0,100', - ], - 'produces_food' => [ - 'sometimes', - 'present', - 'nullable', - 'boolean', - ], - 'produces_firewood' => [ - 'sometimes', - 'present', - 'nullable', - 'boolean', - ], - 'produces_timber' => [ - 'sometimes', - 'present', - 'nullable', - 'boolean', - ], - 'owner' => [ - 'sometimes', - 'present', - 'nullable', - 'string', - 'between:1,255', - ], - 'season' => [ - 'sometimes', - 'required', - 'string', - 'between:1,255', - ], - ]; - } -} diff --git a/app/Http/Requests/V2/TreeSpecies/StoreTreeSpeciesRequest.php b/app/Http/Requests/V2/TreeSpecies/StoreTreeSpeciesRequest.php deleted file mode 100644 index 7eea35aba..000000000 --- a/app/Http/Requests/V2/TreeSpecies/StoreTreeSpeciesRequest.php +++ /dev/null @@ -1,24 +0,0 @@ - 'required|string|in:organisation,project-pitch,site,site-report,project,project-report,nursery,nursery-report', - 'model_uuid' => 'required|string', - 'name' => 'sometimes|nullable|string|between:1,255', - 'amount' => 'sometimes|nullable|integer|between:0,2147483647', - 'type' => 'sometimes|nullable|string', - 'collection' => 'sometimes|nullable|string|in:' . implode(',', array_keys(TreeSpecies::$collections)), - ]; - } -} diff --git a/app/Http/Requests/V2/TreeSpecies/UpdateTreeSpeciesRequest.php b/app/Http/Requests/V2/TreeSpecies/UpdateTreeSpeciesRequest.php deleted file mode 100644 index 478c8ca6f..000000000 --- a/app/Http/Requests/V2/TreeSpecies/UpdateTreeSpeciesRequest.php +++ /dev/null @@ -1,22 +0,0 @@ - 'sometimes|nullable|string|between:1,255', - 'amount' => 'sometimes|nullable|integer|between:0,2147483647', - 'type' => 'sometimes|nullable|string', - 'collection' => 'sometimes|nullable|string|in:' . implode(',', array_keys(TreeSpecies::$collections)), - ]; - } -} diff --git a/app/Http/Resources/V2/Entities/EntityWithSchemaResource.php b/app/Http/Resources/V2/Entities/EntityWithSchemaResource.php index 824cb1bee..37778a04e 100644 --- a/app/Http/Resources/V2/Entities/EntityWithSchemaResource.php +++ b/app/Http/Resources/V2/Entities/EntityWithSchemaResource.php @@ -3,8 +3,6 @@ namespace App\Http\Resources\V2\Entities; use App\Http\Resources\V2\Forms\FormResource; -use App\Models\V2\EntityModel; -use App\Models\V2\Forms\Form; use Illuminate\Http\Resources\Json\JsonResource; class EntityWithSchemaResource extends JsonResource @@ -17,6 +15,7 @@ public function toArray($request) ]; $updateRequest = $this->updateRequests()->isUnapproved()->select('uuid', 'content')->first(); + return [ 'uuid' => $this->uuid, 'name' => $this->name, @@ -32,7 +31,7 @@ public function toArray($request) 'content' => $updateRequest->content, 'feedback' => $updateRequest->feedback, 'feedback_fields' => $updateRequest->feedback_fields, - ] + ], ]; } } diff --git a/openapi-src/V2/definitions/V2TreeSpeciesCreate.yml b/openapi-src/V2/definitions/V2TreeSpeciesCreate.yml deleted file mode 100644 index d99c5dd45..000000000 --- a/openapi-src/V2/definitions/V2TreeSpeciesCreate.yml +++ /dev/null @@ -1,17 +0,0 @@ -title: V2TreeSpeciesCreate -x-stoplight: - id: 5wwltusko93cr -type: object -properties: - model_type: - type: string - model_uuid: - type: integer - name: - type: string - amount: - type: integer - type: - type: string - collection: - type: string \ No newline at end of file diff --git a/openapi-src/V2/definitions/V2TreeSpeciesUpdate.yml b/openapi-src/V2/definitions/V2TreeSpeciesUpdate.yml deleted file mode 100644 index 994ab7959..000000000 --- a/openapi-src/V2/definitions/V2TreeSpeciesUpdate.yml +++ /dev/null @@ -1,13 +0,0 @@ -title: V2TreeSpeciesUpdate -x-stoplight: - id: cp2imcqm79i8w -type: object -properties: - name: - type: string - amount: - type: integer - type: - type: string - collection: - type: string \ No newline at end of file diff --git a/openapi-src/V2/definitions/_index.yml b/openapi-src/V2/definitions/_index.yml index f994f9cd0..0ccdfea3b 100644 --- a/openapi-src/V2/definitions/_index.yml +++ b/openapi-src/V2/definitions/_index.yml @@ -86,12 +86,8 @@ V2FileGallery: $ref: './V2FileGallery.yml' V2FileGalleryLite: $ref: './V2FileGalleryLite.yml' -V2TreeSpeciesCreate: - $ref: './V2TreeSpeciesCreate.yml' V2TreeSpeciesRead: $ref: './V2TreeSpeciesRead.yml' -V2TreeSpeciesUpdate: - $ref: './V2TreeSpeciesUpdate.yml' V2CoreTeamLeaderCreate: $ref: './V2CoreTeamLeaderCreate.yml' V2CoreTeamLeaderRead: diff --git a/openapi-src/V2/paths/_index.yml b/openapi-src/V2/paths/_index.yml index 3dfff4f7c..d96c9f717 100644 --- a/openapi-src/V2/paths/_index.yml +++ b/openapi-src/V2/paths/_index.yml @@ -934,57 +934,6 @@ responses: '200': description: OK -/v2/tree-species: - post: - summary: Create a tree species - operationId: post-v2-tree-species - responses: - '201': - description: Created - schema: - $ref: '../definitions/_index.yml#/V2TreeSpeciesRead' - parameters: - - in: body - name: body - schema: - $ref: '../definitions/_index.yml#/V2TreeSpeciesCreate' - tags: - - V2 Tree Species -'/v2/tree-species/{UUID}': - patch: - summary: Update a tree species - operationId: patch-v2-tree-species-UUID - responses: - '200': - description: OK - schema: - $ref: '../definitions/_index.yml#/V2TreeSpeciesCreate' - tags: - - V2 Tree Species - parameters: - - type: string - name: UUID - in: path - required: true - - in: body - name: body - schema: - $ref: '../definitions/_index.yml#/V2TreeSpeciesUpdate' - delete: - summary: Delete a tree species - operationId: delete-v2-tree-species-UUID - parameters: - - type: string - name: UUID - in: path - required: true - responses: - '200': - description: OK - schema: - $ref: '../definitions/_index.yml#/V2TreeSpeciesRead' - tags: - - V2 Tree Species /v2/funding-type: post: summary: Create a funding type entry diff --git a/resources/docs/swagger-v2.yml b/resources/docs/swagger-v2.yml index 787fdfa04..2c95f725b 100644 --- a/resources/docs/swagger-v2.yml +++ b/resources/docs/swagger-v2.yml @@ -7358,24 +7358,6 @@ definitions: type: number lng: type: number - V2TreeSpeciesCreate: - title: V2TreeSpeciesCreate - x-stoplight: - id: 5wwltusko93cr - type: object - properties: - model_type: - type: string - model_uuid: - type: integer - name: - type: string - amount: - type: integer - type: - type: string - collection: - type: string V2TreeSpeciesRead: title: V2TreeSpeciesRead x-stoplight: @@ -7392,20 +7374,6 @@ definitions: type: string collection: type: string - V2TreeSpeciesUpdate: - title: V2TreeSpeciesUpdate - x-stoplight: - id: cp2imcqm79i8w - type: object - properties: - name: - type: string - amount: - type: integer - type: - type: string - collection: - type: string V2CoreTeamLeaderCreate: title: V2CoreTeamLeaderCreate type: object @@ -69874,129 +69842,6 @@ paths: responses: '200': description: OK - /v2/tree-species: - post: - summary: Create a tree species - operationId: post-v2-tree-species - responses: - '201': - description: Created - schema: - title: V2TreeSpeciesRead - x-stoplight: - id: 04vvsvyndvy8n - type: object - properties: - uuid: - type: string - name: - type: string - amount: - type: integer - type: - type: string - collection: - type: string - parameters: - - in: body - name: body - schema: - title: V2TreeSpeciesCreate - x-stoplight: - id: 5wwltusko93cr - type: object - properties: - model_type: - type: string - model_uuid: - type: integer - name: - type: string - amount: - type: integer - type: - type: string - collection: - type: string - tags: - - V2 Tree Species - '/v2/tree-species/{UUID}': - patch: - summary: Update a tree species - operationId: patch-v2-tree-species-UUID - responses: - '200': - description: OK - schema: - title: V2TreeSpeciesCreate - x-stoplight: - id: 5wwltusko93cr - type: object - properties: - model_type: - type: string - model_uuid: - type: integer - name: - type: string - amount: - type: integer - type: - type: string - collection: - type: string - tags: - - V2 Tree Species - parameters: - - type: string - name: UUID - in: path - required: true - - in: body - name: body - schema: - title: V2TreeSpeciesUpdate - x-stoplight: - id: cp2imcqm79i8w - type: object - properties: - name: - type: string - amount: - type: integer - type: - type: string - collection: - type: string - delete: - summary: Delete a tree species - operationId: delete-v2-tree-species-UUID - parameters: - - type: string - name: UUID - in: path - required: true - responses: - '200': - description: OK - schema: - title: V2TreeSpeciesRead - x-stoplight: - id: 04vvsvyndvy8n - type: object - properties: - uuid: - type: string - name: - type: string - amount: - type: integer - type: - type: string - collection: - type: string - tags: - - V2 Tree Species /v2/funding-type: post: summary: Create a funding type entry diff --git a/routes/api_v2.php b/routes/api_v2.php index d9db5bfd0..10445c3a5 100644 --- a/routes/api_v2.php +++ b/routes/api_v2.php @@ -170,10 +170,7 @@ use App\Http\Controllers\V2\Tasks\AdminIndexTasksController; use App\Http\Controllers\V2\Tasks\SubmitProjectTasksController; use App\Http\Controllers\V2\Tasks\ViewTaskController; -use App\Http\Controllers\V2\TreeSpecies\DeleteTreeSpeciesController; use App\Http\Controllers\V2\TreeSpecies\GetTreeSpeciesForEntityController; -use App\Http\Controllers\V2\TreeSpecies\StoreTreeSpeciesController; -use App\Http\Controllers\V2\TreeSpecies\UpdateTreeSpeciesController; use App\Http\Controllers\V2\UpdateRequests\AdminIndexUpdateRequestsController; use App\Http\Controllers\V2\UpdateRequests\AdminSoftDeleteUpdateRequestController; use App\Http\Controllers\V2\UpdateRequests\AdminStatusUpdateRequestController; @@ -459,9 +456,6 @@ }); Route::prefix('tree-species')->group(function () { - Route::post('/', StoreTreeSpeciesController::class); - Route::patch('/{treeSpecies}', UpdateTreeSpeciesController::class); - Route::delete('/{treeSpecies}', DeleteTreeSpeciesController::class); Route::get('/{entity}/{uuid}', GetTreeSpeciesForEntityController::class); }); diff --git a/tests/V2/TreeSpecies/DeleteTreeSpeciesControllerTest.php b/tests/V2/TreeSpecies/DeleteTreeSpeciesControllerTest.php deleted file mode 100644 index fe86acb65..000000000 --- a/tests/V2/TreeSpecies/DeleteTreeSpeciesControllerTest.php +++ /dev/null @@ -1,41 +0,0 @@ -admin()->create(); - $treeSpecies = TreeSpecies::factory()->create([ - 'speciesable_type' => Organisation::class, - 'speciesable_id' => $user->organisation_id, - ]); - - $this->actingAs($user) - ->deleteJson('/api/v2/tree-species/' . $treeSpecies->uuid) - ->assertStatus(200); - } - - public function test_user_cannot_delete_tree_species_for_other_organisation(): void - { - $user = User::factory()->create(); - $organisation = Organisation::factory()->create(); - $treeSpecies = TreeSpecies::factory()->create([ - 'speciesable_type' => Organisation::class, - 'speciesable_id' => $organisation->id, - ]); - - $this->actingAs($user) - ->deleteJson('/api/v2/tree-species/' . $treeSpecies->uuid) - ->assertStatus(403); - } -} diff --git a/tests/V2/TreeSpecies/StoreTreeSpeciesControllerTest.php b/tests/V2/TreeSpecies/StoreTreeSpeciesControllerTest.php deleted file mode 100644 index 133ce459b..000000000 --- a/tests/V2/TreeSpecies/StoreTreeSpeciesControllerTest.php +++ /dev/null @@ -1,50 +0,0 @@ -create(); - - $payload = [ - 'model_type' => 'organisation', - 'model_uuid' => $user->organisation->uuid, - 'amount' => 100, - 'name' => 'tree species', - ]; - - $this->actingAs($user) - ->postJson('/api/v2/tree-species', $payload) - ->assertStatus(201) - ->assertJsonFragment([ - 'amount' => 100, - 'name' => 'tree species', - ]); - } - - public function test_user_cannot_create_tree_species_for_other_organisation(): void - { - $user = User::factory()->create(); - $organisation = Organisation::factory()->create(); - - $payload = [ - 'model_type' => 'organisation', - 'model_uuid' => $organisation->uuid, - 'amount' => 100, - 'name' => 'tree species', - ]; - - $this->actingAs($user) - ->postJson('/api/v2/tree-species', $payload) - ->assertStatus(403); - } -} diff --git a/tests/V2/TreeSpecies/UpdateTreeSpeciesControllerTest.php b/tests/V2/TreeSpecies/UpdateTreeSpeciesControllerTest.php deleted file mode 100644 index b12318f7c..000000000 --- a/tests/V2/TreeSpecies/UpdateTreeSpeciesControllerTest.php +++ /dev/null @@ -1,55 +0,0 @@ -create(); - $treeSpecies = TreeSpecies::factory()->create([ - 'speciesable_type' => Organisation::class, - 'speciesable_id' => $user->organisation_id, - ]); - - $payload = [ - 'amount' => 100, - 'name' => 'tree species', - ]; - - $this->actingAs($user) - ->patchJson('/api/v2/tree-species/' . $treeSpecies->uuid, $payload) - ->assertStatus(200) - ->assertJsonFragment([ - 'amount' => 100, - 'name' => 'tree species', - ]); - } - - public function test_user_cannot_update_tree_species_for_other_organisation(): void - { - $user = User::factory()->create(); - $organisation = Organisation::factory()->create(); - $treeSpecies = TreeSpecies::factory()->create([ - 'speciesable_type' => Organisation::class, - 'speciesable_id' => $organisation->id, - ]); - - $payload = [ - 'amount' => 100, - 'name' => 'tree species', - ]; - - $this->actingAs($user) - ->patchJson('/api/v2/tree-species/' . $treeSpecies->uuid, $payload) - ->assertStatus(403); - } -} From c58925afb056f4088e445ffd1a318ee68e742875 Mon Sep 17 00:00:00 2001 From: Nathan Curtis Date: Fri, 12 Apr 2024 22:46:07 -0700 Subject: [PATCH 33/44] [TM-812] Include the full update request resource on the EntityWithSchemaResource. --- .../V2/Entities/EntityWithSchemaResource.php | 11 +- openapi-src/V2/definitions/EntityFormRead.yml | 15 +-- .../V2/definitions/UpdateRequestRead.yml | 6 +- resources/docs/swagger-v2.yml | 102 ++++++++++++++++-- 4 files changed, 101 insertions(+), 33 deletions(-) diff --git a/app/Http/Resources/V2/Entities/EntityWithSchemaResource.php b/app/Http/Resources/V2/Entities/EntityWithSchemaResource.php index 37778a04e..add33db9b 100644 --- a/app/Http/Resources/V2/Entities/EntityWithSchemaResource.php +++ b/app/Http/Resources/V2/Entities/EntityWithSchemaResource.php @@ -3,6 +3,7 @@ namespace App\Http\Resources\V2\Entities; use App\Http\Resources\V2\Forms\FormResource; +use App\Http\Resources\V2\UpdateRequests\UpdateRequestResource; use Illuminate\Http\Resources\Json\JsonResource; class EntityWithSchemaResource extends JsonResource @@ -14,7 +15,7 @@ public function toArray($request) 'model' => $this, ]; - $updateRequest = $this->updateRequests()->isUnapproved()->select('uuid', 'content')->first(); + $updateRequest = $this->updateRequests()->isUnapproved()->first(); return [ 'uuid' => $this->uuid, @@ -25,13 +26,7 @@ public function toArray($request) 'form_title' => $this->report_title ?? $this->title ?? $this->name, 'feedback' => $this->feedback, 'feedback_fields' => $this->feedback_fields, - 'update_request' => $updateRequest == null ? null : [ - 'uuid' => $updateRequest->uuid, - 'status' => $updateRequest->status, - 'content' => $updateRequest->content, - 'feedback' => $updateRequest->feedback, - 'feedback_fields' => $updateRequest->feedback_fields, - ], + 'update_request' => $updateRequest == null ? null : new UpdateRequestResource($updateRequest), ]; } } diff --git a/openapi-src/V2/definitions/EntityFormRead.yml b/openapi-src/V2/definitions/EntityFormRead.yml index 781df1f7d..2e41e5e3f 100644 --- a/openapi-src/V2/definitions/EntityFormRead.yml +++ b/openapi-src/V2/definitions/EntityFormRead.yml @@ -20,17 +20,4 @@ properties: items: type: string update_request: - type: object - properties: - uuid: - type: string - status: - type: string - content: - type: object - feedback: - type: string - feedback_fields: - type: array - items: - type: string \ No newline at end of file + $ref: './UpdateRequestRead.yml' \ No newline at end of file diff --git a/openapi-src/V2/definitions/UpdateRequestRead.yml b/openapi-src/V2/definitions/UpdateRequestRead.yml index 56986d99e..7cac990d3 100644 --- a/openapi-src/V2/definitions/UpdateRequestRead.yml +++ b/openapi-src/V2/definitions/UpdateRequestRead.yml @@ -11,8 +11,12 @@ properties: type: string content: type: string - comments: + feedback: type: string + feedback_fields: + type: array + items: + type: string project: type: object organisation: diff --git a/resources/docs/swagger-v2.yml b/resources/docs/swagger-v2.yml index 2c95f725b..77ac99069 100644 --- a/resources/docs/swagger-v2.yml +++ b/resources/docs/swagger-v2.yml @@ -169,20 +169,31 @@ definitions: items: type: string update_request: + title: UpdateRequestRead type: object properties: uuid: type: string + framework_key: + type: string status: type: string + readable_status: + type: string content: - type: object + type: string feedback: type: string feedback_fields: type: array items: type: string + project: + type: object + organisation: + type: object + created_by: + type: object UserRead: type: object properties: @@ -43890,8 +43901,12 @@ definitions: type: string content: type: string - comments: + feedback: type: string + feedback_fields: + type: array + items: + type: string project: type: object organisation: @@ -56871,20 +56886,31 @@ paths: items: type: string update_request: + title: UpdateRequestRead type: object properties: uuid: type: string + framework_key: + type: string status: type: string + readable_status: + type: string content: - type: object + type: string feedback: type: string feedback_fields: type: array items: type: string + project: + type: object + organisation: + type: object + created_by: + type: object put: operationId: put-v2-forms-entity-form-uuid summary: Update a specific entity using a form schema @@ -56945,20 +56971,31 @@ paths: items: type: string update_request: + title: UpdateRequestRead type: object properties: uuid: type: string + framework_key: + type: string status: type: string + readable_status: + type: string content: - type: object + type: string feedback: type: string feedback_fields: type: array items: type: string + project: + type: object + organisation: + type: object + created_by: + type: object '/v2/forms/{ENTITY}/{UUID}/submit': put: operationId: put-v2-forms-entity-form-uuid-submit @@ -57007,20 +57044,31 @@ paths: items: type: string update_request: + title: UpdateRequestRead type: object properties: uuid: type: string + framework_key: + type: string status: type: string + readable_status: + type: string content: - type: object + type: string feedback: type: string feedback_fields: type: array items: type: string + project: + type: object + organisation: + type: object + created_by: + type: object '/v2/forms/{ENTITY}': post: summary: Create an entity with a custom form @@ -57083,20 +57131,31 @@ paths: items: type: string update_request: + title: UpdateRequestRead type: object properties: uuid: type: string + framework_key: + type: string status: type: string + readable_status: + type: string content: - type: object + type: string feedback: type: string feedback_fields: type: array items: type: string + project: + type: object + organisation: + type: object + created_by: + type: object '/v2/forms/projects/{UUID}': post: summary: Create a project with a custom form @@ -57149,20 +57208,31 @@ paths: items: type: string update_request: + title: UpdateRequestRead type: object properties: uuid: type: string + framework_key: + type: string status: type: string + readable_status: + type: string content: - type: object + type: string feedback: type: string feedback_fields: type: array items: type: string + project: + type: object + organisation: + type: object + created_by: + type: object '/v2/projects/{UUID}/site-polygons': get: summary: Get the polygons (geojson) from all sites belonging to a specific project @@ -57380,8 +57450,12 @@ paths: type: string content: type: string - comments: + feedback: type: string + feedback_fields: + type: array + items: + type: string project: type: object organisation: @@ -57458,8 +57532,12 @@ paths: type: string content: type: string - comments: + feedback: type: string + feedback_fields: + type: array + items: + type: string project: type: object organisation: @@ -57512,8 +57590,12 @@ paths: type: string content: type: string - comments: + feedback: type: string + feedback_fields: + type: array + items: + type: string project: type: object organisation: From 09ca621c93ba5d786be76fbf55cd769d9601c394 Mon Sep 17 00:00:00 2001 From: cesarLima1 Date: Mon, 15 Apr 2024 12:28:13 -0400 Subject: [PATCH 34/44] TM-782 fix: change framework reference for exporting --- .../V2/Exports/ExportAllMonitoredEntitiesController.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/Http/Controllers/V2/Exports/ExportAllMonitoredEntitiesController.php b/app/Http/Controllers/V2/Exports/ExportAllMonitoredEntitiesController.php index 5104b984c..ded1eb6fa 100644 --- a/app/Http/Controllers/V2/Exports/ExportAllMonitoredEntitiesController.php +++ b/app/Http/Controllers/V2/Exports/ExportAllMonitoredEntitiesController.php @@ -3,6 +3,7 @@ namespace App\Http\Controllers\V2\Exports; use App\Http\Controllers\Controller; +use App\Models\Framework; use App\Models\V2\Forms\Form; use App\Models\V2\Nurseries\Nursery; use App\Models\V2\Nurseries\NurseryReport; @@ -20,6 +21,7 @@ class ExportAllMonitoredEntitiesController extends Controller public function __invoke(Request $request, string $entity, string $framework) { $modelClass = $this->getModelClass($entity); + $framework = $this->getSlug($framework); $form = $this->getForm($modelClass, $framework); $this->authorize('export', [$modelClass, $form]); @@ -36,6 +38,11 @@ public function __invoke(Request $request, string $entity, string $framework) ]); } + private function getSlug(string $framework) + { + $frameworkModel = Framework::where('access_code', $framework)->firstOrFail(); + return $frameworkModel->slug; + } private function getForm(string $modelClass, string $framework) { return Form::where('model', $modelClass) From e11ad5ad7616d35fb761ceecdd892888d1716fd1 Mon Sep 17 00:00:00 2001 From: Nathan Curtis Date: Mon, 15 Apr 2024 11:20:44 -0700 Subject: [PATCH 35/44] [TM-812] Remove project establishment and seed collection from workday collections. --- app/Models/V2/Projects/ProjectReport.php | 20 --------------- app/Models/V2/Workdays/Workday.php | 8 ------ config/wri/linked-fields.php | 32 ------------------------ 3 files changed, 60 deletions(-) diff --git a/app/Models/V2/Projects/ProjectReport.php b/app/Models/V2/Projects/ProjectReport.php index 5c34ce39a..d56bd7050 100644 --- a/app/Models/V2/Projects/ProjectReport.php +++ b/app/Models/V2/Projects/ProjectReport.php @@ -239,11 +239,6 @@ public function treeSpecies() return $this->morphMany(TreeSpecies::class, 'speciesable'); } - public function workdaysPaidProjectEstablishment() - { - return $this->morphMany(Workday::class, 'workdayable')->where('collection', Workday::COLLECTION_PROJECT_PAID_PROJECT_ESTABLISHMENT); - } - public function workdaysPaidNurseryOperations() { return $this->morphMany(Workday::class, 'workdayable')->where('collection', Workday::COLLECTION_PROJECT_PAID_NURSERY_OPRERATIONS); @@ -254,21 +249,11 @@ public function workdaysPaidProjectManagement() return $this->morphMany(Workday::class, 'workdayable')->where('collection', Workday::COLLECTION_PROJECT_PAID_PROJECT_MANAGEMENT); } - public function workdaysPaidSeedCollection() - { - return $this->morphMany(Workday::class, 'workdayable')->where('collection', Workday::COLLECTION_PROJECT_PAID_SEED_COLLECTION); - } - public function workdaysPaidOtherActivities() { return $this->morphMany(Workday::class, 'workdayable')->where('collection', Workday::COLLECTION_PROJECT_PAID_OTHER); } - public function workdaysVolunteerProjectEstablishment() - { - return $this->morphMany(Workday::class, 'workdayable')->where('collection', Workday::COLLECTION_PROJECT_VOLUNTEER_PROJECT_ESTABLISHMENT); - } - public function workdaysVolunteerNurseryOperations() { return $this->morphMany(Workday::class, 'workdayable')->where('collection', Workday::COLLECTION_PROJECT_VOLUNTEER_NURSERY_OPRERATIONS); @@ -279,11 +264,6 @@ public function workdaysVolunteerProjectManagement() return $this->morphMany(Workday::class, 'workdayable')->where('collection', Workday::COLLECTION_PROJECT_VOLUNTEER_PROJECT_MANAGEMENT); } - public function workdaysVolunteerSeedCollection() - { - return $this->morphMany(Workday::class, 'workdayable')->where('collection', Workday::COLLECTION_PROJECT_VOLUNTEER_SEED_COLLECTION); - } - public function workdaysVolunteerOtherActivities() { return $this->morphMany(Workday::class, 'workdayable')->where('collection', Workday::COLLECTION_PROJECT_VOLUNTEER_OTHER); diff --git a/app/Models/V2/Workdays/Workday.php b/app/Models/V2/Workdays/Workday.php index 80850212f..bb1c3e0b1 100644 --- a/app/Models/V2/Workdays/Workday.php +++ b/app/Models/V2/Workdays/Workday.php @@ -33,27 +33,19 @@ class Workday extends Model 'indigeneity', ]; - public const COLLECTION_PROJECT_PAID_PROJECT_ESTABLISHMENT = 'paid-project-establishment'; public const COLLECTION_PROJECT_PAID_NURSERY_OPRERATIONS = 'paid-nursery-operations'; public const COLLECTION_PROJECT_PAID_PROJECT_MANAGEMENT = 'paid-project-management'; - public const COLLECTION_PROJECT_PAID_SEED_COLLECTION = 'paid-seed-collection'; public const COLLECTION_PROJECT_PAID_OTHER = 'paid-other-activities'; - public const COLLECTION_PROJECT_VOLUNTEER_PROJECT_ESTABLISHMENT = 'volunteer-project-establishment'; public const COLLECTION_PROJECT_VOLUNTEER_NURSERY_OPRERATIONS = 'volunteer-nursery-operations'; public const COLLECTION_PROJECT_VOLUNTEER_PROJECT_MANAGEMENT = 'volunteer-project-management'; - public const COLLECTION_PROJECT_VOLUNTEER_SEED_COLLECTION = 'volunteer-seed-collection'; public const COLLECTION_PROJECT_VOLUNTEER_OTHER = 'volunteer-other-activities'; public static $projectCollections = [ - self::COLLECTION_PROJECT_PAID_PROJECT_ESTABLISHMENT => 'Paid Project Establishment', self::COLLECTION_PROJECT_PAID_NURSERY_OPRERATIONS => 'Paid Nursery Operations', self::COLLECTION_PROJECT_PAID_PROJECT_MANAGEMENT => 'Paid Project Management', - self::COLLECTION_PROJECT_PAID_SEED_COLLECTION => 'Paid Seed Collection', self::COLLECTION_PROJECT_PAID_OTHER => 'Paid Other Activities', - self::COLLECTION_PROJECT_VOLUNTEER_PROJECT_ESTABLISHMENT => 'Volunteer Project Establishment', self::COLLECTION_PROJECT_VOLUNTEER_NURSERY_OPRERATIONS => 'Volunteer Nursery Operations', self::COLLECTION_PROJECT_VOLUNTEER_PROJECT_MANAGEMENT => 'Volunteer Project Management', - self::COLLECTION_PROJECT_VOLUNTEER_SEED_COLLECTION => 'Volunteer Seed Collection', self::COLLECTION_PROJECT_VOLUNTEER_OTHER => 'Volunteer Other Activities', ]; diff --git a/config/wri/linked-fields.php b/config/wri/linked-fields.php index a79b1b5da..e4a2484c8 100644 --- a/config/wri/linked-fields.php +++ b/config/wri/linked-fields.php @@ -424,14 +424,6 @@ 'input_type' => 'treeSpecies', 'collection' => 'tree-planted', ], - // 'pro-rep-rel-paid-project-establishment' => [ - // 'property' => 'workdaysPaidProjectEstablishment', - // 'label' => 'Paid Project Establishment', - // 'resource' => 'App\Http\Resources\V2\Workdays\WorkdayResource', - // 'input_type' => 'workdays', - // 'collection' => 'paid-project-establishment', - // 'option_list_key' => 'workdays-ethnicity', - // ], 'pro-rep-rel-paid-nursery-operations' => [ 'property' => 'workdaysPaidNurseryOperations', 'label' => 'Paid Nursery Operations', @@ -448,14 +440,6 @@ 'collection' => 'paid-project-management', 'option_list_key' => 'workdays-ethnicity', ], - // 'pro-rep-rel-paid-seed-collection' => [ - // 'property' => 'workdaysPaidSeedCollection', - // 'label' => 'Paid Seed Collection', - // 'resource' => 'App\Http\Resources\V2\Workdays\WorkdayResource', - // 'input_type' => 'workdays', - // 'collection' => 'paid-seed-collection', - // 'option_list_key' => 'workdays-ethnicity', - // ], 'pro-rep-rel-paid-other-activities' => [ 'property' => 'workdaysPaidOtherActivities', 'label' => 'Paid Other Activities', @@ -464,14 +448,6 @@ 'collection' => 'paid-other-activities', 'option_list_key' => 'workdays-ethnicity', ], - // 'pro-rep-rel-volunteer-project-establishment' => [ - // 'property' => 'workdaysVolunteerProjectEstablishment', - // 'label' => 'Volunteer Project Establishment', - // 'resource' => 'App\Http\Resources\V2\Workdays\WorkdayResource', - // 'input_type' => 'workdays', - // 'collection' => 'volunteer-project-establishment', - // 'option_list_key' => 'workdays-ethnicity', - // ], 'pro-rep-rel-volunteer-nursery-operations' => [ 'property' => 'workdaysVolunteerNurseryOperations', 'label' => 'Volunteer Nursery Operations', @@ -488,14 +464,6 @@ 'collection' => 'volunteer-project-management', 'option_list_key' => 'workdays-ethnicity', ], - // 'pro-rep-rel-volunteer-seed-collection' => [ - // 'property' => 'workdaysVolunteerSeedCollection', - // 'label' => 'Volunteer Seed Collection', - // 'resource' => 'App\Http\Resources\V2\Workdays\WorkdayResource', - // 'input_type' => 'workdays', - // 'collection' => 'volunteer-seed-collection', - // 'option_list_key' => 'workdays-ethnicity', - // ], 'pro-rep-rel-volunteer-other-activities' => [ 'property' => 'workdaysVolunteerOtherActivities', 'label' => 'Volunteer Other Activities', From 9d365bfdfe32e07c43e7c94dbd018092b1b9eda2 Mon Sep 17 00:00:00 2001 From: Nathan Curtis Date: Mon, 15 Apr 2024 11:49:09 -0700 Subject: [PATCH 36/44] Fix lint --- .../V2/Exports/ExportAllMonitoredEntitiesController.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/Http/Controllers/V2/Exports/ExportAllMonitoredEntitiesController.php b/app/Http/Controllers/V2/Exports/ExportAllMonitoredEntitiesController.php index ded1eb6fa..3cfb9e4d0 100644 --- a/app/Http/Controllers/V2/Exports/ExportAllMonitoredEntitiesController.php +++ b/app/Http/Controllers/V2/Exports/ExportAllMonitoredEntitiesController.php @@ -41,8 +41,10 @@ public function __invoke(Request $request, string $entity, string $framework) private function getSlug(string $framework) { $frameworkModel = Framework::where('access_code', $framework)->firstOrFail(); + return $frameworkModel->slug; } + private function getForm(string $modelClass, string $framework) { return Form::where('model', $modelClass) From 3a466c3e62192bb761cff630040bca3bb760039f Mon Sep 17 00:00:00 2001 From: Nathan Curtis Date: Mon, 15 Apr 2024 13:23:41 -0700 Subject: [PATCH 37/44] [TM-812] Create permissions for the new terrafund-enterprises framework. --- .../Migration/RolesMigrationCommand.php | 9 +++- .../CreateGreenhouseServiceAccountRole.php | 46 ------------------- config/wri/permissions.php | 1 + 3 files changed, 8 insertions(+), 48 deletions(-) delete mode 100644 app/Console/Commands/OneOff/CreateGreenhouseServiceAccountRole.php diff --git a/app/Console/Commands/Migration/RolesMigrationCommand.php b/app/Console/Commands/Migration/RolesMigrationCommand.php index 85c5fb696..47e774300 100644 --- a/app/Console/Commands/Migration/RolesMigrationCommand.php +++ b/app/Console/Commands/Migration/RolesMigrationCommand.php @@ -52,7 +52,7 @@ public function handle() if (Role::where('name', 'admin-super')->count() === 0) { $role = Role::create(['name' => 'admin-super']); - $role->givePermissionTo(['framework-terrafund', 'framework-ppc', 'custom-forms-manage', 'users-manage', 'monitoring-manage', 'reports-manage']); + $role->givePermissionTo(['framework-terrafund', 'framework-ppc', 'framework-terrafund-enterprises', 'custom-forms-manage', 'users-manage', 'monitoring-manage', 'reports-manage']); } if (Role::where('name', 'admin-ppc')->count() === 0) { @@ -62,7 +62,7 @@ public function handle() if (Role::where('name', 'admin-terrafund')->count() === 0) { $role = Role::create(['name' => 'admin-terrafund']); - $role->givePermissionTo(['framework-terrafund', 'custom-forms-manage', 'users-manage', 'monitoring-manage', 'reports-manage']); + $role->givePermissionTo(['framework-terrafund', 'framework-terrafund-enterprises', 'custom-forms-manage', 'users-manage', 'monitoring-manage', 'reports-manage']); } if (Role::where('name', 'project-developer')->count() === 0) { @@ -70,6 +70,11 @@ public function handle() $role->givePermissionTo(['manage-own']); } + if (Role::where('name', 'greenhouse-service-account')->count() === 0) { + $role = Role::create(['name' => 'greenhouse-service-account']); + $role->givePermissionTo(['projects-read', 'polygons-manage', 'media-manage']); + } + User::whereIn('role', ['user','admin', 'terrafund-admin'])->get() ->each(function (User $user) { assignSpatieRole($user); diff --git a/app/Console/Commands/OneOff/CreateGreenhouseServiceAccountRole.php b/app/Console/Commands/OneOff/CreateGreenhouseServiceAccountRole.php deleted file mode 100644 index 40f8576bb..000000000 --- a/app/Console/Commands/OneOff/CreateGreenhouseServiceAccountRole.php +++ /dev/null @@ -1,46 +0,0 @@ -first(); - if ($role == null) { - $role = Role::create(['name' => 'greenhouse-service-account']); - } - - // Make sure all permissions in config/permissions have been created. - $permissionKeys = array_keys(config('wri.permissions')); - foreach ($permissionKeys as $key) { - if (Permission::where('name', $key)->count() === 0) { - Permission::create(['name' => $key]); - } - } - - $role->syncPermissions(['projects-read', 'polygons-manage', 'media-manage']); - } -} diff --git a/config/wri/permissions.php b/config/wri/permissions.php index 3a81863d2..840b63edb 100644 --- a/config/wri/permissions.php +++ b/config/wri/permissions.php @@ -3,6 +3,7 @@ return [ 'framework-ppc' => 'Framework PPC', 'framework-terrafund' => 'Framework Terrafund', + 'framework-terrafund-enterprises' => 'Framework Terrafund Enterprises', 'custom-forms-manage' => 'Manage custom forms', 'users-manage' => 'Manage users', 'monitoring-manage' => 'Manage monitoring', From c4dbdef5020e1a1dc0245e261e1945c147801e7d Mon Sep 17 00:00:00 2001 From: Nathan Curtis Date: Mon, 15 Apr 2024 13:26:06 -0700 Subject: [PATCH 38/44] [TM-812] Use can instead of hasPermissionTo, as it doesn't throw an error when the permission isn't found. --- app/Http/Controllers/Traits/IsAdminIndex.php | 2 +- .../V2/UpdateRequests/AdminIndexUpdateRequestsController.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/Traits/IsAdminIndex.php b/app/Http/Controllers/Traits/IsAdminIndex.php index e97cfb75f..743a67d3b 100644 --- a/app/Http/Controllers/Traits/IsAdminIndex.php +++ b/app/Http/Controllers/Traits/IsAdminIndex.php @@ -33,7 +33,7 @@ protected function isolateAuthorizedFrameworks(QueryBuilder $query, string $tabl $query->where(function ($query) use ($tableName, $frameworkNames, $user) { foreach ($frameworkNames as $framework) { $frameworkPermission = 'framework-' . $framework; - if ($user->hasPermissionTo($frameworkPermission)) { + if ($user->can($frameworkPermission)) { $query->orWhere("$tableName.framework_key", $framework); } } diff --git a/app/Http/Controllers/V2/UpdateRequests/AdminIndexUpdateRequestsController.php b/app/Http/Controllers/V2/UpdateRequests/AdminIndexUpdateRequestsController.php index ce22e4719..68ee42ce0 100644 --- a/app/Http/Controllers/V2/UpdateRequests/AdminIndexUpdateRequestsController.php +++ b/app/Http/Controllers/V2/UpdateRequests/AdminIndexUpdateRequestsController.php @@ -59,7 +59,7 @@ public function __invoke(Request $request): UpdateRequestsCollection $query->where(function ($query) use ($frameworkNames, $user) { foreach ($frameworkNames as $framework) { $frameworkPermission = 'framework-' . $framework; - if ($user->hasPermissionTo($frameworkPermission)) { + if ($user->can($frameworkPermission)) { $query->orWhere('framework_key', $framework); } } From 58b023afb36f65e3288a0122b28639ed052572f2 Mon Sep 17 00:00:00 2001 From: Nathan Curtis Date: Mon, 15 Apr 2024 13:43:30 -0700 Subject: [PATCH 39/44] [TM-782] Fix lint and failing unit test from staging. --- .../V2/Exports/ExportAllMonitoredEntitiesController.php | 2 ++ tests/V2/Exports/ExportAllMonitoredEntitiesControllerTest.php | 3 +++ 2 files changed, 5 insertions(+) diff --git a/app/Http/Controllers/V2/Exports/ExportAllMonitoredEntitiesController.php b/app/Http/Controllers/V2/Exports/ExportAllMonitoredEntitiesController.php index ded1eb6fa..3cfb9e4d0 100644 --- a/app/Http/Controllers/V2/Exports/ExportAllMonitoredEntitiesController.php +++ b/app/Http/Controllers/V2/Exports/ExportAllMonitoredEntitiesController.php @@ -41,8 +41,10 @@ public function __invoke(Request $request, string $entity, string $framework) private function getSlug(string $framework) { $frameworkModel = Framework::where('access_code', $framework)->firstOrFail(); + return $frameworkModel->slug; } + private function getForm(string $modelClass, string $framework) { return Form::where('model', $modelClass) diff --git a/tests/V2/Exports/ExportAllMonitoredEntitiesControllerTest.php b/tests/V2/Exports/ExportAllMonitoredEntitiesControllerTest.php index e1bdbb19e..f8059ba4e 100644 --- a/tests/V2/Exports/ExportAllMonitoredEntitiesControllerTest.php +++ b/tests/V2/Exports/ExportAllMonitoredEntitiesControllerTest.php @@ -4,6 +4,7 @@ use App\Helpers\CustomFormHelper; use App\Jobs\V2\GenerateAdminAllEntityRecordsExportJob; +use App\Models\Framework; use App\Models\User; use App\Models\V2\Nurseries\Nursery; use App\Models\V2\Nurseries\NurseryReport; @@ -31,6 +32,8 @@ public function test_an_admin_user_can_export_all_monitored_entities(string $per $user = User::factory()->admin()->create(); $user->givePermissionTo($permission); + Framework::factory()->create(['slug' => $fmKey, 'access_code' => $fmKey]); + $testCases = [ 'projects' => Project::factory()->count(5)->create(['framework_key' => $fmKey]), 'sites' => Site::factory()->count(5)->create(['framework_key' => $fmKey]), From 93bd4c3bd9513d1fbe9d778332b3ebd60cf4849d Mon Sep 17 00:00:00 2001 From: Nathan Curtis Date: Mon, 15 Apr 2024 13:43:30 -0700 Subject: [PATCH 40/44] [TM-782] Fix lint and failing unit test from staging. --- tests/V2/Exports/ExportAllMonitoredEntitiesControllerTest.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/V2/Exports/ExportAllMonitoredEntitiesControllerTest.php b/tests/V2/Exports/ExportAllMonitoredEntitiesControllerTest.php index e1bdbb19e..f8059ba4e 100644 --- a/tests/V2/Exports/ExportAllMonitoredEntitiesControllerTest.php +++ b/tests/V2/Exports/ExportAllMonitoredEntitiesControllerTest.php @@ -4,6 +4,7 @@ use App\Helpers\CustomFormHelper; use App\Jobs\V2\GenerateAdminAllEntityRecordsExportJob; +use App\Models\Framework; use App\Models\User; use App\Models\V2\Nurseries\Nursery; use App\Models\V2\Nurseries\NurseryReport; @@ -31,6 +32,8 @@ public function test_an_admin_user_can_export_all_monitored_entities(string $per $user = User::factory()->admin()->create(); $user->givePermissionTo($permission); + Framework::factory()->create(['slug' => $fmKey, 'access_code' => $fmKey]); + $testCases = [ 'projects' => Project::factory()->count(5)->create(['framework_key' => $fmKey]), 'sites' => Site::factory()->count(5)->create(['framework_key' => $fmKey]), From bbbc874558496bdc9145935c7542185a3eef00c0 Mon Sep 17 00:00:00 2001 From: Nathan Curtis Date: Mon, 15 Apr 2024 15:13:59 -0700 Subject: [PATCH 41/44] [TM-515] Only assign spatie roles if the user doesn't already have them. --- app/Console/Commands/Migration/RolesMigrationCommand.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/Console/Commands/Migration/RolesMigrationCommand.php b/app/Console/Commands/Migration/RolesMigrationCommand.php index 85c5fb696..dde843401 100644 --- a/app/Console/Commands/Migration/RolesMigrationCommand.php +++ b/app/Console/Commands/Migration/RolesMigrationCommand.php @@ -72,7 +72,9 @@ public function handle() User::whereIn('role', ['user','admin', 'terrafund-admin'])->get() ->each(function (User $user) { - assignSpatieRole($user); + if ($user->primary_role == null) { + assignSpatieRole($user); + } }); if ($this->option('log')) { From 4aef243b603da645a3ef8a4da0d39472d790b6dc Mon Sep 17 00:00:00 2001 From: Nathan Curtis Date: Tue, 16 Apr 2024 15:27:27 -0700 Subject: [PATCH 42/44] [TM-714] Update workdays as an entity relation. --- app/Models/Traits/UsesLinkedFields.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/Models/Traits/UsesLinkedFields.php b/app/Models/Traits/UsesLinkedFields.php index b35a07012..f04d4cb6d 100644 --- a/app/Models/Traits/UsesLinkedFields.php +++ b/app/Models/Traits/UsesLinkedFields.php @@ -77,7 +77,8 @@ public function updateFromForm(array $formData): void } else { $property = data_get($relationsConfig, "$question->linked_field_key.property"); if (! empty($property)) { - $this->syncRelation($property, collect(data_get($formData, $question->uuid))); + $inputType = data_get($relationsConfig, "$question->linked_field_key.input_type"); + $this->syncRelation($property, $inputType, collect(data_get($formData, $question->uuid))); } } @@ -242,10 +243,10 @@ private function updateLinkedFieldValue(array $linkedFieldInfo, $answer): void } } - private function syncRelation(string $property, $data): void + private function syncRelation(string $property, string $inputType, $data): void { // This will expand as we complete more tickets in TM-747, until eventually we support all form relations. - if ($property != 'treeSpecies') { + if (! in_array($inputType, ['treeSpecies', 'workdays'])) { return; } From 8292b998319796f4694ded74b583207d0e2cde28 Mon Sep 17 00:00:00 2001 From: Nathan Curtis Date: Tue, 16 Apr 2024 15:32:17 -0700 Subject: [PATCH 43/44] [TM-714] Remove the workdays mutation endpoints. --- .../V2/Workdays/DeleteWorkdayController.php | 19 --- .../V2/Workdays/StoreWorkdayController.php | 61 ------- .../V2/Workdays/UpdateWorkdayController.php | 20 --- .../V2/definitions/V2WorkdayCreate.yml | 19 --- .../V2/definitions/V2WorkdayUpdate.yml | 15 -- openapi-src/V2/definitions/_index.yml | 4 - .../paths/Workdays/delete-v2-workday-uuid.yml | 12 -- .../paths/Workdays/patch-v2-workday-uuid.yml | 14 -- .../V2/paths/Workdays/post-v2-workday.yml | 14 -- openapi-src/V2/paths/_index.yml | 8 - resources/docs/swagger-v2.yml | 160 ------------------ routes/api_v2.php | 6 - .../Workdays/DeleteWorkdayControllerTest.php | 54 ------ .../Workdays/StoreWorkdayControllerTest.php | 71 -------- .../Workdays/UpdateWorkdayControllerTest.php | 68 -------- 15 files changed, 545 deletions(-) delete mode 100644 app/Http/Controllers/V2/Workdays/DeleteWorkdayController.php delete mode 100644 app/Http/Controllers/V2/Workdays/StoreWorkdayController.php delete mode 100644 app/Http/Controllers/V2/Workdays/UpdateWorkdayController.php delete mode 100644 openapi-src/V2/definitions/V2WorkdayCreate.yml delete mode 100644 openapi-src/V2/definitions/V2WorkdayUpdate.yml delete mode 100644 openapi-src/V2/paths/Workdays/delete-v2-workday-uuid.yml delete mode 100644 openapi-src/V2/paths/Workdays/patch-v2-workday-uuid.yml delete mode 100644 openapi-src/V2/paths/Workdays/post-v2-workday.yml delete mode 100644 tests/V2/Workdays/DeleteWorkdayControllerTest.php delete mode 100644 tests/V2/Workdays/StoreWorkdayControllerTest.php delete mode 100644 tests/V2/Workdays/UpdateWorkdayControllerTest.php diff --git a/app/Http/Controllers/V2/Workdays/DeleteWorkdayController.php b/app/Http/Controllers/V2/Workdays/DeleteWorkdayController.php deleted file mode 100644 index d4dab4635..000000000 --- a/app/Http/Controllers/V2/Workdays/DeleteWorkdayController.php +++ /dev/null @@ -1,19 +0,0 @@ -authorize('update', $workday->workdayable); - $workday->delete(); - $workday->save(); - - return new WorkdayResource($workday); - } -} diff --git a/app/Http/Controllers/V2/Workdays/StoreWorkdayController.php b/app/Http/Controllers/V2/Workdays/StoreWorkdayController.php deleted file mode 100644 index 908a0073d..000000000 --- a/app/Http/Controllers/V2/Workdays/StoreWorkdayController.php +++ /dev/null @@ -1,61 +0,0 @@ -getEntityFromRequest($request); - $this->authorize('read', $model); - - $request->merge([ - 'workdayable_type' => get_class($model), - 'workdayable_id' => $model->id, - ]); - - $workday = Workday::create($request->all()); - - return new WorkdayResource($workday); - } - - private function getEntityFromRequest(StoreWorkdayRequest $request) - { - switch ($request->get('model_type')) { - case 'organisation': - return Organisation::isUuid($request->get('model_uuid'))->firstOrFail(); - case 'project-pitch': - return ProjectPitch::isUuid($request->get('model_uuid'))->firstOrFail(); - case 'project': - return Project::isUuid($request->get('model_uuid'))->firstOrFail(); - case 'project-report': - return ProjectReport::isUuid($request->get('model_uuid'))->firstOrFail(); - case 'site': - return Site::isUuid($request->get('model_uuid'))->firstOrFail(); - case 'site-report': - return SiteReport::isUuid($request->get('model_uuid'))->firstOrFail(); - case 'nursery': - return Nursery::isUuid($request->get('model_uuid'))->firstOrFail(); - case 'nursery-report': - return NurseryReport::isUuid($request->get('model_uuid'))->firstOrFail(); - default: - throw new InvalidMorphableModelException(); - } - - return $request; - } -} diff --git a/app/Http/Controllers/V2/Workdays/UpdateWorkdayController.php b/app/Http/Controllers/V2/Workdays/UpdateWorkdayController.php deleted file mode 100644 index 95e1d3dc0..000000000 --- a/app/Http/Controllers/V2/Workdays/UpdateWorkdayController.php +++ /dev/null @@ -1,20 +0,0 @@ -authorize('read', $workday->workdayable); - $workday->update($request->validated()); - $workday->save(); - - return new WorkdayResource($workday); - } -} diff --git a/openapi-src/V2/definitions/V2WorkdayCreate.yml b/openapi-src/V2/definitions/V2WorkdayCreate.yml deleted file mode 100644 index df1ac1cf8..000000000 --- a/openapi-src/V2/definitions/V2WorkdayCreate.yml +++ /dev/null @@ -1,19 +0,0 @@ -title: V2WorkdayCreate -type: object -properties: - model_type: - type: string - model_uuid: - type: string - amount: - type: integer - collection: - type: string - gender: - type: string - age: - type: string - ethnicity: - type: string - indigeneity: - type: string \ No newline at end of file diff --git a/openapi-src/V2/definitions/V2WorkdayUpdate.yml b/openapi-src/V2/definitions/V2WorkdayUpdate.yml deleted file mode 100644 index 30769e25e..000000000 --- a/openapi-src/V2/definitions/V2WorkdayUpdate.yml +++ /dev/null @@ -1,15 +0,0 @@ -title: V2WorkdayUpdate -type: object -properties: - amount: - type: integer - collection: - type: string - gender: - type: string - age: - type: string - ethnicity: - type: string - indigeneity: - type: string \ No newline at end of file diff --git a/openapi-src/V2/definitions/_index.yml b/openapi-src/V2/definitions/_index.yml index 0ccdfea3b..5ebd90ac2 100644 --- a/openapi-src/V2/definitions/_index.yml +++ b/openapi-src/V2/definitions/_index.yml @@ -152,10 +152,6 @@ V2SeedingPaginated: $ref: './V2SeedingPaginated.yml' V2WorkdayRead: $ref: './V2WorkdayRead.yml' -V2WorkdayCreate: - $ref: './V2WorkdayCreate.yml' -V2WorkdayUpdate: - $ref: './V2WorkdayUpdate.yml' V2WorkdaysPaginated: $ref: './V2WorkdaysPaginated.yml' V2DisturbanceRead: diff --git a/openapi-src/V2/paths/Workdays/delete-v2-workday-uuid.yml b/openapi-src/V2/paths/Workdays/delete-v2-workday-uuid.yml deleted file mode 100644 index e0e866e09..000000000 --- a/openapi-src/V2/paths/Workdays/delete-v2-workday-uuid.yml +++ /dev/null @@ -1,12 +0,0 @@ -operationId: delete-v2-workday-uuid -summary: Delete a workday -tags: - - V2 Workdays -parameters: - - type: string - name: UUID - in: path - required: true -responses: - '200': - description: OK diff --git a/openapi-src/V2/paths/Workdays/patch-v2-workday-uuid.yml b/openapi-src/V2/paths/Workdays/patch-v2-workday-uuid.yml deleted file mode 100644 index b8ce3769b..000000000 --- a/openapi-src/V2/paths/Workdays/patch-v2-workday-uuid.yml +++ /dev/null @@ -1,14 +0,0 @@ -operationId: patch-v2-workday-uuid -summary: Update a workday -tags: - - V2 Workdays -parameters: - - type: string - name: UUID - in: path - required: true -responses: - '200': - description: OK - schema: - $ref: '../../definitions/_index.yml#/V2WorkdaysPaginated' diff --git a/openapi-src/V2/paths/Workdays/post-v2-workday.yml b/openapi-src/V2/paths/Workdays/post-v2-workday.yml deleted file mode 100644 index ebede9de6..000000000 --- a/openapi-src/V2/paths/Workdays/post-v2-workday.yml +++ /dev/null @@ -1,14 +0,0 @@ -operationId: post-v2-workday -summary: Crates a workday -tags: - - V2 Workdays -responses: - '201': - description: Created - schema: - $ref: '../../definitions/_index.yml#/V2WorkdayRead' -parameters: - - in: body - name: body - schema: - $ref: '../../definitions/_index.yml#/V2WorkdayCreate' diff --git a/openapi-src/V2/paths/_index.yml b/openapi-src/V2/paths/_index.yml index d96c9f717..57c46873e 100644 --- a/openapi-src/V2/paths/_index.yml +++ b/openapi-src/V2/paths/_index.yml @@ -104,14 +104,6 @@ /v2/update-requests/{ENTITY}/{UUID}: get: $ref: './UpdateRequests/get-v2-update-requests-entity-uuid.yml' -/v2/workdays: - post: - $ref: './Workdays/post-v2-workday.yml' -/v2/workdays/{UUID}: - patch: - $ref: './Workdays/patch-v2-workday-uuid.yml' - delete: - $ref: './Workdays/delete-v2-workday-uuid.yml' /v2/workdays/{ENTITY}/{UUID}: get: $ref: './Workdays/get-v2-workdays-entity-uuid.yml' diff --git a/resources/docs/swagger-v2.yml b/resources/docs/swagger-v2.yml index 77ac99069..99cecc79a 100644 --- a/resources/docs/swagger-v2.yml +++ b/resources/docs/swagger-v2.yml @@ -9266,42 +9266,6 @@ definitions: type: string indigeneity: type: string - V2WorkdayCreate: - title: V2WorkdayCreate - type: object - properties: - model_type: - type: string - model_uuid: - type: string - amount: - type: integer - collection: - type: string - gender: - type: string - age: - type: string - ethnicity: - type: string - indigeneity: - type: string - V2WorkdayUpdate: - title: V2WorkdayUpdate - type: object - properties: - amount: - type: integer - collection: - type: string - gender: - type: string - age: - type: string - ethnicity: - type: string - indigeneity: - type: string V2WorkdaysPaginated: type: object properties: @@ -57602,130 +57566,6 @@ paths: type: object created_by: type: object - /v2/workdays: - post: - operationId: post-v2-workday - summary: Crates a workday - tags: - - V2 Workdays - responses: - '201': - description: Created - schema: - title: V2WorkdayRead - type: object - properties: - uuid: - type: string - amount: - type: integer - collection: - type: string - gender: - type: string - age: - type: string - ethnicity: - type: string - indigeneity: - type: string - parameters: - - in: body - name: body - schema: - title: V2WorkdayCreate - type: object - properties: - model_type: - type: string - model_uuid: - type: string - amount: - type: integer - collection: - type: string - gender: - type: string - age: - type: string - ethnicity: - type: string - indigeneity: - type: string - '/v2/workdays/{UUID}': - patch: - operationId: patch-v2-workday-uuid - summary: Update a workday - tags: - - V2 Workdays - parameters: - - type: string - name: UUID - in: path - required: true - responses: - '200': - description: OK - schema: - type: object - properties: - data: - type: array - items: - title: V2WorkdayRead - type: object - properties: - uuid: - type: string - amount: - type: integer - collection: - type: string - gender: - type: string - age: - type: string - ethnicity: - type: string - indigeneity: - type: string - links: - type: object - properties: - first: - type: string - last: - type: string - prev: - type: string - next: - type: string - meta: - type: object - properties: - current_page: - type: integer - from: - type: integer - last_page: - type: integer - next: - type: integer - unfiltered_total: - type: integer - delete: - operationId: delete-v2-workday-uuid - summary: Delete a workday - tags: - - V2 Workdays - parameters: - - type: string - name: UUID - in: path - required: true - responses: - '200': - description: OK '/v2/workdays/{ENTITY}/{UUID}': get: operationId: get-v2-workdays-entity-uuid diff --git a/routes/api_v2.php b/routes/api_v2.php index 10445c3a5..631124387 100644 --- a/routes/api_v2.php +++ b/routes/api_v2.php @@ -184,10 +184,7 @@ use App\Http\Controllers\V2\User\CompleteActionController; use App\Http\Controllers\V2\User\IndexMyActionsController; use App\Http\Controllers\V2\User\UpdateMyBannersController; -use App\Http\Controllers\V2\Workdays\DeleteWorkdayController; use App\Http\Controllers\V2\Workdays\GetWorkdaysForEntityController; -use App\Http\Controllers\V2\Workdays\StoreWorkdayController; -use App\Http\Controllers\V2\Workdays\UpdateWorkdayController; use App\Http\Middleware\ModelInterfaceBindingMiddleware; use Illuminate\Support\Facades\Route; @@ -460,9 +457,6 @@ }); Route::prefix('workdays')->group(function () { - Route::post('/', StoreWorkdayController::class); - Route::patch('/{workday}', UpdateWorkdayController::class); - Route::delete('/{workday}', DeleteWorkdayController::class); Route::get('/{entity}/{uuid}', GetWorkdaysForEntityController::class); }); diff --git a/tests/V2/Workdays/DeleteWorkdayControllerTest.php b/tests/V2/Workdays/DeleteWorkdayControllerTest.php deleted file mode 100644 index a8ee600ed..000000000 --- a/tests/V2/Workdays/DeleteWorkdayControllerTest.php +++ /dev/null @@ -1,54 +0,0 @@ -create(); - $owner = User::factory()->create(['organisation_id' => $organisation->id]); - $owner->givePermissionTo('manage-own'); - - $user = User::factory()->create(); - - $project = Project::factory()->create([ - 'organisation_id' => $organisation->id, - 'framework_key' => 'ppc', - ]); - - $site = Site::factory()->create([ - 'project_id' => $project->id, - 'framework_key' => 'ppc', - 'status' => EntityStatusStateMachine::STARTED, - ]); - - $workday = Workday::factory()->create([ - 'workdayable_type' => Site::class, - 'workdayable_id' => $site->id, - ]); - - $uri = '/api/v2/workdays/' . $workday->uuid; - - $this->actingAs($user) - ->deleteJson($uri) - ->assertStatus(403); - - $this->actingAs($owner) - ->deleteJson($uri) - ->assertSuccessful(); - } -} diff --git a/tests/V2/Workdays/StoreWorkdayControllerTest.php b/tests/V2/Workdays/StoreWorkdayControllerTest.php deleted file mode 100644 index 2702018d7..000000000 --- a/tests/V2/Workdays/StoreWorkdayControllerTest.php +++ /dev/null @@ -1,71 +0,0 @@ -create(); - $owner = User::factory()->create(['organisation_id' => $organisation->id]); - $owner->givePermissionTo('manage-own'); - - $user = User::factory()->create(); - - $project = Project::factory()->create([ - 'organisation_id' => $organisation->id, - 'framework_key' => 'ppc', - ]); - - $site = Site::factory()->create([ - 'project_id' => $project->id, - 'framework_key' => 'ppc', - 'status' => EntityStatusStateMachine::STARTED, - ]); - - $report = SiteReport::factory()->create([ - 'site_id' => $site->id, - 'framework_key' => 'ppc', - 'status' => EntityStatusStateMachine::STARTED, - ]); - - $payload = [ - 'model_type' => 'site-report', - 'model_uuid' => $report->uuid, - 'amount' => 14, - 'gender' => 'male', - 'ethnicity' => 'hispanic', - 'collection' => Workday::COLLECTION_PROJECT_VOLUNTEER_NURSERY_OPRERATIONS, - 'age' => 'adult-24-65', - ]; - - $uri = '/api/v2/workdays'; - - $this->actingAs($user) - ->postJson($uri, $payload) - ->assertStatus(403); - - $this->actingAs($owner) - ->postJson($uri, $payload) - ->assertSuccessful() - ->assertJsonPath('data.amount', 14) - ->assertJsonPath('data.gender', 'male') - ->assertJsonPath('data.ethnicity', 'hispanic') - ->assertJsonPath('data.collection', Workday::COLLECTION_PROJECT_VOLUNTEER_NURSERY_OPRERATIONS) - ->assertJsonPath('data.age', 'adult-24-65'); - } -} diff --git a/tests/V2/Workdays/UpdateWorkdayControllerTest.php b/tests/V2/Workdays/UpdateWorkdayControllerTest.php deleted file mode 100644 index 2ae663330..000000000 --- a/tests/V2/Workdays/UpdateWorkdayControllerTest.php +++ /dev/null @@ -1,68 +0,0 @@ -create(); - $owner = User::factory()->create(['organisation_id' => $organisation->id]); - $owner->givePermissionTo('manage-own'); - - $user = User::factory()->create(); - - $project = Project::factory()->create([ - 'organisation_id' => $organisation->id, - 'framework_key' => 'ppc', - ]); - - $site = Site::factory()->create([ - 'project_id' => $project->id, - 'framework_key' => 'ppc', - 'status' => EntityStatusStateMachine::STARTED, - ]); - - $report = SiteReport::factory()->create([ - 'site_id' => $site->id, - 'framework_key' => 'ppc', - 'status' => EntityStatusStateMachine::STARTED, - ]); - - $workday = Workday::factory()->create([ - 'workdayable_type' => SiteReport::class, - 'workdayable_id' => $report->id, - ]); - - $payload = [ - 'amount' => 26, - 'gender' => 'female', - ]; - - $uri = '/api/v2/workdays/' . $workday->uuid; - - $this->actingAs($user) - ->patchJson($uri, $payload) - ->assertStatus(403); - - $this->actingAs($owner) - ->patchJson($uri, $payload) - ->assertSuccessful() - ->assertJsonPath('data.amount', 26) - ->assertJsonPath('data.gender', 'female'); - } -} From 65b931c18abc96b226eb9272cad924255f44d22e Mon Sep 17 00:00:00 2001 From: Limber Mamani <154026979+LimberHope@users.noreply.github.com> Date: Thu, 18 Apr 2024 15:57:35 -0400 Subject: [PATCH 44/44] feat: add old_id (#150) --- .../Controllers/V2/Sites/CreateSiteWithFormController.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/Http/Controllers/V2/Sites/CreateSiteWithFormController.php b/app/Http/Controllers/V2/Sites/CreateSiteWithFormController.php index e3a78586f..b8e72e635 100644 --- a/app/Http/Controllers/V2/Sites/CreateSiteWithFormController.php +++ b/app/Http/Controllers/V2/Sites/CreateSiteWithFormController.php @@ -23,10 +23,14 @@ public function __invoke(Form $form, CreateEntityFormRequest $formRequest) return new JsonResponse('No Project found for this site.', 404); } + $lastOldId = Site::orderByDesc('old_id') + ->value('old_id'); + $site = Site::create([ 'framework_key' => $project->framework_key, 'project_id' => $project->id, 'status' => EntityStatusStateMachine::STARTED, + 'old_id' => $lastOldId + 1, ]); return $site->createSchemaResource();