Skip to content

Commit

Permalink
update default entity factory and test for started entities
Browse files Browse the repository at this point in the history
  • Loading branch information
pachonjcl committed Jan 15, 2025
1 parent 5c4b24e commit 232e34c
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 6 deletions.
4 changes: 2 additions & 2 deletions database/factories/V2/Nurseries/NurseryFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace Database\Factories\V2\Nurseries;

use App\Models\V2\Nurseries\Nursery;
use App\Models\V2\Projects\Project;
use App\StateMachines\EntityStatusStateMachine;
use Illuminate\Database\Eloquent\Factories\Factory;

class NurseryFactory extends Factory
Expand All @@ -22,7 +22,7 @@ public function definition()
return [
'framework_key' => $frameworkKey,
'project_id' => Project::factory()->create(['framework_key' => $frameworkKey])->id,
'status' => array_keys(Nursery::$statuses)[0],
'status' => EntityStatusStateMachine::AWAITING_APPROVAL,
'type' => $this->faker->randomElement($types),
'name' => $this->faker->word(),
'start_date' => $this->faker->date(),
Expand Down
4 changes: 2 additions & 2 deletions database/factories/V2/Projects/ProjectFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Database\Factories\V2\Projects;

use App\Models\V2\Organisation;
use App\Models\V2\Projects\Project;
use App\StateMachines\EntityStatusStateMachine;
use Illuminate\Database\Eloquent\Factories\Factory;

class ProjectFactory extends Factory
Expand Down Expand Up @@ -31,7 +31,7 @@ public function definition()
return [
'framework_key' => $this->faker->randomElement($frameworks),
'name' => $this->faker->words(3, true),
'status' => array_keys(Project::$statuses)[0],
'status' => EntityStatusStateMachine::AWAITING_APPROVAL,
'project_status' => $this->faker->randomElement($projStatus),
'organisation_id' => Organisation::factory()->create()->id,
'boundary_geojson' => $geojson,
Expand Down
4 changes: 2 additions & 2 deletions database/factories/V2/Sites/SiteFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Database\Factories\V2\Sites;

use App\Models\V2\Projects\Project;
use App\Models\V2\Sites\Site;
use App\StateMachines\EntityStatusStateMachine;
use Illuminate\Database\Eloquent\Factories\Factory;

class SiteFactory extends Factory
Expand Down Expand Up @@ -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' => array_keys(Site::$statuses)[0],
'status' => EntityStatusStateMachine::AWAITING_APPROVAL,
'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(
Expand Down
28 changes: 28 additions & 0 deletions tests/Unit/Models/V2/ScheduledJobs/ScheduledJobsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use App\Models\V2\ScheduledJobs\TaskDueJob;
use App\Models\V2\Sites\Site;
use App\Models\V2\User;
use App\StateMachines\EntityStatusStateMachine;
use Carbon\Carbon;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
Expand Down Expand Up @@ -61,6 +62,33 @@ public function test_task_due()
$this->assertEquals($dueAt, $nursery->reports()->first()->due_at);
}

public function test_task_due_ignore_started_entities()
{
$dueAt = Carbon::now()->startOfDay()->addMonth();
$project = Project::factory()->terrafund()->create([
'status' => EntityStatusStateMachine::STARTED,
]);
$this->assertEquals(0, $project->tasks()->count());
$site = Site::factory()->terrafund()->create([
'project_id' => $project->id,
'status' => EntityStatusStateMachine::STARTED,
]);
$nursery = Nursery::factory()->terrafund()->create([
'project_id' => $project->id,
'status' => EntityStatusStateMachine::STARTED
]);
TaskDueJob::createTaskDue(Carbon::now()->subDay(), 'terrafund', $dueAt);

$this->assertEquals(0, $project->tasks()->count());

ScheduledJob::readyToExecute()->first()->execute();

$this->assertEquals(0, $project->tasks()->count());
$this->assertEquals(0, $project->reports()->count());
$this->assertEquals(0, $site->reports()->count());
$this->assertEquals(0, $nursery->reports()->count());
}

public function test_report_reminder()
{
Mail::fake();
Expand Down

0 comments on commit 232e34c

Please sign in to comment.