|
|
|
|
@ -14,7 +14,7 @@ class QccEnterpriseStudentFilterTest extends TestCase
|
|
|
|
|
config(['database.default' => 'sqlite', 'database.connections.sqlite.database' => ':memory:', 'audit.enabled' => false]);
|
|
|
|
|
DB::purge('sqlite');
|
|
|
|
|
Schema::create('companies', function (Blueprint $t) { $t->id(); $t->string('company_name'); $t->string('credit_code'); $t->timestamps(); $t->softDeletes(); });
|
|
|
|
|
Schema::create('company_qcc_accounts', function (Blueprint $t) { $t->id(); $t->integer('company_id'); $t->string('status'); });
|
|
|
|
|
Schema::create('company_qcc_accounts', function (Blueprint $t) { $t->id(); $t->integer('company_id')->unique(); $t->string('status'); $t->integer('selected_by')->nullable(); $t->dateTime('selected_at')->nullable(); $t->timestamps(); });
|
|
|
|
|
Schema::create('users', function (Blueprint $t) { $t->id(); $t->integer('company_id'); $t->string('name'); $t->string('username'); $t->string('no')->nullable(); $t->string('company_position')->nullable(); $t->integer('is_schoolmate'); $t->softDeletes(); });
|
|
|
|
|
Schema::create('courses', function (Blueprint $t) { $t->id(); $t->string('name'); $t->integer('type'); $t->date('start_date')->nullable(); $t->softDeletes(); });
|
|
|
|
|
Schema::create('course_signs', function (Blueprint $t) { $t->id(); $t->integer('course_id'); $t->integer('user_id'); $t->integer('status'); $t->softDeletes(); });
|
|
|
|
|
@ -37,15 +37,19 @@ class QccEnterpriseStudentFilterTest extends TestCase
|
|
|
|
|
{
|
|
|
|
|
return (new QccEnterpriseAccountController())->$method(Request::create('/', 'GET', $params))->getData(true);
|
|
|
|
|
}
|
|
|
|
|
public function test_unfiltered_companies_remain_and_only_approved_students_are_shown(): void
|
|
|
|
|
public function test_candidates_require_an_alumnus_and_do_not_duplicate_companies(): void
|
|
|
|
|
{
|
|
|
|
|
$result = $this->query([]);
|
|
|
|
|
$this->assertEquals(3, $result['total']);
|
|
|
|
|
$this->assertEquals(1, $result['total']);
|
|
|
|
|
$company = collect($result['data'])->firstWhere('id', 1);
|
|
|
|
|
$this->assertCount(2, $company['users']);
|
|
|
|
|
$this->assertCount(1, $company['users'][0]['course_signs']);
|
|
|
|
|
$this->assertEquals('管理课程', $company['users'][0]['course_signs'][0]['course']['name']);
|
|
|
|
|
$this->assertEquals([], collect($result['data'])->firstWhere('id', 2)['users']);
|
|
|
|
|
$this->assertEquals([1], array_column($result['data'], 'id'));
|
|
|
|
|
DB::table('users')->where('id', 2)->update(['is_schoolmate' => 1]);
|
|
|
|
|
$this->assertEquals(1, $this->query([])['total']);
|
|
|
|
|
DB::table('users')->where('company_id', 1)->update(['deleted_at' => now()]);
|
|
|
|
|
$this->assertEquals(0, $this->query([])['total']);
|
|
|
|
|
}
|
|
|
|
|
public function test_combined_filters_match_same_student_and_same_approved_course(): void
|
|
|
|
|
{
|
|
|
|
|
@ -58,4 +62,48 @@ class QccEnterpriseStudentFilterTest extends TestCase
|
|
|
|
|
}
|
|
|
|
|
$this->assertCount(2, $this->query(['keyword' => 'credit1'], 'index')['data'][0]['company']['users']);
|
|
|
|
|
}
|
|
|
|
|
private function actionController(): QccEnterpriseAccountController
|
|
|
|
|
{
|
|
|
|
|
return new class extends QccEnterpriseAccountController {
|
|
|
|
|
public function getUserId() { return 7; }
|
|
|
|
|
protected function log(string $name, string $remark = ''): void {}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
public function test_bulk_non_occupying_enrollment_and_status_filter(): void
|
|
|
|
|
{
|
|
|
|
|
DB::table('company_qcc_accounts')->where('company_id', 1)->delete();
|
|
|
|
|
$controller = $this->actionController();
|
|
|
|
|
$controller->selectNonOccupying(Request::create('/', 'POST', ['company_ids' => [1]]));
|
|
|
|
|
$row = DB::table('company_qcc_accounts')->where('company_id', 1)->first();
|
|
|
|
|
$this->assertEquals('non_occupying', $row->status);
|
|
|
|
|
$this->assertEquals(7, $row->selected_by);
|
|
|
|
|
$this->assertNotNull($row->selected_at);
|
|
|
|
|
$this->assertFalse(\App\Models\CompanyQccAccount::where('company_id', 1)->first()->isCallable());
|
|
|
|
|
foreach (['candidates', 'index'] as $method) {
|
|
|
|
|
$this->assertEquals(1, $this->query(['status' => 'non_occupying'], $method)['total']);
|
|
|
|
|
$this->assertEquals(0, $this->query(['status' => 'selected'], $method)['total']);
|
|
|
|
|
}
|
|
|
|
|
$this->assertEquals(0, $this->query(['status' => 'none'])['total']);
|
|
|
|
|
}
|
|
|
|
|
public function test_bulk_non_occupying_rejects_existing_states_without_partial_changes(): void
|
|
|
|
|
{
|
|
|
|
|
DB::table('company_qcc_accounts')->where('company_id', 1)->delete();
|
|
|
|
|
foreach (['occupied', 'selected', 'unknown', 'non_occupying'] as $status) {
|
|
|
|
|
DB::table('company_qcc_accounts')->where('company_id', 2)->update(['status' => $status]);
|
|
|
|
|
$result = $this->actionController()->selectNonOccupying(Request::create('/', 'POST', ['company_ids' => [1, 2]]))->getData(true);
|
|
|
|
|
$this->assertArrayHasKey('errcode', $result);
|
|
|
|
|
$this->assertFalse(DB::table('company_qcc_accounts')->where('company_id', 1)->exists());
|
|
|
|
|
$this->assertEquals($status, DB::table('company_qcc_accounts')->where('company_id', 2)->value('status'));
|
|
|
|
|
}
|
|
|
|
|
$result = $this->actionController()->selectNonOccupying(Request::create('/', 'POST', ['company_ids' => [1, 999]]))->getData(true);
|
|
|
|
|
$this->assertArrayHasKey('errcode', $result);
|
|
|
|
|
$this->assertFalse(DB::table('company_qcc_accounts')->where('company_id', 1)->exists());
|
|
|
|
|
}
|
|
|
|
|
public function test_candidate_enrollment_still_creates_selected_status(): void
|
|
|
|
|
{
|
|
|
|
|
DB::table('company_qcc_accounts')->where('company_id', 1)->delete();
|
|
|
|
|
$this->actionController()->select(Request::create('/', 'POST', ['company_ids' => [1]]));
|
|
|
|
|
$this->assertEquals('selected', DB::table('company_qcc_accounts')->where('company_id', 1)->value('status'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|