--- /dev/null
+<?php
+
+namespace App\Test\TestCase\Controller\Api\V1;
+
+use App\Test\TestCase\Controller\Api\V1\ApiIntegrationTestCase;
+
+/**
+ * App\Controller\SubscriptionsController Test Case
+ */
+class SubscriptionsControllerTest extends ApiIntegrationTestCase {
+
+ /**
+ * Fixtures
+ *
+ * @var array
+ */
+ public $fixtures = [
+ 'app.subscriptions',
+ 'app.subscriptions_services',
+ 'app.services',
+ ];
+ public $autoFixtures = false;
+
+ public function testWhenGettingAllSubscriptions() {
+ $this->loadFixtures('Subscriptions');
+ $this->iSendAGetRequestTo('/subscriptions.json');
+ $this->theResponseCodeShouldBe(200);
+
+ $expected = [
+ 'subscriptions' => [
+ [
+ 'id' => 1, 'name' => 'ACTES/HELIOS'
+ ],
+ [
+ 'id' => 2, 'name' => 'SIGNATURE'
+ ]
+ ],
+ 'pagination' => [
+ 'page_count' => 1,
+ 'current_page' => 1,
+ 'has_next_page' => FALSE,
+ 'has_prev_page' => FALSE,
+ 'count' => 2,
+ 'limit' => null
+ ]
+ ];
+ $expectedBody = $this->getExpectedValue($expected);
+ $this->theResponseBodyShouldBe($expectedBody);
+ }
+
+ public function testWhenGettingNoSubscription() {
+ $this->iSendAGetRequestTo('/subscriptions.json');
+ $this->theResponseCodeShouldBe(200);
+
+ $expected = [
+ 'subscriptions' => [],
+ 'pagination' => [
+ 'page_count' => 0,
+ 'current_page' => 1,
+ 'has_next_page' => FALSE,
+ 'has_prev_page' => FALSE,
+ 'count' => 0,
+ 'limit' => null
+ ]
+ ];
+ $expectedBody = $this->getExpectedValue($expected);
+
+ $this->theResponseBodyShouldBe($expectedBody);
+ }
+
+ public function testWhenGettingASubscription() {
+ $this->loadFixtures('Subscriptions', 'Services', 'SubscriptionsServices');
+ $this->iSendAGetRequestTo('/subscriptions/2.json');
+ $this->theResponseCodeShouldBe(200);
+
+ $expected = [
+ 'id' => 2,
+ 'name' => 'SIGNATURE',
+ 'services' => [
+ [
+ 'id' => 4,
+ 'name' => 'signature',
+ 'connector_id' => 2
+ ]
+ ]
+ ];
+ $expectedBody = $this->getExpectedValue($expected);
+
+ $this->theResponseBodyShouldBe($expectedBody);
+ }
+
+ public function testWhenDeletingASubscription() {
+ $this->loadFixtures('Subscriptions');
+ $this->iSendADeleteRequestTo('/subscriptions/1.json');
+ $this->theResponseCodeShouldBe(204);
+ }
+
+ public function testWhenDeletingASubscriptionThatDoesNotExist() {
+ $this->loadFixtures('Subscriptions');
+ $this->iSendADeleteRequestTo('/subscriptions/4.json');
+ $this->theResponseCodeShouldBe(404);
+
+ $expected = [
+ 'message' => 'The subscription with the id 4 does not exist',
+ 'url' => '/api/v1/subscriptions/4.json',
+ 'code' => 404
+ ];
+
+ $expectedBody = $this->getExpectedValue($expected);
+
+ $this->theResponseBodyShouldBe($expectedBody);
+ }
+
+ public function testWhenAddingASubscription() {
+ $data = [
+ 'name' => 'test'
+ ];
+ $this->givenIHaveSomeDataToSend($data);
+ $this->iSendAPostRequestTo('/subscriptions.json');
+ }
+
+}