mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Improve test coverage for triggered actions
This commit is contained in:
parent
3a22fd0384
commit
4a4b324af5
@ -388,7 +388,10 @@ class RecurringInvoiceController extends BaseController
|
||||
|
||||
$recurring_invoice = $this->recurring_invoice_repo->save($request->all(), $recurring_invoice);
|
||||
|
||||
$recurring_invoice->service()->deletePdf()->save();
|
||||
$recurring_invoice->service()
|
||||
->triggeredActions($request)
|
||||
->deletePdf()
|
||||
->save();
|
||||
|
||||
event(new RecurringInvoiceWasUpdated($recurring_invoice, $recurring_invoice->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null)));
|
||||
|
||||
|
@ -57,7 +57,10 @@ class TriggeredActions extends AbstractService
|
||||
$this->invoice = $this->invoice->service()->markSent()->save();
|
||||
}
|
||||
|
||||
|
||||
if ($this->request->has('cancel') && $this->request->input('cancel') == 'true') {
|
||||
$this->invoice = $this->invoice->service()->handleCancellation()->save();
|
||||
}
|
||||
|
||||
return $this->invoice;
|
||||
}
|
||||
|
||||
|
@ -50,6 +50,79 @@ class RecurringInvoiceTest extends TestCase
|
||||
$this->makeTestData();
|
||||
}
|
||||
|
||||
public function testPostRecurringInvoice()
|
||||
{
|
||||
$data = [
|
||||
'frequency_id' => 1,
|
||||
'status_id' => 1,
|
||||
'discount' => 0,
|
||||
'is_amount_discount' => 1,
|
||||
'po_number' => '3434343',
|
||||
'public_notes' => 'notes',
|
||||
'is_deleted' => 0,
|
||||
'custom_value1' => 0,
|
||||
'custom_value2' => 0,
|
||||
'custom_value3' => 0,
|
||||
'custom_value4' => 0,
|
||||
'status' => 1,
|
||||
'client_id' => $this->encodePrimaryKey($this->client->id),
|
||||
'line_items' => $this->buildLineItems(),
|
||||
'remaining_cycles' => -1,
|
||||
];
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->post('/api/v1/recurring_invoices/', $data)
|
||||
->assertStatus(200);
|
||||
|
||||
$arr = $response->json();
|
||||
$this->assertEquals(RecurringInvoice::STATUS_DRAFT, $arr['data']['status_id']);
|
||||
|
||||
}
|
||||
|
||||
public function testPostRecurringInvoiceWithStartAndStop()
|
||||
{
|
||||
$data = [
|
||||
'frequency_id' => 1,
|
||||
'status_id' => 1,
|
||||
'discount' => 0,
|
||||
'is_amount_discount' => 1,
|
||||
'po_number' => '3434343',
|
||||
'public_notes' => 'notes',
|
||||
'is_deleted' => 0,
|
||||
'custom_value1' => 0,
|
||||
'custom_value2' => 0,
|
||||
'custom_value3' => 0,
|
||||
'custom_value4' => 0,
|
||||
'status' => 1,
|
||||
'client_id' => $this->encodePrimaryKey($this->client->id),
|
||||
'line_items' => $this->buildLineItems(),
|
||||
'remaining_cycles' => -1,
|
||||
];
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->post('/api/v1/recurring_invoices?start=true', $data)
|
||||
->assertStatus(200);
|
||||
|
||||
$arr = $response->json();
|
||||
|
||||
$this->assertEquals(RecurringInvoice::STATUS_ACTIVE, $arr['data']['status_id']);
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->put('/api/v1/recurring_invoices/'.$arr['data']['id'].'?stop=true', $data)
|
||||
->assertStatus(200);
|
||||
|
||||
$arr = $response->json();
|
||||
$this->assertEquals(RecurringInvoice::STATUS_PAUSED, $arr['data']['status_id']);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function testRecurringInvoiceList()
|
||||
{
|
||||
Client::factory()->create(['user_id' => $this->user->id, 'company_id' => $this->company->id])->each(function ($c) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user