Fixes for tests

This commit is contained in:
David Bomba 2023-08-21 13:29:34 +10:00
parent d5e16f189c
commit cd06dc551a
7 changed files with 250 additions and 213 deletions

View File

@ -81,7 +81,7 @@ class ClientService
$amount = Payment::query()->where('client_id', $this->client->id) $amount = Payment::query()->where('client_id', $this->client->id)
->where('is_deleted', 0) ->where('is_deleted', 0)
->whereIn('status_id', [Payment::STATUS_COMPLETED, Payment::STATUS_PENDING, Payment::STATUS_PARTIALLY_REFUNDED, Payment::STATUS_REFUNDED]) ->whereIn('status_id', [Payment::STATUS_COMPLETED, Payment::STATUS_PENDING, Payment::STATUS_PARTIALLY_REFUNDED, Payment::STATUS_REFUNDED])
->sum(DB::Raw('amount - applied')); ->sum(DB::Raw('amount - applied')->getValue(DB::connection()->getQueryGrammar()));
DB::connection(config('database.default'))->transaction(function () use ($amount) { DB::connection(config('database.default'))->transaction(function () use ($amount) {
$this->client = Client::withTrashed()->where('id', $this->client->id)->lockForUpdate()->first(); $this->client = Client::withTrashed()->where('id', $this->client->id)->lockForUpdate()->first();

View File

@ -129,16 +129,16 @@ class HandleRestore extends AbstractService
$payment_adjustment = $payment->paymentables $payment_adjustment = $payment->paymentables
->where('paymentable_type', '=', 'invoices') ->where('paymentable_type', '=', 'invoices')
->where('paymentable_id', $this->invoice->id) ->where('paymentable_id', $this->invoice->id)
->sum(DB::raw('amount')); ->sum(DB::raw('amount')->getValue(DB::connection()->getQueryGrammar()));
$payment_adjustment -= $payment->paymentables $payment_adjustment -= $payment->paymentables
->where('paymentable_type', '=', 'invoices') ->where('paymentable_type', '=', 'invoices')
->where('paymentable_id', $this->invoice->id) ->where('paymentable_id', $this->invoice->id)
->sum(DB::raw('refunded')); ->sum(DB::raw('refunded')->getValue(DB::connection()->getQueryGrammar()));
$payment_adjustment -= $payment->paymentables $payment_adjustment -= $payment->paymentables
->where('paymentable_type', '=', 'App\Models\Credit') ->where('paymentable_type', '=', 'App\Models\Credit')
->sum(DB::raw('amount')); ->sum(DB::raw('amount')->getValue(DB::connection()->getQueryGrammar()));
$payment->amount += $payment_adjustment; $payment->amount += $payment_adjustment;
$payment->applied += $payment_adjustment; $payment->applied += $payment_adjustment;

View File

@ -121,12 +121,12 @@ class MarkInvoiceDeleted extends AbstractService
$this->adjustment_amount += $payment->paymentables $this->adjustment_amount += $payment->paymentables
->where('paymentable_type', '=', 'invoices') ->where('paymentable_type', '=', 'invoices')
->where('paymentable_id', $this->invoice->id) ->where('paymentable_id', $this->invoice->id)
->sum(DB::raw('amount')); ->sum(DB::raw('amount')->getValue(DB::connection()->getQueryGrammar()));
$this->adjustment_amount -= $payment->paymentables $this->adjustment_amount -= $payment->paymentables
->where('paymentable_type', '=', 'invoices') ->where('paymentable_type', '=', 'invoices')
->where('paymentable_id', $this->invoice->id) ->where('paymentable_id', $this->invoice->id)
->sum(DB::raw('refunded')); ->sum(DB::raw('refunded')->getValue(DB::connection()->getQueryGrammar()));
} }
$this->total_payments = $this->invoice->payments->sum('amount') - $this->invoice->payments->sum('refunded'); $this->total_payments = $this->invoice->payments->sum('amount') - $this->invoice->payments->sum('refunded');

View File

@ -250,7 +250,7 @@ class ProfitLoss
AND invoices.is_deleted = 0 AND invoices.is_deleted = 0
AND (invoices.date BETWEEN :start_date AND :end_date) AND (invoices.date BETWEEN :start_date AND :end_date)
GROUP BY currency_id GROUP BY currency_id
")->getValue(DB::connection()->getQueryGrammar()), ['company_currency' => $this->company->settings->currency_id, 'company_id' => $this->company->id, 'start_date' => $this->start_date, 'end_date' => $this->end_date]); ")->getValue(\DB::connection()->getQueryGrammar()), ['company_currency' => $this->company->settings->currency_id, 'company_id' => $this->company->id, 'start_date' => $this->start_date, 'end_date' => $this->end_date]);
} }
/** /**
@ -421,7 +421,7 @@ class ProfitLoss
AND invoices.is_deleted = 0 AND invoices.is_deleted = 0
AND (invoices.date BETWEEN :start_date AND :end_date) AND (invoices.date BETWEEN :start_date AND :end_date)
GROUP BY currency_id GROUP BY currency_id
")->getValue(DB::connection()->getQueryGrammar()), ['company_currency' => $this->company->settings->currency_id, 'company_id' => $this->company->id, 'start_date' => $this->start_date, 'end_date' => $this->end_date]); ")->getValue(\DB::connection()->getQueryGrammar()), ['company_currency' => $this->company->settings->currency_id, 'company_id' => $this->company->id, 'start_date' => $this->start_date, 'end_date' => $this->end_date]);
} }
/** /**
@ -447,7 +447,7 @@ class ProfitLoss
AND (payments.date BETWEEN :start_date AND :end_date) AND (payments.date BETWEEN :start_date AND :end_date)
GROUP BY currency_id GROUP BY currency_id
ORDER BY currency_id; ORDER BY currency_id;
')->getValue(DB::connection()->getQueryGrammar()), ['company_id' => $this->company->id, 'start_date' => $this->start_date, 'end_date' => $this->end_date]); ')->getValue(\DB::connection()->getQueryGrammar()), ['company_id' => $this->company->id, 'start_date' => $this->start_date, 'end_date' => $this->end_date]);
} }
private function expenseData() private function expenseData()
@ -553,7 +553,7 @@ class ProfitLoss
AND expenses.company_id = :company_id AND expenses.company_id = :company_id
AND (expenses.date BETWEEN :start_date AND :end_date) AND (expenses.date BETWEEN :start_date AND :end_date)
GROUP BY currency_id GROUP BY currency_id
')->getValue(DB::connection()->getQueryGrammar()), ['company_currency' => $this->company->settings->currency_id, 'company_id' => $this->company->id, 'start_date' => $this->start_date, 'end_date' => $this->end_date]); ')->getValue(\DB::connection()->getQueryGrammar()), ['company_currency' => $this->company->settings->currency_id, 'company_id' => $this->company->id, 'start_date' => $this->start_date, 'end_date' => $this->end_date]);
} }
private function setBillingReportType() private function setBillingReportType()

View File

@ -8,79 +8,81 @@
* *
* @license https://www.elastic.co/licensing/elastic-license * @license https://www.elastic.co/licensing/elastic-license
*/ */
namespace Tests\Integration; namespace Tests\Integration;
use App\Events\Client\ClientWasArchived; use Tests\TestCase;
use App\Events\Client\ClientWasCreated; use App\Models\Quote;
use App\Events\Client\ClientWasDeleted; use App\Models\Invoice;
use App\Events\Client\ClientWasRestored; use Tests\MockAccountData;
use App\Events\Client\ClientWasUpdated; use App\Utils\Traits\MakesHash;
use App\Events\Credit\CreditWasArchived;
use App\Events\Credit\CreditWasCreated;
use App\Events\Credit\CreditWasDeleted;
use App\Events\Credit\CreditWasRestored;
use App\Events\Credit\CreditWasUpdated;
use App\Events\Expense\ExpenseWasArchived;
use App\Events\Expense\ExpenseWasCreated;
use App\Events\Expense\ExpenseWasDeleted;
use App\Events\Expense\ExpenseWasRestored;
use App\Events\Expense\ExpenseWasUpdated;
use App\Events\Invoice\InvoiceWasArchived;
use App\Events\Invoice\InvoiceWasCreated;
use App\Events\Invoice\InvoiceWasDeleted;
use App\Events\Invoice\InvoiceWasRestored;
use App\Events\Invoice\InvoiceWasUpdated;
use App\Events\Payment\PaymentWasArchived;
use App\Events\Payment\PaymentWasCreated;
use App\Events\Payment\PaymentWasDeleted;
use App\Events\Payment\PaymentWasRestored;
use App\Events\Payment\PaymentWasUpdated;
use App\Events\PurchaseOrder\PurchaseOrderWasArchived;
use App\Events\PurchaseOrder\PurchaseOrderWasCreated;
use App\Events\PurchaseOrder\PurchaseOrderWasDeleted;
use App\Events\PurchaseOrder\PurchaseOrderWasRestored;
use App\Events\PurchaseOrder\PurchaseOrderWasUpdated;
use App\Events\Quote\QuoteWasApproved;
use App\Events\Quote\QuoteWasArchived;
use App\Events\Quote\QuoteWasCreated;
use App\Events\Quote\QuoteWasDeleted;
use App\Events\Quote\QuoteWasRestored;
use App\Events\Quote\QuoteWasUpdated;
use App\Events\RecurringInvoice\RecurringInvoiceWasArchived;
use App\Events\RecurringInvoice\RecurringInvoiceWasCreated;
use App\Events\RecurringInvoice\RecurringInvoiceWasDeleted;
use App\Events\RecurringInvoice\RecurringInvoiceWasRestored;
use App\Events\RecurringInvoice\RecurringInvoiceWasUpdated;
use App\Events\Subscription\SubscriptionWasArchived;
use App\Events\Subscription\SubscriptionWasCreated;
use App\Events\Subscription\SubscriptionWasDeleted;
use App\Events\Subscription\SubscriptionWasRestored;
use App\Events\Subscription\SubscriptionWasUpdated;
use App\Events\Task\TaskWasArchived;
use App\Events\Task\TaskWasCreated; use App\Events\Task\TaskWasCreated;
use App\Events\Task\TaskWasDeleted; use App\Events\Task\TaskWasDeleted;
use App\Events\Task\TaskWasRestored;
use App\Events\Task\TaskWasUpdated; use App\Events\Task\TaskWasUpdated;
use App\Events\User\UserWasArchived;
use App\Events\User\UserWasCreated; use App\Events\User\UserWasCreated;
use App\Events\User\UserWasDeleted; use App\Events\User\UserWasDeleted;
use App\Events\User\UserWasRestored;
use App\Events\User\UserWasUpdated; use App\Events\User\UserWasUpdated;
use App\Events\Vendor\VendorWasArchived; use App\Events\Task\TaskWasArchived;
use App\Events\Task\TaskWasRestored;
use App\Events\User\UserWasArchived;
use App\Events\User\UserWasRestored;
use App\Events\Quote\QuoteWasCreated;
use App\Events\Quote\QuoteWasDeleted;
use App\Events\Quote\QuoteWasUpdated;
use Illuminate\Support\Facades\Event;
use App\Events\Quote\QuoteWasApproved;
use App\Events\Quote\QuoteWasArchived;
use App\Events\Quote\QuoteWasRestored;
use App\Events\Client\ClientWasCreated;
use App\Events\Client\ClientWasDeleted;
use App\Events\Client\ClientWasUpdated;
use App\Events\Credit\CreditWasCreated;
use App\Events\Credit\CreditWasDeleted;
use App\Events\Credit\CreditWasUpdated;
use App\Events\Vendor\VendorWasCreated; use App\Events\Vendor\VendorWasCreated;
use App\Events\Vendor\VendorWasDeleted; use App\Events\Vendor\VendorWasDeleted;
use App\Events\Vendor\VendorWasRestored;
use App\Events\Vendor\VendorWasUpdated; use App\Events\Vendor\VendorWasUpdated;
use App\Http\Middleware\PasswordProtection;
use App\Models\Invoice;
use App\Models\Quote;
use App\Utils\Traits\MakesHash;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Foundation\Testing\DatabaseTransactions; use App\Events\Client\ClientWasArchived;
use Illuminate\Routing\Middleware\ThrottleRequests; use App\Events\Client\ClientWasRestored;
use App\Events\Credit\CreditWasArchived;
use App\Events\Credit\CreditWasRestored;
use App\Events\Vendor\VendorWasArchived;
use App\Events\Vendor\VendorWasRestored;
use App\Events\Expense\ExpenseWasCreated;
use App\Events\Expense\ExpenseWasDeleted;
use App\Events\Expense\ExpenseWasUpdated;
use App\Events\Invoice\InvoiceWasCreated;
use App\Events\Invoice\InvoiceWasDeleted;
use App\Events\Invoice\InvoiceWasUpdated;
use App\Events\Payment\PaymentWasCreated;
use App\Events\Payment\PaymentWasDeleted;
use App\Events\Payment\PaymentWasUpdated;
use App\Events\Expense\ExpenseWasArchived;
use App\Events\Expense\ExpenseWasRestored;
use App\Events\Invoice\InvoiceWasArchived;
use App\Events\Invoice\InvoiceWasRestored;
use App\Events\Payment\PaymentWasArchived;
use App\Events\Payment\PaymentWasRestored;
use App\Http\Middleware\PasswordProtection;
use Illuminate\Validation\ValidationException; use Illuminate\Validation\ValidationException;
use Tests\MockAccountData; use App\Events\Subscription\SubscriptionWasCreated;
use Tests\TestCase; use App\Events\Subscription\SubscriptionWasDeleted;
use App\Events\Subscription\SubscriptionWasUpdated;
use Illuminate\Routing\Middleware\ThrottleRequests;
use App\Events\Subscription\SubscriptionWasArchived;
use App\Events\Subscription\SubscriptionWasRestored;
use App\Events\PurchaseOrder\PurchaseOrderWasCreated;
use App\Events\PurchaseOrder\PurchaseOrderWasDeleted;
use App\Events\PurchaseOrder\PurchaseOrderWasUpdated;
use App\Events\PurchaseOrder\PurchaseOrderWasArchived;
use App\Events\PurchaseOrder\PurchaseOrderWasRestored;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use App\Events\RecurringInvoice\RecurringInvoiceWasCreated;
use App\Events\RecurringInvoice\RecurringInvoiceWasDeleted;
use App\Events\RecurringInvoice\RecurringInvoiceWasUpdated;
use App\Events\RecurringInvoice\RecurringInvoiceWasArchived;
use App\Events\RecurringInvoice\RecurringInvoiceWasRestored;
/** /**
* @test * @test
@ -91,7 +93,7 @@ class EventTest extends TestCase
use MakesHash; use MakesHash;
use DatabaseTransactions; use DatabaseTransactions;
public function setUp() :void public function setUp(): void
{ {
parent::setUp(); parent::setUp();
@ -109,13 +111,7 @@ class EventTest extends TestCase
public function testExpenseEvents() public function testExpenseEvents()
{ {
$this->expectsEvents([ Event::fake();
ExpenseWasCreated::class,
ExpenseWasUpdated::class,
ExpenseWasArchived::class,
ExpenseWasRestored::class,
ExpenseWasDeleted::class,
]);
$data = [ $data = [
'public_notes' => $this->faker->firstName, 'public_notes' => $this->faker->firstName,
@ -162,18 +158,21 @@ class EventTest extends TestCase
'X-API-TOKEN' => $this->token, 'X-API-TOKEN' => $this->token,
])->postJson('/api/v1/expenses/bulk?action=delete', $data) ])->postJson('/api/v1/expenses/bulk?action=delete', $data)
->assertStatus(200); ->assertStatus(200);
Event::assertDispatched(ExpenseWasCreated::class);
Event::assertDispatched(ExpenseWasUpdated::class);
Event::assertDispatched(ExpenseWasArchived::class);
Event::assertDispatched(ExpenseWasRestored::class);
Event::assertDispatched(ExpenseWasDeleted::class);
} }
public function testVendorEvents() public function testVendorEvents()
{ {
$this->expectsEvents([ Event::fake();
VendorWasCreated::class,
VendorWasUpdated::class,
VendorWasArchived::class,
VendorWasRestored::class,
VendorWasDeleted::class,
]);
$data = [ $data = [
'name' => $this->faker->firstName, 'name' => $this->faker->firstName,
@ -221,6 +220,14 @@ class EventTest extends TestCase
'X-API-TOKEN' => $this->token, 'X-API-TOKEN' => $this->token,
])->postJson('/api/v1/vendors/bulk?action=delete', $data) ])->postJson('/api/v1/vendors/bulk?action=delete', $data)
->assertStatus(200); ->assertStatus(200);
Event::assertDispatched(VendorWasCreated::class);
Event::assertDispatched(VendorWasUpdated::class);
Event::assertDispatched(VendorWasArchived::class);
Event::assertDispatched(VendorWasRestored::class);
Event::assertDispatched(VendorWasDeleted::class);
} }
@ -232,13 +239,8 @@ class EventTest extends TestCase
'description' => 'dude', 'description' => 'dude',
]; ];
$this->expectsEvents([ Event::fake();
TaskWasCreated::class,
TaskWasUpdated::class,
TaskWasArchived::class,
TaskWasRestored::class,
TaskWasDeleted::class,
]);
$response = $this->withHeaders([ $response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'), 'X-API-SECRET' => config('ninja.api_secret'),
@ -282,6 +284,14 @@ class EventTest extends TestCase
'X-API-TOKEN' => $this->token, 'X-API-TOKEN' => $this->token,
])->postJson('/api/v1/tasks/bulk?action=delete', $data) ])->postJson('/api/v1/tasks/bulk?action=delete', $data)
->assertStatus(200); ->assertStatus(200);
Event::assertDispatched(TaskWasCreated::class);
Event::assertDispatched(TaskWasUpdated::class);
Event::assertDispatched(TaskWasArchived::class);
Event::assertDispatched(TaskWasRestored::class);
Event::assertDispatched(TaskWasDeleted::class);
} }
public function testCreditEvents() public function testCreditEvents()
@ -292,13 +302,7 @@ class EventTest extends TestCase
'number' => 'dude', 'number' => 'dude',
]; ];
$this->expectsEvents([ Event::fake();
CreditWasCreated::class,
CreditWasUpdated::class,
CreditWasArchived::class,
CreditWasRestored::class,
CreditWasDeleted::class,
]);
$response = $this->withHeaders([ $response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'), 'X-API-SECRET' => config('ninja.api_secret'),
@ -342,8 +346,17 @@ class EventTest extends TestCase
'X-API-TOKEN' => $this->token, 'X-API-TOKEN' => $this->token,
])->postJson('/api/v1/credits/bulk?action=delete', $data) ])->postJson('/api/v1/credits/bulk?action=delete', $data)
->assertStatus(200); ->assertStatus(200);
Event::assertDispatched(CreditWasCreated::class);
Event::assertDispatched(CreditWasUpdated::class);
Event::assertDispatched(CreditWasArchived::class);
Event::assertDispatched(CreditWasRestored::class);
Event::assertDispatched(CreditWasDeleted::class);
} }
public function testQuoteEvents() public function testQuoteEvents()
{ {
/* Test fire new invoice */ /* Test fire new invoice */
@ -352,14 +365,8 @@ class EventTest extends TestCase
'number' => 'dude', 'number' => 'dude',
]; ];
$this->expectsEvents([ Event::fake();
QuoteWasCreated::class,
QuoteWasUpdated::class,
QuoteWasArchived::class,
QuoteWasRestored::class,
QuoteWasDeleted::class,
QuoteWasApproved::class,
]);
$response = $this->withHeaders([ $response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'), 'X-API-SECRET' => config('ninja.api_secret'),
@ -413,6 +420,15 @@ class EventTest extends TestCase
'X-API-TOKEN' => $this->token, 'X-API-TOKEN' => $this->token,
])->postJson('/api/v1/quotes/bulk?action=delete', $data) ])->postJson('/api/v1/quotes/bulk?action=delete', $data)
->assertStatus(200); ->assertStatus(200);
Event::assertDispatched(QuoteWasCreated::class);
Event::assertDispatched(QuoteWasUpdated::class);
Event::assertDispatched(QuoteWasArchived::class);
Event::assertDispatched(QuoteWasRestored::class);
Event::assertDispatched(QuoteWasDeleted::class);
Event::assertDispatched(QuoteWasApproved::class);
} }
@ -421,13 +437,8 @@ class EventTest extends TestCase
public function testPaymentEvents() public function testPaymentEvents()
{ {
$this->expectsEvents([ Event::fake();
PaymentWasCreated::class,
PaymentWasUpdated::class,
PaymentWasArchived::class,
PaymentWasRestored::class,
PaymentWasDeleted::class,
]);
$data = [ $data = [
'amount' => $this->invoice->amount, 'amount' => $this->invoice->amount,
@ -481,6 +492,14 @@ class EventTest extends TestCase
'X-API-TOKEN' => $this->token, 'X-API-TOKEN' => $this->token,
])->postJson('/api/v1/payments/bulk?action=delete', $data) ])->postJson('/api/v1/payments/bulk?action=delete', $data)
->assertStatus(200); ->assertStatus(200);
Event::assertDispatched(PaymentWasCreated::class);
Event::assertDispatched(PaymentWasUpdated::class);
Event::assertDispatched(PaymentWasArchived::class);
Event::assertDispatched(PaymentWasRestored::class);
Event::assertDispatched(PaymentWasDeleted::class);
} }
@ -492,13 +511,8 @@ class EventTest extends TestCase
'number' => 'dude', 'number' => 'dude',
]; ];
$this->expectsEvents([ Event::fake();
InvoiceWasCreated::class,
InvoiceWasUpdated::class,
InvoiceWasArchived::class,
InvoiceWasRestored::class,
InvoiceWasDeleted::class,
]);
$response = $this->withHeaders([ $response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'), 'X-API-SECRET' => config('ninja.api_secret'),
@ -542,6 +556,14 @@ class EventTest extends TestCase
'X-API-TOKEN' => $this->token, 'X-API-TOKEN' => $this->token,
])->postJson('/api/v1/invoices/bulk?action=delete', $data) ])->postJson('/api/v1/invoices/bulk?action=delete', $data)
->assertStatus(200); ->assertStatus(200);
Event::assertDispatched(InvoiceWasCreated::class);
Event::assertDispatched(InvoiceWasUpdated::class);
Event::assertDispatched(InvoiceWasArchived::class);
Event::assertDispatched(InvoiceWasRestored::class);
Event::assertDispatched(InvoiceWasDeleted::class);
} }
@ -555,13 +577,8 @@ class EventTest extends TestCase
'frequency_id' => 1, 'frequency_id' => 1,
]; ];
$this->expectsEvents([ Event::fake();
RecurringInvoiceWasCreated::class,
RecurringInvoiceWasUpdated::class,
RecurringInvoiceWasArchived::class,
RecurringInvoiceWasRestored::class,
RecurringInvoiceWasDeleted::class,
]);
try { try {
$response = $this->withHeaders([ $response = $this->withHeaders([
@ -611,19 +628,21 @@ class EventTest extends TestCase
'X-API-TOKEN' => $this->token, 'X-API-TOKEN' => $this->token,
])->postJson('/api/v1/recurring_invoices/bulk?action=delete', $data) ])->postJson('/api/v1/recurring_invoices/bulk?action=delete', $data)
->assertStatus(200); ->assertStatus(200);
Event::assertDispatched(RecurringInvoiceWasCreated::class);
Event::assertDispatched(RecurringInvoiceWasUpdated::class);
Event::assertDispatched(RecurringInvoiceWasArchived::class);
Event::assertDispatched(RecurringInvoiceWasRestored::class);
Event::assertDispatched(RecurringInvoiceWasDeleted::class);
} }
public function testClientEvents() public function testClientEvents()
{ {
$this->expectsEvents([ Event::fake();
ClientWasCreated::class,
ClientWasUpdated::class,
ClientWasArchived::class,
ClientWasRestored::class,
ClientWasDeleted::class,
]);
$data = [ $data = [
'name' => $this->faker->firstName, 'name' => $this->faker->firstName,
@ -669,6 +688,14 @@ class EventTest extends TestCase
'X-API-TOKEN' => $this->token, 'X-API-TOKEN' => $this->token,
])->postJson('/api/v1/clients/bulk?action=delete', $data) ])->postJson('/api/v1/clients/bulk?action=delete', $data)
->assertStatus(200); ->assertStatus(200);
Event::assertDispatched(ClientWasCreated::class);
Event::assertDispatched(ClientWasUpdated::class);
Event::assertDispatched(ClientWasArchived::class);
Event::assertDispatched(ClientWasRestored::class);
Event::assertDispatched(ClientWasDeleted::class);
} }
@ -676,13 +703,7 @@ class EventTest extends TestCase
{ {
$this->withoutMiddleware(PasswordProtection::class); $this->withoutMiddleware(PasswordProtection::class);
$this->expectsEvents([ Event::fake();
UserWasCreated::class,
UserWasUpdated::class,
UserWasArchived::class,
UserWasRestored::class,
UserWasDeleted::class,
]);
$data = [ $data = [
'first_name' => 'hey', 'first_name' => 'hey',
@ -701,7 +722,7 @@ class EventTest extends TestCase
'X-API-PASSWORD' => 'ALongAndBriliantPassword', 'X-API-PASSWORD' => 'ALongAndBriliantPassword',
])->postJson('/api/v1/users?include=company_user', $data) ])->postJson('/api/v1/users?include=company_user', $data)
->assertStatus(200); ->assertStatus(200);
$arr = $response->json(); $arr = $response->json();
$data = [ $data = [
@ -747,17 +768,27 @@ class EventTest extends TestCase
'X-API-PASSWORD' => 'ALongAndBriliantPassword', 'X-API-PASSWORD' => 'ALongAndBriliantPassword',
])->postJson('/api/v1/users/bulk?action=delete', $data) ])->postJson('/api/v1/users/bulk?action=delete', $data)
->assertStatus(200); ->assertStatus(200);
Event::assertDispatched(UserWasCreated::class);
Event::assertDispatched(UserWasUpdated::class);
Event::assertDispatched(UserWasArchived::class);
Event::assertDispatched(UserWasRestored::class);
Event::assertDispatched(UserWasDeleted::class);
} }
public function testSubscriptionEvents() public function testSubscriptionEvents()
{ {
$this->expectsEvents([ Event::fake();
SubscriptionWasCreated::class,
SubscriptionWasUpdated::class,
SubscriptionWasArchived::class,
SubscriptionWasRestored::class,
SubscriptionWasDeleted::class,
]);
$data = [ $data = [
'name' => $this->faker->firstName, 'name' => $this->faker->firstName,
@ -804,76 +835,86 @@ class EventTest extends TestCase
'X-API-TOKEN' => $this->token, 'X-API-TOKEN' => $this->token,
])->postJson('/api/v1/subscriptions/bulk?action=delete', $data) ])->postJson('/api/v1/subscriptions/bulk?action=delete', $data)
->assertStatus(200); ->assertStatus(200);
Event::assertDispatched(SubscriptionWasCreated::class);
Event::assertDispatched(SubscriptionWasUpdated::class);
Event::assertDispatched(SubscriptionWasArchived::class);
Event::assertDispatched(SubscriptionWasRestored::class);
Event::assertDispatched(SubscriptionWasDeleted::class);
} }
public function PurchaseOrderEvents() public function PurchaseOrderEvents()
{ {
/* Test fire new invoice */ /* Test fire new invoice */
$data = [ $data = [
'client_id' => $this->vendor->hashed_id, 'client_id' => $this->vendor->hashed_id,
'number' => 'dude', 'number' => 'dude',
]; ];
$this->expectsEvents([ Event::fake();
PurchaseOrderWasCreated::class,
PurchaseOrderWasUpdated::class,
PurchaseOrderWasArchived::class,
PurchaseOrderWasRestored::class,
PurchaseOrderWasDeleted::class,
]);
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->postJson('/api/v1/purchase_orders/', $data)
->assertStatus(200);
$arr = $response->json(); $response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
$data = [ 'X-API-TOKEN' => $this->token,
'client_id' => $this->vendor->hashed_id, ])->postJson('/api/v1/purchase_orders/', $data)
'number' => 'dude2', ->assertStatus(200);
];
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->putJson('/api/v1/purchase_orders/' . $arr['data']['id'], $data)
->assertStatus(200);
$data = [ $arr = $response->json();
'ids' => [$arr['data']['id']],
];
$quote = PurchaseOrder::find($this->decodePrimaryKey($arr['data']['id'])); $data = [
$quote->status_id = PurchaseOrder::STATUS_SENT; 'client_id' => $this->vendor->hashed_id,
$quote->save(); 'number' => 'dude2',
];
$response = $this->withHeaders([ $response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'), 'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token, 'X-API-TOKEN' => $this->token,
])->postJson('/api/v1/purchase_orders/bulk?action=archive', $data) ])->putJson('/api/v1/purchase_orders/' . $arr['data']['id'], $data)
->assertStatus(200); ->assertStatus(200);
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->postJson('/api/v1/purchase_orders/bulk?action=restore', $data)
->assertStatus(200);
$response = $this->withHeaders([ $data = [
'X-API-SECRET' => config('ninja.api_secret'), 'ids' => [$arr['data']['id']],
'X-API-TOKEN' => $this->token, ];
])->postJson('/api/v1/purchase_orders/bulk?action=approve', $data)
->assertStatus(200);
$response = $this->withHeaders([ $quote = PurchaseOrder::find($this->decodePrimaryKey($arr['data']['id']));
'X-API-SECRET' => config('ninja.api_secret'), $quote->status_id = PurchaseOrder::STATUS_SENT;
'X-API-TOKEN' => $this->token, $quote->save();
])->postJson('/api/v1/purchase_orders/bulk?action=delete', $data)
->assertStatus(200); $response = $this->withHeaders([
} 'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->postJson('/api/v1/purchase_orders/bulk?action=archive', $data)
->assertStatus(200);
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->postJson('/api/v1/purchase_orders/bulk?action=restore', $data)
->assertStatus(200);
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->postJson('/api/v1/purchase_orders/bulk?action=approve', $data)
->assertStatus(200);
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->postJson('/api/v1/purchase_orders/bulk?action=delete', $data)
->assertStatus(200);
Event::assertDispatched(PurchaseOrderWasCreated::class);
Event::assertDispatched(PurchaseOrderWasUpdated::class);
Event::assertDispatched(PurchaseOrderWasArchived::class);
Event::assertDispatched(PurchaseOrderWasRestored::class);
Event::assertDispatched(PurchaseOrderWasDeleted::class);
}
} }

View File

@ -34,7 +34,6 @@ class GoogleAnalyticsTest extends TestCase
public function testGoogleAnalyticsLogic() public function testGoogleAnalyticsLogic()
{ {
$this->withoutEvents();
$analytics_id = 'analytics_id'; $analytics_id = 'analytics_id';
$invoice = $this->invoice; $invoice = $this->invoice;

View File

@ -43,7 +43,6 @@ class InvoiceActionsTest extends TestCase
public function testInvoiceIsReversable() public function testInvoiceIsReversable()
{ {
$this->withoutEvents();
$this->invoice = $this->invoice->service()->markPaid()->save(); $this->invoice = $this->invoice->service()->markPaid()->save();
@ -54,7 +53,6 @@ class InvoiceActionsTest extends TestCase
public function testInvoiceIsCancellable() public function testInvoiceIsCancellable()
{ {
$this->withoutEvents();
$payment = PaymentFactory::create($this->invoice->company_id, $this->invoice->user_id); $payment = PaymentFactory::create($this->invoice->company_id, $this->invoice->user_id);
$payment->amount = 40; $payment->amount = 40;
@ -73,7 +71,6 @@ class InvoiceActionsTest extends TestCase
public function testInvoiceUnactionable() public function testInvoiceUnactionable()
{ {
$this->withoutEvents();
$this->invoice->delete(); $this->invoice->delete();