Clean up test names and remove laravel/browser-kit-testing

This commit is contained in:
James Brooks
2018-06-16 21:21:38 +01:00
parent 1593b7b451
commit aa2a39da6d
13 changed files with 444 additions and 405 deletions

View File

@@ -62,7 +62,6 @@
"filp/whoops": "^2.1", "filp/whoops": "^2.1",
"fzaninotto/faker": "^1.6", "fzaninotto/faker": "^1.6",
"graham-campbell/testbench-core": "^1.1", "graham-campbell/testbench-core": "^1.1",
"laravel/browser-kit-testing": "^2.0",
"mockery/mockery": "0.9.9", "mockery/mockery": "0.9.9",
"nikic/php-parser": "^3.0", "nikic/php-parser": "^3.0",
"phpunit/phpunit": "5.7.20", "phpunit/phpunit": "5.7.20",

49
composer.lock generated
View File

@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "83a7fb073c9dd90ffa9b6ddb056ab7e9", "content-hash": "902bc48c3a37a1d269f457d015b1f06a",
"packages": [ "packages": [
{ {
"name": "alt-three/badger", "name": "alt-three/badger",
@@ -5220,53 +5220,6 @@
], ],
"time": "2015-05-11T14:41:42+00:00" "time": "2015-05-11T14:41:42+00:00"
}, },
{
"name": "laravel/browser-kit-testing",
"version": "v2.0.0",
"source": {
"type": "git",
"url": "https://github.com/laravel/browser-kit-testing.git",
"reference": "23f1a7eefcbca0797305b236600aa5426c9528f2"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/laravel/browser-kit-testing/zipball/23f1a7eefcbca0797305b236600aa5426c9528f2",
"reference": "23f1a7eefcbca0797305b236600aa5426c9528f2",
"shasum": ""
},
"require": {
"php": ">=5.5.9",
"symfony/css-selector": "~3.1",
"symfony/dom-crawler": "~3.1"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.0-dev"
}
},
"autoload": {
"psr-4": {
"Laravel\\BrowserKitTesting\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Taylor Otwell",
"email": "taylor@laravel.com"
}
],
"description": "Provides backwards compatibility for BrowserKit testing in Laravel 5.4.",
"keywords": [
"laravel",
"testing"
],
"time": "2017-05-26T12:46:48+00:00"
},
{ {
"name": "maximebf/debugbar", "name": "maximebf/debugbar",
"version": "1.13.1", "version": "1.13.1",

View File

@@ -15,7 +15,7 @@ use CachetHQ\Cachet\Models\User;
use CachetHQ\Cachet\Settings\Cache; use CachetHQ\Cachet\Settings\Cache;
use CachetHQ\Cachet\Settings\Repository; use CachetHQ\Cachet\Settings\Repository;
use Illuminate\Contracts\Console\Kernel; use Illuminate\Contracts\Console\Kernel;
use Laravel\BrowserKitTesting\TestCase; use Illuminate\Foundation\Testing\TestCase;
/** /**
* This is the abstract test case class. * This is the abstract test case class.

View File

@@ -28,12 +28,16 @@ abstract class AbstractApiTestCase extends AbstractTestCase
/** /**
* Become a user. * Become a user.
* *
* @return void * @return $this
*/ */
protected function beUser() protected function beUser()
{ {
$this->user = factory(User::class)->create(); $this->user = factory(User::class)->create([
'username' => 'cachet-test',
]);
$this->be($this->user); $this->be($this->user);
return $this;
} }
} }

View File

@@ -25,109 +25,145 @@ class ComponentGroupTest extends AbstractApiTestCase
const COMPONENT_GROUP_1_NAME = 'Component Group 1'; const COMPONENT_GROUP_1_NAME = 'Component Group 1';
const COMPONENT_GROUP_2_NAME = 'Component Group 2'; const COMPONENT_GROUP_2_NAME = 'Component Group 2';
public function testGetGroups() public function test_can_get_all_component_groups()
{ {
$groups = factory('CachetHQ\Cachet\Models\ComponentGroup', 3) $groups = factory(ComponentGroup::class, 2)
->create(['visible' => ComponentGroup::VISIBLE_GUEST]); ->create(['visible' => ComponentGroup::VISIBLE_GUEST]);
$this->get('/api/v1/components/groups'); $response = $this->json('GET', '/api/v1/components/groups');
$this->seeJsonContains(['id' => $groups[0]->id]);
$this->seeJsonContains(['id' => $groups[1]->id]); $response->assertStatus(200);
$this->seeJsonContains(['id' => $groups[2]->id]); $response->assertJsonFragment([
$this->assertResponseOk(); [
'id' => $groups[0]->id,
'name' => $groups[0]->name,
'created_at' => (string) $groups[0]->created_at,
'updated_at' => (string) $groups[0]->updated_at,
'order' => $groups[0]->order,
'collapsed' => $groups[0]->collapsed,
'visible' => $groups[0]->visible,
'enabled_components' => $groups[0]->enabled_components,
'enabled_components_lowest' => $groups[0]->enabled_components_lowest,
'lowest_human_status' => $groups[0]->lowest_human_status,
]
]);
$response->assertJsonFragment([
[
'id' => $groups[1]->id,
'name' => $groups[1]->name,
'created_at' => (string) $groups[1]->created_at,
'updated_at' => (string) $groups[1]->updated_at,
'order' => $groups[1]->order,
'collapsed' => $groups[1]->collapsed,
'visible' => $groups[1]->visible,
'enabled_components' => $groups[1]->enabled_components,
'enabled_components_lowest' => $groups[1]->enabled_components_lowest,
'lowest_human_status' => $groups[1]->lowest_human_status,
]
]);
} }
public function testGetInvalidGroup() public function test_cannot_get_invalid_component_group()
{ {
$this->get('/api/v1/components/groups/1'); $response = $this->json('GET', '/api/v1/components/groups/1');
$this->assertResponseStatus(404);
$response->assertStatus(404);
} }
public function testPostGroupUnauthorized() public function test_cannot_create_component_group_without_authorization()
{ {
$this->post('/api/v1/components/groups'); $response = $this->json('POST', '/api/v1/components/groups');
$this->assertResponseStatus(401); $response->assertStatus(401);
} }
public function testPostGroupNoData() public function test_cannot_create_component_group_without_data()
{ {
$this->beUser(); $this->beUser();
$this->post('/api/v1/components/groups'); $response = $this->json('POST', '/api/v1/components/groups');
$this->assertResponseStatus(400);
$response->assertStatus(400);
} }
public function testPostGroup() public function test_can_create_new_component_group()
{ {
$this->beUser(); $this->beUser();
$this->post('/api/v1/components/groups', [ $response = $this->json('POST', '/api/v1/components/groups', [
'name' => 'Foo',
'order' => 1,
'collapsed' => 1,
'visible' => ComponentGroup::VISIBLE_GUEST,
]);
$response->assertStatus(200);
$response->assertJsonFragment([
'name' => 'Foo', 'name' => 'Foo',
'order' => 1, 'order' => 1,
'collapsed' => 1, 'collapsed' => 1,
'visible' => ComponentGroup::VISIBLE_GUEST, 'visible' => ComponentGroup::VISIBLE_GUEST,
]); ]);
$this->seeJsonContains(['name' => 'Foo', 'order' => 1, 'collapsed' => 1, 'visible' => ComponentGroup::VISIBLE_GUEST]);
$this->assertResponseOk();
} }
public function testGetNewGroup() public function test_can_get_single_component_group()
{ {
$group = factory('CachetHQ\Cachet\Models\ComponentGroup')->create(); $group = factory(ComponentGroup::class)->create();
$this->get('/api/v1/components/groups/1'); $response = $this->json('GET', '/api/v1/components/groups/1');
$this->seeJsonContains(['name' => $group->name]);
$this->assertResponseOk(); $response->assertStatus(200);
$response->assertJsonFragment(['name' => $group->name]);
} }
public function testPutGroup() public function test_can_update_component_group()
{ {
$this->beUser(); $this->beUser();
$group = factory('CachetHQ\Cachet\Models\ComponentGroup')->create(); $group = factory(ComponentGroup::class)->create();
$this->put('/api/v1/components/groups/1', [ $response = $this->json('PUT', '/api/v1/components/groups/1', [
'name' => 'Lorem Ipsum Groupous', 'name' => 'Lorem Ipsum Groupous',
]); ]);
$this->seeJsonContains(['name' => 'Lorem Ipsum Groupous']);
$this->assertResponseOk(); $response->assertStatus(200);
$response->assertJsonFragment(['name' => 'Lorem Ipsum Groupous']);
} }
public function testDeleteGroup() public function test_can_delete_component_group()
{ {
$this->beUser(); $this->beUser();
$group = factory('CachetHQ\Cachet\Models\ComponentGroup')->create(); $group = factory(ComponentGroup::class)->create();
$this->delete('/api/v1/components/groups/1'); $response = $this->json('DELETE', '/api/v1/components/groups/1');
$this->assertResponseStatus(204);
$response->assertStatus(204);
} }
/** @test */ public function test_only_public_component_groups_are_shown_for_a_guest()
public function only_public_component_groups_are_shown_for_a_guest()
{ {
$this->createComponentGroups(); $this->createComponentGroups();
$this->get('/api/v1/components/groups') $response = $this->json('GET', '/api/v1/components/groups');
->seeJsonContains(['name' => self::COMPONENT_GROUP_1_NAME]);
$this->assertResponseOk(); $response->assertStatus(200);
$response->assertJsonFragment(['name' => self::COMPONENT_GROUP_1_NAME]);
} }
/** @test */ public function test_all_component_groups_are_displayed_for_logged_in_users()
public function all_component_groups_are_displayed_for_loggedin_users()
{ {
$this->createComponentGroups() $this->createComponentGroups()
->signIn(); ->signIn();
$this->get('/api/v1/components/groups') $response = $this->json('GET', '/api/v1/components/groups');
->seeJsonContains(['name' => self::COMPONENT_GROUP_1_NAME])
->seeJsonContains(['name' => self::COMPONENT_GROUP_2_NAME]); $response->assertStatus(200);
$this->assertResponseOk(); $response->assertJsonFragment(['name' => self::COMPONENT_GROUP_1_NAME]);
} }
/** /**
* Set up the needed data for the tests. * Set up the needed data for the tests.
* *
* @return TestCase * @return $this
*/ */
protected function createComponentGroups() protected function createComponentGroups()
{ {
@@ -139,13 +175,13 @@ class ComponentGroupTest extends AbstractApiTestCase
/** /**
* Create a component group. * Create a component group.
* Also attaches a creator if any given as a parameter *
* or exists in the test class. * Also attaches a creator if any given as a parameter or exists in the test class.
* *
* @param string $name * @param string $name
* @param string $visible * @param string $visible
* *
* @return AbstractApiTestCase * @return $this
*/ */
protected function createComponentGroup($name, $visible) protected function createComponentGroup($name, $visible)
{ {

View File

@@ -11,6 +11,8 @@
namespace CachetHQ\Tests\Cachet\Api; namespace CachetHQ\Tests\Cachet\Api;
use CachetHQ\Cachet\Models\Component;
/** /**
* This is the component test class. * This is the component test class.
* *
@@ -19,43 +21,46 @@ namespace CachetHQ\Tests\Cachet\Api;
*/ */
class ComponentTest extends AbstractApiTestCase class ComponentTest extends AbstractApiTestCase
{ {
public function testGetComponents() public function test_can_get_all_components()
{ {
$components = factory('CachetHQ\Cachet\Models\Component', 3)->create(); $components = factory(Component::class, 3)->create();
$this->get('/api/v1/components'); $response = $this->json('GET', '/api/v1/components');
$this->seeJsonContains(['id' => $components[0]->id]);
$this->seeJsonContains(['id' => $components[1]->id]); $response->assertStatus(200);
$this->seeJsonContains(['id' => $components[2]->id]); $response->assertJsonFragment(['id' => $components[0]->id]);
$this->assertResponseOk(); $response->assertJsonFragment(['id' => $components[1]->id]);
$response->assertJsonFragment(['id' => $components[2]->id]);
} }
public function testGetInvalidComponent() public function test_cannot_get_invalid_component()
{ {
$this->get('/api/v1/components/1'); $response = $this->json('GET', '/api/v1/components/1');
$this->assertResponseStatus(404);
$response->assertStatus(404);
} }
public function testPostComponentUnauthorized() public function test_cannot_create_component_without_authorization()
{ {
$this->post('/api/v1/components'); $response = $this->json('POST', '/api/v1/components');
$this->assertResponseStatus(401); $response->assertStatus(401);
} }
public function testPostComponentNoData() public function test_cannot_create_component_without_data()
{ {
$this->beUser(); $this->beUser();
$this->post('/api/v1/components'); $response = $this->json('POST', '/api/v1/components');
$this->assertResponseStatus(400);
$response->assertStatus(400);
} }
public function testPostComponent() public function test_can_create_component()
{ {
$this->beUser(); $this->beUser();
$this->post('/api/v1/components', [ $response = $this->json('POST', '/api/v1/components', [
'name' => 'Foo', 'name' => 'Foo',
'description' => 'Bar', 'description' => 'Bar',
'status' => 1, 'status' => 1,
@@ -64,15 +69,16 @@ class ComponentTest extends AbstractApiTestCase
'group_id' => 1, 'group_id' => 1,
'enabled' => true, 'enabled' => true,
]); ]);
$this->seeJsonContains(['name' => 'Foo']);
$this->assertResponseOk(); $response->assertStatus(200);
$response->assertJsonFragment(['name' => 'Foo']);
} }
public function testPostComponentWithoutEnabledField() public function test_can_create_component_without_enabled_field()
{ {
$this->beUser(); $this->beUser();
$this->post('/api/v1/components', [ $response = $this->json('POST', '/api/v1/components', [
'name' => 'Foo', 'name' => 'Foo',
'description' => 'Bar', 'description' => 'Bar',
'status' => 1, 'status' => 1,
@@ -80,15 +86,16 @@ class ComponentTest extends AbstractApiTestCase
'order' => 1, 'order' => 1,
'group_id' => 1, 'group_id' => 1,
]); ]);
$this->seeJsonContains(['name' => 'Foo', 'enabled' => true]);
$this->assertResponseOk(); $response->assertStatus(200);
$response->assertJsonFragment(['name' => 'Foo', 'enabled' => true]);
} }
public function testPostComponentWithMetaData() public function test_can_create_component_with_meta_data()
{ {
$this->beUser(); $this->beUser();
$this->post('/api/v1/components', [ $response = $this->json('POST', '/api/v1/components', [
'name' => 'Foo', 'name' => 'Foo',
'description' => 'Bar', 'description' => 'Bar',
'status' => 1, 'status' => 1,
@@ -101,19 +108,21 @@ class ComponentTest extends AbstractApiTestCase
], ],
]); ]);
$this->seeJsonContains([ $response->assertStatus(200);
'meta' => [ $response->assertJsonFragment([
'name' => 'Foo',
'status' => 1,
'meta' => [
'uuid' => '172ff3fb-41f7-49d3-8bcd-f57b53627fa0', 'uuid' => '172ff3fb-41f7-49d3-8bcd-f57b53627fa0',
], ],
]); ]);
$this->assertResponseOk();
} }
public function testPostDisabledComponent() public function test_can_create_disabled_component()
{ {
$this->beUser(); $this->beUser();
$this->post('/api/v1/components', [ $response = $this->json('POST', '/api/v1/components', [
'name' => 'Foo', 'name' => 'Foo',
'description' => 'Bar', 'description' => 'Bar',
'status' => 1, 'status' => 1,
@@ -122,62 +131,65 @@ class ComponentTest extends AbstractApiTestCase
'group_id' => 1, 'group_id' => 1,
'enabled' => 0, 'enabled' => 0,
]); ]);
$this->seeJsonContains(['name' => 'Foo', 'enabled' => false]);
$this->assertResponseOk(); $response->assertStatus(200);
$response->assertJsonFragment(['name' => 'Foo', 'enabled' => false]);
} }
public function testGetNewComponent() public function test_can_get_newly_created_component()
{ {
$component = factory('CachetHQ\Cachet\Models\Component')->create(); $component = factory(Component::class)->create();
$this->get('/api/v1/components/1'); $response = $this->json('GET', '/api/v1/components/1');
$this->seeJsonContains(['name' => $component->name]);
$this->assertResponseOk(); $response->assertStatus(200);
$response->assertJsonFragment(['name' => $component->name]);
} }
public function testPutComponent() public function test_can_update_component()
{ {
$this->beUser(); $this->beUser();
$component = factory('CachetHQ\Cachet\Models\Component')->create(); $component = factory(Component::class)->create();
$this->put('/api/v1/components/1', [ $response = $this->json('PUT', '/api/v1/components/1', [
'name' => 'Foo', 'name' => 'Foo',
]); ]);
$this->seeJsonContains(['name' => 'Foo']);
$this->assertResponseOk(); $response->assertStatus(200);
$response->assertJsonFragment(['name' => 'Foo']);
} }
public function testPutComponentWithMetaData() public function test_can_update_component_with_meta_data()
{ {
$this->beUser(); $this->beUser();
$component = factory('CachetHQ\Cachet\Models\Component')->create([ $component = factory(Component::class)->create([
'meta' => [ 'meta' => [
'uuid' => '172ff3fb-41f7-49d3-8bcd-f57b53627fa0', 'uuid' => '172ff3fb-41f7-49d3-8bcd-f57b53627fa0',
], ],
]); ]);
$this->put('/api/v1/components/1', [ $response = $this->json('PUT', '/api/v1/components/1', [
'meta' => [ 'meta' => [
'uuid' => '172ff3fb-41f7-49d3-8bcd-f57b53627fa0', 'uuid' => '172ff3fb-41f7-49d3-8bcd-f57b53627fa0',
'foo' => 'bar', 'foo' => 'bar',
], ],
]); ]);
$this->seeJsonContains([ $response->assertStatus(200);
$response->assertJsonFragment([
'meta' => [ 'meta' => [
'uuid' => '172ff3fb-41f7-49d3-8bcd-f57b53627fa0', 'uuid' => '172ff3fb-41f7-49d3-8bcd-f57b53627fa0',
'foo' => 'bar', 'foo' => 'bar',
], ],
]); ]);
$this->assertResponseOk();
} }
public function testDeleteComponent() public function test_can_delete_component()
{ {
$this->beUser(); $this->beUser();
$component = factory('CachetHQ\Cachet\Models\Component')->create(); $component = factory(Component::class)->create();
$this->delete('/api/v1/components/1'); $response = $this->delete('/api/v1/components/1');
$this->assertResponseStatus(204); $response->assertStatus(204);
} }
} }

View File

@@ -19,26 +19,27 @@ namespace CachetHQ\Tests\Cachet\Api;
*/ */
class GeneralTest extends AbstractApiTestCase class GeneralTest extends AbstractApiTestCase
{ {
public function testGetPing() public function test_can_ping()
{ {
$this->get('/api/v1/ping'); $response = $this->json('GET', '/api/v1/ping');
$this->seeJsonContains(['data' => 'Pong!']);
$this->assertResponseOk(); $response->assertStatus(200);
$this->seeHeader('Content-Type', 'application/json'); $response->assertHeader('Content-Type', 'application/json');
$response->assertJsonFragment(['data' => 'Pong!']);
} }
public function testErrorPage() public function test_see_error_page_for_unknown_endpoint()
{ {
$this->get('/api/v1/not-found'); $response = $this->json('GET', '/api/v1/not-found');
$this->assertResponseStatus(404); $response->assertStatus(404);
$this->seeHeader('Content-Type', 'application/json'); $response->assertHeader('Content-Type', 'application/json');
} }
public function testNotAcceptableContentType() public function test_non_acceptable_content_type()
{ {
$this->get('/api/v1/ping', ['HTTP_Accept' => 'text/html']); $response = $this->json('GET', '/api/v1/ping', [], ['HTTP_Accept' => 'text/html']);
$this->assertResponseStatus(406); $response->assertStatus(406);
} }
} }

View File

@@ -11,6 +11,9 @@
namespace CachetHQ\Tests\Cachet\Api; namespace CachetHQ\Tests\Cachet\Api;
use CachetHQ\Cachet\Models\Incident;
use CachetHQ\Cachet\Models\IncidentTemplate;
/** /**
* This is the incident test class. * This is the incident test class.
* *
@@ -19,59 +22,65 @@ namespace CachetHQ\Tests\Cachet\Api;
*/ */
class IncidentTest extends AbstractApiTestCase class IncidentTest extends AbstractApiTestCase
{ {
public function testGetIncidents() public function test_can_get_all_incidents()
{ {
$incidents = factory('CachetHQ\Cachet\Models\Incident', 3)->create(); $incidents = factory(Incident::class, 3)->create();
$this->get('/api/v1/incidents'); $response = $this->json('GET', '/api/v1/incidents');
$this->seeJsonContains(['id' => $incidents[0]->id]);
$this->seeJsonContains(['id' => $incidents[1]->id]); $response->assertStatus(200);
$this->seeJsonContains(['id' => $incidents[2]->id]);
$this->assertResponseOk(); $response->assertJsonFragment(['id' => $incidents[0]->id]);
$response->assertJsonFragment(['id' => $incidents[1]->id]);
$response->assertJsonFragment(['id' => $incidents[2]->id]);
} }
public function testGetInvalidIncident() public function test_cannot_get_invalid_component()
{ {
$this->get('/api/v1/incidents/0'); $response = $this->json('GET', '/api/v1/incidents/0');
$this->assertResponseStatus(404);
$response->assertStatus(404);
} }
public function testPostIncidentUnauthorized() public function test_cannot_create_incident_without_authorization()
{ {
$this->post('/api/v1/incidents'); $response = $this->json('POST', '/api/v1/incidents');
$this->assertResponseStatus(401);
$response->assertStatus(401);
} }
public function testPostIncidentNoData() public function test_cannot_create_incident_with_missing_data()
{ {
$this->beUser(); $this->beUser();
$this->post('/api/v1/incidents'); $response = $this->json('POST', '/api/v1/incidents');
$this->assertResponseStatus(400);
$response->assertStatus(400);
} }
public function testPostIncident() public function test_can_create_incident()
{ {
$this->beUser(); $this->beUser();
$this->post('/api/v1/incidents', [ $response = $this->json('POST', '/api/v1/incidents', [
'name' => 'Foo', 'name' => 'Foo',
'message' => 'Lorem ipsum dolor sit amet', 'message' => 'Lorem ipsum dolor sit amet',
'status' => 1, 'status' => 1,
'visible' => 1, 'visible' => 1,
'stickied' => false, 'stickied' => false,
]); ]);
$this->seeJsonContains(['name' => 'Foo']);
$this->assertResponseOk(); $response->assertStatus(200);
$response->assertJsonFragment(['name' => 'Foo']);
} }
public function testPostIncidentWithComponentStatus() public function test_can_create_incident_with_component_status()
{ {
$component = factory('CachetHQ\Cachet\Models\Component')->create(); $component = factory('CachetHQ\Cachet\Models\Component')->create();
$this->beUser(); $this->beUser();
$this->post('/api/v1/incidents', [ $response = $this->json('POST', '/api/v1/incidents', [
'name' => 'Foo', 'name' => 'Foo',
'message' => 'Lorem ipsum dolor sit amet', 'message' => 'Lorem ipsum dolor sit amet',
'status' => 1, 'status' => 1,
@@ -80,16 +89,17 @@ class IncidentTest extends AbstractApiTestCase
'visible' => 1, 'visible' => 1,
'stickied' => false, 'stickied' => false,
]); ]);
$this->seeJsonContains(['name' => 'Foo']);
$this->assertResponseOk(); $response->assertStatus(200);
$response->assertJsonFragment(['name' => 'Foo']);
} }
public function testCreateIncidentWithTemplate() public function test_can_create_incident_with_template()
{ {
$template = factory('CachetHQ\Cachet\Models\IncidentTemplate')->create(); $template = factory(IncidentTemplate::class)->create();
$this->beUser(); $this->beUser();
$this->post('/api/v1/incidents', [ $response = $this->json('POST', '/api/v1/incidents', [
'name' => 'Foo', 'name' => 'Foo',
'status' => 1, 'status' => 1,
'visible' => 1, 'visible' => 1,
@@ -100,66 +110,72 @@ class IncidentTest extends AbstractApiTestCase
'message' => 'Hello there this is a foo!', 'message' => 'Hello there this is a foo!',
], ],
]); ]);
$this->seeJsonContains([
$response->assertStatus(200);
$response->assertJsonFragment([
'name' => 'Foo', 'name' => 'Foo',
'message' => "Name: Foo,\nMessage: Hello there this is a foo!", 'message' => "Name: Foo,\nMessage: Hello there this is a foo!",
]); ]);
} }
public function testGetNewIncident() public function test_can_get_newly_created_incident()
{ {
$incident = factory('CachetHQ\Cachet\Models\Incident')->create(); $incident = factory(Incident::class)->create();
$this->get('/api/v1/incidents/1'); $response = $this->json('GET', '/api/v1/incidents/1');
$this->seeJsonContains(['name' => $incident->name]);
$this->assertResponseOk(); $response->assertStatus(200);
$response->assertJsonFragment(['name' => $incident->name]);
} }
public function testPutIncident() public function test_can_update_incident()
{ {
$this->beUser(); $this->beUser();
$component = factory('CachetHQ\Cachet\Models\Incident')->create(); $component = factory(Incident::class)->create();
$this->put('/api/v1/incidents/1', [ $response = $this->json('PUT', '/api/v1/incidents/1', [
'name' => 'Foo', 'name' => 'Foo',
]); ]);
$this->seeJsonContains(['name' => 'Foo']);
$this->assertResponseOk(); $response->assertStatus(200);
$response->assertJsonFragment(['name' => 'Foo']);
} }
public function testPutIncidentWithTemplate() public function test_can_update_incident_with_template()
{ {
$this->beUser(); $this->beUser();
$template = factory('CachetHQ\Cachet\Models\IncidentTemplate')->create([ $template = factory(IncidentTemplate::class)->create([
'template' => 'Hello there this is a foo in my {{ incident.name }}!', 'template' => 'Hello there this is a foo in my {{ incident.name }}!',
]); ]);
$component = factory('CachetHQ\Cachet\Models\Incident')->create(); $component = factory(Incident::class)->create();
$this->put('/api/v1/incidents/1', [ $response = $this->json('PUT', '/api/v1/incidents/1', [
'name' => 'Foo', 'name' => 'Foo',
'template' => $template->slug, 'template' => $template->slug,
]); ]);
$this->seeJsonContains([
$response->assertStatus(200);
$response->assertJsonFragment([
'name' => 'Foo', 'name' => 'Foo',
'message' => 'Hello there this is a foo in my Foo!', 'message' => 'Hello there this is a foo in my Foo!',
]); ]);
$this->assertResponseOk();
} }
public function testDeleteIncident() public function test_can_delete_incident()
{ {
$this->beUser(); $this->beUser();
$component = factory('CachetHQ\Cachet\Models\Incident')->create(); $component = factory(Incident::class)->create();
$this->delete('/api/v1/incidents/1'); $response = $this->json('DELETE', '/api/v1/incidents/1');
$this->assertResponseStatus(204);
$response->assertStatus(204);
} }
public function testCreateIncidentWithMeta() public function test_can_create_incident_with_meta_data()
{ {
$this->beUser(); $this->beUser();
$this->post('/api/v1/incidents', [ $response = $this->json('POST', '/api/v1/incidents', [
'name' => 'Foo', 'name' => 'Foo',
'message' => 'Lorem ipsum dolor sit amet', 'message' => 'Lorem ipsum dolor sit amet',
'status' => 1, 'status' => 1,
@@ -167,11 +183,12 @@ class IncidentTest extends AbstractApiTestCase
'id' => 123456789, 'id' => 123456789,
], ],
]); ]);
$this->seeJsonContains([
$response->assertStatus(200);
$response->assertJsonFragment([
'meta' => [ 'meta' => [
'id' => 123456789, 'id' => 123456789,
], ],
]); ]);
$this->assertResponseOk();
} }
} }

View File

@@ -11,6 +11,9 @@
namespace CachetHQ\Tests\Cachet\Api; namespace CachetHQ\Tests\Cachet\Api;
use CachetHQ\Cachet\Models\Incident;
use CachetHQ\Cachet\Models\IncidentUpdate;
/** /**
* This is the incident update test class. * This is the incident update test class.
* *
@@ -18,85 +21,84 @@ namespace CachetHQ\Tests\Cachet\Api;
*/ */
class IncidentUpdateTest extends AbstractApiTestCase class IncidentUpdateTest extends AbstractApiTestCase
{ {
public function testGetIncidentUpdates() public function test_can_get_all_incident_updates()
{ {
$incident = factory('CachetHQ\Cachet\Models\Incident')->create(); $incident = factory(Incident::class)->create();
$updates = factory('CachetHQ\Cachet\Models\IncidentUpdate', 3)->create([ $updates = factory(IncidentUpdate::class, 3)->create([
'incident_id' => $incident->id, 'incident_id' => $incident->id,
]); ]);
$this->get("/api/v1/incidents/{$incident->id}/updates"); $response = $this->json('GET', "/api/v1/incidents/{$incident->id}/updates");
$this->assertResponseOk(); $response->assertStatus(200);
$this->seeJsonContains(['id' => $updates[0]->id]); $response->assertJsonFragment(['id' => $updates[0]->id]);
$this->seeJsonContains(['id' => $updates[1]->id]); $response->assertJsonFragment(['id' => $updates[1]->id]);
$this->seeJsonContains(['id' => $updates[2]->id]); $response->assertJsonFragment(['id' => $updates[2]->id]);
} }
public function testGetInvalidIncidentUpdate() public function test_cannot_get_invalid_incident_update()
{ {
$this->get('/api/v1/incidents/1/updates/1'); $response = $this->json('GET', '/api/v1/incidents/1/updates/1');
$this->assertResponseStatus(404); $response->assertStatus(404);
} }
public function testPostIncidentUpdateUnauthorized() public function test_cannot_create_incident_update_without_authorization()
{ {
$incident = factory('CachetHQ\Cachet\Models\Incident')->create(); $incident = factory(Incident::class)->create();
$this->post("/api/v1/incidents/{$incident->id}/updates");
$this->assertResponseStatus(401); $response = $this->json('POST', "/api/v1/incidents/{$incident->id}/updates");
$response->assertStatus(401);
} }
public function testPostIncidentUpdateNoData() public function test_cannot_create_incident_update_without_data()
{ {
$this->beUser(); $this->beUser();
$incident = factory('CachetHQ\Cachet\Models\Incident')->create(); $incident = factory(Incident::class)->create();
$this->post("/api/v1/incidents/{$incident->id}/updates"); $response = $this->json('POST', "/api/v1/incidents/{$incident->id}/updates");
$this->assertResponseStatus(400); $response->assertStatus(400);
} }
public function testPostIncidentUpdate() public function test_can_create_incident_update()
{ {
$this->beUser(); $this->beUser();
$incident = factory('CachetHQ\Cachet\Models\Incident')->create(); $incident = factory(Incident::class)->create();
$this->post("/api/v1/incidents/{$incident->id}/updates", [ $response = $this->json('POST', "/api/v1/incidents/{$incident->id}/updates", [
'status' => 4, 'status' => 4,
'message' => 'Incident fixed!', 'message' => 'Incident fixed!',
]); ]);
$this->assertResponseOk(); $response->assertStatus(200);
$response->assertJsonFragment(['incident_id' => $incident->id]);
$this->seeJsonContains(['incident_id' => $incident->id]);
} }
public function testPutIncidentUpdate() public function test_can_update_incident_update()
{ {
$this->beUser(); $this->beUser();
$incident = factory('CachetHQ\Cachet\Models\Incident')->create(); $incident = factory(Incident::class)->create();
$update = factory('CachetHQ\Cachet\Models\IncidentUpdate')->create(); $update = factory(IncidentUpdate::class)->create();
$this->put("/api/v1/incidents/{$incident->id}/updates/{$update->id}", [ $response = $this->json('PUT', "/api/v1/incidents/{$incident->id}/updates/{$update->id}", [
'message' => 'Message updated :smile:', 'message' => 'Message updated :smile:',
]); ]);
$this->assertResponseOk(); $response->assertStatus(200);
$response->assertJsonFragment(['message' => 'Message updated :smile:']);
$this->seeJsonContains(['message' => 'Message updated :smile:']);
} }
public function testDeleteIncidentUpdate() public function test_can_delete_incident_update()
{ {
$this->beUser(); $this->beUser();
$incident = factory('CachetHQ\Cachet\Models\Incident')->create(); $incident = factory(Incident::class)->create();
$update = factory('CachetHQ\Cachet\Models\IncidentUpdate')->create(); $update = factory(IncidentUpdate::class)->create();
$this->delete("/api/v1/incidents/{$incident->id}/updates/{$update->id}"); $response = $this->json('DELETE', "/api/v1/incidents/{$incident->id}/updates/{$update->id}");
$this->assertResponseStatus(204); $response->assertStatus(204);
} }
} }

View File

@@ -11,6 +11,8 @@
namespace CachetHQ\Tests\Cachet\Api; namespace CachetHQ\Tests\Cachet\Api;
use CachetHQ\Cachet\Models\Metric;
use CachetHQ\Cachet\Models\MetricPoint;
use Carbon\Carbon; use Carbon\Carbon;
/** /**
@@ -21,72 +23,70 @@ use Carbon\Carbon;
*/ */
class MetricPointTest extends AbstractApiTestCase class MetricPointTest extends AbstractApiTestCase
{ {
public function testGetMetricPoint() public function test_can_get_all_metric_points()
{ {
$metric = factory('CachetHQ\Cachet\Models\Metric')->create(); $metric = factory(Metric::class)->create();
$metricPoint = factory('CachetHQ\Cachet\Models\MetricPoint', 3)->create([ $metricPoint = factory(MetricPoint::class, 3)->create([
'metric_id' => $metric->id, 'metric_id' => $metric->id,
]); ]);
$this->get("/api/v1/metrics/{$metric->id}/points"); $response = $this->json('GET', "/api/v1/metrics/{$metric->id}/points");
$this->seeJsonContains(['id' => $metricPoint[0]->id]); $response->assertJsonFragment(['id' => $metricPoint[0]->id]);
$this->seeJsonContains(['id' => $metricPoint[1]->id]); $response->assertJsonFragment(['id' => $metricPoint[1]->id]);
$this->seeJsonContains(['id' => $metricPoint[2]->id]); $response->assertJsonFragment(['id' => $metricPoint[2]->id]);
$this->assertResponseOk(); $response->assertStatus(200);
} }
public function testPostMetricPointUnauthorized() public function test_cannot_create_metric_point_without_authorization()
{ {
$metric = factory('CachetHQ\Cachet\Models\Metric')->create(); $metric = factory(Metric::class)->create();
$metricPoint = factory('CachetHQ\Cachet\Models\MetricPoint')->create([ $metricPoint = factory(MetricPoint::class)->create([
'metric_id' => $metric->id, 'metric_id' => $metric->id,
]); ]);
$this->post("/api/v1/metrics/{$metric->id}/points"); $response = $this->json('POST', "/api/v1/metrics/{$metric->id}/points");
$this->assertResponseStatus(401); $response->assertStatus(401);
} }
public function testPostMetricPoint() public function test_can_create_metric_point()
{ {
$this->beUser(); $this->beUser();
$metric = factory('CachetHQ\Cachet\Models\Metric')->create(); $metric = factory(Metric::class)->create();
$metricPoint = factory('CachetHQ\Cachet\Models\MetricPoint')->make([ $metricPoint = factory(MetricPoint::class)->make([
'metric_id' => $metric->id, 'metric_id' => $metric->id,
]); ]);
$this->post("/api/v1/metrics/{$metric->id}/points", $metricPoint->toArray()); $response = $this->json('POST', "/api/v1/metrics/{$metric->id}/points", $metricPoint->toArray());
$this->seeJsonContains(['value' => $metricPoint->value]); $response->assertStatus(200);
$response->assertJsonFragment(['value' => $metricPoint->value]);
$this->assertResponseOk();
} }
public function testPostMetricPointTimestamp() public function test_can_create_metric_point_with_timestamp()
{ {
$this->beUser(); $this->beUser();
$metric = factory('CachetHQ\Cachet\Models\Metric')->create(); $metric = factory(Metric::class)->create();
$timestamp = 1434369116; $timestamp = 1434369116;
$metricPoint = factory('CachetHQ\Cachet\Models\MetricPoint')->make([ $metricPoint = factory(MetricPoint::class)->make([
'metric_id' => $metric->id, 'metric_id' => $metric->id,
]); ]);
$postData = $metricPoint->toArray(); $postData = $metricPoint->toArray();
$postData['timestamp'] = $timestamp; $postData['timestamp'] = $timestamp;
$this->post("/api/v1/metrics/{$metric->id}/points", $postData); $response = $this->json('POST', "/api/v1/metrics/{$metric->id}/points", $postData);
$this->seeJsonContains([ $response->assertStatus(200);
$response->assertJsonFragment([
'value' => $metricPoint->value, 'value' => $metricPoint->value,
'created_at' => date('Y-m-d H:i:s', 1434369116), 'created_at' => date('Y-m-d H:i:s', 1434369116),
]); ]);
$this->assertResponseOk();
} }
public function testPostMetricPointTimestampTimezone() public function test_can_create_metric_point_with_timestamp_timezone()
{ {
$this->beUser(); $this->beUser();
@@ -94,48 +94,46 @@ class MetricPointTest extends AbstractApiTestCase
Carbon::setTestNow(Carbon::now()); Carbon::setTestNow(Carbon::now());
$timezone = 'America/Mexico_City'; $timezone = 'America/Mexico_City';
$metric = factory('CachetHQ\Cachet\Models\Metric')->create(); $metric = factory(Metric::class)->create();
$datetime = Carbon::now()->timezone($timezone); $datetime = Carbon::now()->timezone($timezone);
$metricPoint = factory('CachetHQ\Cachet\Models\MetricPoint')->make([ $metricPoint = factory(MetricPoint::class)->make([
'metric_id' => $metric->id, 'metric_id' => $metric->id,
]); ]);
$postData = $metricPoint->toArray(); $postData = $metricPoint->toArray();
$postData['timestamp'] = $datetime->timestamp; $postData['timestamp'] = $datetime->timestamp;
$this->post("/api/v1/metrics/{$metric->id}/points", $postData, ['Time-Zone' => $timezone]); $response = $this->json('POST', "/api/v1/metrics/{$metric->id}/points", $postData, ['Time-Zone' => $timezone]);
$this->seeJsonContains(['value' => $metricPoint->value, 'created_at' => $datetime->toDateTimeString()]); $response->assertStatus(200);
$response->assertJsonFragment(['value' => $metricPoint->value, 'created_at' => $datetime->toDateTimeString()]);
$this->assertResponseOk();
} }
public function testPutMetricPoint() public function test_can_update_metric_point()
{ {
$this->beUser(); $this->beUser();
$metric = factory('CachetHQ\Cachet\Models\Metric')->create(); $metric = factory(Metric::class)->create();
$metricPoint = factory('CachetHQ\Cachet\Models\MetricPoint')->create([ $metricPoint = factory(MetricPoint::class)->create([
'metric_id' => $metric->id, 'metric_id' => $metric->id,
]); ]);
$this->put("/api/v1/metrics/{$metric->id}/points/{$metricPoint->id}", [ $response = $this->json('PUT', "/api/v1/metrics/{$metric->id}/points/{$metricPoint->id}", [
'value' => 999, 'value' => 999,
]); ]);
$this->seeJsonContains(['value' => 999]); $response->assertStatus(200);
$response->assertJsonFragment(['value' => 999]);
$this->assertResponseOk();
} }
public function testDeleteMetricPoint() public function test_can_delete_metric_point()
{ {
$this->beUser(); $this->beUser();
$metric = factory('CachetHQ\Cachet\Models\Metric')->create(); $metric = factory(Metric::class)->create();
$metricPoint = factory('CachetHQ\Cachet\Models\MetricPoint')->create([ $metricPoint = factory(MetricPoint::class)->create([
'metric_id' => $metric->id, 'metric_id' => $metric->id,
]); ]);
$this->delete("/api/v1/metrics/{$metric->id}/points/{$metricPoint->id}"); $response = $this->json('DELETE', "/api/v1/metrics/{$metric->id}/points/{$metricPoint->id}");
$this->assertResponseStatus(204); $response->assertStatus(204);
} }
} }

View File

@@ -11,6 +11,8 @@
namespace CachetHQ\Tests\Cachet\Api; namespace CachetHQ\Tests\Cachet\Api;
use CachetHQ\Cachet\Models\Metric;
/** /**
* This is the metric test class. * This is the metric test class.
* *
@@ -19,42 +21,43 @@ namespace CachetHQ\Tests\Cachet\Api;
*/ */
class MetricTest extends AbstractApiTestCase class MetricTest extends AbstractApiTestCase
{ {
public function testGetMetrics() public function test_can_get_all_metrics()
{ {
$metrics = factory('CachetHQ\Cachet\Models\Metric', 3)->create(); $metrics = factory(Metric::class, 3)->create();
$this->get('/api/v1/metrics'); $response = $this->json('GET', '/api/v1/metrics');
$this->seeJsonContains(['id' => $metrics[0]->id]);
$this->seeJsonContains(['id' => $metrics[1]->id]); $response->assertJsonFragment(['id' => $metrics[0]->id]);
$this->seeJsonContains(['id' => $metrics[2]->id]); $response->assertJsonFragment(['id' => $metrics[1]->id]);
$this->assertResponseOk(); $response->assertJsonFragment(['id' => $metrics[2]->id]);
$response->assertStatus(200);
} }
public function testGetInvalidMetric() public function test_cannot_get_invalid_metric()
{ {
$this->get('/api/v1/metrics/0'); $response = $this->json('GET', '/api/v1/metrics/0');
$this->assertResponseStatus(404); $response->assertStatus(404);
} }
public function testPostMetricUnauthorized() public function test_cannot_create_metric_without_authorization()
{ {
$this->post('/api/v1/metrics'); $response = $this->json('POST', '/api/v1/metrics');
$this->assertResponseStatus(401); $response->assertStatus(401);
} }
public function testPostMetricNoData() public function test_cannot_create_metric_without_data()
{ {
$this->beUser(); $this->beUser();
$this->post('/api/v1/metrics'); $response = $this->json('POST', '/api/v1/metrics');
$this->assertResponseStatus(400); $response->assertStatus(400);
} }
public function testPostMetric() public function test_can_create_metric()
{ {
$this->beUser(); $this->beUser();
$this->post('/api/v1/metrics', [ $response = $this->json('POST', '/api/v1/metrics', [
'name' => 'Foo', 'name' => 'Foo',
'suffix' => 'foo\'s per second', 'suffix' => 'foo\'s per second',
'description' => 'Lorem ipsum dolor', 'description' => 'Lorem ipsum dolor',
@@ -65,38 +68,42 @@ class MetricTest extends AbstractApiTestCase
'threshold' => 5, 'threshold' => 5,
'order' => 1, 'order' => 1,
]); ]);
$this->seeJsonContains(['name' => 'Foo']);
$this->assertResponseOk(); $response->assertStatus(200);
$response->assertJsonFragment(['name' => 'Foo']);
} }
public function testGetNewMetric() public function test_can_get_newly_created_metric()
{ {
$incident = factory('CachetHQ\Cachet\Models\Metric')->create(); $incident = factory(Metric::class)->create();
$this->get('/api/v1/metrics/1'); $response = $this->json('GET', '/api/v1/metrics/1');
$this->seeJsonContains(['name' => $incident->name]);
$this->assertResponseOk(); $response->assertStatus(200);
$response->assertJsonFragment(['name' => $incident->name]);
} }
public function testPutMetric() public function test_can_update_metric()
{ {
$this->beUser(); $this->beUser();
$metric = factory('CachetHQ\Cachet\Models\Metric')->create(); $metric = factory(Metric::class)->create();
$this->put('/api/v1/metrics/1', [ $response = $this->json('PUT', '/api/v1/metrics/1', [
'name' => 'Foo', 'name' => 'Foo',
'view' => 2, 'view' => 2,
]); ]);
$this->seeJsonContains(['name' => 'Foo', 'default_view' => 2]);
$this->assertResponseOk(); $response->assertStatus(200);
$response->assertJsonFragment(['name' => 'Foo', 'default_view' => 2]);
} }
public function testDeleteMetric() public function test_can_delete_metric()
{ {
$this->beUser(); $this->beUser();
$metric = factory('CachetHQ\Cachet\Models\Metric')->create(); $metric = factory(Metric::class)->create();
$this->delete('/api/v1/metrics/1'); $response = $this->json('DELETE', '/api/v1/metrics/1');
$this->assertResponseStatus(204);
$response->assertStatus(204);
} }
} }

View File

@@ -11,6 +11,8 @@
namespace CachetHQ\Tests\Cachet\Api; namespace CachetHQ\Tests\Cachet\Api;
use CachetHQ\Cachet\Models\Schedule;
/** /**
* This is the schedule test class. * This is the schedule test class.
* *
@@ -18,31 +20,29 @@ namespace CachetHQ\Tests\Cachet\Api;
*/ */
class ScheduleTest extends AbstractApiTestCase class ScheduleTest extends AbstractApiTestCase
{ {
public function testGetSchedules() public function test_can_get_all_schedules()
{ {
$schedules = factory('CachetHQ\Cachet\Models\Schedule', 3)->create(); $schedules = factory(Schedule::class, 3)->create();
$this->get('/api/v1/schedules'); $response = $this->json('GET', '/api/v1/schedules');
$this->assertResponseOk(); $response->assertStatus(200);
$response->assertJsonFragment(['id' => $schedules[0]->id]);
$this->seeJsonContains(['id' => $schedules[0]->id]); $response->assertJsonFragment(['id' => $schedules[1]->id]);
$this->seeJsonContains(['id' => $schedules[1]->id]); $response->assertJsonFragment(['id' => $schedules[2]->id]);
$this->seeJsonContains(['id' => $schedules[2]->id]);
} }
public function testGetSchedule() public function test_can_get_single_schedule()
{ {
$schedule = factory('CachetHQ\Cachet\Models\Schedule')->create(); $schedule = factory(Schedule::class)->create();
$this->get('/api/v1/schedules/'.$schedule->id); $response = $this->json('GET', '/api/v1/schedules/'.$schedule->id);
$this->assertResponseOk(); $response->assertStatus(200);
$response->assertJsonFragment(['name' => $schedule->name]);
$this->seeJsonContains(['name' => $schedule->name]);
} }
public function testCreateSchedule() public function test_can_create_schedule()
{ {
$this->beUser(); $this->beUser();
@@ -53,36 +53,35 @@ class ScheduleTest extends AbstractApiTestCase
'scheduled_at' => date('Y-m-d H:i'), 'scheduled_at' => date('Y-m-d H:i'),
]; ];
$this->post('/api/v1/schedules/', $schedule); $response = $this->json('POST', '/api/v1/schedules/', $schedule);
array_forget($schedule, 'scheduled_at'); array_forget($schedule, 'scheduled_at');
$this->assertResponseOk(); $response->assertStatus(200);
$this->seeJsonContains($schedule); $response->assertJsonFragment($schedule);
} }
public function testUpdateSchedule() public function test_can_update_schedule()
{ {
$this->beUser(); $this->beUser();
$schedule = factory('CachetHQ\Cachet\Models\Schedule')->create(); $schedule = factory(Schedule::class)->create();
$this->put('/api/v1/schedules/'.$schedule->id, [ $response = $this->json('PUT', '/api/v1/schedules/'.$schedule->id, [
'name' => 'Updated schedule', 'name' => 'Updated schedule',
]); ]);
$this->assertResponseOk(); $response->assertStatus(200);
$response->assertJsonFragment(['name' => 'Updated schedule']);
$this->seeJsonContains(['name' => 'Updated schedule']);
} }
public function testDeleteSchedule() public function test_can_delete_schedule()
{ {
$this->beUser(); $this->beUser();
factory('CachetHQ\Cachet\Models\Schedule')->create(); factory(Schedule::class)->create();
$this->delete('/api/v1/schedules/1'); $response = $this->json('DELETE', '/api/v1/schedules/1');
$this->assertResponseStatus(204); $response->assertStatus(204);
} }
} }

View File

@@ -11,6 +11,10 @@
namespace CachetHQ\Tests\Cachet\Api; namespace CachetHQ\Tests\Cachet\Api;
use CachetHQ\Cachet\Bus\Events\Subscriber\SubscriberHasSubscribedEvent;
use CachetHQ\Cachet\Models\Component;
use CachetHQ\Cachet\Models\Subscriber;
use CachetHQ\Cachet\Models\Subscription;
use Illuminate\Support\Facades\Notification; use Illuminate\Support\Facades\Notification;
/** /**
@@ -21,97 +25,104 @@ use Illuminate\Support\Facades\Notification;
*/ */
class SubscriberTest extends AbstractApiTestCase class SubscriberTest extends AbstractApiTestCase
{ {
public function testGetSubscribersUnauthenticated() public function test_can_get_all_subscribers()
{
$this->get('/api/v1/subscribers');
$this->assertResponseStatus(401);
$this->seeHeader('Content-Type', 'application/json');
}
public function testGetSubscribers()
{ {
$this->beUser(); $this->beUser();
$subscriber = factory('CachetHQ\Cachet\Models\Subscriber')->create(); $subscriber = factory(Subscriber::class)->create();
$this->get('/api/v1/subscribers'); $response = $this->json('GET', '/api/v1/subscribers');
$this->seeHeader('Content-Type', 'application/json');
$this->assertResponseOk(); $response->assertStatus(200);
$response->assertHeader('Content-Type', 'application/json');
} }
public function testCreateSubscriber() public function test_cannot_get_subscribers_without_authorization()
{
$response = $this->json('GET', '/api/v1/subscribers');
$response->assertStatus(401);
$response->assertHeader('Content-Type', 'application/json');
}
public function test_can_create_subscriber()
{ {
$this->beUser(); $this->beUser();
Notification::fake(); Notification::fake();
$this->expectsEvents('CachetHQ\Cachet\Bus\Events\Subscriber\SubscriberHasSubscribedEvent'); $this->expectsEvents(SubscriberHasSubscribedEvent::class);
$this->post('/api/v1/subscribers', [ $response = $this->json('POST', '/api/v1/subscribers', [
'email' => 'support@alt-three.com', 'email' => 'support@alt-three.com',
]); ]);
$this->assertResponseOk();
$this->seeHeader('Content-Type', 'application/json'); $response->assertStatus(200);
$this->seeJsonContains(['email' => 'support@alt-three.com']); $response->assertHeader('Content-Type', 'application/json');
$response->assertJsonFragment(['email' => 'support@alt-three.com']);
} }
public function testCreateSubscriberAutoVerified() public function test_can_create_subscriber_automatically_verified()
{ {
$this->beUser(); $this->beUser();
Notification::fake(); Notification::fake();
$this->expectsEvents('CachetHQ\Cachet\Bus\Events\Subscriber\SubscriberHasSubscribedEvent'); $this->expectsEvents(SubscriberHasSubscribedEvent::class);
$this->post('/api/v1/subscribers', [ $response = $this->json('POST', '/api/v1/subscribers', [
'email' => 'support@alt-three.com', 'email' => 'support@alt-three.com',
'verify' => true, 'verify' => true,
]); ]);
$this->assertResponseOk();
$this->seeHeader('Content-Type', 'application/json'); $response->assertStatus(200);
$this->seeJsonContains(['email' => 'support@alt-three.com']); $response->assertHeader('Content-Type', 'application/json');
$response->assertJsonFragment(['email' => 'support@alt-three.com']);
} }
public function testCreateSubscriberWithSubscriptions() public function test_can_create_subscriber_with_subscription()
{ {
$this->beUser(); $this->beUser();
factory('CachetHQ\Cachet\Models\Component', 3)->create(); factory(Component::class, 3)->create();
$this->post('/api/v1/subscribers', [ $response = $this->json('POST', '/api/v1/subscribers', [
'email' => 'support@alt-three.com', 'email' => 'support@alt-three.com',
'verify' => true, 'verify' => true,
'components' => [ 'components' => [
1, 1,
3, 3,
], ],
]); ]);
$this->assertResponseOk();
$this->seeHeader('Content-Type', 'application/json');
$this->seeJsonContains(['email' => 'support@alt-three.com']);
$this->seeJsonStructure(['data' => ['subscriptions' => []]]);
$data = $this->decodeResponseJson(); $response->assertStatus(200);
$response->assertHeader('Content-Type', 'application/json');
$response->assertJsonFragment(['email' => 'support@alt-three.com']);
$data = $response->decodeResponseJson();
$this->assertCount(2, $data['data']['subscriptions']); $this->assertCount(2, $data['data']['subscriptions']);
$this->assertEquals(1, $data['data']['subscriptions'][0]['component_id']); $this->assertEquals(1, $data['data']['subscriptions'][0]['component_id']);
$this->assertEquals(3, $data['data']['subscriptions'][1]['component_id']); $this->assertEquals(3, $data['data']['subscriptions'][1]['component_id']);
} }
public function testDeleteSubscriber() public function test_can_delete_subscriber()
{ {
$this->beUser(); $this->beUser();
$subscriber = factory('CachetHQ\Cachet\Models\Subscriber')->create(); $subscriber = factory(Subscriber::class)->create();
$this->delete("/api/v1/subscribers/{$subscriber->id}"); $response = $this->json('DELETE', "/api/v1/subscribers/{$subscriber->id}");
$this->assertResponseStatus(204);
$response->assertStatus(204);
} }
public function testDeleteSubscription() public function test_can_delete_subscription()
{ {
$this->beUser(); $this->beUser();
$subscription = factory('CachetHQ\Cachet\Models\Subscription')->create(); $subscription = factory(Subscription::class)->create();
$this->delete("/api/v1/subscriptions/{$subscription->id}");
$this->assertResponseStatus(204); $response = $this->json('DELETE', "/api/v1/subscriptions/{$subscription->id}");
$response->assertStatus(204);
} }
} }