Skip to content

Commit

Permalink
Merge pull request #864 from AgID/fix-test
Browse files Browse the repository at this point in the history
Use local vars as they are used only in one test
  • Loading branch information
pdavide authored Feb 3, 2021
2 parents bd7da79 + 147db9f commit df9e395
Showing 1 changed file with 22 additions and 41 deletions.
63 changes: 22 additions & 41 deletions tests/Feature/CRUDWebsiteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,6 @@ class CRUDWebsiteTest extends TestCase
*/
private $faker;

/**
* The custom public administration.
*
* @var PublicAdministration the custom public administration
*/
private $customPublicAdministration;

/**
* The custom website.
*
* @var Website the website for custom public administration
*/
private $customWebsite;

/**
* Pre-test setup.
*
Expand Down Expand Up @@ -121,26 +107,6 @@ protected function setUp(): void

$this->user->registerAnalyticsServiceAccount();

do {
$customPublicAdministration = factory(PublicAdministration::class)->make([
'status' => PublicAdministrationStatus::PENDING,
]);
} while ($customPublicAdministration->ipa_code === $this->publicAdministration->ipa_code);
$this->customPublicAdministration = $customPublicAdministration;
$this->customPublicAdministration->save();

do {
$customWebsite = factory(Website::class)->make([
'public_administration_id' => $this->customPublicAdministration->id,
'status' => WebsiteStatus::PENDING,
'type' => WebsiteType::INSTITUTIONAL_PLAY,
]);
} while ($customWebsite->slug === $this->website->slug);
$this->customWebsite = $customWebsite;
$this->customWebsite->save();

$this->customPublicAdministration->users()->sync([$this->user->id]);

Bouncer::dontCache();
Bouncer::scope()->onceTo($this->publicAdministration->id, function () {
$this->user->assign(UserRole::ADMIN);
Expand Down Expand Up @@ -367,27 +333,42 @@ public function testForceActivationCustomWebsiteSuccessful(): void
]);

$user->registerAnalyticsServiceAccount();
$this->customPublicAdministration->users()->sync([$user->id => ['user_status' => UserStatus::PENDING]]);

$this->assertTrue($this->customWebsite->status->is(WebsiteStatus::PENDING));
do {
$customPublicAdministration = factory(PublicAdministration::class)->make([
'status' => PublicAdministrationStatus::PENDING,
]);
} while ($customPublicAdministration->ipa_code === $this->publicAdministration->ipa_code);
$customPublicAdministration->save();

do {
$customWebsite = factory(Website::class)->make([
'public_administration_id' => $customPublicAdministration->id,
'status' => WebsiteStatus::PENDING,
'type' => WebsiteType::INSTITUTIONAL_PLAY,
]);
} while ($customWebsite->slug === $this->website->slug);
$customWebsite->save();

$customPublicAdministration->users()->sync([$user->id => ['user_status' => UserStatus::PENDING]]);

$this->actingAs($user)
->withSession([
'spid_sessionIndex' => 'fake-session-index',
'spid_user' => $spidUser,
'tenant_id' => $this->customPublicAdministration->id,
'tenant_id' => $customPublicAdministration->id,
])
->from(route('websites.index'))
->json('GET', route('websites.activate.force', ['website' => $this->customWebsite->slug]))
->json('GET', route('websites.activate.force', ['website' => $customWebsite->slug]))
->assertOk()
->assertJsonFragment([
'website_name' => e($this->customWebsite->name),
'website_name' => e($customWebsite->name),
]);

$user->refresh();
$this->customWebsite->refresh();
$customWebsite->refresh();

$this->assertTrue($this->customWebsite->status->is(WebsiteStatus::ACTIVE));
$this->assertTrue($customWebsite->status->is(WebsiteStatus::ACTIVE));
}

/**
Expand Down

0 comments on commit df9e395

Please sign in to comment.