1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-20 08:21:34 +02:00

Fixes for tests

This commit is contained in:
David Bomba 2023-02-23 06:22:20 +11:00
parent 5c20266641
commit 010f324b4c
3 changed files with 132 additions and 94 deletions

View File

@ -49,7 +49,7 @@ class EmailPayment implements ShouldQueue
* @param $contact
* @param $company
*/
public function __construct(Payment $payment, Company $company, ClientContact $contact)
public function __construct(Payment $payment, Company $company, ?ClientContact $contact)
{
$this->payment = $payment;
$this->contact = $contact;
@ -72,6 +72,10 @@ class EmailPayment implements ShouldQueue
MultiDB::setDb($this->company->db);
$this->payment->load('invoices');
if(!$this->contact)
$this->contact = $this->payment->client->contacts()->first();
$this->contact->load('client');
$email_builder = (new PaymentEmailEngine($this->payment, $this->contact))->build();

View File

@ -20,16 +20,8 @@ use App\Utils\Ninja;
class MarkSent extends AbstractService
{
public $client;
public $invoice;
public function __construct(Client $client, Invoice $invoice)
{
$this->client = $client;
$this->invoice = $invoice;
}
public function __construct(public Client $client, public Invoice $invoice)
{}
public function run($fire_webhook = false)
{

View File

@ -230,8 +230,13 @@ class PaymentTest extends TestCase
public function testStorePaymentWithClientId()
{
$client = ClientFactory::create($this->company->id, $this->user->id);
$client->save();
$client = Client::factory()->create(['company_id' =>$this->company->id, 'user_id' => $this->user->id]);
ClientContact::factory()->create([
'user_id' => $this->user->id,
'client_id' => $client->id,
'company_id' => $this->company->id,
'is_primary' => 1,
]);
$invoice = InvoiceFactory::create($this->company->id, $this->user->id); //stub the company and user_id
$invoice->client_id = $client->id;
@ -289,8 +294,14 @@ class PaymentTest extends TestCase
public function testStorePaymentWithNoInvoiecs()
{
$client = ClientFactory::create($this->company->id, $this->user->id);
$client->save();
$client = Client::factory()->create(['company_id' =>$this->company->id, 'user_id' => $this->user->id]);
ClientContact::factory()->create([
'user_id' => $this->user->id,
'client_id' => $client->id,
'company_id' => $this->company->id,
'is_primary' => 1,
]);
$invoice = InvoiceFactory::create($this->company->id, $this->user->id); //stub the company and user_id
$invoice->client_id = $client->id;
@ -336,16 +347,15 @@ class PaymentTest extends TestCase
{
$invoice = null;
$client = ClientFactory::create($this->company->id, $this->user->id);
$client->save();
$client = Client::factory()->create(['company_id' =>$this->company->id, 'user_id' => $this->user->id]);
ClientContact::factory()->create([
'user_id' => $this->user->id,
'client_id' => $client->id,
'company_id' =>$this->company->id,
'is_primary' => true,
'company_id' => $this->company->id,
'is_primary' => 1,
]);
$invoice = InvoiceFactory::create($this->company->id, $this->user->id); //stub the company and user_id
$invoice->client_id = $client->id;
@ -626,8 +636,14 @@ class PaymentTest extends TestCase
{
$invoice = null;
$client = ClientFactory::create($this->company->id, $this->user->id);
$client->save();
$client = Client::factory()->create(['company_id' =>$this->company->id, 'user_id' => $this->user->id]);
ClientContact::factory()->create([
'user_id' => $this->user->id,
'client_id' => $client->id,
'company_id' => $this->company->id,
'is_primary' => 1,
]);
$invoice = InvoiceFactory::create($this->company->id, $this->user->id); //stub the company and user_id
$invoice->client_id = $client->id;
@ -686,8 +702,14 @@ class PaymentTest extends TestCase
{
$invoice = null;
$client = ClientFactory::create($this->company->id, $this->user->id);
$client->save();
$client = Client::factory()->create(['company_id' =>$this->company->id, 'user_id' => $this->user->id]);
ClientContact::factory()->create([
'user_id' => $this->user->id,
'client_id' => $client->id,
'company_id' => $this->company->id,
'is_primary' => 1,
]);
$invoice = InvoiceFactory::create($this->company->id, $this->user->id); //stub the company and user_id
$invoice->client_id = $client->id;
@ -739,8 +761,13 @@ class PaymentTest extends TestCase
{
$invoice = null;
$client = ClientFactory::create($this->company->id, $this->user->id);
$client->save();
$client = Client::factory()->create(['company_id' =>$this->company->id, 'user_id' => $this->user->id]);
ClientContact::factory()->create([
'user_id' => $this->user->id,
'client_id' => $client->id,
'company_id' => $this->company->id,
'is_primary' => 1,
]);
$invoice = InvoiceFactory::create($this->company->id, $this->user->id); //stub the company and user_id
$invoice->client_id = $client->id;
@ -799,8 +826,14 @@ class PaymentTest extends TestCase
{
$invoice = null;
$client = ClientFactory::create($this->company->id, $this->user->id);
$client->save();
$client = Client::factory()->create(['company_id' =>$this->company->id, 'user_id' => $this->user->id]);
ClientContact::factory()->create([
'user_id' => $this->user->id,
'client_id' => $client->id,
'company_id' => $this->company->id,
'is_primary' => 1,
]);
$invoice = InvoiceFactory::create($this->company->id, $this->user->id); //stub the company and user_id
$invoice->client_id = $client->id;
@ -898,8 +931,13 @@ class PaymentTest extends TestCase
{
$invoice = null;
$client = ClientFactory::create($this->company->id, $this->user->id);
$client->save();
$client = Client::factory()->create(['company_id' =>$this->company->id, 'user_id' => $this->user->id]);
ClientContact::factory()->create([
'user_id' => $this->user->id,
'client_id' => $client->id,
'company_id' => $this->company->id,
'is_primary' => 1,
]);
$invoice = InvoiceFactory::create($this->company->id, $this->user->id); //stub the company and user_id
$invoice->client_id = $client->id;
@ -944,59 +982,18 @@ class PaymentTest extends TestCase
$this->assertEquals($payment->amount, 20);
$this->assertEquals($payment->applied, 10);
// $invoice = null;
// $invoice = InvoiceFactory::create($this->company->id, $this->user->id);//stub the company and user_id
// $invoice->client_id = $client->id;
// $invoice->line_items = $this->buildLineItems();
// $invoice->uses_inclusive_taxes = false;
// $invoice->save();
// $invoice_calc = new InvoiceSum($invoice);
// $invoice_calc->build();
// $invoice = $invoice_calc->getInvoice();
// $invoice->save();
// $invoice->service()->markSent()->createInvitations()->save();
// $data = [
// 'amount' => 20.0,
// 'client_id' => $this->encodePrimaryKey($client->id),
// 'invoices' => [
// [
// 'invoice_id' => $this->encodePrimaryKey($invoice->id),
// 'amount' => 10,
// ]
// ],
// 'date' => '2019/12/12',
// ];
// $response = false;
// try {
// $response = $this->withHeaders([
// 'X-API-SECRET' => config('ninja.api_secret'),
// 'X-API-TOKEN' => $this->token,
// ])->put('/api/v1/payments/'.$this->encodePrimaryKey($payment->id), $data);
// } catch (ValidationException $e) {
// $message = json_decode($e->validator->getMessageBag(), 1);
// \Log::error(print_r($e->validator->getMessageBag(), 1));
// $this->assertTrue(array_key_exists('invoices', $message));
// }
// $response->assertStatus(200);
// $arr = $response->json();
// $this->assertEquals(20, $arr['data']['applied']);
}
public function testStorePaymentWithNoAmountField()
{
$client = ClientFactory::create($this->company->id, $this->user->id);
$client->save();
$client = Client::factory()->create(['company_id' =>$this->company->id, 'user_id' => $this->user->id]);
ClientContact::factory()->create([
'user_id' => $this->user->id,
'client_id' => $client->id,
'company_id' => $this->company->id,
'is_primary' => 1,
]);
$invoice = InvoiceFactory::create($this->company->id, $this->user->id); //stub the company and user_id
$invoice->client_id = $client->id;
@ -1055,8 +1052,13 @@ class PaymentTest extends TestCase
public function testStorePaymentWithZeroAmountField()
{
$client = ClientFactory::create($this->company->id, $this->user->id);
$client->save();
$client = Client::factory()->create(['company_id' =>$this->company->id, 'user_id' => $this->user->id]);
ClientContact::factory()->create([
'user_id' => $this->user->id,
'client_id' => $client->id,
'company_id' => $this->company->id,
'is_primary' => 1,
]);
$invoice = InvoiceFactory::create($this->company->id, $this->user->id); //stub the company and user_id
$invoice->client_id = $client->id;
@ -1109,11 +1111,22 @@ class PaymentTest extends TestCase
public function testPaymentForInvoicesFromDifferentClients()
{
$client1 = ClientFactory::create($this->company->id, $this->user->id);
$client1->save();
$client1 = Client::factory()->create(['company_id' =>$this->company->id, 'user_id' => $this->user->id]);
ClientContact::factory()->create([
'user_id' => $this->user->id,
'client_id' => $client1->id,
'company_id' => $this->company->id,
'is_primary' => 1,
]);
$client2 = ClientFactory::create($this->company->id, $this->user->id);
$client2->save();
$client2 = Client::factory()->create(['company_id' =>$this->company->id, 'user_id' => $this->user->id]);
ClientContact::factory()->create([
'user_id' => $this->user->id,
'client_id' => $client2->id,
'company_id' => $this->company->id,
'is_primary' => 1,
]);
$invoice1 = InvoiceFactory::create($this->company->id, $this->user->id); //stub the company and user_id
$invoice1->client_id = $client1->id;
@ -1175,8 +1188,13 @@ class PaymentTest extends TestCase
public function testPaymentWithSameInvoiceMultipleTimes()
{
$client1 = ClientFactory::create($this->company->id, $this->user->id);
$client1->save();
$client1 = Client::factory()->create(['company_id' =>$this->company->id, 'user_id' => $this->user->id]);
ClientContact::factory()->create([
'user_id' => $this->user->id,
'client_id' => $client1->id,
'company_id' => $this->company->id,
'is_primary' => 1,
]);
$invoice1 = InvoiceFactory::create($this->company->id, $this->user->id); //stub the company and user_id
$invoice1->client_id = $client1->id;
@ -1227,8 +1245,13 @@ class PaymentTest extends TestCase
public function testStorePaymentWithCredits()
{
$client = ClientFactory::create($this->company->id, $this->user->id);
$client->save();
$client = Client::factory()->create(['company_id' =>$this->company->id, 'user_id' => $this->user->id]);
ClientContact::factory()->create([
'user_id' => $this->user->id,
'client_id' => $client->id,
'company_id' => $this->company->id,
'is_primary' => 1,
]);
$invoice = InvoiceFactory::create($this->company->id, $this->user->id); //stub the company and user_id
$invoice->client_id = $client->id;
@ -1310,7 +1333,14 @@ class PaymentTest extends TestCase
$settings = ClientSettings::defaults();
$settings->currency_id = '2';
$client = ClientFactory::create($this->company->id, $this->user->id);
$client = Client::factory()->create(['company_id' =>$this->company->id, 'user_id' => $this->user->id]);
ClientContact::factory()->create([
'user_id' => $this->user->id,
'client_id' => $client->id,
'company_id' => $this->company->id,
'is_primary' => 1,
]);
$client->settings = $settings;
$client->save();
@ -1374,8 +1404,14 @@ class PaymentTest extends TestCase
{
$invoice = null;
$client = ClientFactory::create($this->company->id, $this->user->id);
$client->save();
$client = Client::factory()->create(['company_id' =>$this->company->id, 'user_id' => $this->user->id]);
ClientContact::factory()->create([
'user_id' => $this->user->id,
'client_id' => $client->id,
'company_id' => $this->company->id,
'is_primary' => 1,
]);
$invoice = InvoiceFactory::create($this->company->id, $this->user->id); //stub the company and user_id
$invoice->client_id = $client->id;
@ -1453,8 +1489,14 @@ class PaymentTest extends TestCase
{
$invoice = null;
$client = ClientFactory::create($this->company->id, $this->user->id);
$client->save();
$client = Client::factory()->create(['company_id' =>$this->company->id, 'user_id' => $this->user->id]);
ClientContact::factory()->create([
'user_id' => $this->user->id,
'client_id' => $client->id,
'company_id' => $this->company->id,
'is_primary' => 1,
]);
$invoice = InvoiceFactory::create($this->company->id, $this->user->id); //stub the company and user_id
$invoice->client_id = $client->id;