From cb19234d9e65d2185d03c10f6a30580c1dcc1e26 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 4 Dec 2020 17:40:59 +1100 Subject: [PATCH] Working on tests for delete invoice refactor --- tests/Feature/DeleteInvoiceTest.php | 121 ++++++++++++++++++++++++++++ tests/MockAccountData.php | 8 ++ 2 files changed, 129 insertions(+) create mode 100644 tests/Feature/DeleteInvoiceTest.php diff --git a/tests/Feature/DeleteInvoiceTest.php b/tests/Feature/DeleteInvoiceTest.php new file mode 100644 index 0000000000..c8cd2b592d --- /dev/null +++ b/tests/Feature/DeleteInvoiceTest.php @@ -0,0 +1,121 @@ +makeTestData(); + + $this->withoutMiddleware( + ThrottleRequests::class + ); + } + + public function testInvoiceDeletion() + { + //create new client + + $data = [ + 'name' => 'A Nice Client', + ]; + + $response = $this->withHeaders([ + 'X-API-SECRET' => config('ninja.api_secret'), + 'X-API-TOKEN' => $this->token, + ])->post('/api/v1/clients', $data); + + $response->assertStatus(200); + + $arr = $response->json(); + + $client_hash_id = $arr['data']['id']; + + //create new invoice. + + // $line_items = []; + + $item = InvoiceItemFactory::create(); + $item->quantity = 1; + $item->cost = 10; + + $line_items[] = (array)$item; + + $item = InvoiceItemFactory::create(); + $item->quantity = 1; + $item->cost = 10; + + $line_items[] = (array)$item; + + $invoice = [ + 'status_id' => 1, + 'number' => 'dfdfd', + '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, + 'client_id' => $client_hash_id, + 'line_items' => (array)$line_items, + ]; + + $response = $this->withHeaders([ + 'X-API-SECRET' => config('ninja.api_secret'), + 'X-API-TOKEN' => $this->token, + ])->post('/api/v1/invoices/', $invoice) + ->assertStatus(200); + + + + + + + + + //mark as paid + + //test balance + + //hydrate associated payment + + //delete invoice + + //test ledger balance + + //test client balance + + //test client paid to date + + + + } +} diff --git a/tests/MockAccountData.php b/tests/MockAccountData.php index 6e973b4eb9..312c167e4d 100644 --- a/tests/MockAccountData.php +++ b/tests/MockAccountData.php @@ -47,6 +47,7 @@ use Illuminate\Support\Carbon; use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\Hash; use Illuminate\Support\Facades\Schema; +use Illuminate\Support\Facades\Storage; /** * Class MockAccountData. @@ -157,6 +158,9 @@ trait MockAccountData 'account_id' => $this->account->id, ]); + Storage::makeDirectory($this->company->company_key.'/documents', 0755, true); + Storage::makeDirectory($this->company->company_key.'/images', 0755, true); + $settings = CompanySettings::defaults(); $settings->company_logo = 'https://www.invoiceninja.com/wp-content/uploads/2019/01/InvoiceNinja-Logo-Round-300x300.png'; @@ -219,6 +223,10 @@ trait MockAccountData 'company_id' => $this->company->id, ]); + Storage::makeDirectory($this->company->company_key.'/'.$this->client->client_hash.'/invoices', 0755, true); + Storage::makeDirectory($this->company->company_key.'/'.$this->client->client_hash.'/credits', 0755, true); + Storage::makeDirectory($this->company->company_key.'/'.$this->client->client_hash.'/quotes', 0755, true); + $contact = ClientContact::factory()->create([ 'user_id' => $this->user->id, 'client_id' => $this->client->id,