Skip to content

Commit

Permalink
factories
Browse files Browse the repository at this point in the history
  • Loading branch information
alexPopaCode4 committed Jun 6, 2024
1 parent a870a8b commit 4ad03a0
Show file tree
Hide file tree
Showing 13 changed files with 26 additions and 57 deletions.
3 changes: 0 additions & 3 deletions database/factories/AggressorFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use App\Enums\Ternary;
use App\Enums\Violence;
use App\Models\Aggressor;
use App\Models\Beneficiary;
use Illuminate\Database\Eloquent\Factories\Factory;

/**
Expand All @@ -30,8 +29,6 @@ class AggressorFactory extends Factory
public function definition(): array
{
return [
'beneficiary_id' => Beneficiary::factory(),

'relationship' => fake()->randomElement(AggressorRelationship::values()),
'age' => fake()->randomNumber(2),
'gender' => fake()->randomElement(Gender::values()),
Expand Down
27 changes: 26 additions & 1 deletion database/factories/BeneficiaryFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@
use App\Models\ReferringInstitution;
use App\Models\RequestedServices;
use App\Models\RiskFactors;
use App\Models\User;
use App\Models\Violence;
use App\Models\ViolenceHistory;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Database\Eloquent\Factories\Sequence;

/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Beneficiary>
Expand Down Expand Up @@ -189,9 +192,22 @@ public function configure(): static
->for($beneficiary)
->create();

$count = rand(1, 5);
$users = User::query()
->whereHas(
'organizations',
fn (Builder $query) => $query->where('organizations.id', $beneficiary->organization->id)
)
->inRandomOrder()
->limit($count)
->get()
->map(fn ($item) => ['user_id' => $item->id])
->toArray();

CaseTeam::factory()
->for($beneficiary)
->count(rand(1, 5))
->state(new Sequence(...$users))
->count($count)
->create();

DetailedEvaluationResult::factory()
Expand All @@ -200,6 +216,15 @@ public function configure(): static

EvaluateDetails::factory()
->for($beneficiary)
->state(['specialist_id' => User::query()
->whereHas(
'organizations',
fn (Builder $query) => $query->where('organizations.id', $beneficiary->organization->id)
)
->inRandomOrder()
->first()
->id,
])
->create();

Meeting::factory()
Expand Down
2 changes: 0 additions & 2 deletions database/factories/BeneficiaryPartnerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Database\Factories;

use App\Enums\Occupation;
use App\Models\Beneficiary;
use App\Models\City;
use Illuminate\Database\Eloquent\Factories\Factory;

Expand All @@ -26,7 +25,6 @@ public function definition(): array
$sameAddress = fake()->boolean();

return [
'beneficiary_id' => Beneficiary::inRandomOrder()->first()->id,
'last_name' => fake()->lastName(),
'first_name' => fake()->firstName(),
'age' => fake()->numberBetween(10, 99),
Expand Down
2 changes: 0 additions & 2 deletions database/factories/BeneficiarySituationFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Database\Factories;

use App\Models\Beneficiary;
use Illuminate\Database\Eloquent\Factories\Factory;

/**
Expand All @@ -20,7 +19,6 @@ class BeneficiarySituationFactory extends Factory
public function definition(): array
{
return [
'beneficiary_id' => Beneficiary::inRandomOrder()->first()->id,
'moment_of_evaluation' => fake()->text(),
'description_of_situation' => fake()->text(),
];
Expand Down
18 changes: 0 additions & 18 deletions database/factories/CaseTeamFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
namespace Database\Factories;

use App\Enums\Role;
use App\Models\Beneficiary;
use App\Models\User;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\Factory;

/**
Expand All @@ -22,22 +19,7 @@ class CaseTeamFactory extends Factory
*/
public function definition(): array
{
$beneficiary = Beneficiary::query()
->with('organization')
->has('organization')
->inRandomOrder()
->first();

return [
'beneficiary_id' => $beneficiary->id,
'user_id' => User::query()
->whereHas(
'organizations',
fn (Builder $query) => $query->where('organizations.id', $beneficiary->organization->id)
)
->inRandomOrder()
->first()
->id,
'roles' => collect(fake()->randomElements(Role::values(), rand(1, 5))),
];
}
Expand Down
2 changes: 0 additions & 2 deletions database/factories/DetailedEvaluationResultFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Database\Factories;

use App\Enums\Ternary;
use App\Models\Beneficiary;
use Illuminate\Database\Eloquent\Factories\Factory;

/**
Expand All @@ -21,7 +20,6 @@ class DetailedEvaluationResultFactory extends Factory
public function definition(): array
{
return [
'beneficiary_id' => Beneficiary::inRandomOrder()->first()->id,
'psychological_advice' => fake()->randomElement(Ternary::values()),
'legal_advice' => fake()->randomElement(Ternary::values()),
'legal_assistance' => fake()->randomElement(Ternary::values()),
Expand Down
17 changes: 0 additions & 17 deletions database/factories/EvaluateDetailsFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@

namespace Database\Factories;

use App\Models\Beneficiary;
use App\Models\User;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\Factory;

/**
Expand All @@ -21,21 +18,7 @@ class EvaluateDetailsFactory extends Factory
*/
public function definition(): array
{
$beneficiary = Beneficiary::query()
->with('organization')
->inRandomOrder()
->first();

return [
'beneficiary_id' => $beneficiary->id,
'specialist_id' => User::query()
->whereHas(
'organizations',
fn (Builder $query) => $query->where('organizations.id', $beneficiary->organization->id)
)
->inRandomOrder()
->first()
->id,
'registered_date' => fake()->date(),
'file_number' => fake()->randomNumber(),
'method_of_identifying_the_service' => fake()->text(),
Expand Down
2 changes: 0 additions & 2 deletions database/factories/MeetingFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Database\Factories;

use App\Models\Beneficiary;
use Illuminate\Database\Eloquent\Factories\Factory;

/**
Expand All @@ -20,7 +19,6 @@ class MeetingFactory extends Factory
public function definition(): array
{
return [
'beneficiary_id' => Beneficiary::inRandomOrder()->first()->id,
'specialist' => fake()->text(),
'date' => fake()->date(),
'location' => fake()->text(),
Expand Down
2 changes: 0 additions & 2 deletions database/factories/MultidisciplinaryEvaluationFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Database\Factories;

use App\Enums\Applicant;
use App\Models\Beneficiary;
use Illuminate\Database\Eloquent\Factories\Factory;

/**
Expand All @@ -23,7 +22,6 @@ public function definition(): array
$applicant = fake()->randomElement(Applicant::values());

return [
'beneficiary_id' => Beneficiary::inRandomOrder()->first()->id,
'applicant' => $applicant,
'reporting_by' => Applicant::OTHER->is($applicant) ? fake()->text() : null,
'medical_need' => fake()->text(),
Expand Down
2 changes: 0 additions & 2 deletions database/factories/RequestedServicesFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Database\Factories;

use App\Enums\Ternary;
use App\Models\Beneficiary;
use Illuminate\Database\Eloquent\Factories\Factory;

/**
Expand All @@ -21,7 +20,6 @@ class RequestedServicesFactory extends Factory
public function definition(): array
{
return [
'beneficiary_id' => Beneficiary::inRandomOrder()->first()->id,
'psychological_advice' => fake()->randomElement(Ternary::values()),
'legal_advice' => fake()->randomElement(Ternary::values()),
'legal_assistance' => fake()->randomElement(Ternary::values()),
Expand Down
2 changes: 0 additions & 2 deletions database/factories/RiskFactorsFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use App\Enums\VictimPerceptionOfTheRiskSchema;
use App\Enums\ViolenceHistorySchema;
use App\Enums\ViolencesTypesSchema;
use App\Models\Beneficiary;
use Illuminate\Database\Eloquent\Factories\Factory;

/**
Expand Down Expand Up @@ -43,7 +42,6 @@ public function definition(): array
}

return [
'beneficiary_id' => Beneficiary::inRandomOrder()->first()->id,
'risk_factors' => $selectedRiskFactors,
'extended_family_can_provide' => fake()->randomElements(Helps::values(), rand(0, 5)),
'friends_can_provide' => fake()->randomElements(Helps::values(), rand(0, 5)),
Expand Down
2 changes: 0 additions & 2 deletions database/factories/ViolenceFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use App\Enums\Frequency;
use App\Enums\Violence;
use App\Models\Beneficiary;
use Illuminate\Database\Eloquent\Factories\Factory;

/**
Expand All @@ -22,7 +21,6 @@ class ViolenceFactory extends Factory
public function definition(): array
{
return [
'beneficiary_id' => Beneficiary::inRandomOrder()->first()->id,
'violence_types' => fake()->randomElements(Violence::values(), rand(0, 5)),
'violence_primary_type' => fake()->randomElement(Violence::values()),
'frequency_violence' => fake()->randomElement(Frequency::values()),
Expand Down
2 changes: 0 additions & 2 deletions database/factories/ViolenceHistoryFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Database\Factories;

use App\Models\Beneficiary;
use Illuminate\Database\Eloquent\Factories\Factory;

/**
Expand All @@ -20,7 +19,6 @@ class ViolenceHistoryFactory extends Factory
public function definition(): array
{
return [
'beneficiary_id' => Beneficiary::inRandomOrder()->first()->id,
'date_interval' => fake()->text(),
'significant_events' => fake()->text(),
];
Expand Down

0 comments on commit 4ad03a0

Please sign in to comment.