Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
iamgergo committed May 28, 2021
1 parent ec749da commit e8d6eca
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 15 deletions.
7 changes: 7 additions & 0 deletions src/Contracts/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@

interface User extends Breadcrumbable
{
/**
* Get the carts for the user.
*
* @return \Illuminate\Database\Eloquent\Relations\v
*/
public function carts(): HasMany;

/**
* Get the cart for the user.
*
Expand Down
16 changes: 8 additions & 8 deletions src/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,23 +114,23 @@ protected static function newFactory(): ?UserFactory
}

/**
* Get the active cart for the user.
* Get the carts for the user.
*
* @return \Illuminate\Database\Eloquent\Relations\HasOne
* @return \Illuminate\Database\Eloquent\Relations\v
*/
public function cart(): HasOne
public function carts(): HasMany
{
return $this->hasOne(Cart::getProxiedClass())->latestOfMany();
return $this->hasMany(Cart::getProxiedClass());
}

/**
* Get the carts for the user.
* Get the active cart for the user.
*
* @return \Illuminate\Database\Eloquent\Relations\v
* @return \Illuminate\Database\Eloquent\Relations\HasOne
*/
public function carts(): HasMany
public function cart(): HasOne
{
return $this->hasMany(Cart::getProxiedClass());
return $this->hasOne(Cart::getProxiedClass())->latestOfMany();
}

/**
Expand Down
26 changes: 19 additions & 7 deletions tests/Unit/UserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
class UserTest extends TestCase
{
/** @test */
public function it_can_have_a_cart()
public function a_user_has_cart()
{
$this->assertNull($this->user->cart);

Expand All @@ -25,7 +25,19 @@ public function it_can_have_a_cart()
}

/** @test */
public function it_has_orders()
public function a_user_has_carts()
{
$cart = $this->user->carts()->save(
Cart::factory()->make()
);

$this->user->refresh();

$this->assertTrue($this->user->carts->pluck('id')->contains($cart->id));
}

/** @test */
public function a_user_has_orders()
{
$orders = $this->user->orders()->saveMany(
Order::factory()->count(3)->make()
Expand All @@ -37,7 +49,7 @@ public function it_has_orders()
}

/** @test */
public function it_has_addresses()
public function a_user_has_addresses()
{
$addresses = $this->user->addresses()->saveMany(
Address::factory()->count(3)->make()
Expand All @@ -55,7 +67,7 @@ public function it_has_addresses()
}

/** @test */
public function it_has_avatar()
public function a_user_has_avatar()
{
$this->assertEquals(
asset('vendor/bazar/img/avatar-placeholder.svg'),
Expand All @@ -64,21 +76,21 @@ public function it_has_avatar()
}

/** @test */
public function it_can_be_admin()
public function a_user_can_be_admin()
{
$this->assertFalse($this->user->isAdmin());
$this->assertTrue($this->admin->isAdmin());
}

/** @test */
public function it_is_breadcrumbable()
public function a_user_is_breadcrumbable()
{
$this->assertInstanceOf(Breadcrumbable::class, $this->user);
$this->assertSame($this->user->name, $this->user->toBreadcrumb($this->app['request']));
}

/** @test */
public function it_has_query_scopes()
public function a_user_has_query_scopes()
{
$this->assertSame(
$this->user->newQuery()->where(function ($q) {
Expand Down

0 comments on commit e8d6eca

Please sign in to comment.