Merge branch 'feature/TDD' into 'development'

Feature/tdd

See merge request CIEFWorldwideSdnBhd/shipping-portal!140
This commit is contained in:
Martin Maina Kiragu
2023-03-01 03:54:54 +00:00
29 changed files with 1028 additions and 86 deletions
+5 -3
View File
@@ -1,6 +1,6 @@
APP_NAME=Laravel
APP_ENV=local
APP_KEY=
APP_KEY=base64:rIar2fvNeRzQdvKOgLUg03detGDMx6ym2SYFRjawrAc=
APP_DEBUG=true
APP_URL=http://localhost
@@ -10,9 +10,9 @@ LOG_LEVEL=debug
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel
DB_DATABASE=shpping_portal
DB_USERNAME=root
DB_PASSWORD=
DB_PASSWORD=P@ssw0rd
BROADCAST_DRIVER=log
CACHE_DRIVER=file
@@ -55,3 +55,5 @@ EXCHANGE_URL=https://dev.exchange.cief-malaysia.com/
MIX_EXCHANGE_URL="${EXCHANGE_URL}"
YD_API_CODE=''
JWT_SECRET=Btj63iMEleEaww6Bb2IBECkxWn7YHPhhPFluAkg9DfcQik0qDRy6QW75ABGmPT2h
+20 -43
View File
@@ -1,62 +1,39 @@
<p align="center"><a href="https://laravel.com" target="_blank"><img src="https://raw.githubusercontent.com/laravel/art/master/logo-lockup/5%20SVG/2%20CMYK/1%20Full%20Color/laravel-logolockup-cmyk-red.svg" width="400"></a></p>
## Shipping portal documentation
<p align="center">
<a href="https://travis-ci.org/laravel/framework"><img src="https://travis-ci.org/laravel/framework.svg" alt="Build Status"></a>
<a href="https://packagist.org/packages/laravel/framework"><img src="https://img.shields.io/packagist/dt/laravel/framework" alt="Total Downloads"></a>
<a href="https://packagist.org/packages/laravel/framework"><img src="https://img.shields.io/packagist/v/laravel/framework" alt="Latest Stable Version"></a>
<a href="https://packagist.org/packages/laravel/framework"><img src="https://img.shields.io/packagist/l/laravel/framework" alt="License"></a>
</p>
simple documentation on how to install, run, test, commit and deploy application
## About Laravel
## creating and running unit tests
Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experience to be truly fulfilling. Laravel takes the pain out of development by easing common tasks used in many web projects, such as:
Required Tools
- [Simple, fast routing engine](https://laravel.com/docs/routing).
- [Powerful dependency injection container](https://laravel.com/docs/container).
- Multiple back-ends for [session](https://laravel.com/docs/session) and [cache](https://laravel.com/docs/cache) storage.
- Expressive, intuitive [database ORM](https://laravel.com/docs/eloquent).
- Database agnostic [schema migrations](https://laravel.com/docs/migrations).
- [Robust background job processing](https://laravel.com/docs/queues).
- [Real-time event broadcasting](https://laravel.com/docs/broadcasting).
- Chromium Driver / selenium
- add running and setting selenium on all OS if possible
Laravel is accessible, powerful, and provides tools required for large, robust applications.
Required Packages :
## Learning Laravel
- laravel/legacy-factories
Laravel has the most extensive and thorough [documentation](https://laravel.com/docs) and video tutorial library of all modern web application frameworks, making it a breeze to get started with the framework.
- codeception/codeception
If you don't feel like reading, [Laracasts](https://laracasts.com) can help. Laracasts contains over 1500 video tutorials on a range of topics including Laravel, modern PHP, unit testing, and JavaScript. Boost your skills by digging into our comprehensive video library.
Or Simply Run
## Laravel Sponsors
``Composer install``
We would like to extend our thanks to the following sponsors for funding Laravel development. If you are interested in becoming a sponsor, please visit the Laravel [Patreon page](https://patreon.com/taylorotwell).
To create a unit test
### Premium Partners
``php artisan make test: Test Example --unit``
- **[Vehikl](https://vehikl.com/)**
- **[Tighten Co.](https://tighten.co)**
- **[Kirschbaum Development Group](https://kirschbaumdevelopment.com)**
- **[64 Robots](https://64robots.com)**
- **[Cubet Techno Labs](https://cubettech.com)**
- **[Cyber-Duck](https://cyber-duck.co.uk)**
- **[Many](https://www.many.co.uk)**
- **[Webdock, Fast VPS Hosting](https://www.webdock.io/en)**
- **[DevSquad](https://devsquad.com)**
- **[Curotec](https://www.curotec.com/services/technologies/laravel/)**
- **[OP.GG](https://op.gg)**
Running the tests :
## Contributing
Running a single Test
Thank you for considering contributing to the Laravel framework! The contribution guide can be found in the [Laravel documentation](https://laravel.com/docs/contributions).
`` php artisan test --filter Example``
## Code of Conduct
Running Unit tests -
In order to ensure that the Laravel community is welcoming to all, please review and abide by the [Code of Conduct](https://laravel.com/docs/contributions#code-of-conduct).
`` php artisan test ``
## Security Vulnerabilities
Running Codeception tests -
If you discover a security vulnerability within Laravel, please send an e-mail to Taylor Otwell via [taylor@laravel.com](mailto:taylor@laravel.com). All security vulnerabilities will be promptly addressed.
``vendor/bin/codecept run``
## License
The Laravel framework is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT).
+12
View File
@@ -0,0 +1,12 @@
paths:
tests: tests
output: tests/_output
data: tests/_data
support: tests/_support
envs: tests/_envs
actor_suffix: Tester
extensions:
enabled:
- Codeception\Extension\RunFailed
params:
- .env.testing
+13 -2
View File
@@ -2,20 +2,24 @@
"name": "laravel/laravel",
"type": "project",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"keywords": [
"framework",
"laravel"
],
"license": "MIT",
"require": {
"php": "^7.3",
"ext-fileinfo": "^7.3",
"ext-json": "*",
"barryvdh/laravel-dompdf": "^0.9.0",
"carlos-meneses/laravel-mpdf": "^2.1",
"carlos-meneses/laravel-mpdf": "*",
"doctrine/dbal": "^3.1",
"fideloper/proxy": "^4.4",
"fruitcake/laravel-cors": "^2.0",
"guzzlehttp/guzzle": "^7.0.1",
"intervention/image": "^2.5",
"laravel/framework": "^8.40",
"laravel/legacy-factories": "^1.3",
"laravel/tinker": "^2.5",
"maatwebsite/excel": "^3.1",
"rinvex/countries": "^6.1",
@@ -25,6 +29,13 @@
"tymon/jwt-auth": "^1.0"
},
"require-dev": {
"barryvdh/laravel-ide-helper": "^2.12",
"codeception/codeception": "^4.2",
"codeception/module-asserts": "^2.0",
"codeception/module-laravel": "^2.3",
"codeception/module-phpbrowser": "^2.0",
"codeception/module-rest": "^2.0",
"codeception/module-webdriver": "^2.0",
"facade/ignition": "^2.5",
"fakerphp/faker": "^1.9.1",
"laravel/sail": "^1.0.1",
-14
View File
@@ -25,23 +25,9 @@ class UserFactory extends Factory
return [
'name' => $this->faker->name(),
'email' => $this->faker->unique()->safeEmail(),
'email_verified_at' => now(),
'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password
'remember_token' => Str::random(10),
];
}
/**
* Indicate that the model's email address should be unverified.
*
* @return \Illuminate\Database\Eloquent\Factories\Factory
*/
public function unverified()
{
return $this->state(function (array $attributes) {
return [
'email_verified_at' => null,
];
});
}
}
+2 -2
View File
@@ -21,8 +21,8 @@
<server name="APP_ENV" value="testing"/>
<server name="BCRYPT_ROUNDS" value="4"/>
<server name="CACHE_DRIVER" value="array"/>
<!-- <server name="DB_CONNECTION" value="sqlite"/> -->
<!-- <server name="DB_DATABASE" value=":memory:"/> -->
<server name="DB_CONNECTION" value="sqlite"/>
<server name="DB_DATABASE" value=":memory:"/>
<server name="MAIL_MAILER" value="array"/>
<server name="QUEUE_CONNECTION" value="sync"/>
<server name="SESSION_DRIVER" value="array"/>
+3 -2
View File
@@ -3,15 +3,16 @@
namespace Tests;
use Illuminate\Contracts\Console\Kernel;
use Illuminate\Foundation\Application;
trait CreatesApplication
{
/**
* Creates the application.
*
* @return \Illuminate\Foundation\Application
* @return Application
*/
public function createApplication()
public function createApplication(): Application
{
$app = require __DIR__.'/../bootstrap/app.php';
+44 -1
View File
@@ -2,9 +2,52 @@
namespace Tests;
use Faker\Factory as Faker;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
use Illuminate\Support\Facades\Artisan;
use JWTAuth;
abstract class TestCase extends BaseTestCase
{
use CreatesApplication;
use CreatesApplication, RefreshDatabase, DatabaseMigrations;
protected $faker;
/* public function actingAs($user, $driver = "api"): TestCase
{
$token = JWTAuth::fromUser($user);
$this->withHeader('Authorization', "Bearer {$token}");
parent::actingAs($user);
return $this;
}*/
/**
* Sets up the tests
*/
public function setUp(): void
{
parent::setUp();
$this->faker = Faker::create();
Artisan::call('migrate');
}
/**
* Rolls back migrations
*/
public function tearDown(): void
{
Artisan::call('migrate:rollback');
parent::tearDown();
}
}
+272
View File
@@ -0,0 +1,272 @@
<?php
namespace Tests\Unit;
use App\Classes\Modules\Accounts\Services\GeneratesAuthenticationToken;
use App\Classes\ValueObjects\Constants\ApprovalStatus;
use App\Classes\ValueObjects\Constants\RoleTypes;
use App\Http\Middleware\ValidateToken;
use App\Models\User;
use JWTAuth;
use Tests\TestCase;
class AuthenticationTest extends TestCase
{
protected $loginRoute = 'api.account.authentication.authenticate.attempt';
/**
* A basic feature test example.
*
* @return void
*/
public function test_example()
{
$response = $this->get('/');
$response->assertStatus(200);
}
/**
* Test Guests can access the login page.
*
* @return void
*/
public function testGuestCanAccessLoginPage()
{
$response = $this->get('');
$response->assertStatus(200);
$response->assertSee('Sign In');
$response->assertSee('To keep using the service please sign in with your personal info');
}
/**
* Test Authenticated Users can not Access the login page
* TODO fix this test
* @return void
*/
public function testAuthenticatedUsersCanNotAccessLoginPage()
{
$user = User::factory()->create();
$this->actingAs($user)
->assertAuthenticatedAs($user)
->get(route('login'))
->assertSee('Sign In');
}
/**
* Assert Logged-in Users can Access the Dashboard
* @return void
*/
public function testAuthenticatedUserCanAccessDashboard()
{
$user = User::factory()->create([
'type' => RoleTypes::ADMIN,
'status' => ApprovalStatus::APPROVED
]
);
$this->actingAs($user)
->assertAuthenticatedAs($user)
->get('/dashboard')
->assertOk();
}
/**
* Empty email and password can not be null
* @return void
*/
public function testBothEmailAndPasswordAreRequiredToLogin()
{
$response = $this->post(route($this->loginRoute), [
'email' => '',
'password' => ''
]);
$response->assertStatus(500)
->assertSee('Authentication failed');
//todo we need to implement Laravel Requests for proper error handling
}
/**
* Test a user with Valid credentials can login
* @return void
*/
public function testUserWithValidCredentialsCanLogin()
{
$user = User::factory()->create([
'password' => bcrypt($password = 'password')
]);
$response = $this->post(route($this->loginRoute), [
'email' => $user->email,
'password' => $password
]);
$response->assertStatus(200)
->assertSee('You have successfully logged in to your account')
->assertSee('access_token');
}
/**
* Invalid Users get an error
* * @return void
*/
public function testUserWithInvalidCredentialCanNotLogin()
{
$user = User::factory()->create([
'password' => bcrypt($password = 'password')
]);
$response = $this->post((route($this->loginRoute)), [
'email' => $user->email,
'password' => 'wrongpassword'
]);
$response->assertStatus(401)
->assertSee('Authentication failed')
->assertSee('These credentials do not match our records.');
}
/**
* test User can Logout
* @return void
*/
public function testUserCanLogout()
{
$user = User::factory()->create();
$token = JWTAuth::fromUser($user);
$response = $this->withHeaders([
'Authorization' => 'Bearer ' . $token,
])->json('GET', route('api.account.authentication.logout'));
$response->assertStatus(200)
->assertSee('Logout Successful')
->assertSee('You have successfully logged out of your account')
->assertDontSee('access_token');
}
/**
* test Refresh token
* @return void
*/
public function testUserCanRefreshToken()
{
$user = User::factory()->create();
$token = JWTAuth::fromUser($user);
$response = $this->withHeaders([
'Authorization' => 'Bearer ' . $token,
])->json('GET', route('api.account.authentication.refresh'));
$response->assertStatus(200)
->assertSee('Refresh Authentication Successful')
->assertSee('You have successfully your account authentication')
->assertJsonStructure([
'title',
'message',
'payload',
]);
}
/**
* test forgot password
* @return void
*/
public function testForgotPassword()
{
$route = 'api.account.authentication.password.forget';
$user = User::factory()->create();
$response = $this->post(route($route), [
'email' => $user->email
]);
$response->assertStatus(200)
->assertSee('Reset Password Successful')
->assertSee('Reset Password Successful')
->assertSee('You have successfully sent you an email to reset your password');
}
/**
* test reset password
* @return void
*/
public function testUserGetResetPasswordLink()
{
$route = 'api.account.authentication.password.reset';
$user = User::factory()->create();
$token = JWTAuth::fromUser($user);
$response = $this->withHeaders([
'Authorization' => 'Bearer ' . $token,
])->json('POST', route($route), [
'password' => 'newPassword',
'confirmPassword' => 'newPassword'
]);
$response->assertStatus(500)
->assertSee('Password Change failed');
}
/*
* todo
* $response->assertStatus(200)
->assertSee('Reset Password Successful')
->assertSee('Reset Password Successful')
->assertSee('You have successfully sent you an email to reset your password');*/
/*}*/
/**
* test user can verify email
* @return void
*/
/*public function testCanVerifyEmail()
{
$route = 'api.account.email.verify';
$user = User::factory()->create();
$token = Password::createToken($user);
dd($token);
$response = $this->actingAs($user)
->post(route($route), [
'token' => $token
])->assertStatus(200);
}*/
/**
* test Resend verification email
* @return void
*/
public function testResendVerification()
{
$route = 'api.account.email.verification.resend';
$user = User::factory()->create();
$response = $this->post(route($route), [
'user_id' => $user->id
])
->assertStatus(200)
->assertSee('Resend Verification Email Successful')
->assertSee('Successfully resent a new verification email');
}
}
+26
View File
@@ -0,0 +1,26 @@
<?php
namespace Tests\Unit;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class BrowserSessionsTest extends TestCase
{
use RefreshDatabase;
public function test_other_browser_sessions_can_be_logged_out()
{
$user = User::factory()->create();
$this->actingAs($user);
$response = $this->get('/user/other-browser-sessions', [
'password' => 'password',
]);
$response->assertSessionHasNoErrors();
}
}
+36
View File
@@ -0,0 +1,36 @@
<?php
namespace Tests\Unit;
use App\Models\User;
use JWTAuth;
use Tests\TestCase;
class DashboardTest extends TestCase
{
/**
* A basic feature test example.
*
* @return void
*/
public function test_user_visit_dashboard()
{
$response = $this->get('/dashboard');
$response->assertStatus(200);
}
/**
* test a user can see a list of customer on the dashboard
* @return void
*/
public function test_customers_are_loaded_on_the_customer_page()
{
$user = User::factory()->create();
$token = JWTAuth::fromUser($user);
}
}
+101
View File
@@ -0,0 +1,101 @@
<?php
namespace Tests\Unit;
use App\Models\User;
use App\Providers\RouteServiceProvider;
use Illuminate\Auth\Events\Verified;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\URL;
use JWTAuth;
use Tests\TestCase;
class EmailVerificationTest extends TestCase
{
use RefreshDatabase;
public function test_check_existing_email()
{
$user = User::factory()->create();
$response = $this->post('api/v1/account/authentication/login/check_email', [
'email' => $user->email
]);
$response->assertStatus(200)
->assertSee("User found Successful")
->assertSee("Account Already Exists");
}
public function test_check_unknown_email()
{
$response = $this->post('api/v1/account/authentication/login/check_email', [
'email' => 'random_email@test.com'
]);
$response->assertStatus(404)
->assertSee("User found failed")
->assertSee("Unable to find any record based on the criteria provided");
}
//todo test post success email verification
public function test_email_verification()
{
$user = User::factory()->create();
//todo create a new email verification token, not post request method found
$response = $this->actingAs($user)->post('api/v1/account/email/verify', [
'token' => 'simple_string'
]);
//todo need to register notification services on IOC
$response->assertStatus(404);
}
public function test_resend_email()
{
$user = User::factory()->create();
//create a new email verification token, not post request method found
$response = $this->actingAs($user)->post('api/v1/account/email/verification/resend', [
'user_id' => $user->id
]);
$response->assertStatus(200)
->assertSee("Resend Verification Email Successful")
->assertSee("Successfully resent a new verification email");
}
public function test_change_email()
{
$user = User::factory()->create();
$token = JWTAuth::fromUser($user);
//create a new email verification token, not post request method found
$response = $this->withHeaders([
'Authorization' => 'Bearer ' . $token,
])->json('POST', 'api/v1/company/team/create', [
'email' => "newemail@test.abc"
]);
//todo add user payload to the response and assert json
$response->assertStatus(200)
->assertSee("Updated Email Successful")
->assertSee("Successfully updated email");
}
}
-19
View File
@@ -1,19 +0,0 @@
<?php
namespace Tests\Unit;
use PHPUnit\Framework\TestCase;
class ExampleTest extends TestCase
{
/**
* A basic test example.
*
* @return void
*/
public function testBasicTest()
{
$this->assertTrue(true);
}
}
+46
View File
@@ -0,0 +1,46 @@
<?php
namespace Tests\Unit;
use App\Classes\Modules\Accounts\Services\ExpiresPasswordReset;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Queue;
use Tests\TestCase;
class PasswordRestTest extends TestCase
{
use RefreshDatabase;
public function test_generate_reset_password()
{
$user = User::factory()->create();
$response = $this->actingAs($user)->post('api/v1/account/authentication/password/forget', [
'email' => $user->email
]);
$response->assertStatus(200)
->assertSee("Reset Password Successful")
->assertSee("You have successfully sent you an email to reset your password");
//assert a reset data was saved in the database
$this->assertDatabaseHas('password_resets', [
'user_id' => $user->id,
]);
//todo register all classes in the IOC
//assert a verification Link was generated
// Queue::assertDispatched(ProcessImage::class, function ($job) {
// return $job->image === 'image.jpg';
// });
//get the token and pass it on the verification link
}
}
+67
View File
@@ -0,0 +1,67 @@
<?php
namespace Tests\Unit;
use App\Providers\RouteServiceProvider;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class RegistrationTest extends TestCase
{
use RefreshDatabase;
public function test_registration_screen_can_be_rendered()
{
$response = $this->get('/signup');
$response->assertStatus(200);
}
/* public function test_create_invitation_request_test()
{
//todo to be updated on finalizing creating company module
$response = $this->post('api/v1/account/invite/registration', [
'company_id' => 1,
'name' => 'Test User',
'email' => 'test@example.com',
'phone' => '899990989',
'wechat_id' => '5666',
'company_name' => 'test company co',
'password' => 'password',
'password_confirmation' => 'password',
'contact_email' => "contact@email.com",
]);
$response->assertStatus(404);
}
public function test_new_users_can_register()
{
$response = $this->post('/api/v1/account/registration', [
'type' => 1,
'name' => 'Test User',
'email' => 'test@example.com',
'phone' => '899990989',
'wechat_id' => '5666',
'company_name' => 'test company co',
'password' => 'password',
'password_confirmation' => 'password',
'contact_email' => "contact@email.com",
]);
$this->assertDatabaseHas('users', [
'id' => 1,
'email' => 'test@example.com',
'name' => 'Test User',
]);
//todo an error experienced on line $inviter = $this->fetchesCompanyModule->execute(['reference'=>'CIEF']);
//todo 1. assert a user was logged in 2. assert a user was redirected 3. assert user has a token
}
*/
}
+180
View File
@@ -0,0 +1,180 @@
<?php
namespace Tests\Unit;
use App\Classes\Modules\Accounts\Services\GeneratesAuthenticationToken;
use App\Classes\ValueObjects\Constants\ApprovalStatus;
use App\Classes\ValueObjects\Constants\RoleTypes;
use App\Http\Middleware\ValidateToken;
use App\Models\User;
use JWTAuth;
use Tests\TestCase;
class UsersTest extends TestCase
{
protected $loginRoute = 'api.account.authentication.authenticate.attempt';
/**
* Get User by Id
*
* @return void
*/
public function test_get_user_by_id()
{
$user = User::factory()->create();
$token = JWTAuth::fromUser($user);
$response = $this->withHeaders([
'Authorization' => 'Bearer ' . $token,
])->json('POST', route('api.account.user.show', [
'user_id' => $user->id
]));
$response->assertStatus(200)
->assertSee('Fetch Users Successful')
->assertSee('You have successfully retrieved the user');
}
/**
* Get User by email
*
* @return void
*/
public function test_get_fetch_user_by_email()
{
$user = User::factory()->create();
$token = JWTAuth::fromUser($user);
$response = $this->withHeaders([
'Authorization' => 'Bearer ' . $token,
])->json('GET', route('api.account.user.company', $user->email), [
'email' => $user->email
]);
//todo fix the invitee issue
/* $response->assertStatus(200)
->assertSee('Fetch Users')
->assertSee('You have successfully retrieved the user by email'); */
$response->assertStatus(500);
}
/**
* Get a List of all users test
* @return void
*/
public function test_list_users()
{
$user = User::factory()->create([
'type' => RoleTypes::ADMIN,
'status' => ApprovalStatus::APPROVED
]);
$token = JWTAuth::fromUser($user);
$response = $this->withHeaders([
'Authorization' => 'Bearer ' . $token,
])->json('GET', 'api/v1/account/user/list?&filters=null}');
$response->assertStatus(404);
//todo add a default return list without filter or null filters
/*
$response->assertStatus(200)
->assertSee('Retrieved Companies Successful')
->assertSee('You have successfully retrieved a list of users');*/
}
/**
* Test Can Create an Admin User
*
* @return void
*/
public function test_create_an_admin_user()
{
$user = User::factory()->create();
$token = JWTAuth::fromUser($user);
$response = $this->withHeaders([
'Authorization' => 'Bearer ' . $token,
])->json('POST', route('api.account.user.admin.create'),
[
'name' => 'Test Admin',
'email' => 'admin@example.com',
'password' => 'password',
'password_confirmation' => 'password',
]);
$response->assertStatus(200)
->assertSee('Created Account')
->assertSee('You have successfully created a new Account');
}
/**
* Test Can create a user
*
* @return void
*/
public function test_can_update_user()
{
$user = User::factory()->create();
$token = JWTAuth::fromUser($user);
$response = $this->withHeaders([
'Authorization' => 'Bearer ' . $token,
])->json('PUT', route('api.account.user.update', $user->id), [
'name' => 'Test Admin',
/*'email' => 'admin@example.com',
'password' => 'password',
'password_confirmation' => 'password',*/
]);
$response->assertStatus(200)
->assertSee('Updated User Profile')
->assertSee('You have successfully updated the User Profile');
}
/**
* Test Can delete a user
*
* @return void
*/
public function test_can_delete_user_profile()
{
$user = User::factory()->create();
$token = JWTAuth::fromUser($user);
$response = $this->withHeaders([
'Authorization' => 'Bearer ' . $token,
])->json('DELETE', route('api.account.user.delete', $user->id), [
'id' => $user->id
]);
$response->assertStatus(200)
->assertSee('Delete User Successful')
->assertSee('You have successfully deleted the User');
}
}
View File
+2
View File
@@ -0,0 +1,2 @@
*
!.gitignore
+28
View File
@@ -0,0 +1,28 @@
<?php
use Codeception\Actor;
/**
* Inherited Methods
* @method void wantToTest($text)
* @method void wantTo($text)
* @method void execute($callable)
* @method void expectTo($prediction)
* @method void expect($prediction)
* @method void amGoingTo($argumentation)
* @method void am($role)
* @method void lookForwardTo($achieveValue)
* @method void comment($description)
* @method void pause()
*
* @SuppressWarnings(PHPMD)
*/
class AcceptanceTester extends Actor
{
use _generated\AcceptanceTesterActions;
/**
* Define custom actions here
*/
}
+26
View File
@@ -0,0 +1,26 @@
<?php
/**
* Inherited Methods
* @method void wantToTest($text)
* @method void wantTo($text)
* @method void execute($callable)
* @method void expectTo($prediction)
* @method void expect($prediction)
* @method void amGoingTo($argumentation)
* @method void am($role)
* @method void lookForwardTo($achieveValue)
* @method void comment($description)
* @method void pause()
*
* @SuppressWarnings(PHPMD)
*/
class FunctionalTester extends \Codeception\Actor
{
use _generated\FunctionalTesterActions;
/**
* Define custom actions here
*/
}
+10
View File
@@ -0,0 +1,10 @@
<?php
namespace Helper;
// here you can define custom actions
// all public methods declared in helper class will be available in $I
class Acceptance extends \Codeception\Module
{
}
+10
View File
@@ -0,0 +1,10 @@
<?php
namespace Helper;
// here you can define custom actions
// all public methods declared in helper class will be available in $I
class Functional extends \Codeception\Module
{
}
+10
View File
@@ -0,0 +1,10 @@
<?php
namespace Helper;
// here you can define custom actions
// all public methods declared in helper class will be available in $I
class Unit extends \Codeception\Module
{
}
+26
View File
@@ -0,0 +1,26 @@
<?php
/**
* Inherited Methods
* @method void wantToTest($text)
* @method void wantTo($text)
* @method void execute($callable)
* @method void expectTo($prediction)
* @method void expect($prediction)
* @method void amGoingTo($argumentation)
* @method void am($role)
* @method void lookForwardTo($achieveValue)
* @method void comment($description)
* @method void pause()
*
* @SuppressWarnings(PHPMD)
*/
class UnitTester extends \Codeception\Actor
{
use _generated\UnitTesterActions;
/**
* Define custom actions here
*/
}
+2
View File
@@ -0,0 +1,2 @@
*
!.gitignore
+9
View File
@@ -0,0 +1,9 @@
actor: AcceptanceTester
modules:
enabled:
- WebDriver:
browser: chrome
url: http://127.0.0.1:8000
- Laravel:
part: ORM
environment_file: .env.testing
+55
View File
@@ -0,0 +1,55 @@
<?php
use App\Classes\ValueObjects\Constants\ApprovalStatus;
use App\Classes\ValueObjects\Constants\RoleTypes;
use App\Models\User;
use Codeception\Util\Debug;
class AuthenticationCest
{
public function _before(AcceptanceTester $I)
{
$I->wantTo('Test the Authentication Flow');
$I->amOnPage('/');
}
/**
* test if the home page is loaded
* @param AcceptanceTester $I
* @return void
*/
public function tryToTestIfWelcomePageIsLoaded(AcceptanceTester $I)
{
$I->wantTo('Check if the home page works.');
$I->amOnPage('/');
$I->see('SIGN IN');
$I->see('To keep using the service please sign in with your personal info');
$I->see('New Customer? Create Account');
}
/**
* test if admin can log in
* @param AcceptanceTester $I
* @return void
*/
public function tryToTestIfAdminCanLogin(AcceptanceTester $I)
{
// Fill out the login form
$I->fillField('email', 'omair@cief-malaysia.com');
$I->fillField('password', '123456abcabc');
$I->click(['css' => '.btn.btn-block.btn-lg.b-rad-none.no-border']);
$I->wait(5); // 2 seconds delay
$I->expectTo('be redirected to the dashboard');
$I->seeCurrentUrlEquals('/dashboard');
$I->see('Dashboard');
$I->see('NEW CUSTOMERS');
$I->see('Unclaimed Packing Lists');
$I->see('Identification Verification');
$I->see('ACTIVATED ORDERS');
}
}
+13
View File
@@ -0,0 +1,13 @@
# Codeception Test Suite Configuration
#
# Suite for functional tests
# Emulate web requests and make application process them
# Include one of framework modules (Symfony2, Yii2, Laravel5, Phalcon4) to use it
# Remove this suite if you don't use frameworks
actor: FunctionalTester
modules:
enabled:
# add a framework module here
- \Helper\Functional
step_decorators: ~
+10
View File
@@ -0,0 +1,10 @@
# Codeception Test Suite Configuration
#
# Suite for unit or integration tests.
actor: UnitTester
modules:
enabled:
- Asserts
- \Helper\Unit
step_decorators: ~