Ejemplo n.º 1
0
 /** @test */
 public function it_returns_users_having_any_company_of_an_industry()
 {
     $dbUserRepository = new DbUserRepository();
     $dbCompanyRepository = new DbCompanyRepository();
     factory(User::class, 2)->create();
     // Use to validate it does not return these.
     $expectedUsers = factory(User::class, 2)->create();
     $dbUserRepository->assignCompanyRepresentativeRole($expectedUsers->get(0));
     $dbUserRepository->assignCompanyRepresentativeRole($expectedUsers->get(1));
     $industry = factory(Industry::class)->create();
     factory(Company::class)->create();
     factory(Company::class)->create(['industry_id' => $industry->id, 'user_id' => $expectedUsers->get(0)->id]);
     $keys = $expectedUsers->get(0)->getFillable();
     $actualUsers = $dbUserRepository->whereCompaniesIndustry($industry)->get();
     $this->assertTrue($dbUserRepository->hasCompanyRepresentativeRole($actualUsers->get(0)));
     $this->assertCount(1, $actualUsers);
     $this->assertSame(array_only($expectedUsers->toArray(), $keys), array_only($actualUsers->toArray(), $keys));
     $company = factory(Company::class)->create(['industry_id' => $industry->id]);
     $dbCompanyRepository->assignRepresentativeUser($company, $expectedUsers->get(0));
     $actualUsers = $dbUserRepository->whereCompaniesIndustry($industry)->get();
     $this->assertCount(2, $actualUsers);
 }