From 970c9bb87de2b4ade1070baa6b33e1a354853843 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sat, 23 May 2020 13:28:24 +1000 Subject: [PATCH] Payment Terms (#3737) * Fixes for converting a quote to invoice * Fixes for deleting an invoice * Payment Terms CRUD * Payment Terms * Push PaymentTerms back into the DB * Payment Terms * Payment Terms * Create api docs for payment terms --- app/Factory/PaymentTermFactory.php | 26 ++ app/Http/Controllers/InvoiceController.php | 3 + .../Controllers/OpenAPI/PaymentTermSchema.php | 12 + .../Controllers/PaymentTermController.php | 391 ++++++++++++++++++ .../PaymentTerm/ActionPaymentTermRequest.php | 29 ++ .../PaymentTerm/CreatePaymentTermRequest.php | 29 ++ .../PaymentTerm/DestroyPaymentTermRequest.php | 29 ++ .../PaymentTerm/EditPaymentTermRequest.php | 46 +++ .../PaymentTerm/ShowPaymentTermRequest.php | 29 ++ .../PaymentTerm/StorePaymentTermRequest.php | 48 +++ .../PaymentTerm/UpdatePaymentTermRequest.php | 46 +++ app/Models/PaymentTerm.php | 4 +- app/Transformers/PaymentTermTransformer.php | 32 ++ config/ninja.php | 35 -- .../2014_10_13_000000_create_users_table.php | 4 +- database/seeds/DatabaseSeeder.php | 1 + database/seeds/PaymentTermsSeeder.php | 28 ++ routes/api.php | 2 + tests/Feature/PaymentTermsApiTest.php | 113 +++++ tests/Unit/CollectionMergingTest.php | 2 +- 20 files changed, 870 insertions(+), 39 deletions(-) create mode 100644 app/Factory/PaymentTermFactory.php create mode 100644 app/Http/Controllers/OpenAPI/PaymentTermSchema.php create mode 100644 app/Http/Controllers/PaymentTermController.php create mode 100644 app/Http/Requests/PaymentTerm/ActionPaymentTermRequest.php create mode 100644 app/Http/Requests/PaymentTerm/CreatePaymentTermRequest.php create mode 100644 app/Http/Requests/PaymentTerm/DestroyPaymentTermRequest.php create mode 100644 app/Http/Requests/PaymentTerm/EditPaymentTermRequest.php create mode 100644 app/Http/Requests/PaymentTerm/ShowPaymentTermRequest.php create mode 100644 app/Http/Requests/PaymentTerm/StorePaymentTermRequest.php create mode 100644 app/Http/Requests/PaymentTerm/UpdatePaymentTermRequest.php create mode 100644 app/Transformers/PaymentTermTransformer.php create mode 100644 database/seeds/PaymentTermsSeeder.php create mode 100644 tests/Feature/PaymentTermsApiTest.php diff --git a/app/Factory/PaymentTermFactory.php b/app/Factory/PaymentTermFactory.php new file mode 100644 index 000000000000..ec18c4aed9fa --- /dev/null +++ b/app/Factory/PaymentTermFactory.php @@ -0,0 +1,26 @@ +user_id = $user_id; + $payment_term->company_id = $company_id; + + return $payment_term; + } +} diff --git a/app/Http/Controllers/InvoiceController.php b/app/Http/Controllers/InvoiceController.php index 5dc6a348b8f8..8649ccd1d749 100644 --- a/app/Http/Controllers/InvoiceController.php +++ b/app/Http/Controllers/InvoiceController.php @@ -670,6 +670,9 @@ class InvoiceController extends BaseController } break; case 'delete': + //need to make sure the invoice is cancelled first!! + $invoice->service()->handleCancellation()->save(); + $this->invoice_repo->delete($invoice); if (!$bulk) { diff --git a/app/Http/Controllers/OpenAPI/PaymentTermSchema.php b/app/Http/Controllers/OpenAPI/PaymentTermSchema.php new file mode 100644 index 000000000000..f1faa5f6cce1 --- /dev/null +++ b/app/Http/Controllers/OpenAPI/PaymentTermSchema.php @@ -0,0 +1,12 @@ +user()->company()->id)->orWhere('company_id', null); + + return $this->listResponse($payment_terms); + } + + /** + * Show the form for creating a new resource. + * + * @param \App\Http\Requests\Payment\CreatePaymentTermRequest $request The request + * + * @return \Illuminate\Http\Response + * + * + * + * @OA\Get( + * path="/api/v1/payment_terms/create", + * operationId="getPaymentTermsCreate", + * tags={"payment_terms"}, + * summary="Gets a new blank PaymentTerm object", + * description="Returns a blank object with default values", + * @OA\Parameter(ref="#/components/parameters/X-Api-Secret"), + * @OA\Parameter(ref="#/components/parameters/X-Api-Token"), + * @OA\Parameter(ref="#/components/parameters/X-Requested-With"), + * @OA\Parameter(ref="#/components/parameters/include"), + * @OA\Response( + * response=200, + * description="A blank PaymentTerm object", + * @OA\Header(header="X-API-Version", ref="#/components/headers/X-API-Version"), + * @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"), + * @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"), + * @OA\JsonContent(ref="#/components/schemas/Payment"), + * ), + * @OA\Response( + * response=422, + * description="Validation error", + * @OA\JsonContent(ref="#/components/schemas/ValidationError"), + * + * ), + * @OA\Response( + * response="default", + * description="Unexpected Error", + * @OA\JsonContent(ref="#/components/schemas/Error"), + * ), + * ) + * + */ + public function create(CreatePaymentTermRequest $request) + { + $payment_term = PaymentTermFactory::create(auth()->user()->company()->id, auth()->user()->id); + + return $this->itemResponse($payment_term); + } + + /** + * Store a newly created resource in storage. + * + * @param \App\Http\Requests\Payment\StorePaymentRequest $request The request + * + * @return \Illuminate\Http\Response + * + * + * + * @OA\Post( + * path="/api/v1/payment_terms", + * operationId="storePaymentTerm", + * tags={"payment_terms"}, + * summary="Adds a Payment", + * description="Adds a Payment Term to the system", + * @OA\Parameter(ref="#/components/parameters/X-Api-Secret"), + * @OA\Parameter(ref="#/components/parameters/X-Api-Token"), + * @OA\Parameter(ref="#/components/parameters/X-Requested-With"), + * @OA\Parameter(ref="#/components/parameters/include"), + * @OA\RequestBody( + * description="The payment_terms request", + * required=true, + * @OA\JsonContent(ref="#/components/schemas/PaymentTerm"), + * ), + * @OA\Response( + * response=200, + * description="Returns the saved Payment object", + * @OA\Header(header="X-API-Version", ref="#/components/headers/X-API-Version"), + * @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"), + * @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"), + * @OA\JsonContent(ref="#/components/schemas/PaymentTerm"), + * ), + * @OA\Response( + * response=422, + * description="Validation error", + * @OA\JsonContent(ref="#/components/schemas/ValidationError"), + * + * ), + * @OA\Response( + * response="default", + * description="Unexpected Error", + * @OA\JsonContent(ref="#/components/schemas/Error"), + * ), + * ) + * + */ + public function store(StorePaymentTermRequest $request) + { + $payment_term = PaymentTermFactory::create(auth()->user()->company()->id, auth()->user()->id); + $payment_term->fill($request->all()); + $payment_term->save(); + + return $this->itemResponse($payment_term->fresh()); + } + + /** + * @OA\Get( + * path="/api/v1/payment_terms/{id}", + * operationId="showPaymentTerm", + * tags={"payment_terms"}, + * summary="Shows a Payment Term", + * description="Displays an Payment Term by id", + * @OA\Parameter(ref="#/components/parameters/X-Api-Secret"), + * @OA\Parameter(ref="#/components/parameters/X-Api-Token"), + * @OA\Parameter(ref="#/components/parameters/X-Requested-With"), + * @OA\Parameter(ref="#/components/parameters/include"), + * @OA\Parameter( + * name="id", + * in="path", + * description="The Payment Term Hashed ID", + * example="D2J234DFA", + * required=true, + * @OA\Schema( + * type="string", + * format="string", + * ), + * ), + * @OA\Response( + * response=200, + * description="Returns the Payment Term object", + * @OA\Header(header="X-API-Version", ref="#/components/headers/X-API-Version"), + * @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"), + * @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"), + * @OA\JsonContent(ref="#/components/schemas/PaymentTerm"), + * ), + * @OA\Response( + * response=422, + * description="Validation error", + * @OA\JsonContent(ref="#/components/schemas/ValidationError"), + * + * ), + * @OA\Response( + * response="default", + * description="Unexpected Error", + * @OA\JsonContent(ref="#/components/schemas/Error"), + * ), + * ) + * + */ + public function show(ShowPaymentTermRequest $request, PaymentTerm $payment_term) + { + return $this->itemResponse($payment_term); + } + + + /** + * @OA\Get( + * path="/api/v1/payment_terms/{id}/edit", + * operationId="editPaymentTerms", + * tags={"payment_terms"}, + * summary="Shows an Payment Term for editting", + * description="Displays an Payment Term by id", + * @OA\Parameter(ref="#/components/parameters/X-Api-Secret"), + * @OA\Parameter(ref="#/components/parameters/X-Api-Token"), + * @OA\Parameter(ref="#/components/parameters/X-Requested-With"), + * @OA\Parameter(ref="#/components/parameters/include"), + * @OA\Parameter( + * name="id", + * in="path", + * description="The Payment Term Hashed ID", + * example="D2J234DFA", + * required=true, + * @OA\Schema( + * type="string", + * format="string", + * ), + * ), + * @OA\Response( + * response=200, + * description="Returns the Payment object", + * @OA\Header(header="X-API-Version", ref="#/components/headers/X-API-Version"), + * @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"), + * @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"), + * @OA\JsonContent(ref="#/components/schemas/PaymentTerm"), + * ), + * @OA\Response( + * response=422, + * description="Validation error", + * @OA\JsonContent(ref="#/components/schemas/ValidationError"), + * + * ), + * @OA\Response( + * response="default", + * description="Unexpected Error", + * @OA\JsonContent(ref="#/components/schemas/Error"), + * ), + * ) + * + */ + public function edit(EditPaymentRequest $request, Payment $payment) + { + return $this->itemResponse($payment); + } + + /** + * Update the specified resource in storage. + * + * @param \App\Http\Requests\PaymentTerm\UpdatePaymentTermRequest $request The request + * @param \App\Models\PaymentTerm $payment_term The payment term + * + * @return \Illuminate\Http\Response + * + * + * @OA\Put( + * path="/api/v1/payment_terms/{id}", + * operationId="updatePaymentTerm", + * tags={"payment_terms"}, + * summary="Updates a Payment Term", + * description="Handles the updating of an Payment Termby id", + * @OA\Parameter(ref="#/components/parameters/X-Api-Secret"), + * @OA\Parameter(ref="#/components/parameters/X-Api-Token"), + * @OA\Parameter(ref="#/components/parameters/X-Requested-With"), + * @OA\Parameter(ref="#/components/parameters/include"), + * @OA\Parameter( + * name="id", + * in="path", + * description="The Payment Term Hashed ID", + * example="D2J234DFA", + * required=true, + * @OA\Schema( + * type="string", + * format="string", + * ), + * ), + * @OA\Response( + * response=200, + * description="Returns the Payment Term object", + * @OA\Header(header="X-API-Version", ref="#/components/headers/X-API-Version"), + * @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"), + * @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"), + * @OA\JsonContent(ref="#/components/schemas/PaymentTerm"), + * ), + * @OA\Response( + * response=422, + * description="Validation error", + * @OA\JsonContent(ref="#/components/schemas/ValidationError"), + * + * ), + * @OA\Response( + * response="default", + * description="Unexpected Error", + * @OA\JsonContent(ref="#/components/schemas/Error"), + * ), + * ) + * + */ + public function update(UpdatePaymentTermRequest $request, PaymentTerm $payment_term) + { + $payment_term->fill($request->all()); + $payment_term->save(); + + return $this->itemResponse($payment_term->fresh()); + } + + /** + * Remove the specified resource from storage. + * + * @param \App\Http\Requests\PaymentTerm\DestroyPaymentTermRequest $request + * @param \App\Models\PaymentTerm $payment_term + * + * @return \Illuminate\Http\Response + * + * + * @OA\Delete( + * path="/api/v1/payment_terms/{id}", + * operationId="deletePaymentTerm", + * tags={"payment_termss"}, + * summary="Deletes a Payment Term", + * description="Handles the deletion of an PaymentTerm by id", + * @OA\Parameter(ref="#/components/parameters/X-Api-Secret"), + * @OA\Parameter(ref="#/components/parameters/X-Api-Token"), + * @OA\Parameter(ref="#/components/parameters/X-Requested-With"), + * @OA\Parameter(ref="#/components/parameters/include"), + * @OA\Parameter( + * name="id", + * in="path", + * description="The Payment Term Hashed ID", + * example="D2J234DFA", + * required=true, + * @OA\Schema( + * type="string", + * format="string", + * ), + * ), + * @OA\Response( + * response=200, + * description="Returns a HTTP status", + * @OA\Header(header="X-API-Version", ref="#/components/headers/X-API-Version"), + * @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"), + * @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"), + * ), + * @OA\Response( + * response=422, + * description="Validation error", + * @OA\JsonContent(ref="#/components/schemas/ValidationError"), + * + * ), + * @OA\Response( + * response="default", + * description="Unexpected Error", + * @OA\JsonContent(ref="#/components/schemas/Error"), + * ), + * ) + * + */ + public function destroy(DestroyPaymentTermRequest $request, PaymentTerm $payment_term) + { + + $payment_term->delete(); + + return response()->json([], 200); + } + +} diff --git a/app/Http/Requests/PaymentTerm/ActionPaymentTermRequest.php b/app/Http/Requests/PaymentTerm/ActionPaymentTermRequest.php new file mode 100644 index 000000000000..6f0dbd5b1900 --- /dev/null +++ b/app/Http/Requests/PaymentTerm/ActionPaymentTermRequest.php @@ -0,0 +1,29 @@ +user()->isAdmin(); + } +} diff --git a/app/Http/Requests/PaymentTerm/CreatePaymentTermRequest.php b/app/Http/Requests/PaymentTerm/CreatePaymentTermRequest.php new file mode 100644 index 000000000000..afdeb2fdfc3a --- /dev/null +++ b/app/Http/Requests/PaymentTerm/CreatePaymentTermRequest.php @@ -0,0 +1,29 @@ +user()->isAdmin(); + } +} diff --git a/app/Http/Requests/PaymentTerm/DestroyPaymentTermRequest.php b/app/Http/Requests/PaymentTerm/DestroyPaymentTermRequest.php new file mode 100644 index 000000000000..b7d271d2cf2d --- /dev/null +++ b/app/Http/Requests/PaymentTerm/DestroyPaymentTermRequest.php @@ -0,0 +1,29 @@ +user()->isAdmin(); + } +} diff --git a/app/Http/Requests/PaymentTerm/EditPaymentTermRequest.php b/app/Http/Requests/PaymentTerm/EditPaymentTermRequest.php new file mode 100644 index 000000000000..6c9f3d6e2c59 --- /dev/null +++ b/app/Http/Requests/PaymentTerm/EditPaymentTermRequest.php @@ -0,0 +1,46 @@ +user()->isAdmin(); + } + + public function rules() + { + $rules = []; + + return $rules; + } + + + protected function prepareForValidation() + { + $input = $this->all(); + + //$input['id'] = $this->encodePrimaryKey($input['id']); + + $this->replace($input); + } +} diff --git a/app/Http/Requests/PaymentTerm/ShowPaymentTermRequest.php b/app/Http/Requests/PaymentTerm/ShowPaymentTermRequest.php new file mode 100644 index 000000000000..22bb184a4bcd --- /dev/null +++ b/app/Http/Requests/PaymentTerm/ShowPaymentTermRequest.php @@ -0,0 +1,29 @@ +user()->isAdmin(); + } +} diff --git a/app/Http/Requests/PaymentTerm/StorePaymentTermRequest.php b/app/Http/Requests/PaymentTerm/StorePaymentTermRequest.php new file mode 100644 index 000000000000..56c89ea67394 --- /dev/null +++ b/app/Http/Requests/PaymentTerm/StorePaymentTermRequest.php @@ -0,0 +1,48 @@ +user()->isAdmin(); + } + + protected function prepareForValidation() + { + $input = $this->all(); + + $this->replace($input); + } + + public function rules() + { + $rules = [ + + ]; + + return $rules; + } +} diff --git a/app/Http/Requests/PaymentTerm/UpdatePaymentTermRequest.php b/app/Http/Requests/PaymentTerm/UpdatePaymentTermRequest.php new file mode 100644 index 000000000000..b6e6c2f40bef --- /dev/null +++ b/app/Http/Requests/PaymentTerm/UpdatePaymentTermRequest.php @@ -0,0 +1,46 @@ +user()->isAdmin(); + } + + + public function rules() + { + return [ + 'num_days' => 'required', + ]; + } + + protected function prepareForValidation() + { + $input = $this->all(); + + $this->replace($input); + } +} diff --git a/app/Models/PaymentTerm.php b/app/Models/PaymentTerm.php index e3ff02a80d92..61eb90f51f32 100644 --- a/app/Models/PaymentTerm.php +++ b/app/Models/PaymentTerm.php @@ -30,6 +30,8 @@ class PaymentTerm extends BaseModel */ protected $dates = ['deleted_at']; + protected $fillable = ['num_days']; + public function getNumDays() { return $this->num_days == -1 ? 0 : $this->num_days; @@ -39,7 +41,7 @@ class PaymentTerm extends BaseModel { $default_terms = collect(config('ninja.payment_terms')); - $terms = self::scope()->get(); + $terms = self::whereCompanyId(auth()->user()->company()->id)->orWhere('company_id', null)->get(); $terms->map(function ($term) { return $term['num_days']; diff --git a/app/Transformers/PaymentTermTransformer.php b/app/Transformers/PaymentTermTransformer.php new file mode 100644 index 000000000000..cc6c6b05f0b0 --- /dev/null +++ b/app/Transformers/PaymentTermTransformer.php @@ -0,0 +1,32 @@ + (string) $this->encodePrimaryKey($payment_term->id), + 'num_days' => (int) $payment_term->num_days, + 'name' => (string) ctrans('texts.payment_terms_net') . ' ' . $payment_term->getNumDays(), + 'created_at' => (int)$payment_term->created_at, + 'updated_at' => (int)$payment_term->updated_at, + 'archived_at' => (int)$payment_term->deleted_at, + ]; + } + +} diff --git a/config/ninja.php b/config/ninja.php index ca274ea3d2cc..d513a319dba4 100644 --- a/config/ninja.php +++ b/config/ninja.php @@ -97,41 +97,6 @@ return [ 'slack' => env('SLACK_WEBHOOK_URL', ''), 'mail' => env('HOSTED_EMAIL', ''), ], - 'payment_terms' => [ - [ - 'num_days' => 0, - 'name' => '', - ], - [ - 'num_days' => 7, - 'name' => '', - ], - [ - 'num_days' => 10, - 'name' => '', - ], - [ - 'num_days' => 14, - 'name' => '', - ], - [ - 'num_days' => 15, - 'name' => '', - ], - [ - 'num_days' => 30, - 'name' => '', - ], - [ - 'num_days' => 60, - 'name' => '', - ], - [ - 'num_days' => 90, - 'name' => '', - ] - ], - 'themes' => [ 'global' => 'ninja2020', 'portal' => 'ninja2020', diff --git a/database/migrations/2014_10_13_000000_create_users_table.php b/database/migrations/2014_10_13_000000_create_users_table.php index 57d09a2b4eae..ceaf2564c25e 100644 --- a/database/migrations/2014_10_13_000000_create_users_table.php +++ b/database/migrations/2014_10_13_000000_create_users_table.php @@ -1026,8 +1026,8 @@ class CreateUsersTable extends Migration $table->increments('id'); $table->integer('num_days'); $table->string('name')->nullable(); - $table->unsignedInteger('company_id'); - $table->unsignedInteger('user_id'); + $table->unsignedInteger('company_id')->nullable(); + $table->unsignedInteger('user_id')->nullable(); $table->timestamps(6); $table->softDeletes('deleted_at', 6); diff --git a/database/seeds/DatabaseSeeder.php b/database/seeds/DatabaseSeeder.php index c22b0498e1ac..191679ce3ff7 100644 --- a/database/seeds/DatabaseSeeder.php +++ b/database/seeds/DatabaseSeeder.php @@ -28,6 +28,7 @@ class DatabaseSeeder extends Seeder $this->call('LanguageSeeder'); $this->call('CountriesSeeder'); $this->call('IndustrySeeder'); + $this->call('PaymentTermsSeeder'); $this->call('PaymentTypesSeeder'); $this->call('GatewayTypesSeeder'); $this->call('DateFormatsSeeder'); diff --git a/database/seeds/PaymentTermsSeeder.php b/database/seeds/PaymentTermsSeeder.php new file mode 100644 index 000000000000..8679671df5dc --- /dev/null +++ b/database/seeds/PaymentTermsSeeder.php @@ -0,0 +1,28 @@ + -1, 'name' => 'Net 0'], + ['num_days' => 7, 'name' => ''], + ['num_days' => 10, 'name' => ''], + ['num_days' => 14, 'name' => ''], + ['num_days' => 15, 'name' => ''], + ['num_days' => 30, 'name' => ''], + ['num_days' => 60, 'name' => ''], + ['num_days' => 90, 'name' => ''], + ]; + + foreach ($paymentTerms as $paymentTerm) { + PaymentTerm::create($paymentTerm); + } + + } +} diff --git a/routes/api.php b/routes/api.php index 2fbfc207ba30..2b38c22f3661 100644 --- a/routes/api.php +++ b/routes/api.php @@ -71,6 +71,8 @@ Route::group(['middleware' => ['api_db', 'token_auth', 'locale'], 'prefix' => 'a Route::resource('client_statement', 'ClientStatementController@statement');// name = (client_statement. index / create / show / update / destroy / edit + Route::resource('payment_terms', 'PaymentTermController');// name = (payments. index / create / show / update / destroy / edit + Route::resource('payments', 'PaymentController');// name = (payments. index / create / show / update / destroy / edit Route::post('payments/refund', 'PaymentController@refund')->name('payments.refund'); diff --git a/tests/Feature/PaymentTermsApiTest.php b/tests/Feature/PaymentTermsApiTest.php new file mode 100644 index 000000000000..de49b4339bf2 --- /dev/null +++ b/tests/Feature/PaymentTermsApiTest.php @@ -0,0 +1,113 @@ +makeTestData(); + + Session::start(); + + $this->faker = \Faker\Factory::create(); + + Model::reguard(); + } + + + public function testPaymentTermsGet() + { + + $response = $this->withHeaders([ + 'X-API-SECRET' => config('ninja.api_secret'), + 'X-API-TOKEN' => $this->token + ])->get('/api/v1/payment_terms'); + + + $response->assertStatus(200); + } + + public function testPostPaymentTerm() + { + + $response = $this->withHeaders([ + 'X-API-SECRET' => config('ninja.api_secret'), + 'X-API-TOKEN' => $this->token + ])->post('/api/v1/payment_terms', ['num_days' => 50 ]); + + $response->assertStatus(200); + + $data = $response->json(); + + $this->hashed_id = $data['data']['id']; + } + + public function testPutPaymentTerms() + { + + $payment_term = PaymentTermFactory::create($this->company->id, $this->user->id); + $payment_term->num_days = 500; + $payment_term->save(); + + $response = $this->withHeaders([ + 'X-API-SECRET' => config('ninja.api_secret'), + 'X-API-TOKEN' => $this->token + ])->put('/api/v1/payment_terms/' . $this->encodePrimaryKey($payment_term->id), ['num_days' => 5000 ]); + + $response->assertStatus(200); + + } + + public function testDeletePaymentTerm() + { + + $payment_term = PaymentTermFactory::create($this->company->id, $this->user->id); + $payment_term->num_days = 500; + $payment_term->save(); + + $response = $this->withHeaders([ + 'X-API-SECRET' => config('ninja.api_secret'), + 'X-API-TOKEN' => $this->token + ])->delete('/api/v1/payment_terms/' . $this->encodePrimaryKey($payment_term->id)); + + $response->assertStatus(200); + + $payment_term = PaymentTerm::find($payment_term->id); + + $this->assertNull($payment_term); + + } + +} diff --git a/tests/Unit/CollectionMergingTest.php b/tests/Unit/CollectionMergingTest.php index 2125cc1e6278..ec29983786a0 100644 --- a/tests/Unit/CollectionMergingTest.php +++ b/tests/Unit/CollectionMergingTest.php @@ -27,7 +27,7 @@ class CollectionMergingTest extends TestCase public function testBlankCollectionReturned() { - $this->assertEquals($this->terms->count(), 0); + $this->assertEquals($this->terms->count(), 8); } public function testMergingCollection()