Skip to content

Commit

Permalink
Adapt dusk tests to GDPR
Browse files Browse the repository at this point in the history
  • Loading branch information
danon committed Dec 21, 2023
1 parent 8820fd2 commit 706edfc
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 33 deletions.
7 changes: 3 additions & 4 deletions tests/Browser/ApiTokenTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class ApiTokenTest extends DuskTestCase

public function testCreateToken()
{
$user = factory(User::class)->create();
$user = factory(User::class)->create(['gdpr' => '{}']);

$this->browse(function (Browser $browser) use ($user) {
$browser
Expand All @@ -22,9 +22,8 @@ public function testCreateToken()
->press('Dodaj')
->waitForText('Twój nowy token')
->press('OK')
->assertSee($token);

$browser->logout();
->assertSee($token)
->logout();
});
}
}
26 changes: 22 additions & 4 deletions tests/Browser/ConfirmTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

namespace Tests\Browser;

use Coyote\User;
Expand All @@ -8,12 +7,25 @@

class ConfirmTest extends DuskTestCase
{
public function tearDown(): void
{
parent::setUp();
$this->browse(fn(Browser $browser) => $browser->script('window.localStorage.clear()'));
}

public function testSendVerificationEmail()
{
$user = factory(User::class)->create(['password' => bcrypt('123'), 'is_confirm' => false]);
/** @var User $user */
$user = factory(User::class)->create([
'password' => bcrypt('123'),
'is_confirm' => false,
]);

$this->browse(function (Browser $browser) use ($user) {
$browser->visit('/Confirm')
$browser
->visit('/Confirm')
->click('#gdpr-all')
->waitUntilMissing('.gdpr-modal')
->type('email', $user->email)
->press('Wyślij e-mail z linkiem aktywacyjnym')
->assertSee('Na podany adres e-mail został wysłany link aktywacyjny.');
Expand All @@ -26,6 +38,8 @@ public function testSendVerificationFailedToDueInvalidEmail()

$this->browse(function (Browser $browser) use ($faker) {
$browser->visit('/Confirm')
->click('#gdpr-all')
->waitUntilMissing('.gdpr-modal')
->type('email', $faker->email)
->press('Wyślij e-mail z linkiem aktywacyjnym')
->assertSee('Podany adres e-mail nie istnieje.');
Expand All @@ -34,10 +48,13 @@ public function testSendVerificationFailedToDueInvalidEmail()

public function testSendVerificationFailedToDuePreviousVerificationProcess()
{
/** @var User $user */
$user = factory(User::class)->create(['password' => bcrypt('123')]);

$this->browse(function (Browser $browser) use ($user) {
$browser->visit('/Confirm')
->click('#gdpr-all')
->waitUntilMissing('.gdpr-modal')
->type('email', $user->email)
->press('Wyślij e-mail z linkiem aktywacyjnym')
->assertSee('Ten adres e-mail jest już zweryfikowany.');
Expand All @@ -46,7 +63,8 @@ public function testSendVerificationFailedToDuePreviousVerificationProcess()

public function testSendVerificationEmailWithDifferentEmail()
{
$user = factory(User::class)->create(['password' => bcrypt('123'), 'is_confirm' => false]);
/** @var User $user */
$user = factory(User::class)->create(['password' => bcrypt('123'), 'is_confirm' => false, 'gdpr' => '{}']);
$faker = Factory::create();

$this->browse(function (Browser $browser) use ($user, $faker) {
Expand Down
2 changes: 1 addition & 1 deletion tests/Browser/ForumTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function testShowValidateErrors()
public function testWriteTopic()
{
$forum = $this->createForum();
$user = factory(User::class)->create(['reputation' => 5000]);
$user = factory(User::class)->create(['reputation' => 5000, 'gdpr' => '{}']);

$this->browse(function (Browser $browser) use ($forum, $user) {
$faker = Factory::create();
Expand Down
7 changes: 2 additions & 5 deletions tests/Browser/JobApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ class JobApplicationTest extends DuskTestCase

public function testSuccessfulSubmitJobApplication()
{


try {
$mpdf = new Mpdf(['tempDir' => storage_path('app')]);
$mpdf->WriteHTML($this->faker->text);
Expand All @@ -24,16 +22,15 @@ public function testSuccessfulSubmitJobApplication()
$this->browse(function (Browser $browser) {
$job = factory(Job::class)->create(['email' => $this->faker->email]);

$browser->visit('/Praca/Application/' . $job->id)
$browser
->visit('/Praca/Application/' . $job->id)
->resize(1920, 1080)
->check('label[for="enable-invoice"]')
->attach('.thumbnail-mask', storage_path('demo.pdf'))

->type('name', $name = $this->faker->name)
->type('email', $email = $this->faker->email)
->type('phone', $phone = $this->faker->phoneNumber)
->type('github', $url = $this->faker->url)

->press('Wyślij')
->waitForText('Zgłoszenie zostało prawidłowo wysłane.');

Expand Down
13 changes: 6 additions & 7 deletions tests/Browser/JobPostingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ protected function setUp(): void
{
parent::setUp();

$this->user = factory(User::class)->create();
$this->user = factory(User::class)->create(['gdpr' => '{}']);
}

public function testSubmitWithoutFirm()
{
$fake = Factory::create();

$this->browse(function (Browser $browser) use ($fake) {
$browser->loginAs($this->user);

$browser->visit('/Praca/Submit')
$browser
->loginAs($this->user)
->visit('/Praca/Submit')
->resize(1920, 1080)
->type('title', $title = $fake->text(50))
->type('salary_from', $salaryFrom = $fake->numberBetween(0, 999))
Expand All @@ -39,9 +39,8 @@ public function testSubmitWithoutFirm()
->clickLink('Powrót do ogłoszenia')
->assertSeeIn('.media-heading', $title)
->assertSeeIn('.salary', $salaryFrom)
->assertSeeIn('.salary', '');

$browser->logout();
->assertSeeIn('.salary', '')
->logout();
});
}

Expand Down
22 changes: 12 additions & 10 deletions tests/Browser/RegisterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,18 @@ public function testRegisterUser()
$this->browse(function (Browser $browser) {
$faker = Factory::create();

$browser->visit('/Register')
->type('name', $faker->userName)
->type('email', $faker->email)
->type('password', $password = $faker->password)
->type('password_confirmation', $password)
->check('label[for="terms"]')
->press('Utwórz konto')
->assertPathIs('/User');

$browser->logout();
$browser
->visit('/Register')
->click('#gdpr-all')
->waitUntilMissing('.gdpr-modal')
->type('name', $faker->userName)
->type('email', $faker->email)
->type('password', $password = $faker->password)
->type('password_confirmation', $password)
->check('label[for="terms"]')
->press('Utwórz konto')
->assertPathIs('/User')
->logout();
});
}

Expand Down
4 changes: 2 additions & 2 deletions tests/Browser/UserAccountTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class UserAccountTest extends DuskTestCase
{
public function testDeleteAccountWithPassword()
{
$user = factory(User::class)->create(['password' => Hash::make('123')]);
$user = factory(User::class)->create(['password' => Hash::make('123'), 'gdpr' => '{}']);

$this->browse(function (Browser $browser) use ($user) {
$faker = Factory::create();
Expand All @@ -34,7 +34,7 @@ public function testDeleteAccountWithPassword()

public function testDeleteAccountWithoutPassword()
{
$user = factory(User::class)->create(['password' => null]);
$user = factory(User::class)->create(['password' => null, 'gdpr' => '{}']);

$this->browse(function (Browser $browser) use ($user) {
$browser
Expand Down

0 comments on commit 706edfc

Please sign in to comment.