unit testing

This commit is contained in:
JiaSheng
2023-10-30 22:07:08 +08:00
parent 5c5f54e03b
commit 50468a81a8
14 changed files with 1105 additions and 4 deletions
@@ -14,6 +14,7 @@ use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Http\Resources\Json\ResourceCollection;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
@@ -54,7 +55,7 @@ abstract class AbstractControllerLogic
public function execute(Request $request) : JsonResponse {
try {
if(Auth::user()){
if(Auth::user() && App::environment('production')){
if(Auth::user()->type === 3) UserRiskAnalysis::dispatch(Auth::user(), $request->header('captcha-token'));
}
@@ -155,7 +155,9 @@ class CreateCustomerLogic extends AbstractControllerLogic
CreatePerfexCRMCustomer::dispatch($createLeadPerfexCRMObject);
}
$this->generateEmailVerificationAttemptProcessor->execute($user);
if (App::environment(['production'])) {
$this->generateEmailVerificationAttemptProcessor->execute($user);
}
$this->newCustomerToVoucherifyProcessor->execute($company->id, $user, true);
+20
View File
@@ -63,6 +63,26 @@ return [
]) : [],
],
'mysql_test' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE_TEST', 'exchange_test'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'prefix_indexes' => true,
'strict' => false,
'engine' => null,
'options' => extension_loaded('pdo_mysql') ? array_filter([
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
]) : [],
],
'dusk' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
+1
View File
@@ -1,5 +1,6 @@
<?php
namespace Database\Seeders;
use App\Classes\ValueObjects\Constants\ApprovalStatus;
use App\Classes\ValueObjects\Constants\BusinessType;
use App\Classes\ValueObjects\Constants\CompanyType;
+1
View File
@@ -1,5 +1,6 @@
<?php
namespace Database\Seeders;
use App\Classes\Modules\Countries\DataTransferObjects\CountryObject;
use App\Classes\Modules\Countries\Services\CreatesCountry;
use Illuminate\Database\Seeder;
+1
View File
@@ -1,5 +1,6 @@
<?php
namespace Database\Seeders;
use App\Classes\Modules\Countries\Services\FetchesCountry;
use App\Classes\Modules\Currencies\DataTransferObjects\CurrencyObject;
use App\Classes\Modules\Currencies\Services\CreatesCurrency;
+4
View File
@@ -2,11 +2,15 @@
use Database\Seeders\BanksTableDevelopmentSeeder;
use Database\Seeders\CompaniesTableDevelopmentSeeder;
use Database\Seeders\CompaniesTableSeeder;
use Database\Seeders\CountriesTableSeeder;
use Database\Seeders\CurrenciesTableDevelopmentSeeder;
use Database\Seeders\CurrenciesTableSeeder;
use Database\Seeders\CurrencyRatesTableDevelopmentSeeder;
use Database\Seeders\DummyDataSeeder;
use Database\Seeders\SegmentConstantsTableDevelopmentSeeder;
use Database\Seeders\SegmentsTableDevelopmentSeeder;
use Database\Seeders\SegmentsTableSeeder;
use Database\Seeders\ServiceTypesTableDevelopmentSeeder;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
+1
View File
@@ -1,5 +1,6 @@
<?php
namespace Database\Seeders;
use App\Classes\Modules\Segments\DataTransferObjects\SegmentObject;
use App\Classes\Modules\Segments\Services\CreatesSegment;
use App\Classes\ValueObjects\Constants\SegmentConstants;
+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="mysql_test"/>
<server name="DB_DATABASE" value="exchange_test"/>
<server name="MAIL_MAILER" value="array"/>
<server name="QUEUE_CONNECTION" value="sync"/>
<server name="SESSION_DRIVER" value="array"/>
@@ -0,0 +1,53 @@
<?php
namespace Tests\Feature\Accounts;
use App\Models\User;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class CheckEmailControllerTest extends TestCase
{
use DatabaseMigrations;
public function testExistingUserEmail()
{
// create a user
$response = $this->postJson(route('api.account.registration.register', [
"company_name" => "",
"name" => "user one",
"email" => "user1@mail.com",
"password" => "password",
"password_confirmation" => "password",
"phone" => "0123456789",
"type" => 0
]));
$response = $this->postJson(route('api.account.authentication.authenticate.email.check', [
'email' => 'user1@mail.com',
]));
$response->assertStatus(200)->assertJson([
"title" => "User found Successful",
"message" => "Account Already Exists",
"payload" => []
]);
}
public function testNonExistingUserEmail()
{
$response = $this->postJson(route('api.account.authentication.authenticate.email.check', [
'email' => 'user2@mail.com',
]));
// dd($response);
$response->assertStatus(404)->assertJson([
"title" => "User found failed",
"message" => "Unable to find any record based on the criteria provided",
"payload" => []
]);
}
}
@@ -0,0 +1,45 @@
<?php
namespace Tests\Feature\Accounts;
use App\Models\User;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class UserAuthenticationControllerTest extends TestCase
{
use DatabaseMigrations;
public function test_existing_user_login()
{
// create a user
$response = $this->postJson(route('api.account.registration.register', [
"company_name" => "",
"name" => "user one",
"email" => "user1@mail.com",
"password" => "password",
"password_confirmation" => "password",
"phone" => "0123456789",
"type" => 0
]));
$response = $this->postJson(route('api.account.authentication.authenticate.attempt', [
'email' => 'user1@mail.com',
'password' => 'password'
]));
$response->assertStatus(200);
}
public function test_non_existing_user_login()
{
$response = $this->postJson(route('api.account.authentication.authenticate.attempt', [
'email' => 'user2@mail.com',
'password' => 'password'
]));
$response->assertStatus(401);
}
}
@@ -0,0 +1,186 @@
<?php
namespace Tests\Feature\Bookings;
use App\Classes\ValueObjects\Constants\BankAccountType;
use App\Classes\ValueObjects\Constants\SegmentConstants;
use App\Models\Company;
use Database\Seeders\CompaniesTableSeeder;
use Database\Seeders\CountriesTableSeeder;
use Database\Seeders\CurrenciesTableSeeder;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Support\Facades\DB;
use Tests\TestCase;
class CreateBookingControllerTest extends TestCase
{
use DatabaseMigrations;
private $curr_rate_std_cash = 1.52800;
private $curr_rate_std_cheque = 1.51800;
private $curr_rate_std_wallet = 1.53400;
private $curr_rate_std_online = 1.53100;
private $curr_rate_plat_cash = 1.54100;
private $curr_rate_plat_cheque = 1.53100;
private $curr_rate_plat_wallet = 1.54700;
private $curr_rate_plat_online = 1.54400;
protected function setUp(): void
{
parent::setUp();
$this->seed(CountriesTableSeeder::class);
$this->seed(CurrenciesTableSeeder::class);
$this->seed(CompaniesTableSeeder::class);
// create currency rate
DB::table('currency_rates')->insert(array (
0 =>
array (
'id' => 1,
'currency_id' => 2,
'selling' => $this->curr_rate_std_cash,
'payment_method_type' => 1,
'service_id' => 1,
),
1 =>
array (
'id' => 2,
'currency_id' => 2,
'selling' => $this->curr_rate_std_cheque,
'payment_method_type' => 2,
'service_id' => 1,
),
2 =>
array (
'id' => 3,
'currency_id' => 2,
'selling' => $this->curr_rate_std_wallet,
'payment_method_type' => 4,
'service_id' => 1,
),
3 =>
array (
'id' => 4,
'currency_id' => 2,
'selling' => $this->curr_rate_std_online,
'payment_method_type' => 5,
'service_id' => 1,
)
));
// create service
DB::table('service_types')->insert([
'id' => 1,
'name' => 'X1 Transfer',
'status' => 2,
]);
// create standard segment
DB::table('segments')->insert([
'id' => 1,
'name' => 'Standard Segment',
'type' => SegmentConstants::STANDARD_SEGMENT,
'status' => 2
]);
// create platinum segment
DB::table('segments')->insert([
'id' => 2,
'name' => 'platinum member',
'type' => SegmentConstants::CUSTOM_SEGMENT,
'status' => 2,
]);
// create standard segment constant
DB::table('segment_constants')->insert([
'id' => 1,
'segment_id' => 1,
'name' => 'Service Type',
'reference' => 'SERVICE_TYPE',
'detail' => '{"id":1,"bank_id":1,"service_charge":{"type":"percentage","value":2},"minimum_charge":{"type":"fixed_amount","value":10},"tax":{"type":"percentage","value":0},"po_limit":{"type":"fixed_amount","value":3},"is_active":true,"is_billable":true,"currencies":[{"id":2,"max_limit":{"type":"fixed_amount","value":500000},"min_limit":{"type":"fixed_amount","value":100},"rates":[]}]}',
]);
// create platinum segment constant
DB::table('segment_constants')->insert([
'id' => 2,
'segment_id' => 2,
'name' => 'Custom Service Type',
'reference' => 'CUSTOM_SERVICE_TYPE',
'detail' => '{"id":1,"minimum_charge":{"type":"fixed_amount","value":0},"is_active":true,"is_billable":true,"currencies":[{"id":2,"max_limit":{"type":"fixed_amount","value":500000},"min_limit":{"type":"fixed_amount","value":0.01},"rates":[{"payment_type":1,"payment_method":"cash","selling":{"type":"rate","value":"1.54100"}},{"payment_type":2,"payment_method":"cheque","selling":{"type":"rate","value":"1.53100"}},{"payment_type":4,"payment_method":"wallet","selling":{"type":"rate","value":"1.54700"}},{"payment_type":5,"payment_method":"payment_gateway","selling":{"type":"rate","value":"1.54400"}}]}]}',
]);
// create a user
$this->postJson(route('api.account.registration.register', [
"company_name" => "",
"name" => "user one",
"email" => "user1@mail.com",
"password" => "password",
"password_confirmation" => "password",
"phone" => "0123456789",
"type" => 0
]));
$response = $this->postJson(route('api.account.authentication.authenticate.attempt', [
'email' => 'user1@mail.com',
'password' => 'password'
]));
$company = Company::where('name', 'user one')->first();
// create recipient bank
DB::table('banks')->insert([
'company_id' => $company->id,
'bank_name' => 'Maybank',
'holder_name' => 'user one recipient',
'account_no' => '123456789',
'country_id' => 2,
'status' => 2,
'type' => 2,
]);
$token = json_decode($response->getContent(), true)['payload']['access_token'];
$this->withHeaders([
'Accept' => 'application/json',
'Authorization' => "Bearer $token",
'Captcha-Token' => "test"
]);
}
public function test_create_booking()
{
$company = Company::where('name', 'user one')->first();
$foreign_total = 1000;
$quotation_response = $this->postJson(route('api.company.currency.convert', [
'id' => $company->id,
'amount' => $foreign_total,
'currency_id' => 2,
'service_id' => 1,
'type' => 1,
]));
$recipient_bank = $company->banks->where('type', BankAccountType::EXTERNAL)->first();
$response = $this->postJson(route('api.booking.create', ['company_id' => $company->id]),
[
'convertible_currency_id' => 2,
'fix_amount' => json_decode($quotation_response->getContent(), true)['payload']['data']['foreign_total'],
'service_id' => 1,
'transferable_bank_id' => $recipient_bank->id,
'type' => 1,
]);
$response->assertStatus(200);
$this->assertDatabaseHas("bookings", [
"company_id" => $company->id,
"service_id" => 1,
"bank_id" => $recipient_bank->id,
"fix_amount" => $foreign_total,
"fix_currency_id" => 2,
"convertible_currency_id" => 2,
"conversion_currency_id" => 1,
"status" => 2
]);
}
}
@@ -0,0 +1,597 @@
<?php
namespace Tests\Feature\Companies;
use App\Classes\ValueObjects\Constants\BankAccountType;
use App\Classes\ValueObjects\Constants\SegmentConstants;
use App\Models\Bank;
use App\Models\Booking;
use App\Models\Company;
use Database\Seeders\CompaniesTableSeeder;
use Database\Seeders\CountriesTableSeeder;
use Database\Seeders\CurrenciesTableSeeder;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Support\Facades\DB;
use Tests\TestCase;
class FetchBookingPaymentQuotationControllerTest extends TestCase
{
use DatabaseMigrations;
private $curr_rate_std_cash = 1.52800;
private $curr_rate_std_cheque = 1.51800;
private $curr_rate_std_wallet = 1.53400;
private $curr_rate_std_online = 1.53100;
private $curr_rate_plat_cash = 1.54100;
private $curr_rate_plat_cheque = 1.53100;
private $curr_rate_plat_wallet = 1.54700;
private $curr_rate_plat_online = 1.54400;
protected function setUp(): void
{
parent::setUp();
$this->seed(CountriesTableSeeder::class);
$this->seed(CurrenciesTableSeeder::class);
$this->seed(CompaniesTableSeeder::class);
// create currency rate
DB::table('currency_rates')->insert(array (
0 =>
array (
'id' => 1,
'currency_id' => 2,
'selling' => $this->curr_rate_std_cash,
'payment_method_type' => 1,
'service_id' => 1,
),
1 =>
array (
'id' => 2,
'currency_id' => 2,
'selling' => $this->curr_rate_std_cheque,
'payment_method_type' => 2,
'service_id' => 1,
),
2 =>
array (
'id' => 3,
'currency_id' => 2,
'selling' => $this->curr_rate_std_wallet,
'payment_method_type' => 4,
'service_id' => 1,
),
3 =>
array (
'id' => 4,
'currency_id' => 2,
'selling' => $this->curr_rate_std_online,
'payment_method_type' => 5,
'service_id' => 1,
)
));
// create service
DB::table('service_types')->insert([
'id' => 1,
'name' => 'X1 Transfer',
'status' => 2,
]);
// create standard segment
DB::table('segments')->insert([
'id' => 1,
'name' => 'Standard Segment',
'type' => SegmentConstants::STANDARD_SEGMENT,
'status' => 2
]);
// create platinum segment
DB::table('segments')->insert([
'id' => 2,
'name' => 'platinum member',
'type' => SegmentConstants::CUSTOM_SEGMENT,
'status' => 2,
]);
// create standard segment constant
DB::table('segment_constants')->insert([
'id' => 1,
'segment_id' => 1,
'name' => 'Service Type',
'reference' => 'SERVICE_TYPE',
'detail' => '{"id":1,"bank_id":1,"service_charge":{"type":"percentage","value":2},"minimum_charge":{"type":"fixed_amount","value":10},"tax":{"type":"percentage","value":0},"po_limit":{"type":"fixed_amount","value":3},"is_active":true,"is_billable":true,"currencies":[{"id":2,"max_limit":{"type":"fixed_amount","value":500000},"min_limit":{"type":"fixed_amount","value":100},"rates":[]}]}',
]);
// create platinum segment constant
DB::table('segment_constants')->insert([
'id' => 2,
'segment_id' => 2,
'name' => 'Custom Service Type',
'reference' => 'CUSTOM_SERVICE_TYPE',
'detail' => '{"id":1,"minimum_charge":{"type":"fixed_amount","value":0},"is_active":true,"is_billable":true,"currencies":[{"id":2,"max_limit":{"type":"fixed_amount","value":500000},"min_limit":{"type":"fixed_amount","value":0.01},"rates":[{"payment_type":1,"payment_method":"cash","selling":{"type":"rate","value":"1.54100"}},{"payment_type":2,"payment_method":"cheque","selling":{"type":"rate","value":"1.53100"}},{"payment_type":4,"payment_method":"wallet","selling":{"type":"rate","value":"1.54700"}},{"payment_type":5,"payment_method":"payment_gateway","selling":{"type":"rate","value":"1.54400"}}]}]}',
]);
// create a user
$this->postJson(route('api.account.registration.register', [
"company_name" => "",
"name" => "user one",
"email" => "user1@mail.com",
"password" => "password",
"password_confirmation" => "password",
"phone" => "0123456789",
"type" => 0
]));
$response = $this->postJson(route('api.account.authentication.authenticate.attempt', [
'email' => 'user1@mail.com',
'password' => 'password'
]));
$company = Company::where('name', 'user one')->first();
// create recipient bank
DB::table('banks')->insert([
'company_id' => $company->id,
'bank_name' => 'Maybank',
'holder_name' => 'user one recipient',
'account_no' => '123456789',
'country_id' => 2,
'status' => 2,
'type' => 2,
]);
$token = json_decode($response->getContent(), true)['payload']['access_token'];
$this->withHeaders([
'Accept' => 'application/json',
'Authorization' => "Bearer $token",
'Captcha-Token' => "test"
]);
$recipient_bank = $company->banks->where('type', BankAccountType::EXTERNAL)->first();
// create booking
$this->postJson(route('api.booking.create', ['company_id' => $company->id]),
[
'convertible_currency_id' => 2,
'fix_amount' => 1000,
'service_id' => 1,
'transferable_bank_id' => $recipient_bank->id,
'type' => 1,
]);
}
public function test_standard_customer_fetch_booking_payment_quotation_cash()
{
$booking = Booking::first();
$foreign_total = 1000;
$local_total = 1000 / $this->curr_rate_std_cash;
$conversion_amount = $local_total;
$service_charge = $conversion_amount * 0.02;
$sub_total = $local_total + $service_charge;
$response = $this->postJson(route('api.booking.payment.quotation', [
'id' => $booking->id,
'amount' => 1000,
'payment_method' => 'cash',
'voucherCode' => ''
]));
$response->assertStatus(200)->assertJsonStructure([
"title",
"message",
"payload" => [
"data" => [
"conversion_amount",
"foreign_total",
"local_total",
"rate",
"service_charge",
"sub_total",
"tax",
"tax_total",
"total",
"voucher_code",
"voucher_discount_amount"
]
]
]);
$data = json_decode($response->getContent(), true)['payload']['data'];
$this->assertEqualsWithDelta($conversion_amount, $data['conversion_amount'], 0.0000001);
$this->assertEqualsWithDelta($foreign_total, $data['foreign_total'], 0.0000001);
$this->assertEqualsWithDelta($local_total, $data['local_total'], 0.0000001);
$this->assertEqualsWithDelta($this->curr_rate_std_cash, $data['rate'], 0.0000001);
$this->assertEqualsWithDelta($service_charge, $data['service_charge'], 0.0000001);
$this->assertEqualsWithDelta($sub_total, $data['sub_total'], 0.0000001);
$this->assertEquals(0, $data['tax']);
$this->assertEquals(0, $data['tax_total']);
$this->assertEqualsWithDelta($sub_total, $data['total'], 0.0000001);
$this->assertEquals("", $data['voucher_code']);
$this->assertEquals(0, $data['voucher_discount_amount']);
}
public function test_standard_customer_fetch_booking_payment_quotation_cheque()
{
$booking = Booking::first();
$foreign_total = 1000;
$local_total = 1000 / $this->curr_rate_std_cheque;
$conversion_amount = $local_total;
$service_charge = $conversion_amount * 0.02;
$sub_total = $local_total + $service_charge;
$response = $this->postJson(route('api.booking.payment.quotation', ['id' => $booking->id]),
[
'amount' => 1000,
'payment_method' => 'cheque',
'voucherCode' => ''
]);
$response->assertStatus(200)->assertJsonStructure([
"title",
"message",
"payload" => [
"data" => [
"conversion_amount",
"foreign_total",
"local_total",
"rate",
"service_charge",
"sub_total",
"tax",
"tax_total",
"total",
"voucher_code",
"voucher_discount_amount"
]
]
]);
$data = json_decode($response->getContent(), true)['payload']['data'];
$this->assertEqualsWithDelta($conversion_amount, $data['conversion_amount'], 0.0000001);
$this->assertEqualsWithDelta($foreign_total, $data['foreign_total'], 0.0000001);
$this->assertEqualsWithDelta($local_total, $data['local_total'], 0.0000001);
$this->assertEqualsWithDelta($this->curr_rate_std_cheque, $data['rate'], 0.0000001);
$this->assertEqualsWithDelta($service_charge, $data['service_charge'], 0.0000001);
$this->assertEqualsWithDelta($sub_total, $data['sub_total'], 0.0000001);
$this->assertEquals(0, $data['tax']);
$this->assertEquals(0, $data['tax_total']);
$this->assertEqualsWithDelta($sub_total, $data['total'], 0.0000001);
$this->assertEquals("", $data['voucher_code']);
$this->assertEquals(0, $data['voucher_discount_amount']);
}
public function test_standard_customer_fetch_booking_payment_quotation_wallet()
{
$booking = Booking::first();
$foreign_total = 1000;
$local_total = 1000 / $this->curr_rate_std_wallet;
$conversion_amount = $local_total;
$service_charge = $conversion_amount * 0.02;
$sub_total = $local_total + $service_charge;
$response = $this->postJson(route('api.booking.payment.quotation', ['id' => $booking->id]),
[
'amount' => 1000,
'payment_method' => 'wallet',
'voucherCode' => ''
]);
$response->assertStatus(200)->assertJsonStructure([
"title",
"message",
"payload" => [
"data" => [
"conversion_amount",
"foreign_total",
"local_total",
"rate",
"service_charge",
"sub_total",
"tax",
"tax_total",
"total",
"voucher_code",
"voucher_discount_amount"
]
]
]);
$data = json_decode($response->getContent(), true)['payload']['data'];
$this->assertEqualsWithDelta($conversion_amount, $data['conversion_amount'], 0.0000001);
$this->assertEqualsWithDelta($foreign_total, $data['foreign_total'], 0.0000001);
$this->assertEqualsWithDelta($local_total, $data['local_total'], 0.0000001);
$this->assertEqualsWithDelta($this->curr_rate_std_wallet, $data['rate'], 0.0000001);
$this->assertEqualsWithDelta($service_charge, $data['service_charge'], 0.0000001);
$this->assertEqualsWithDelta($sub_total, $data['sub_total'], 0.0000001);
$this->assertEquals(0, $data['tax']);
$this->assertEquals(0, $data['tax_total']);
$this->assertEqualsWithDelta($sub_total, $data['total'], 0.0000001);
$this->assertEquals("", $data['voucher_code']);
$this->assertEquals(0, $data['voucher_discount_amount']);
}
public function test_standard_customer_fetch_booking_payment_quotation_online()
{
$booking = Booking::first();
$foreign_total = 1000;
$local_total = 1000 / $this->curr_rate_std_online;
$conversion_amount = $local_total;
$service_charge = $conversion_amount * 0.02;
$sub_total = $local_total + $service_charge;
$response = $this->postJson(route('api.booking.payment.quotation', ['id' => $booking->id]),
[
'amount' => 1000,
'payment_method' => 'payment_gateway',
'voucherCode' => ''
]);
$response->assertStatus(200)->assertJsonStructure([
"title",
"message",
"payload" => [
"data" => [
"conversion_amount",
"foreign_total",
"local_total",
"rate",
"service_charge",
"sub_total",
"tax",
"tax_total",
"total",
"voucher_code",
"voucher_discount_amount"
]
]
]);
$data = json_decode($response->getContent(), true)['payload']['data'];
$this->assertEqualsWithDelta($conversion_amount, $data['conversion_amount'], 0.0000001);
$this->assertEqualsWithDelta($foreign_total, $data['foreign_total'], 0.0000001);
$this->assertEqualsWithDelta($local_total, $data['local_total'], 0.0000001);
$this->assertEqualsWithDelta($this->curr_rate_std_online, $data['rate'], 0.0000001);
$this->assertEqualsWithDelta($service_charge, $data['service_charge'], 0.0000001);
$this->assertEqualsWithDelta($sub_total, $data['sub_total'], 0.0000001);
$this->assertEquals(0, $data['tax']);
$this->assertEquals(0, $data['tax_total']);
$this->assertEqualsWithDelta($sub_total, $data['total'], 0.0000001);
$this->assertEquals("", $data['voucher_code']);
$this->assertEquals(0, $data['voucher_discount_amount']);
}
public function test_platinum_customer_fetch_booking_payment_quotation_cash()
{
$company = Company::where('name', 'user one')->first();
DB::table('segment_companies')->insert([
'segment_id' => 2,
'company_id' => $company->id,
]);
$booking = Booking::first();
$foreign_total = 1000;
$local_total = 1000 / $this->curr_rate_plat_cash;
$conversion_amount = $local_total;
$service_charge = $conversion_amount * 0.02;
$sub_total = $local_total + $service_charge;
$response = $this->postJson(route('api.booking.payment.quotation', [
'id' => $booking->id,
'amount' => 1000,
'payment_method' => 'cash',
'voucherCode' => ''
]));
$response->assertStatus(200)->assertJsonStructure([
"title",
"message",
"payload" => [
"data" => [
"conversion_amount",
"foreign_total",
"local_total",
"rate",
"service_charge",
"sub_total",
"tax",
"tax_total",
"total",
"voucher_code",
"voucher_discount_amount"
]
]
]);
$data = json_decode($response->getContent(), true)['payload']['data'];
$this->assertEqualsWithDelta($conversion_amount, $data['conversion_amount'], 0.0000001);
$this->assertEqualsWithDelta($foreign_total, $data['foreign_total'], 0.0000001);
$this->assertEqualsWithDelta($local_total, $data['local_total'], 0.0000001);
$this->assertEqualsWithDelta($this->curr_rate_plat_cash, $data['rate'], 0.0000001);
$this->assertEqualsWithDelta($service_charge, $data['service_charge'], 0.0000001);
$this->assertEqualsWithDelta($sub_total, $data['sub_total'], 0.0000001);
$this->assertEquals(0, $data['tax']);
$this->assertEquals(0, $data['tax_total']);
$this->assertEqualsWithDelta($sub_total, $data['total'], 0.0000001);
$this->assertEquals("", $data['voucher_code']);
$this->assertEquals(0, $data['voucher_discount_amount']);
}
public function test_platinum_customer_fetch_booking_payment_quotation_cheque()
{
$company = Company::where('name', 'user one')->first();
DB::table('segment_companies')->insert([
'segment_id' => 2,
'company_id' => $company->id,
]);
$booking = Booking::first();
$foreign_total = 1000;
$local_total = 1000 / $this->curr_rate_plat_cheque;
$conversion_amount = $local_total;
$service_charge = $conversion_amount * 0.02;
$sub_total = $local_total + $service_charge;
$response = $this->postJson(route('api.booking.payment.quotation', ['id' => $booking->id]),
[
'amount' => 1000,
'payment_method' => 'cheque',
'voucherCode' => ''
]);
$response->assertStatus(200)->assertJsonStructure([
"title",
"message",
"payload" => [
"data" => [
"conversion_amount",
"foreign_total",
"local_total",
"rate",
"service_charge",
"sub_total",
"tax",
"tax_total",
"total",
"voucher_code",
"voucher_discount_amount"
]
]
]);
$data = json_decode($response->getContent(), true)['payload']['data'];
$this->assertEqualsWithDelta($conversion_amount, $data['conversion_amount'], 0.0000001);
$this->assertEqualsWithDelta($foreign_total, $data['foreign_total'], 0.0000001);
$this->assertEqualsWithDelta($local_total, $data['local_total'], 0.0000001);
$this->assertEqualsWithDelta($this->curr_rate_plat_cheque, $data['rate'], 0.0000001);
$this->assertEqualsWithDelta($service_charge, $data['service_charge'], 0.0000001);
$this->assertEqualsWithDelta($sub_total, $data['sub_total'], 0.0000001);
$this->assertEquals(0, $data['tax']);
$this->assertEquals(0, $data['tax_total']);
$this->assertEqualsWithDelta($sub_total, $data['total'], 0.0000001);
$this->assertEquals("", $data['voucher_code']);
$this->assertEquals(0, $data['voucher_discount_amount']);
}
public function test_platinum_customer_fetch_booking_payment_quotation_wallet()
{
$company = Company::where('name', 'user one')->first();
DB::table('segment_companies')->insert([
'segment_id' => 2,
'company_id' => $company->id,
]);
$booking = Booking::first();
$foreign_total = 1000;
$local_total = 1000 / $this->curr_rate_plat_wallet;
$conversion_amount = $local_total;
$service_charge = $conversion_amount * 0.02;
$sub_total = $local_total + $service_charge;
$response = $this->postJson(route('api.booking.payment.quotation', ['id' => $booking->id]),
[
'amount' => 1000,
'payment_method' => 'wallet',
'voucherCode' => ''
]);
$response->assertStatus(200)->assertJsonStructure([
"title",
"message",
"payload" => [
"data" => [
"conversion_amount",
"foreign_total",
"local_total",
"rate",
"service_charge",
"sub_total",
"tax",
"tax_total",
"total",
"voucher_code",
"voucher_discount_amount"
]
]
]);
$data = json_decode($response->getContent(), true)['payload']['data'];
$this->assertEqualsWithDelta($conversion_amount, $data['conversion_amount'], 0.0000001);
$this->assertEqualsWithDelta($foreign_total, $data['foreign_total'], 0.0000001);
$this->assertEqualsWithDelta($local_total, $data['local_total'], 0.0000001);
$this->assertEqualsWithDelta($this->curr_rate_plat_wallet, $data['rate'], 0.0000001);
$this->assertEqualsWithDelta($service_charge, $data['service_charge'], 0.0000001);
$this->assertEqualsWithDelta($sub_total, $data['sub_total'], 0.0000001);
$this->assertEquals(0, $data['tax']);
$this->assertEquals(0, $data['tax_total']);
$this->assertEqualsWithDelta($sub_total, $data['total'], 0.0000001);
$this->assertEquals("", $data['voucher_code']);
$this->assertEquals(0, $data['voucher_discount_amount']);
}
public function test_platinum_customer_fetch_booking_payment_quotation_online()
{
$company = Company::where('name', 'user one')->first();
DB::table('segment_companies')->insert([
'segment_id' => 2,
'company_id' => $company->id,
]);
$booking = Booking::first();
$foreign_total = 1000;
$local_total = 1000 / $this->curr_rate_plat_online;
$conversion_amount = $local_total;
$service_charge = $conversion_amount * 0.02;
$sub_total = $local_total + $service_charge;
$response = $this->postJson(route('api.booking.payment.quotation', ['id' => $booking->id]),
[
'amount' => 1000,
'payment_method' => 'payment_gateway',
'voucherCode' => ''
]);
$response->assertStatus(200)->assertJsonStructure([
"title",
"message",
"payload" => [
"data" => [
"conversion_amount",
"foreign_total",
"local_total",
"rate",
"service_charge",
"sub_total",
"tax",
"tax_total",
"total",
"voucher_code",
"voucher_discount_amount"
]
]
]);
$data = json_decode($response->getContent(), true)['payload']['data'];
$this->assertEqualsWithDelta($conversion_amount, $data['conversion_amount'], 0.0000001);
$this->assertEqualsWithDelta($foreign_total, $data['foreign_total'], 0.0000001);
$this->assertEqualsWithDelta($local_total, $data['local_total'], 0.0000001);
$this->assertEqualsWithDelta($this->curr_rate_plat_online, $data['rate'], 0.0000001);
$this->assertEqualsWithDelta($service_charge, $data['service_charge'], 0.0000001);
$this->assertEqualsWithDelta($sub_total, $data['sub_total'], 0.0000001);
$this->assertEquals(0, $data['tax']);
$this->assertEquals(0, $data['tax_total']);
$this->assertEqualsWithDelta($sub_total, $data['total'], 0.0000001);
$this->assertEquals("", $data['voucher_code']);
$this->assertEquals(0, $data['voucher_discount_amount']);
}
}
@@ -0,0 +1,189 @@
<?php
namespace Tests\Feature\Companies;
use App\Classes\ValueObjects\Constants\SegmentConstants;
use App\Models\Company;
use Database\Seeders\CompaniesTableSeeder;
use Database\Seeders\CountriesTableSeeder;
use Database\Seeders\CurrenciesTableSeeder;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Support\Facades\DB;
use Tests\TestCase;
class FetchCompanyBookingQuotationControllerTest extends TestCase
{
use DatabaseMigrations;
private $curr_rate_std_cash = 1.52800;
private $curr_rate_std_cheque = 1.51800;
private $curr_rate_std_wallet = 1.53400;
private $curr_rate_std_online = 1.53100;
private $curr_rate_plat_cash = 1.54100;
private $curr_rate_plat_cheque = 1.53100;
private $curr_rate_plat_wallet = 1.54700;
private $curr_rate_plat_online = 1.54400;
protected function setUp(): void
{
parent::setUp();
$this->seed(CountriesTableSeeder::class);
$this->seed(CurrenciesTableSeeder::class);
$this->seed(CompaniesTableSeeder::class);
// create currency rate
DB::table('currency_rates')->insert(array (
0 =>
array (
'id' => 1,
'currency_id' => 2,
'selling' => $this->curr_rate_std_cash,
'payment_method_type' => 1,
'service_id' => 1,
),
1 =>
array (
'id' => 2,
'currency_id' => 2,
'selling' => $this->curr_rate_std_cheque,
'payment_method_type' => 2,
'service_id' => 1,
),
2 =>
array (
'id' => 3,
'currency_id' => 2,
'selling' => $this->curr_rate_std_wallet,
'payment_method_type' => 4,
'service_id' => 1,
),
3 =>
array (
'id' => 4,
'currency_id' => 2,
'selling' => $this->curr_rate_std_online,
'payment_method_type' => 5,
'service_id' => 1,
)
));
// create service
DB::table('service_types')->insert([
'id' => 1,
'name' => 'X1 Transfer',
'status' => 2,
]);
// create standard segment
DB::table('segments')->insert([
'id' => 1,
'name' => 'Standard Segment',
'type' => SegmentConstants::STANDARD_SEGMENT,
'status' => 2
]);
// create platinum segment
DB::table('segments')->insert([
'id' => 2,
'name' => 'platinum member',
'type' => SegmentConstants::CUSTOM_SEGMENT,
'status' => 2,
]);
// create standard segment constant
DB::table('segment_constants')->insert([
'id' => 1,
'segment_id' => 1,
'name' => 'Service Type',
'reference' => 'SERVICE_TYPE',
'detail' => '{"id":1,"bank_id":1,"service_charge":{"type":"percentage","value":2},"minimum_charge":{"type":"fixed_amount","value":10},"tax":{"type":"percentage","value":0},"po_limit":{"type":"fixed_amount","value":3},"is_active":true,"is_billable":true,"currencies":[{"id":2,"max_limit":{"type":"fixed_amount","value":500000},"min_limit":{"type":"fixed_amount","value":100},"rates":[]}]}',
]);
// create platinum segment constant
// Rate
// 1. Cash:
DB::table('segment_constants')->insert([
'id' => 2,
'segment_id' => 2,
'name' => 'Custom Service Type',
'reference' => 'CUSTOM_SERVICE_TYPE',
'detail' => '{"id":1,"minimum_charge":{"type":"fixed_amount","value":0},"is_active":true,"is_billable":true,"currencies":[{"id":2,"max_limit":{"type":"fixed_amount","value":500000},"min_limit":{"type":"fixed_amount","value":0.01},"rates":[{"payment_type":1,"payment_method":"cash","selling":{"type":"rate","value":"1.54100"}},{"payment_type":2,"payment_method":"cheque","selling":{"type":"rate","value":"1.53100"}},{"payment_type":4,"payment_method":"wallet","selling":{"type":"rate","value":"1.54700"}},{"payment_type":5,"payment_method":"payment_gateway","selling":{"type":"rate","value":"1.54400"}}]}]}',
]);
// create a user
$this->postJson(route('api.account.registration.register', [
"company_name" => "",
"name" => "user one",
"email" => "user1@mail.com",
"password" => "password",
"password_confirmation" => "password",
"phone" => "0123456789",
"type" => 0
]));
$response = $this->postJson(route('api.account.authentication.authenticate.attempt', [
'email' => 'user1@mail.com',
'password' => 'password'
]));
$token = json_decode($response->getContent(), true)['payload']['access_token'];
$this->withHeaders([
'Accept' => 'application/json',
'Authorization' => "Bearer $token",
'Captcha-Token' => "test"
]);
}
public function test_standard_customer_fetch_booking_quotation_cash()
{
$company = Company::where('name', 'user one')->first();
$foreign_total = 1000;
$local_total = 1000 / $this->curr_rate_std_cash;
$conversion_amount = $local_total;
$service_charge = $conversion_amount * 0.02;
$sub_total = $local_total + $service_charge;
$response = $this->postJson(route('api.company.currency.convert', [
'id' => $company->id,
'amount' => $foreign_total,
'currency_id' => 2,
'service_id' => 1,
'type' => 1,
]));
$response->assertStatus(200)->assertJsonStructure([
"title",
"message",
"payload" => [
"data" => [
"conversion_amount",
"foreign_total",
"local_total",
"rate",
"service_charge",
"sub_total",
"tax",
"tax_total",
"total",
"voucher_code",
"voucher_discount_amount"
]
]
]);
$data = json_decode($response->getContent(), true)['payload']['data'];
$this->assertEqualsWithDelta($conversion_amount, $data['conversion_amount'], 0.0000001);
$this->assertEqualsWithDelta($foreign_total, $data['foreign_total'], 0.0000001);
$this->assertEqualsWithDelta($local_total, $data['local_total'], 0.0000001);
$this->assertEqualsWithDelta($this->curr_rate_std_cash, $data['rate'], 0.0000001);
$this->assertEqualsWithDelta($service_charge, $data['service_charge'], 0.0000001);
$this->assertEqualsWithDelta($sub_total, $data['sub_total'], 0.0000001);
$this->assertEquals(0, $data['tax']);
$this->assertEquals(0, $data['tax_total']);
$this->assertEqualsWithDelta($sub_total, $data['total'], 0.0000001);
$this->assertEquals("", $data['voucher_code']);
$this->assertEquals(0, $data['voucher_discount_amount']);
}
}