* @author Graham Campbell */ class ComponentTest extends AbstractApiTestCase { public function test_can_get_all_components() { $components = factory(Component::class, 3)->create(); $response = $this->json('GET', '/api/v1/components'); $response->assertStatus(200); $response->assertJsonFragment(['id' => $components[0]->id]); $response->assertJsonFragment(['id' => $components[1]->id]); $response->assertJsonFragment(['id' => $components[2]->id]); } public function test_cannot_get_invalid_component() { $response = $this->json('GET', '/api/v1/components/1'); $response->assertStatus(404); } public function test_cannot_create_component_without_authorization() { $response = $this->json('POST', '/api/v1/components'); $response->assertStatus(401); } public function test_cannot_create_component_without_data() { $this->beUser(); $response = $this->json('POST', '/api/v1/components'); $response->assertStatus(400); } public function test_can_create_component() { $this->beUser(); $response = $this->json('POST', '/api/v1/components', [ 'name' => 'Foo', 'description' => 'Bar', 'status' => 1, 'link' => 'http://example.com', 'order' => 1, 'group_id' => 1, 'enabled' => true, ]); $response->assertStatus(200); $response->assertJsonFragment(['name' => 'Foo']); } public function test_can_create_component_without_enabled_field() { $this->beUser(); $response = $this->json('POST', '/api/v1/components', [ 'name' => 'Foo', 'description' => 'Bar', 'status' => 1, 'link' => 'http://example.com', 'order' => 1, 'group_id' => 1, ]); $response->assertStatus(200); $response->assertJsonFragment(['name' => 'Foo', 'enabled' => true]); } public function test_can_create_component_with_meta_data() { $this->beUser(); $response = $this->json('POST', '/api/v1/components', [ 'name' => 'Foo', 'description' => 'Bar', 'status' => 1, 'link' => 'http://example.com', 'order' => 1, 'group_id' => 1, 'enabled' => true, 'meta' => [ 'uuid' => '172ff3fb-41f7-49d3-8bcd-f57b53627fa0', ], ]); $response->assertStatus(200); $response->assertJsonFragment([ 'name' => 'Foo', 'status' => 1, 'meta' => [ 'uuid' => '172ff3fb-41f7-49d3-8bcd-f57b53627fa0', ], ]); } public function test_can_create_disabled_component() { $this->beUser(); $response = $this->json('POST', '/api/v1/components', [ 'name' => 'Foo', 'description' => 'Bar', 'status' => 1, 'link' => 'http://example.com', 'order' => 1, 'group_id' => 1, 'enabled' => 0, ]); $response->assertStatus(200); $response->assertJsonFragment(['name' => 'Foo', 'enabled' => false]); } public function test_can_get_newly_created_component() { $component = factory(Component::class)->create(); $response = $this->json('GET', '/api/v1/components/1'); $response->assertStatus(200); $response->assertJsonFragment(['name' => $component->name]); } public function test_can_update_component() { $this->beUser(); $component = factory(Component::class)->create(); $response = $this->json('PUT', '/api/v1/components/1', [ 'name' => 'Foo', ]); $response->assertStatus(200); $response->assertJsonFragment(['name' => 'Foo']); } public function test_can_update_component_with_meta_data() { $this->beUser(); $component = factory(Component::class)->create([ 'meta' => [ 'uuid' => '172ff3fb-41f7-49d3-8bcd-f57b53627fa0', ], ]); $response = $this->json('PUT', '/api/v1/components/1', [ 'meta' => [ 'uuid' => '172ff3fb-41f7-49d3-8bcd-f57b53627fa0', 'foo' => 'bar', ], ]); $response->assertStatus(200); $response->assertJsonFragment([ 'meta' => [ 'uuid' => '172ff3fb-41f7-49d3-8bcd-f57b53627fa0', 'foo' => 'bar', ], ]); } public function test_can_delete_component() { $this->beUser(); $component = factory(Component::class)->create(); $response = $this->delete('/api/v1/components/1'); $response->assertStatus(204); } }