From d8553faa4939889fa7b7ef7329aa474a81cbbdb9 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 23 Nov 2017 14:37:00 +0100 Subject: [PATCH] Better follows tests --- .../lib/activitypub/process/process-undo.ts | 8 +-- server/lib/activitypub/send/send-undo.ts | 11 ++-- server/tests/api/follows.ts | 65 ++++++++++++++++++- server/tests/api/multiple-servers.ts | 2 +- 4 files changed, 74 insertions(+), 12 deletions(-) diff --git a/server/lib/activitypub/process/process-undo.ts b/server/lib/activitypub/process/process-undo.ts index caa835714..9fe066c01 100644 --- a/server/lib/activitypub/process/process-undo.ts +++ b/server/lib/activitypub/process/process-undo.ts @@ -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 diff --git a/server/lib/activitypub/send/send-undo.ts b/server/lib/activitypub/send/send-undo.ts index 53fddd0cb..8f46a051e 100644 --- a/server/lib/activitypub/send/send-undo.ts +++ b/server/lib/activitypub/send/send-undo.ts @@ -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 { broadcastToFollowers, getAccountsToForwardVideoAction, unicastTo } from './misc' -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 { getAccountFollowActivityPubUrl, getUndoActivityPubUrl, getVideoDislikeActivityPubUrl, getVideoLikeActivityPubUrl } from '../url' +import { broadcastToFollowers, getAccountsToForwardVideoAction, unicastTo } from './misc' import { createActivityData, createDislikeActivityData } from './send-create' -import { getServerAccount } from '../../../helpers/utils' +import { followActivityData } from './send-follow' +import { likeActivityData } from './send-like' 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 { diff --git a/server/tests/api/follows.ts b/server/tests/api/follows.ts index 875d814a7..aadae3cce 100644 --- a/server/tests/api/follows.ts +++ b/server/tests/api/follows.ts @@ -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 () { diff --git a/server/tests/api/multiple-servers.ts b/server/tests/api/multiple-servers.ts index 405dcf625..601e5f39a 100644 --- a/server/tests/api/multiple-servers.ts +++ b/server/tests/api/multiple-servers.ts @@ -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) {