Fixes for validation. (#3130)

* Fixes for OpenAPI Documentation + fix support for docs for PHP 7.4

* Minor fixes for GMail API

* Add fix for 2 contacts with no email addresses failing validation, emails are optional! but cannot be duplicated if a value is set

* Return template as a object with subject and body components

* Fixes for OpenAPI Schema

* Stubs for payment edge cases

* payment tests
This commit is contained in:
David Bomba 2019-12-05 17:22:20 +11:00 committed by GitHub
parent a2cf42766d
commit 01173c66d8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 140 additions and 11 deletions

View File

@ -12,8 +12,8 @@ class GmailTransportManager extends TransportManager
{
$token = $this->app['config']->get('services.gmail.token', []);
$mail = new Mail;
return new GmailTransport($mail, string $token);
return new GmailTransport($mail, $token);
}
}

View File

@ -351,8 +351,8 @@ class ClientController extends BaseController
* path="/api/v1/clients",
* operationId="storeClient",
* tags={"clients"},
* summary="Adds a company",
* description="Adds an company to the system",
* summary="Adds a client",
* description="Adds an client to a copmany",
* @OA\Parameter(ref="#/components/parameters/X-Api-Secret"),
* @OA\Parameter(ref="#/components/parameters/X-Api-Token"),
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),

View File

@ -14,6 +14,7 @@
* @OA\Property(property="enable_invoice_quantity", type="boolean", example=true, description="Toggles filling a product description based on product key"),
* @OA\Property(property="convert_products", type="boolean", example=true, description="___________"),
* @OA\Property(property="update_products", type="boolean", example=true, description="Toggles updating a product description which description changes"),
* @OA\Property(property="show_product_details", type="boolean", example=true, description="Toggles showing a product description which description changes"),
* @OA\Property(property="custom_fields", type="object", description="Custom fields map"),
* @OA\Property(property="enable_product_cost", type="boolean", example=true, description="______________"),
* @OA\Property(property="enable_product_quantity", type="boolean", example=true, description="______________"),

View File

@ -25,6 +25,7 @@
* @OA\Property(property="tax_rate2", type="number", format="float", example="10.00", description="_________"),
* @OA\Property(property="tax_name3", type="string", example="", description="________"),
* @OA\Property(property="tax_rate3", type="number", format="float", example="10.00", description="_________"),
* @OA\Property(property="total_taxes", type="number", format="float", example="10.00", description="The total taxes for the invoice"),
* @OA\Property(property="line_items", type="object", example="", description="_________"),
* @OA\Property(property="amount", type="number", format="float", example="10.00", description="_________"),
* @OA\Property(property="balance", type="number", format="float", example="10.00", description="_________"),

View File

@ -4,5 +4,6 @@
* schema="Quote",
* type="object",
* @OA\Property(property="id", type="string", example="Opnel5aKBz", description="______"),
* @OA\Property(property="total_taxes", type="number", format="float", example="10.00", description="The total taxes for the quote"),
* )
*/

View File

@ -111,10 +111,12 @@ class TemplateController extends BaseController
$subject = request()->input('subject');
$body = request()->input('body');
$body = Parsedown::instance()->text(request()->input('body'));
$subject = Parsedown::instance()->text(request()->input('subject'));
$data = [
'subject' => Parsedown::instance()->text(request()->input('subject')),
'body' => Parsedown::instance()->text(request()->input('body')),
];
return response()->json($body, 200);
return response()->json($data, 200);
}

View File

@ -44,7 +44,7 @@ class StoreClientRequest extends Request
//$rules['name'] = 'required|min:1';
$rules['id_number'] = 'unique:clients,id_number,' . $this->id . ',id,company_id,' . $this->company_id;
$rules['settings'] = new ValidClientGroupSettingsRule();
$rules['contacts.*.email'] = 'distinct';
$rules['contacts.*.email'] = 'nullable|distinct';
$contacts = request('contacts');

View File

@ -44,7 +44,7 @@ class UpdateClientRequest extends Request
//$rules['id_number'] = 'unique:clients,id_number,,id,company_id,' . auth()->user()->company()->id;
$rules['id_number'] = 'unique:clients,id_number,' . $this->id . ',id,company_id,' . $this->company_id;
$rules['settings'] = new ValidClientGroupSettingsRule();
$rules['contacts.*.email'] = 'distinct';
$rules['contacts.*.email'] = 'nullable|distinct';
$contacts = request('contacts');

View File

@ -146,8 +146,10 @@ class CreateUsersTable extends Migration
$table->string('company_key',100)->unique();
$table->string('logo')->nullable();
$table->boolean('convert_products')->default(false);
$table->boolean('fill_products')->default(false);
$table->boolean('update_products')->default(false);
$table->boolean('fill_products')->default(true);
$table->boolean('update_products')->default(true);
$table->boolean('show_product_details')->default(true);
$table->boolean('custom_surcharge_taxes1')->default(false);
$table->boolean('custom_surcharge_taxes2')->default(false);
$table->boolean('custom_surcharge_taxes3')->default(false);

View File

@ -328,4 +328,126 @@ class PaymentTest extends TestCase
}
public function testPaymentGreaterThanPartial()
{
$this->invoice = null;
$client = ClientFactory::create($this->company->id, $this->user->id);
$client->save();
$this->invoice = InvoiceFactory::create($this->company->id,$this->user->id);//stub the company and user_id
$this->invoice->client_id = $client->id;
$this->invoice->partial = 5.0;
$this->invoice->line_items = $this->buildLineItems();
$this->invoice->uses_inclusive_taxes = false;
$this->invoice->save();
$this->invoice_calc = new InvoiceSum($this->invoice);
$this->invoice_calc->build();
$this->invoice = $this->invoice_calc->getInvoice();
$this->invoice->save();
$this->invoice->markSent();
$this->invoice->save();
$data = [
'amount' => 6.0,
'client_id' => $client->hashed_id,
'invoices' => [
[
'id' => $this->invoice->hashed_id,
'amount' => 6.0
],
],
'payment_date' => '2019/12/12',
];
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->post('/api/v1/payments?include=invoices', $data);
$arr = $response->json();
$response->assertStatus(200);
$payment_id = $arr['data']['id'];
$payment = Payment::find($this->decodePrimaryKey($payment_id))->first();
$this->assertNotNull($payment);
$this->assertNotNull($payment->invoices());
$this->assertEquals(1, $payment->invoices()->count());
$invoice = $payment->invoices()->first();
$this->assertEquals($invoice->partial, 0);
$this->assertEquals($invoice->balance, 4);
}
public function testPaymentLessThanPartialAmount()
{
$this->invoice = null;
$client = ClientFactory::create($this->company->id, $this->user->id);
$client->save();
$this->invoice = InvoiceFactory::create($this->company->id,$this->user->id);//stub the company and user_id
$this->invoice->client_id = $client->id;
$this->invoice->partial = 5.0;
$this->invoice->line_items = $this->buildLineItems();
$this->invoice->uses_inclusive_taxes = false;
$this->invoice->save();
$this->invoice_calc = new InvoiceSum($this->invoice);
$this->invoice_calc->build();
$this->invoice = $this->invoice_calc->getInvoice();
$this->invoice->save();
$this->invoice->markSent();
$this->invoice->save();
$data = [
'amount' => 2.0,
'client_id' => $client->hashed_id,
'invoices' => [
[
'id' => $this->invoice->hashed_id,
'amount' => 2.0
],
],
'payment_date' => '2019/12/12',
];
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->post('/api/v1/payments?include=invoices', $data);
$arr = $response->json();
$response->assertStatus(200);
$payment_id = $arr['data']['id'];
$payment = Payment::find($this->decodePrimaryKey($payment_id))->first();
$this->assertNotNull($payment);
$this->assertNotNull($payment->invoices());
$this->assertEquals(1, $payment->invoices()->count());
$invoice = $payment->invoices()->first();
$this->assertEquals($invoice->partial, 3);
$this->assertEquals($invoice->balance, 8);
}
}