]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Better follows tests
authorChocobozzz <florian.bigard@gmail.com>
Thu, 23 Nov 2017 13:37:00 +0000 (14:37 +0100)
committerChocobozzz <florian.bigard@gmail.com>
Mon, 27 Nov 2017 18:40:53 +0000 (19:40 +0100)
server/lib/activitypub/process/process-undo.ts
server/lib/activitypub/send/send-undo.ts
server/tests/api/follows.ts
server/tests/api/multiple-servers.ts

index caa835714b1f91cdd6913919915d458e715737b7..9fe066c01422fb6ddfd20620f9726ddafe6b6f60 100644 (file)
@@ -1,10 +1,10 @@
-import { ActivityCreate, ActivityFollow, ActivityLike, ActivityUndo } from '../../../../shared/models/activitypub/activity'
+import { ActivityFollow, ActivityLike, ActivityUndo } from '../../../../shared/models/activitypub/activity'
+import { DislikeObject } from '../../../../shared/models/activitypub/objects/dislike-object'
+import { retryTransactionWrapper } from '../../../helpers/database-utils'
 import { logger } from '../../../helpers/logger'
 import { database as db } from '../../../initializers'
-import { retryTransactionWrapper } from '../../../helpers/database-utils'
-import { DislikeObject } from '../../../../shared/models/activitypub/objects/dislike-object'
-import { sendUndoLikeToVideoFollowers } from '../send/send-undo'
 import { sendUndoDislikeToVideoFollowers } from '../index'
+import { sendUndoLikeToVideoFollowers } from '../send/send-undo'
 
 async function processUndoActivity (activity: ActivityUndo) {
   const activityToUndo = activity.object
index 53fddd0cbfb4b8be0d2f161455b2cc6c363e04f7..8f46a051e192f646e64c071ac9b5419a7e3d6695 100644 (file)
@@ -1,14 +1,14 @@
 import { Transaction } from 'sequelize'
 import { ActivityCreate, ActivityFollow, ActivityLike, ActivityUndo } from '../../../../shared/models/activitypub/activity'
+import { getServerAccount } from '../../../helpers/utils'
 import { AccountInstance } from '../../../models'
 import { AccountFollowInstance } from '../../../models/account/account-follow-interface'
+import { VideoInstance } from '../../../models/video/video-interface'
+import { getAccountFollowActivityPubUrl, getUndoActivityPubUrl, getVideoDislikeActivityPubUrl, getVideoLikeActivityPubUrl } from '../url'
 import { broadcastToFollowers, getAccountsToForwardVideoAction, unicastTo } from './misc'
+import { createActivityData, createDislikeActivityData } from './send-create'
 import { followActivityData } from './send-follow'
-import { getAccountFollowActivityPubUrl, getUndoActivityPubUrl, getVideoDislikeActivityPubUrl, getVideoLikeActivityPubUrl } from '../url'
-import { VideoInstance } from '../../../models/video/video-interface'
 import { likeActivityData } from './send-like'
-import { createActivityData, createDislikeActivityData } from './send-create'
-import { getServerAccount } from '../../../helpers/utils'
 
 async function sendUndoFollow (accountFollow: AccountFollowInstance, t: Transaction) {
   const me = accountFollow.AccountFollower
@@ -75,7 +75,6 @@ async function sendUndoDislikeToVideoFollowers (byAccount: AccountInstance, vide
   return broadcastToFollowers(data, serverAccount, accountsToForwardView, t, followersException)
 }
 
-
 // ---------------------------------------------------------------------------
 
 export {
index 875d814a7d2074c50873fba6834720ceda5a7a7c..aadae3cced8187084cdc5fea653d57ff755e757e 100644 (file)
@@ -14,6 +14,10 @@ import {
   wait
 } from '../utils'
 import { follow, getFollowersListPaginationAndSort, getFollowingListPaginationAndSort, unfollow } from '../utils/follows'
+import { getUserAccessToken } from '../utils/login'
+import { dateIsValid, webtorrentAdd } from '../utils/miscs'
+import { createUser } from '../utils/users'
+import { getVideo, rateVideo, testVideoImage } from '../utils/videos'
 
 const expect = chai.expect
 
@@ -166,12 +170,32 @@ describe('Test follows', function () {
   it('Should propagate previous uploaded videos on a new following', async function () {
     this.timeout(20000)
 
+    const video4Attributes = {
+      name: 'server3-4',
+      category: 2,
+      nsfw: true,
+      licence: 6,
+      tags: [ 'tag1', 'tag2', 'tag3' ]
+    }
+
     await uploadVideo(servers[2].url, servers[2].accessToken, { name: 'server3-2' })
     await uploadVideo(servers[2].url, servers[2].accessToken, { name: 'server3-3' })
-    await uploadVideo(servers[2].url, servers[2].accessToken, { name: 'server3-4' })
+    await uploadVideo(servers[2].url, servers[2].accessToken, video4Attributes)
     await uploadVideo(servers[2].url, servers[2].accessToken, { name: 'server3-5' })
     await uploadVideo(servers[2].url, servers[2].accessToken, { name: 'server3-6' })
 
+    {
+      const user = { username: 'captain', password: 'password' }
+      await createUser(servers[2].url, servers[2].accessToken, user.username, user.password)
+      const userAccessToken = await getUserAccessToken(servers[2], user)
+
+      const res = await getVideosList(servers[2].url)
+      const video4 = res.body.data.find(v => v.name === 'server3-4')
+
+      await rateVideo(servers[2].url, servers[2].accessToken, video4.id, 'like')
+      await rateVideo(servers[2].url, userAccessToken, video4.id, 'dislike')
+    }
+
     await wait(5000)
 
     // Server 1 follows server 3
@@ -189,6 +213,45 @@ describe('Test follows', function () {
     expect(video2).to.not.be.undefined
     expect(video4).to.not.be.undefined
     expect(video6).to.not.be.undefined
+
+    const res2 = await getVideo(servers[0].url, video4.id)
+    const videoDetails = res2.body
+
+    expect(videoDetails.name).to.equal('server3-4')
+    expect(videoDetails.category).to.equal(2)
+    expect(videoDetails.categoryLabel).to.equal('Films')
+    expect(videoDetails.licence).to.equal(6)
+    expect(videoDetails.licenceLabel).to.equal('Attribution - Non Commercial - No Derivatives')
+    expect(videoDetails.language).to.equal(3)
+    expect(videoDetails.languageLabel).to.equal('Mandarin')
+    expect(videoDetails.nsfw).to.be.ok
+    expect(videoDetails.description).to.equal('my super description')
+    expect(videoDetails.serverHost).to.equal('localhost:9003')
+    expect(videoDetails.account).to.equal('root')
+    expect(videoDetails.likes).to.equal(1)
+    expect(videoDetails.dislikes).to.equal(1)
+    expect(videoDetails.isLocal).to.be.false
+    expect(videoDetails.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
+    expect(dateIsValid(videoDetails.createdAt)).to.be.true
+    expect(dateIsValid(videoDetails.updatedAt)).to.be.true
+    expect(videoDetails.files).to.have.lengthOf(1)
+
+    const file = videoDetails.files[0]
+    const magnetUri = file.magnetUri
+    expect(file.magnetUri).to.have.lengthOf.above(2)
+    expect(file.torrentUrl).to.equal(`${servers[2].url}/static/torrents/${videoDetails.uuid}-${file.resolution}.torrent`)
+    expect(file.fileUrl).to.equal(`${servers[2].url}/static/webseed/${videoDetails.uuid}-${file.resolution}.webm`)
+    expect(file.resolution).to.equal(720)
+    expect(file.resolutionLabel).to.equal('720p')
+    expect(file.size).to.equal(218910)
+
+    const test = await testVideoImage(servers[2].url, 'video_short.webm', videoDetails.thumbnailPath)
+    expect(test).to.equal(true)
+
+    const torrent = await webtorrentAdd(magnetUri)
+    expect(torrent.files).to.be.an('array')
+    expect(torrent.files.length).to.equal(1)
+    expect(torrent.files[0].path).to.exist.and.to.not.equal('')
   })
 
   after(async function () {
index 405dcf62577fa57adcc528019b202a6e4bfcd49e..601e5f39a10b80e9613f68bc8dd401a1a375ec82 100644 (file)
@@ -175,7 +175,7 @@ describe('Test multiple servers', function () {
       await uploadVideo(servers[1].url, userAccessToken, videoAttributes)
 
       // Transcoding
-      await wait(15000)
+      await wait(25000)
 
       // All servers should have this video
       for (const server of servers) {