1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 05:02:36 +01:00

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)
->where('is_deleted', 0)
->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) {
$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
->where('paymentable_type', '=', 'invoices')
->where('paymentable_id', $this->invoice->id)
->sum(DB::raw('amount'));
->sum(DB::raw('amount')->getValue(DB::connection()->getQueryGrammar()));
$payment_adjustment -= $payment->paymentables
->where('paymentable_type', '=', 'invoices')
->where('paymentable_id', $this->invoice->id)
->sum(DB::raw('refunded'));
->sum(DB::raw('refunded')->getValue(DB::connection()->getQueryGrammar()));
$payment_adjustment -= $payment->paymentables
->where('paymentable_type', '=', 'App\Models\Credit')
->sum(DB::raw('amount'));
->sum(DB::raw('amount')->getValue(DB::connection()->getQueryGrammar()));
$payment->amount += $payment_adjustment;
$payment->applied += $payment_adjustment;

View File

@ -121,12 +121,12 @@ class MarkInvoiceDeleted extends AbstractService
$this->adjustment_amount += $payment->paymentables
->where('paymentable_type', '=', 'invoices')
->where('paymentable_id', $this->invoice->id)
->sum(DB::raw('amount'));
->sum(DB::raw('amount')->getValue(DB::connection()->getQueryGrammar()));
$this->adjustment_amount -= $payment->paymentables
->where('paymentable_type', '=', 'invoices')
->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');

View File

@ -250,7 +250,7 @@ class ProfitLoss
AND invoices.is_deleted = 0
AND (invoices.date BETWEEN :start_date AND :end_date)
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.date BETWEEN :start_date AND :end_date)
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)
GROUP 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()
@ -553,7 +553,7 @@ class ProfitLoss
AND expenses.company_id = :company_id
AND (expenses.date BETWEEN :start_date AND :end_date)
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()

View File

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

View File

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