]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/api/check-params/user-subscriptions.ts
Add migrations
[github/Chocobozzz/PeerTube.git] / server / tests / api / check-params / user-subscriptions.ts
index 628a744760bb1f93e6f6dbccda6d240685aeb3bd..d33b3bca6374a8a414aed35f3d6b2c3a085ab34a 100644 (file)
@@ -13,8 +13,14 @@ import {
   ServerInfo,
   setAccessTokensToServers,
   userLogin
-} from '../../utils'
-import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params'
+} from '../../../../shared/extra-utils'
+
+import {
+  checkBadCountPagination,
+  checkBadSortPagination,
+  checkBadStartPagination
+} from '../../../../shared/extra-utils/requests/check-api-params'
+import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
 
 describe('Test user subscriptions API validators', function () {
   const path = '/api/v1/users/me/subscriptions'
@@ -36,7 +42,7 @@ describe('Test user subscriptions API validators', function () {
       username: 'user1',
       password: 'my super password'
     }
-    await createUser(server.url, server.accessToken, user.username, user.password)
+    await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
     userAccessToken = await userLogin(server, user)
   })
 
@@ -61,7 +67,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 +100,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 +146,9 @@ 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 () {
+      this.timeout(20000)
+
       await makePostBodyRequest({
         url: server.url,
         path,
@@ -148,6 +156,99 @@ describe('Test user subscriptions API validators', function () {
         fields: { uri: 'user1_channel@localhost:9001' },
         statusCodeExpected: 204
       })
+
+      await waitJobs([ server ])
+    })
+  })
+
+  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 checking if subscriptions exist', function () {
+    const existPath = path + '/exist'
+
+    it('Should fail with a non authenticated user', async function () {
+      await makeGetRequest({
+        url: server.url,
+        path: existPath,
+        statusCodeExpected: 401
+      })
+    })
+
+    it('Should fail with bad URIs', async function () {
+      await makeGetRequest({
+        url: server.url,
+        path: existPath,
+        query: { uris: 'toto' },
+        token: server.accessToken,
+        statusCodeExpected: 400
+      })
+
+      await makeGetRequest({
+        url: server.url,
+        path: existPath,
+        query: { 'uris[]': 1 },
+        token: server.accessToken,
+        statusCodeExpected: 400
+      })
+    })
+
+    it('Should succeed with the correct parameters', async function () {
+      await makeGetRequest({
+        url: server.url,
+        path: existPath,
+        query: { 'uris[]': 'coucou@localhost:9001' },
+        token: server.accessToken,
+        statusCodeExpected: 200
+      })
     })
   })
 
@@ -192,7 +293,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',