Skip to content

Commit

Permalink
Adding the pending code tests
Browse files Browse the repository at this point in the history
  • Loading branch information
amitavroy committed Dec 25, 2024
1 parent f47ce98 commit 11aa913
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
10 changes: 10 additions & 0 deletions tests/Feature/Customers/CustomerControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,14 @@

get(route('customer.index'))->assertOk();
});

it('returns not found if user is not customer', function () {
$this->withoutVite();

$user = User::factory()->admin()->create();

actingAs(User::factory()->admin()->create());

get(route('customer.show', ['customer' => $user]))->assertNotFound();
});
});
24 changes: 24 additions & 0 deletions tests/Feature/Models/NotificationModelTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

use App\Domain\Notification\Models\Notification;
use App\Models\User;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;

uses(RefreshDatabase::class);

describe('Notification model test', function () {
it('belongs to many users', function () {
$user = User::factory()->create();
$notification = Notification::factory()->create();

DB::table('user_notification')->insert([
'user_id' => $user->id,
'notification_id' => $notification->id,
'read_at' => now(),
]);

expect($notification->readByUsers())->toBeInstanceOf(BelongsToMany::class);
});
});
24 changes: 24 additions & 0 deletions tests/Feature/Models/UserModelTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

use App\Models\User;
use App\Domain\Notification\Models\Notification;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;

uses(RefreshDatabase::class);

describe('User model test', function () {
it('belongs to many notifications', function () {
$user = User::factory()->create();
$notification = Notification::factory()->create();

DB::table('user_notification')->insert([
'user_id' => $user->id,
'notification_id' => $notification->id,
'read_at' => now(),
]);

expect($user->readNotifications())->toBeInstanceOf(BelongsToMany::class);
});
});

0 comments on commit 11aa913

Please sign in to comment.