mirror of
https://gitlab.com/izyim/wetrack.git
synced 2026-08-19 04:23:57 +00:00
Initial commit
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Support;
|
||||
|
||||
use Database\Factories\UserFactory;
|
||||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
use Illuminate\Testing\TestResponse;
|
||||
|
||||
trait WithLogin
|
||||
{
|
||||
use WithFaker;
|
||||
|
||||
/**
|
||||
* Create a new user instance.
|
||||
*/
|
||||
private function validCredentials(array $attributes = null): array
|
||||
{
|
||||
$password = $this->faker->password(8);
|
||||
$user = UserFactory::new($attributes);
|
||||
$userEloquentModel = UserMapper::toEloquent($user);
|
||||
$userEloquentModel->password = $password;
|
||||
$userEloquentModel->save();
|
||||
|
||||
return [
|
||||
'id' => $userEloquentModel->id,
|
||||
'email' => $user->email,
|
||||
'password' => $password,
|
||||
];
|
||||
}
|
||||
|
||||
private function newLoggedAdmin(): array
|
||||
{
|
||||
$credentials = $this->validCredentials(['is_admin' => true]);
|
||||
$response = $this->post('auth/login', $credentials);
|
||||
return ['token' => $this->getToken($response), ...$credentials];
|
||||
}
|
||||
|
||||
private function newLoggedUser(): array
|
||||
{
|
||||
$credentials = $this->validCredentials(['is_admin' => false]);
|
||||
$response = $this->post('auth/login', $credentials);
|
||||
return ['token' => $this->getToken($response), ...$credentials];
|
||||
}
|
||||
|
||||
private function getToken(TestResponse $response)
|
||||
{
|
||||
$arResponse = json_decode($response->getContent(), true);
|
||||
return $arResponse['accessToken'];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Support;
|
||||
|
||||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
use Src\Services\Project\Application\Mappers\ProjectMapper;
|
||||
use Src\Services\Project\Domain\Factories\ProjectFactory;
|
||||
use Src\Services\Project\Domain\Models\Project;
|
||||
|
||||
trait WithProjects
|
||||
{
|
||||
use WithFaker;
|
||||
|
||||
public function newProject(): Project
|
||||
{
|
||||
$project = ProjectFactory::new();
|
||||
$projectEloquentModel = ProjectMapper::toEloquent($project);
|
||||
$projectEloquentModel->save();
|
||||
return ProjectMapper::fromEloquent($projectEloquentModel);
|
||||
}
|
||||
|
||||
public function createRandomProjects(int $projectsCount) : void
|
||||
{
|
||||
foreach (range(1, $projectsCount) as $_) {
|
||||
$this->newProject();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user