-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Debt] Improve seeding for RoD #10290
Changes from 45 commits
6cbfd3f
b3a2955
931aadc
d8f04dd
ce6cbbc
3588404
846834e
11aee99
c53fbd4
5be18a8
b33243a
d54122c
93b58f4
f921bcd
0c2e15c
6e23470
583b0fc
53b92ff
a36ece9
c819cbc
9790600
7a4c8a1
add3038
5788334
8f825e6
23ba5e3
22322fb
23122e2
590e70e
13356bf
e5d14d7
0cd7f01
d97a986
ea11119
e899cbf
5fd24d8
927ad79
77f1328
641bbe4
326ee85
a674653
cce5ff8
c178ca0
e036c05
1e5d6ec
8b25203
9594209
5059c9f
5bddd16
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,6 @@ | |
use App\Models\Classification; | ||
use App\Models\GeneralQuestion; | ||
use App\Models\Pool; | ||
use App\Models\PoolSkill; | ||
use App\Models\ScreeningQuestion; | ||
use App\Models\Skill; | ||
use App\Models\Team; | ||
|
@@ -72,65 +71,117 @@ public function definition() | |
]; | ||
} | ||
|
||
public function configure() | ||
public function withPoolSkills($essentialCount, $nonEssentialCount) | ||
{ | ||
return $this->afterCreating(function (Pool $pool) { | ||
return $this->afterCreating(function (Pool $pool) use ($essentialCount, $nonEssentialCount) { | ||
$skills = Skill::inRandomOrder()->limit(10)->get(); | ||
//slice first set of skills as essential skills | ||
$essentialSkills = $skills->slice(0, $essentialCount); | ||
//slice next set of skills as non essential skills | ||
$nonEssentialSkills = $skills->slice($essentialCount, $nonEssentialCount); | ||
$this->createPoolSkills($pool, $essentialSkills, PoolSkillType::ESSENTIAL->name); | ||
$this->createPoolSkills($pool, $nonEssentialSkills, PoolSkillType::NONESSENTIAL->name); | ||
}); | ||
} | ||
|
||
foreach ($skills->slice(0, 5) as $skill) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've removed this hard coded skills during pool creation as we need diff no. of skills for the tests. |
||
$poolSkill = new PoolSkill(); | ||
$poolSkill->skill_id = $skill->id; | ||
$poolSkill->type = PoolSkillType::ESSENTIAL->name; | ||
$poolSkill->required_skill_level = $this->faker->randomElement(array_column(SkillLevel::cases(), 'name')); | ||
$pool->poolSkills()->save($poolSkill); | ||
} | ||
foreach ($skills->slice(5, 5) as $skill) { | ||
$poolSkill = new PoolSkill(); | ||
$poolSkill->skill_id = $skill->id; | ||
$poolSkill->type = PoolSkillType::NONESSENTIAL->name; | ||
$poolSkill->required_skill_level = $this->faker->randomElement(array_column(SkillLevel::cases(), 'name')); | ||
$pool->poolSkills()->save($poolSkill); | ||
} | ||
private function createPoolSkills($pool, $skills, $type) | ||
{ | ||
// for each skills create it as pool skill | ||
foreach ($skills as $skill) { | ||
$pool->poolSkills()->create([ | ||
'skill_id' => $skill->id, | ||
'type' => $type, | ||
'required_skill_level' => $this->faker->randomElement(array_column(SkillLevel::cases(), 'name')), | ||
]); | ||
} | ||
} | ||
|
||
GeneralQuestion::factory() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this also has been taken out so we can customize the no. of questions per pool |
||
->count(3) | ||
->sequence( | ||
['sort_order' => 1], | ||
['sort_order' => 2], | ||
['sort_order' => 3], | ||
) | ||
->create(['pool_id' => $pool->id]); | ||
|
||
$screeningAssessmentStep = AssessmentStep::factory()->create( | ||
[ | ||
'pool_id' => $pool->id, | ||
'type' => AssessmentStepType::SCREENING_QUESTIONS_AT_APPLICATION->name, | ||
] | ||
); | ||
ScreeningQuestion::factory() | ||
->count(3) | ||
->sequence( | ||
['sort_order' => 1], | ||
['sort_order' => 2], | ||
['sort_order' => 3], | ||
) | ||
->create( | ||
[ | ||
'pool_id' => $pool->id, | ||
'assessment_step_id' => $screeningAssessmentStep->id, | ||
] | ||
); | ||
public function withQuestions($generalQuestionsCount, $screeningQuestionsCount) | ||
{ | ||
return $this->afterCreating(function (Pool $pool) use ($generalQuestionsCount, $screeningQuestionsCount) { | ||
$this->createQuestions(GeneralQuestion::class, $generalQuestionsCount, $pool->id); | ||
$this->createQuestions(ScreeningQuestion::class, $screeningQuestionsCount, $pool->id, $this->createAssessmentStepWithPoolSkills($pool, AssessmentStepType::SCREENING_QUESTIONS_AT_APPLICATION->name)->id); | ||
}); | ||
} | ||
|
||
private function createAssessmentStep($pool, $type) | ||
{ | ||
return AssessmentStep::factory() | ||
->create([ | ||
'pool_id' => $pool->id, | ||
'type' => $type, | ||
]); | ||
} | ||
|
||
private function createAssessmentStepWithPoolSkills($pool, $type) | ||
{ | ||
$step = $this->createAssessmentStep($pool, $type); | ||
$poolSkillArray = $pool->poolSkills->pluck('id')->toArray(); | ||
$step->poolSkills()->sync($poolSkillArray); | ||
|
||
return $step; | ||
} | ||
|
||
public function withAssessmentStepAndWithoutPoolSkills() | ||
{ | ||
return $this->afterCreating(function (Pool $pool) { | ||
$step = $this->createAssessmentStep($pool, AssessmentStepType::SCREENING_QUESTIONS_AT_APPLICATION->name); | ||
|
||
return $step; | ||
}); | ||
} | ||
|
||
private function createQuestions($factory, $count, $poolId, $assessmentStepId = null) | ||
{ | ||
$sequence = []; | ||
for ($i = 1; $i <= $count; $i++) { | ||
$sequence[] = ['sort_order' => $i]; | ||
} | ||
if ($assessmentStepId !== null) { | ||
$factory::factory() | ||
->count($count) | ||
->sequence(...$sequence) | ||
->create([ | ||
'pool_id' => $poolId, | ||
'assessment_step_id' => $assessmentStepId, | ||
]); | ||
} else { | ||
$factory::factory() | ||
->count($count) | ||
->sequence(...$sequence) | ||
->create([ | ||
'pool_id' => $poolId, | ||
]); | ||
} | ||
} | ||
|
||
/** | ||
* Indicate that the pool is draft. | ||
*/ | ||
public function draft(): Factory | ||
{ | ||
return $this->state(function (array $attributes) { | ||
// the base state is draft already | ||
return []; | ||
$hasSpecialNote = $this->faker->boolean(); | ||
$isRemote = $this->faker->boolean(); | ||
|
||
return [ | ||
'operational_requirements' => $this->faker->randomElements(array_column(OperationalRequirement::cases(), 'name'), 2), | ||
'key_tasks' => ['en' => $this->faker->paragraph().' EN', 'fr' => $this->faker->paragraph().' FR'], | ||
'your_impact' => ['en' => $this->faker->paragraph().' EN', 'fr' => $this->faker->paragraph().' FR'], | ||
'what_to_expect' => ['en' => $this->faker->paragraph().' EN', 'fr' => $this->faker->paragraph().' FR'], | ||
'what_to_expect_admission' => ['en' => $this->faker->paragraph().' EN', 'fr' => $this->faker->paragraph().' FR'], | ||
'about_us' => ['en' => $this->faker->paragraph().' EN', 'fr' => $this->faker->paragraph().' FR'], | ||
'security_clearance' => $this->faker->randomElement(array_column(SecurityStatus::cases(), 'name')), | ||
'advertisement_language' => $this->faker->randomElement(array_column(PoolLanguage::cases(), 'name')), | ||
'advertisement_location' => ! $isRemote ? ['en' => $this->faker->country(), 'fr' => $this->faker->country()] : null, | ||
'special_note' => ! $hasSpecialNote ? ['en' => $this->faker->paragraph().' EN', 'fr' => $this->faker->paragraph().' FR'] : null, | ||
'is_remote' => $this->faker->boolean, | ||
'stream' => $this->faker->randomElement(PoolStream::cases())->name, | ||
'process_number' => $this->faker->word(), | ||
'publishing_group' => $this->faker->randomElement(array_column(PublishingGroup::cases(), 'name')), | ||
'opportunity_length' => $this->faker->randomElement(array_column(PoolOpportunityLength::cases(), 'name')), | ||
]; | ||
}); | ||
} | ||
|
||
|
@@ -146,7 +197,6 @@ public function published(): Factory | |
return [ | ||
// published in the past, closes in the future | ||
'published_at' => $this->faker->dateTimeBetween('-30 days', '-1 days'), | ||
|
||
'operational_requirements' => $this->faker->randomElements(array_column(OperationalRequirement::cases(), 'name'), 2), | ||
'key_tasks' => ['en' => $this->faker->paragraph().' EN', 'fr' => $this->faker->paragraph().' FR'], | ||
'your_impact' => ['en' => $this->faker->paragraph().' EN', 'fr' => $this->faker->paragraph().' FR'], | ||
|
@@ -217,16 +267,47 @@ public function candidatesAvailableInSearch() | |
* | ||
* @return \Illuminate\Database\Eloquent\Factories\Factory | ||
*/ | ||
public function withAssessments() | ||
public function withAssessments($noOfAssessmentSteps = 2) | ||
{ | ||
return $this->afterCreating(function (Pool $pool) { | ||
$step1 = AssessmentStep::factory() | ||
->create(['pool_id' => $pool->id]); | ||
$step2 = AssessmentStep::factory() | ||
->create(['pool_id' => $pool->id]); | ||
$poolSkillArray = $pool->poolSkills->pluck('id')->toArray(); | ||
$step1->poolSkills()->sync(array_slice($poolSkillArray, 0, 5, true)); | ||
$step2->poolSkills()->sync(array_slice($poolSkillArray, 5, 5, true)); | ||
return $this->afterCreating(function (Pool $pool, $noOfAssessmentSteps) { | ||
$steps = []; | ||
$this->createAssessmentStepWithPoolSkills($pool, AssessmentStepType::SCREENING_QUESTIONS_AT_APPLICATION->name); | ||
|
||
for ($i = 0; $i < $noOfAssessmentSteps - 1; $i++) { | ||
$steps[$i] = $this->createAssessmentStepWithPoolSkills($pool, $this->faker->randomElement(array_column(AssessmentStepType::cases(), 'name'))->name); | ||
} | ||
}); | ||
} | ||
|
||
// Add a single assessment step to the pool for the given assessment step type | ||
public function WithAssessmentStep(AssessmentStepType $type) | ||
{ | ||
return $this->afterCreating(function (Pool $pool) use ($type) { | ||
|
||
$step = $this->createAssessmentStep($pool, $type->name); | ||
$poolSkillArray = $pool->poolSkills()->pluck('id')->toArray(); | ||
$step->poolSkills()->sync($poolSkillArray); | ||
|
||
return $step; | ||
}); | ||
} | ||
|
||
/** | ||
* Create a new pool or get an existing pool based on the given attributes. | ||
* | ||
* @param array $attributes The attributes of the pool. | ||
* @return Pool The created or existing pool. | ||
*/ | ||
public function createOrGetExisting($attributes = []) | ||
{ | ||
$pool = Pool::where('name->en', $attributes['name']['en']) | ||
->where('name->fr', $attributes['name']['fr']) | ||
->first(); | ||
|
||
if ($pool) { | ||
return $pool; | ||
} | ||
|
||
return $this->create($attributes); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The removal of the
configure()
function seemed to trip some stuff up as I believe it runs automatically.Resolved test failure by calling the needed function in 8f825e6