Skip to content

Commit

Permalink
tests fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
rigonlucas committed Aug 24, 2024
1 parent 1668a9d commit 0128632
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
18 changes: 13 additions & 5 deletions infra/Database/Account/Repository/AccountRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,40 +7,48 @@
use Core\Application\Account\Commons\Gateways\AccountRepositoryInterface;
use Core\Domain\Entities\Account\AccountEntity;
use Core\Domain\Entities\Account\AccountJoinCodeEntity;
use Ramsey\Uuid\Uuid;

class AccountRepository implements AccountRepositoryInterface
{
public function findByid(int $id): ?AccountEntity
{
$accountModel = Account::query()->where('id', $id)->first();
$accountModel = Account::query()
->select(['id', 'name', 'uuid'])
->where('id', $id)
->first();
if (!$accountModel) {
return null;
}

return AccountEntity::forDetail(
id: $accountModel->id,
name: $accountModel->name,
uuid: $accountModel->uuid
uuid: Uuid::fromString($accountModel->uuid)
);
}

public function findByUuid(string $uuid): ?AccountEntity
{
$accountModel = Account::query()->where('uuid', $uuid)->first();
$accountModel = Account::query()
->select(['id', 'name', 'uuid'])
->where('uuid', $uuid)
->first();
if (!$accountModel) {
return null;
}

return AccountEntity::forDetail(
id: $accountModel->id,
name: $accountModel->name,
uuid: $accountModel->uuid
uuid: Uuid::fromString($accountModel->uuid)
);
}

public function findByAccessCode(string $code): ?AccountEntity
{
$accountJoin = AccountJoinCode::query()
->select(['id', 'code', 'account_id', 'expired_at'])
->where('code', '=', $code)
->whereNull('user_id')
->with(['account:id,name,uuid'])
Expand All @@ -57,7 +65,7 @@ public function findByAccessCode(string $code): ?AccountEntity
$accountEntity = AccountEntity::forDetail(
id: $accountJoin->account->id,
name: $accountJoin->account->name,
uuid: $accountJoin->account->uuid,
uuid: Uuid::fromString($accountJoin->account->uuid),
);

return $accountEntity->setJoinCodeEntity($accountJoinEntity);
Expand Down
3 changes: 2 additions & 1 deletion tests/Feature/Persistence/User/CreateUserCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Core\Domain\Entities\User\UserEntity;
use Core\Services\Framework\FrameworkContract;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Ramsey\Uuid\Uuid;
use Tests\TestCase;

class CreateUserCommandTest extends TestCase
Expand All @@ -26,7 +27,7 @@ public function test_deve_testar_create_de_um_usuario(): void
account: AccountEntity::forDetail(
id: $accountModel->id,
name: $accountModel->name,
uuid: $accountModel->uuid
uuid: Uuid::fromString($accountModel->uuid)
),
uuid: $this->app->make(FrameworkContract::class)::getInstance()->uuid()->uuid7Generate(),
birthday: now()->subYears(18)
Expand Down
5 changes: 3 additions & 2 deletions tests/Unit/Account/AccountEntityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Core\Application\Account\Commons\Exceptions\AccountNameInvalidException;
use Core\Domain\Entities\Account\AccountEntity;
use Core\Support\Http\ResponseStatus;
use Ramsey\Uuid\Uuid;
use Tests\TestCase;

class AccountEntityTest extends TestCase
Expand All @@ -14,7 +15,7 @@ public function test_create_account_for_create_name_is_valid()
// Arrange and Act
AccountEntity::forCreate(
name: '1',
uuid: 'uuid'
uuid: Uuid::uuid7()
);

// Assert
Expand All @@ -30,7 +31,7 @@ public function test_create_account_for_create_name_is_invalid()
// Arrange and Act
AccountEntity::forCreate(
name: '',
uuid: 'uuid'
uuid: Uuid::uuid7()
);
}
}

0 comments on commit 0128632

Please sign in to comment.