From 99492dbc0d87ef54d0dab7d8d44f8d0de5722bdd Mon Sep 17 00:00:00 2001
From: Chocobozzz <me@florianbigard.com>
Date: Tue, 21 Aug 2018 10:34:18 +0200
Subject: Add get subscription endpoint

---
 .../tests/api/check-params/user-subscriptions.ts   | 59 ++++++++++++++++++++--
 server/tests/api/users/user-subscriptions.ts       | 27 +++++++++-
 2 files changed, 81 insertions(+), 5 deletions(-)

(limited to 'server/tests/api')

diff --git a/server/tests/api/check-params/user-subscriptions.ts b/server/tests/api/check-params/user-subscriptions.ts
index 628a74476..6a6dd9a6f 100644
--- a/server/tests/api/check-params/user-subscriptions.ts
+++ b/server/tests/api/check-params/user-subscriptions.ts
@@ -61,7 +61,7 @@ describe('Test user subscriptions API validators', function () {
       })
     })
 
-    it('Should success with the correct parameters', async function () {
+    it('Should succeed with the correct parameters', async function () {
       await makeGetRequest({
         url: server.url,
         path,
@@ -94,7 +94,7 @@ describe('Test user subscriptions API validators', function () {
       })
     })
 
-    it('Should success with the correct parameters', async function () {
+    it('Should succeed with the correct parameters', async function () {
       await makeGetRequest({
         url: server.url,
         path,
@@ -140,7 +140,7 @@ describe('Test user subscriptions API validators', function () {
       })
     })
 
-    it('Should success with the correct parameters', async function () {
+    it('Should succeed with the correct parameters', async function () {
       await makePostBodyRequest({
         url: server.url,
         path,
@@ -151,6 +151,57 @@ describe('Test user subscriptions API validators', function () {
     })
   })
 
+  describe('When getting a subscription', function () {
+    it('Should fail with a non authenticated user', async function () {
+      await makeGetRequest({
+        url: server.url,
+        path: path + '/user1_channel@localhost:9001',
+        statusCodeExpected: 401
+      })
+    })
+
+    it('Should fail with bad URIs', async function () {
+      await makeGetRequest({
+        url: server.url,
+        path: path + '/root',
+        token: server.accessToken,
+        statusCodeExpected: 400
+      })
+
+      await makeGetRequest({
+        url: server.url,
+        path: path + '/root@',
+        token: server.accessToken,
+        statusCodeExpected: 400
+      })
+
+      await makeGetRequest({
+        url: server.url,
+        path: path + '/root@hello@',
+        token: server.accessToken,
+        statusCodeExpected: 400
+      })
+    })
+
+    it('Should fail with an unknown subscription', async function () {
+      await makeGetRequest({
+        url: server.url,
+        path: path + '/root1@localhost:9001',
+        token: server.accessToken,
+        statusCodeExpected: 404
+      })
+    })
+
+    it('Should succeed with the correct parameters', async function () {
+      await makeGetRequest({
+        url: server.url,
+        path: path + '/user1_channel@localhost:9001',
+        token: server.accessToken,
+        statusCodeExpected: 200
+      })
+    })
+  })
+
   describe('When removing a subscription', function () {
     it('Should fail with a non authenticated user', async function () {
       await makeDeleteRequest({
@@ -192,7 +243,7 @@ describe('Test user subscriptions API validators', function () {
       })
     })
 
-    it('Should success with the correct parameters', async function () {
+    it('Should succeed with the correct parameters', async function () {
       await makeDeleteRequest({
         url: server.url,
         path: path + '/user1_channel@localhost:9001',
diff --git a/server/tests/api/users/user-subscriptions.ts b/server/tests/api/users/user-subscriptions.ts
index ba59a9a60..2fbda6828 100644
--- a/server/tests/api/users/user-subscriptions.ts
+++ b/server/tests/api/users/user-subscriptions.ts
@@ -11,7 +11,8 @@ import {
   addUserSubscription,
   listUserSubscriptions,
   listUserSubscriptionVideos,
-  removeUserSubscription
+  removeUserSubscription,
+  getUserSubscription
 } from '../../utils/users/user-subscriptions'
 
 const expect = chai.expect
@@ -101,6 +102,30 @@ describe('Test users subscriptions', function () {
     }
   })
 
+  it('Should get subscription', async function () {
+    {
+      const res = await getUserSubscription(servers[ 0 ].url, users[ 0 ].accessToken, 'user3_channel@localhost:9003')
+      const videoChannel: VideoChannel = res.body
+
+      expect(videoChannel.name).to.equal('user3_channel')
+      expect(videoChannel.host).to.equal('localhost:9003')
+      expect(videoChannel.displayName).to.equal('Main user3 channel')
+      expect(videoChannel.followingCount).to.equal(0)
+      expect(videoChannel.followersCount).to.equal(1)
+    }
+
+    {
+      const res = await getUserSubscription(servers[ 0 ].url, users[ 0 ].accessToken, 'root_channel@localhost:9001')
+      const videoChannel: VideoChannel = res.body
+
+      expect(videoChannel.name).to.equal('root_channel')
+      expect(videoChannel.host).to.equal('localhost:9001')
+      expect(videoChannel.displayName).to.equal('Main root channel')
+      expect(videoChannel.followingCount).to.equal(0)
+      expect(videoChannel.followersCount).to.equal(1)
+    }
+  })
+
   it('Should list subscription videos', async function () {
     {
       const res = await listUserSubscriptionVideos(servers[0].url, servers[0].accessToken)
-- 
cgit v1.2.3