Additional rules around tests
This commit is contained in:
parent
81ec3986ca
commit
5482f44bea
|
|
@ -43,15 +43,15 @@ class RestoreDisabledRule implements ValidationRule
|
||||||
$delete_query = clone $base_query;
|
$delete_query = clone $base_query;
|
||||||
|
|
||||||
$mutated_query = $delete_query->where(function ($q){
|
$mutated_query = $delete_query->where(function ($q){
|
||||||
$q->whereNotNull('backup->parent_invoice_id')->orWhere('backup->child_invoice_ids', '!=', []);
|
$q->whereNotNull('backup->parent_invoice_id')->orWhere('backup->child_invoice_ids', '!=', '[]');
|
||||||
});
|
});
|
||||||
|
|
||||||
/** For verifactu, we do not allow restores of deleted invoices */
|
/** For verifactu, we do not allow restores of deleted invoices */
|
||||||
if($value == 'restore' && $restore_query->where('is_deleted', true)->exists()) {
|
if($value == 'restore' && $restore_query->where('is_deleted', true)->exists()) {
|
||||||
$fail(ctrans('texts.restore_disabled_verifactu'));
|
$fail(ctrans('texts.restore_disabled_verifactu'));
|
||||||
}
|
}
|
||||||
elseif(in_array($value, ['delete', 'cancel']) && $delete_query->exists()) {
|
elseif(in_array($value, ['delete', 'cancel']) && $mutated_query->exists()) {
|
||||||
nlog($delete_query->pluck('backup')->toArray()); // any verifactu invoices that have a parent can NEVER be deleted. The parent can also NEVER be deleted
|
// any verifactu invoices that have a parent can NEVER be deleted. The parent can also NEVER be deleted
|
||||||
$fail(ctrans('texts.delete_disabled_verifactu'));
|
$fail(ctrans('texts.delete_disabled_verifactu'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -91,6 +91,129 @@ class VerifactuApiTest extends TestCase
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function test_archive_invoice_with_no_parent()
|
||||||
|
{
|
||||||
|
|
||||||
|
$settings = $this->company->settings;
|
||||||
|
$settings->e_invoice_type = 'verifactu';
|
||||||
|
$settings->is_locked = 'when_sent';
|
||||||
|
|
||||||
|
$this->company->settings = $settings;
|
||||||
|
$this->company->save();
|
||||||
|
|
||||||
|
$invoice = $this->buildData();
|
||||||
|
$invoice->service()->markSent()->save();
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'action' => 'archive',
|
||||||
|
'ids' => [$invoice->hashed_id]
|
||||||
|
];
|
||||||
|
|
||||||
|
$response = $this->withHeaders([
|
||||||
|
'X-API-SECRET' => config('ninja.api_secret'),
|
||||||
|
'X-API-TOKEN' => $this->token,
|
||||||
|
])->postJson('/api/v1/invoices/bulk', $data);
|
||||||
|
|
||||||
|
$response->assertStatus(200);
|
||||||
|
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'action' => 'restore',
|
||||||
|
'ids' => [$invoice->hashed_id]
|
||||||
|
];
|
||||||
|
|
||||||
|
$response = $this->withHeaders([
|
||||||
|
'X-API-SECRET' => config('ninja.api_secret'),
|
||||||
|
'X-API-TOKEN' => $this->token,
|
||||||
|
])->postJson('/api/v1/invoices/bulk', $data);
|
||||||
|
|
||||||
|
$response->assertStatus(200);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_delete_invoice_with_parent()
|
||||||
|
{
|
||||||
|
|
||||||
|
$settings = $this->company->settings;
|
||||||
|
$settings->e_invoice_type = 'verifactu';
|
||||||
|
|
||||||
|
$this->company->settings = $settings;
|
||||||
|
$this->company->save();
|
||||||
|
|
||||||
|
$invoice = $this->buildData();
|
||||||
|
$invoice->service()->markSent()->save();
|
||||||
|
|
||||||
|
$this->assertEquals(121, $invoice->amount);
|
||||||
|
|
||||||
|
$data = $invoice->toArray();
|
||||||
|
unset($data['client']);
|
||||||
|
unset($data['invitations']);
|
||||||
|
$data['client_id'] = $this->client->hashed_id;
|
||||||
|
$data['verifactu_modified'] = true;
|
||||||
|
$data['modified_invoice_id'] = $invoice->hashed_id;
|
||||||
|
$data['number'] = null;
|
||||||
|
$data['discount'] = 121;
|
||||||
|
$data['is_amount_discount'] = true;
|
||||||
|
|
||||||
|
$response = $this->withHeaders([
|
||||||
|
'X-API-SECRET' => config('ninja.api_secret'),
|
||||||
|
'X-API-TOKEN' => $this->token,
|
||||||
|
])->postJson('/api/v1/invoices', $data);
|
||||||
|
|
||||||
|
$response->assertStatus(200);
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'action' => 'delete',
|
||||||
|
'ids' => [$invoice->hashed_id]
|
||||||
|
];
|
||||||
|
|
||||||
|
$response = $this->withHeaders([
|
||||||
|
'X-API-SECRET' => config('ninja.api_secret'),
|
||||||
|
'X-API-TOKEN' => $this->token,
|
||||||
|
])->postJson('/api/v1/invoices/bulk', $data);
|
||||||
|
|
||||||
|
$response->assertStatus(422);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_delete_invoice_with_no_parent()
|
||||||
|
{
|
||||||
|
|
||||||
|
$settings = $this->company->settings;
|
||||||
|
$settings->e_invoice_type = 'verifactu';
|
||||||
|
|
||||||
|
$this->company->settings = $settings;
|
||||||
|
$this->company->save();
|
||||||
|
|
||||||
|
$invoice = $this->buildData();
|
||||||
|
$invoice->service()->markSent()->save();
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'action' => 'delete',
|
||||||
|
'ids' => [$invoice->hashed_id]
|
||||||
|
];
|
||||||
|
|
||||||
|
$response = $this->withHeaders([
|
||||||
|
'X-API-SECRET' => config('ninja.api_secret'),
|
||||||
|
'X-API-TOKEN' => $this->token,
|
||||||
|
])->postJson('/api/v1/invoices/bulk', $data);
|
||||||
|
|
||||||
|
$response->assertStatus(200);
|
||||||
|
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'action' => 'restore',
|
||||||
|
'ids' => [$invoice->hashed_id]
|
||||||
|
];
|
||||||
|
|
||||||
|
$response = $this->withHeaders([
|
||||||
|
'X-API-SECRET' => config('ninja.api_secret'),
|
||||||
|
'X-API-TOKEN' => $this->token,
|
||||||
|
])->postJson('/api/v1/invoices/bulk', $data);
|
||||||
|
|
||||||
|
$response->assertStatus(422);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public function test_credits_never_exceed_original_invoice9()
|
public function test_credits_never_exceed_original_invoice9()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue