faker = \Faker\Factory::create(); Model::reguard(); $this->withoutMiddleware( ThrottleRequests::class ); $this->makeTestData(); } public function testRecurringInvoiceList() { factory(\App\Models\Client::class, 1)->create(['user_id' => $this->user->id, 'company_id' => $this->company->id])->each(function ($c) { factory(\App\Models\ClientContact::class, 1)->create([ 'user_id' => $this->user->id, 'client_id' => $c->id, 'company_id' => $this->company->id, 'is_primary' => 1 ]); factory(\App\Models\ClientContact::class, 1)->create([ 'user_id' => $this->user->id, 'client_id' => $c->id, 'company_id' => $this->company->id ]); }); $client = Client::all()->first(); factory(\App\Models\RecurringInvoice::class, 1)->create(['user_id' => $this->user->id, 'company_id' => $this->company->id, 'client_id' => $this->client->id]); $response = $this->withHeaders([ 'X-API-SECRET' => config('ninja.api_secret'), 'X-API-TOKEN' => $this->token, ])->get('/api/v1/recurring_invoices'); $response->assertStatus(200); } public function testRecurringInvoiceRESTEndPoints() { factory(\App\Models\Client::class, 1)->create(['user_id' => $this->user->id, 'company_id' => $this->company->id])->each(function ($c) { factory(\App\Models\ClientContact::class, 1)->create([ 'user_id' => $this->user->id, 'client_id' => $c->id, 'company_id' => $this->company->id, 'is_primary' => 1 ]); factory(\App\Models\ClientContact::class, 1)->create([ 'user_id' => $this->user->id, 'client_id' => $c->id, 'company_id' => $this->company->id ]); }); $client = Client::all()->first(); factory(\App\Models\RecurringInvoice::class, 1)->create(['user_id' => $this->user->id, 'company_id' => $this->company->id, 'client_id' => $this->client->id]); $RecurringInvoice = RecurringInvoice::where('user_id', $this->user->id)->first(); $RecurringInvoice->save(); $response = $this->withHeaders([ 'X-API-SECRET' => config('ninja.api_secret'), 'X-API-TOKEN' => $this->token, ])->get('/api/v1/recurring_invoices/'.$this->encodePrimaryKey($RecurringInvoice->id)); $response->assertStatus(200); $response = $this->withHeaders([ 'X-API-SECRET' => config('ninja.api_secret'), 'X-API-TOKEN' => $this->token, ])->get('/api/v1/recurring_invoices/'.$this->encodePrimaryKey($RecurringInvoice->id).'/edit'); $response->assertStatus(200); $RecurringInvoice_update = [ 'status_id' => RecurringInvoice::STATUS_DRAFT, 'client_id' => $RecurringInvoice->client_id, ]; $this->assertNotNull($RecurringInvoice); $response = $this->withHeaders([ 'X-API-SECRET' => config('ninja.api_secret'), 'X-API-TOKEN' => $this->token, ])->put('/api/v1/recurring_invoices/'.$this->encodePrimaryKey($RecurringInvoice->id), $RecurringInvoice_update) ->assertStatus(200); $response = $this->withHeaders([ 'X-API-SECRET' => config('ninja.api_secret'), 'X-API-TOKEN' => $this->token, ])->delete('/api/v1/recurring_invoices/'.$this->encodePrimaryKey($RecurringInvoice->id)); $response->assertStatus(200); } }