2015-06-01 21:32:02 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of Cachet.
|
|
|
|
*
|
2015-07-06 17:37:01 +01:00
|
|
|
* (c) Alt Three Services Limited
|
2015-06-01 21:32:02 +01:00
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace CachetHQ\Tests\Cachet\Api;
|
|
|
|
|
2015-12-06 11:04:02 +00:00
|
|
|
/**
|
|
|
|
* This is the incident test class.
|
|
|
|
*
|
|
|
|
* @author James Brooks <james@alt-three.com>
|
|
|
|
* @author Graham Campbell <graham@alt-three.com>
|
|
|
|
*/
|
|
|
|
class IncidentTest extends AbstractApiTestCase
|
2015-06-01 21:32:02 +01:00
|
|
|
{
|
|
|
|
public function testGetIncidents()
|
|
|
|
{
|
2015-05-23 19:09:24 +01:00
|
|
|
$incidents = factory('CachetHQ\Cachet\Models\Incident', 3)->create();
|
|
|
|
|
2015-06-03 08:28:48 +01:00
|
|
|
$this->get('/api/v1/incidents');
|
2017-06-24 18:52:55 +01:00
|
|
|
$this->seeJsonContains(['id' => $incidents[0]->id]);
|
|
|
|
$this->seeJsonContains(['id' => $incidents[1]->id]);
|
|
|
|
$this->seeJsonContains(['id' => $incidents[2]->id]);
|
2015-06-03 08:28:48 +01:00
|
|
|
$this->assertResponseOk();
|
2015-06-01 21:32:02 +01:00
|
|
|
}
|
2015-06-02 14:19:24 +01:00
|
|
|
|
|
|
|
public function testGetInvalidIncident()
|
|
|
|
{
|
2015-05-23 19:09:24 +01:00
|
|
|
$this->get('/api/v1/incidents/0');
|
2015-06-02 14:19:24 +01:00
|
|
|
$this->assertResponseStatus(404);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testPostIncidentUnauthorized()
|
|
|
|
{
|
|
|
|
$this->post('/api/v1/incidents');
|
|
|
|
$this->assertResponseStatus(401);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testPostIncidentNoData()
|
|
|
|
{
|
|
|
|
$this->beUser();
|
|
|
|
|
|
|
|
$this->post('/api/v1/incidents');
|
|
|
|
$this->assertResponseStatus(400);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testPostIncident()
|
|
|
|
{
|
|
|
|
$this->beUser();
|
|
|
|
|
|
|
|
$this->post('/api/v1/incidents', [
|
2016-08-17 01:12:21 +02:00
|
|
|
'name' => 'Foo',
|
|
|
|
'message' => 'Lorem ipsum dolor sit amet',
|
|
|
|
'status' => 1,
|
|
|
|
'visible' => 1,
|
|
|
|
'stickied' => false,
|
2015-06-02 14:19:24 +01:00
|
|
|
]);
|
2017-06-24 18:52:55 +01:00
|
|
|
$this->seeJsonContains(['name' => 'Foo']);
|
2015-06-03 08:28:48 +01:00
|
|
|
$this->assertResponseOk();
|
2015-06-02 14:19:24 +01:00
|
|
|
}
|
2015-06-02 19:48:09 +01:00
|
|
|
|
2016-01-29 16:42:04 +00:00
|
|
|
public function testPostIncidentWithComponentStatus()
|
|
|
|
{
|
|
|
|
$component = factory('CachetHQ\Cachet\Models\Component')->create();
|
|
|
|
|
|
|
|
$this->beUser();
|
|
|
|
|
|
|
|
$this->post('/api/v1/incidents', [
|
|
|
|
'name' => 'Foo',
|
|
|
|
'message' => 'Lorem ipsum dolor sit amet',
|
|
|
|
'status' => 1,
|
|
|
|
'component_id' => $component->id,
|
|
|
|
'component_status' => 1,
|
|
|
|
'visible' => 1,
|
2016-08-17 01:12:21 +02:00
|
|
|
'stickied' => false,
|
2016-01-29 16:42:04 +00:00
|
|
|
]);
|
2017-06-24 18:52:55 +01:00
|
|
|
$this->seeJsonContains(['name' => 'Foo']);
|
2016-01-29 16:42:04 +00:00
|
|
|
$this->assertResponseOk();
|
|
|
|
}
|
|
|
|
|
2015-11-12 14:55:25 +00:00
|
|
|
public function testCreateIncidentWithTemplate()
|
|
|
|
{
|
|
|
|
$template = factory('CachetHQ\Cachet\Models\IncidentTemplate')->create();
|
|
|
|
$this->beUser();
|
|
|
|
|
|
|
|
$this->post('/api/v1/incidents', [
|
|
|
|
'name' => 'Foo',
|
|
|
|
'status' => 1,
|
|
|
|
'visible' => 1,
|
2016-08-17 01:12:21 +02:00
|
|
|
'stickied' => false,
|
2015-11-12 14:55:25 +00:00
|
|
|
'template' => $template->slug,
|
|
|
|
'vars' => [
|
|
|
|
'name' => 'Foo',
|
|
|
|
'message' => 'Hello there this is a foo!',
|
|
|
|
],
|
|
|
|
]);
|
2017-06-24 18:52:55 +01:00
|
|
|
$this->seeJsonContains([
|
2015-11-12 14:55:25 +00:00
|
|
|
'name' => 'Foo',
|
|
|
|
'message' => "Name: Foo,\nMessage: Hello there this is a foo!",
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2015-06-02 19:48:09 +01:00
|
|
|
public function testGetNewIncident()
|
|
|
|
{
|
|
|
|
$incident = factory('CachetHQ\Cachet\Models\Incident')->create();
|
|
|
|
|
|
|
|
$this->get('/api/v1/incidents/1');
|
2017-06-24 18:52:55 +01:00
|
|
|
$this->seeJsonContains(['name' => $incident->name]);
|
2015-06-03 08:28:48 +01:00
|
|
|
$this->assertResponseOk();
|
2015-06-02 19:48:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testPutIncident()
|
|
|
|
{
|
|
|
|
$this->beUser();
|
|
|
|
$component = factory('CachetHQ\Cachet\Models\Incident')->create();
|
|
|
|
|
|
|
|
$this->put('/api/v1/incidents/1', [
|
|
|
|
'name' => 'Foo',
|
|
|
|
]);
|
2017-06-24 18:52:55 +01:00
|
|
|
$this->seeJsonContains(['name' => 'Foo']);
|
2015-06-03 08:28:48 +01:00
|
|
|
$this->assertResponseOk();
|
2015-06-02 19:48:09 +01:00
|
|
|
}
|
|
|
|
|
2015-11-12 14:55:25 +00:00
|
|
|
public function testPutIncidentWithTemplate()
|
|
|
|
{
|
|
|
|
$this->beUser();
|
2016-10-14 08:03:19 +01:00
|
|
|
$template = factory('CachetHQ\Cachet\Models\IncidentTemplate')->create([
|
|
|
|
'template' => 'Hello there this is a foo in my {{ incident.name }}!',
|
|
|
|
]);
|
2015-11-12 14:55:25 +00:00
|
|
|
$component = factory('CachetHQ\Cachet\Models\Incident')->create();
|
|
|
|
|
|
|
|
$this->put('/api/v1/incidents/1', [
|
|
|
|
'name' => 'Foo',
|
|
|
|
'template' => $template->slug,
|
|
|
|
]);
|
2017-06-24 18:52:55 +01:00
|
|
|
$this->seeJsonContains([
|
2015-11-12 14:55:25 +00:00
|
|
|
'name' => 'Foo',
|
2016-10-14 08:03:19 +01:00
|
|
|
'message' => 'Hello there this is a foo in my Foo!',
|
2015-11-12 14:55:25 +00:00
|
|
|
]);
|
|
|
|
$this->assertResponseOk();
|
|
|
|
}
|
|
|
|
|
2015-06-02 19:48:09 +01:00
|
|
|
public function testDeleteIncident()
|
|
|
|
{
|
|
|
|
$this->beUser();
|
|
|
|
$component = factory('CachetHQ\Cachet\Models\Incident')->create();
|
|
|
|
|
|
|
|
$this->delete('/api/v1/incidents/1');
|
|
|
|
$this->assertResponseStatus(204);
|
|
|
|
}
|
2017-06-13 19:34:50 +01:00
|
|
|
|
|
|
|
public function testCreateIncidentWithMeta()
|
|
|
|
{
|
|
|
|
$this->beUser();
|
|
|
|
|
|
|
|
$this->post('/api/v1/incidents', [
|
|
|
|
'name' => 'Foo',
|
|
|
|
'message' => 'Lorem ipsum dolor sit amet',
|
|
|
|
'status' => 1,
|
|
|
|
'meta' => [
|
|
|
|
'id' => 123456789,
|
|
|
|
],
|
|
|
|
]);
|
2017-06-24 18:52:55 +01:00
|
|
|
$this->seeJsonContains([
|
2017-06-13 19:34:50 +01:00
|
|
|
'meta' => [
|
|
|
|
'id' => 123456789,
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
$this->assertResponseOk();
|
|
|
|
}
|
2015-06-01 21:32:02 +01:00
|
|
|
}
|