]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/utils/follows.ts
Better view counter
[github/Chocobozzz/PeerTube.git] / server / tests / utils / follows.ts
index b454fe2f8f3a1f303f675cbf585e9a13c60807a7..b88776011e590f4235782b60a806f101062305b1 100644 (file)
@@ -29,7 +29,7 @@ function getFollowingListPaginationAndSort (url: string, start: number, count: n
 }
 
 async function follow (follower: string, following: string[], accessToken: string, expectedStatus = 204) {
-  const path = '/api/v1/server/follow'
+  const path = '/api/v1/server/following'
 
   const followingHosts = following.map(f => f.replace(/^http:\/\//, ''))
   const res = await request(follower)
@@ -39,8 +39,17 @@ async function follow (follower: string, following: string[], accessToken: strin
     .send({ 'hosts': followingHosts })
     .expect(expectedStatus)
 
-  // Wait request propagation
-  await wait(20000)
+  return res
+}
+
+async function unfollow (url: string, accessToken: string, id: number, expectedStatus = 204) {
+  const path = '/api/v1/server/following/' + id
+
+  const res = await request(url)
+    .delete(path)
+    .set('Accept', 'application/json')
+    .set('Authorization', 'Bearer ' + accessToken)
+    .expect(expectedStatus)
 
   return res
 }
@@ -51,6 +60,9 @@ async function doubleFollow (server1: ServerInfo, server2: ServerInfo) {
     follow(server2.url, [ server1.url ], server2.accessToken)
   ])
 
+  // Wait request propagation
+  await wait(20000)
+
   return true
 }
 
@@ -59,6 +71,7 @@ async function doubleFollow (server1: ServerInfo, server2: ServerInfo) {
 export {
   getFollowersListPaginationAndSort,
   getFollowingListPaginationAndSort,
+  unfollow,
   follow,
   doubleFollow
 }