makeTestData(); Session::start(); $this->faker = \Faker\Factory::create(); Model::reguard(); } public function testDesignPost() { $data = [ 'name' => $this->faker->firstName, 'design' => 'withHeaders([ 'X-API-SECRET' => config('ninja.api_secret'), 'X-API-TOKEN' => $this->token ])->post('/api/v1/designs', $data); $response->assertStatus(200); $arr = $response->json(); $this->id = $arr['data']['id']; $this->assertEquals($data['name'], $arr['data']['name']); $response = $this->withHeaders([ 'X-API-SECRET' => config('ninja.api_secret'), 'X-API-TOKEN' => $this->token ])->get('/api/v1/designs'); $response->assertStatus(200); $arr = $response->json(); $response = $this->withHeaders([ 'X-API-SECRET' => config('ninja.api_secret'), 'X-API-TOKEN' => $this->token ])->get('/api/v1/designs/'.$this->id); $response->assertStatus(200); $arr = $response->json(); $this->assertEquals($this->id, $arr['data']['id']); $data = [ 'name' => $this->faker->firstName, 'design' => 'changed' ]; $response = $this->withHeaders([ 'X-API-SECRET' => config('ninja.api_secret'), 'X-API-TOKEN' => $this->token ])->put('/api/v1/designs/'.$this->id, $data); $response->assertStatus(200); $arr = $response->json(); $this->assertEquals($data['name'], $arr['data']['name']); $this->assertEquals($data['design'], $arr['data']['design']); $response = $this->withHeaders([ 'X-API-SECRET' => config('ninja.api_secret'), 'X-API-TOKEN' => $this->token ])->delete('/api/v1/designs/'.$this->id, $data); $response->assertStatus(200); $arr = $response->json(); $design = Design::whereId($this->decodePrimaryKey($this->id))->withTrashed()->first(); $this->assertTrue((bool)$design->is_deleted); $this->assertGreaterThan(0, $design->deleted_at); } }