Skip to content
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

Test cases for Jobs (HR-> Opportunities) #3385

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
112 changes: 112 additions & 0 deletions Modules/HR/Tests/Feature/OpportunitiesTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
<?php

namespace Modules\HR\Tests\Unit;

/*
* @var \Illuminate\Database\Eloquent\Factory $factory
*/

use Illuminate\Foundation\Testing\RefreshDatabase;
use Modules\HR\Entities\Job;
use Tests\TestCase;

class OpportunitiesTest extends TestCase
{
use RefreshDatabase;

public function setUp(): void
{
parent::setUp();
$this->setUpRolesAndPermissions();
$this->signIn('super-admin');
}

public function tearDown(): void
{
parent::tearDown();
}

/**
* A basic test example.
*
* @return void
*/
public function test_job_listing()
{
$response = $this->get(route('recruitment.opportunities'));
$response->assertStatus(200);
}

public function test_create_job()
{
$job = Job::factory()->raw([
'title' => 'This is a new job',
]);

$response = $this->post(route('recruitment.opportunities.store'), $job);

$rawJob = Job::first()->get('id');
$job = json_decode($rawJob);
$jobId = $job[0]->id;

$response->assertRedirect(route('recruitment.opportunities.edit', $jobId));
}

public function test_fail_creation_without_required_fields()
{
$job = Job::factory()->raw([
'title' => '',
'description' => '',
'domain' => '',
]);

$response = $this->from('recruitment.opportunities.create')->post(route('recruitment.opportunities.store'), $job);
$response->assertRedirect('recruitment.opportunities.create');
}

public function test_update_job()
{
Job::factory()->count(3)->create();
$jobToUpdate = Job::find(2);
$jobId = $jobToUpdate->id;
$updateRoute = route('recruitment.opportunities.update', $jobId);

$updatedJob = [
'title' => 'This is updated title.',
'description' => $jobToUpdate->description,
'domain' => $jobToUpdate->domain,
'type' => 'internship',
'status' => 'closed',
];

if ($updatedJob['type'] == 'volunteer') {
$updateRoute = route('volunteer.opportunities.update', $jobId);
}

$response = $this->patch($updateRoute, $updatedJob);
$response->assertRedirect(route('recruitment.opportunities.edit', $jobId));
}

public function test_fail_update_without_required_fields()
{
Job::factory()->count(10)->create();

$jobToUpdate = Job::find(6);
$jobId = $jobToUpdate->id;
$updateRoute = route('recruitment.opportunities.update', $jobId);
$updatedJob = [
'title' => '',
'description' => '',
'domain' => '',
'type' => '',
'status' => '',
];

if ($updatedJob['type'] == 'volunteer') {
$updateRoute = route('volunteer.opportunities.update', $jobId);
}

$response = $this->from(route('recruitment.opportunities.edit', $jobId))->patch($updateRoute, $updatedJob);
$response->assertRedirect(route('recruitment.opportunities.edit', $jobId));
}
}
2 changes: 1 addition & 1 deletion routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@

Route::post('projects/{project}/add-employee', 'ProjectController@addEmployee');
Route::post('projects/{project}/remove-employee', 'ProjectController@removeEmployee');
Route::get('my-projects/{employee}', 'hr\Employees\EmployeeController@showProjects')->name('projects.my-projects');
// Route::get('my-projects/{employee}', 'hr\Employees\EmployeeController@showProjects')->name('projects.my-projects');
Route::get('clients/{client}/get-projects', 'ClientController@getProjects');

Route::prefix('settings')->namespace('Settings')->group(function () {
Expand Down