From 12edc1495a36b2199f1bf1ba37f50c7b694be382 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 9 Jul 2021 14:15:11 +0200 Subject: Introduce comments command --- server/tests/api/activitypub/cleaner.ts | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'server/tests/api/activitypub/cleaner.ts') diff --git a/server/tests/api/activitypub/cleaner.ts b/server/tests/api/activitypub/cleaner.ts index 75ef56ce3..27f17b4d6 100644 --- a/server/tests/api/activitypub/cleaner.ts +++ b/server/tests/api/activitypub/cleaner.ts @@ -7,16 +7,19 @@ import { closeAllSequelize, deleteAll, doubleFollow, + flushAndRunMultipleServers, getCount, + getVideo, + rateVideo, selectQuery, + ServerInfo, + setAccessTokensToServers, setVideoField, updateQuery, - wait -} from '../../../../shared/extra-utils' -import { flushAndRunMultipleServers, ServerInfo, setAccessTokensToServers } from '../../../../shared/extra-utils/index' -import { waitJobs } from '../../../../shared/extra-utils/server/jobs' -import { addVideoCommentThread, getVideoCommentThreads } from '../../../../shared/extra-utils/videos/video-comments' -import { getVideo, rateVideo, uploadVideoAndGetId } from '../../../../shared/extra-utils/videos/videos' + uploadVideoAndGetId, + wait, + waitJobs +} from '@shared/extra-utils' const expect = chai.expect @@ -63,7 +66,7 @@ describe('Test AP cleaner', function () { for (const server of servers) { for (const uuid of videoUUIDs) { await rateVideo(server.url, server.accessToken, uuid, 'like') - await addVideoCommentThread(server.url, server.accessToken, uuid, 'comment') + await server.commentsCommand.createThread({ videoId: uuid, text: 'comment' }) } } @@ -172,8 +175,8 @@ describe('Test AP cleaner', function () { this.timeout(20000) { - const res = await getVideoCommentThreads(servers[0].url, videoUUID1, 0, 5) - expect(res.body.total).to.equal(3) + const { total } = await servers[0].commentsCommand.listThreads({ videoId: videoUUID1 }) + expect(total).to.equal(3) } await deleteAll(servers[2].internalServerNumber, 'videoComment') @@ -182,8 +185,8 @@ describe('Test AP cleaner', function () { await waitJobs(servers) { - const res = await getVideoCommentThreads(servers[0].url, videoUUID1, 0, 5) - expect(res.body.total).to.equal(2) + const { total } = await servers[0].commentsCommand.listThreads({ videoId: videoUUID1 }) + expect(total).to.equal(2) } }) -- cgit v1.2.3 From 9293139fde7091e9badcafa9b570b83cea9a10ad Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 9 Jul 2021 15:37:43 +0200 Subject: Introduce sql command --- server/tests/api/activitypub/cleaner.ts | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) (limited to 'server/tests/api/activitypub/cleaner.ts') diff --git a/server/tests/api/activitypub/cleaner.ts b/server/tests/api/activitypub/cleaner.ts index 27f17b4d6..5b08880bf 100644 --- a/server/tests/api/activitypub/cleaner.ts +++ b/server/tests/api/activitypub/cleaner.ts @@ -4,18 +4,12 @@ import 'mocha' import * as chai from 'chai' import { cleanupTests, - closeAllSequelize, - deleteAll, doubleFollow, flushAndRunMultipleServers, - getCount, getVideo, rateVideo, - selectQuery, ServerInfo, setAccessTokensToServers, - setVideoField, - updateQuery, uploadVideoAndGetId, wait, waitJobs @@ -86,9 +80,9 @@ describe('Test AP cleaner', function () { it('Should destroy server 3 internal likes and correctly clean them', async function () { this.timeout(20000) - await deleteAll(servers[2].internalServerNumber, 'accountVideoRate') + await servers[2].sqlCommand.deleteAll('accountVideoRate') for (const uuid of videoUUIDs) { - await setVideoField(servers[2].internalServerNumber, uuid, 'likes', '0') + await servers[2].sqlCommand.setVideoField(uuid, 'likes', '0') } await wait(5000) @@ -132,10 +126,10 @@ describe('Test AP cleaner', function () { it('Should destroy server 3 internal dislikes and correctly clean them', async function () { this.timeout(20000) - await deleteAll(servers[2].internalServerNumber, 'accountVideoRate') + await servers[2].sqlCommand.deleteAll('accountVideoRate') for (const uuid of videoUUIDs) { - await setVideoField(servers[2].internalServerNumber, uuid, 'dislikes', '0') + await servers[2].sqlCommand.setVideoField(uuid, 'dislikes', '0') } await wait(5000) @@ -159,15 +153,15 @@ describe('Test AP cleaner', function () { it('Should destroy server 3 internal shares and correctly clean them', async function () { this.timeout(20000) - const preCount = await getCount(servers[0].internalServerNumber, 'videoShare') + const preCount = await servers[0].sqlCommand.getCount('videoShare') expect(preCount).to.equal(6) - await deleteAll(servers[2].internalServerNumber, 'videoShare') + await servers[2].sqlCommand.deleteAll('videoShare') await wait(5000) await waitJobs(servers) // Still 6 because we don't have remote shares on local videos - const postCount = await getCount(servers[0].internalServerNumber, 'videoShare') + const postCount = await servers[0].sqlCommand.getCount('videoShare') expect(postCount).to.equal(6) }) @@ -179,7 +173,7 @@ describe('Test AP cleaner', function () { expect(total).to.equal(3) } - await deleteAll(servers[2].internalServerNumber, 'videoComment') + await servers[2].sqlCommand.deleteAll('videoComment') await wait(5000) await waitJobs(servers) @@ -196,7 +190,7 @@ describe('Test AP cleaner', function () { async function check (like: string, ofServerUrl: string, urlSuffix: string, remote: 'true' | 'false') { const query = `SELECT "videoId", "accountVideoRate".url FROM "accountVideoRate" ` + `INNER JOIN video ON "accountVideoRate"."videoId" = video.id AND remote IS ${remote} WHERE "accountVideoRate"."url" LIKE '${like}'` - const res = await selectQuery(servers[0].internalServerNumber, query) + const res = await servers[0].sqlCommand.selectQuery(query) for (const rate of res) { const matcher = new RegExp(`^${ofServerUrl}/accounts/root/dislikes/\\d+${urlSuffix}$`) @@ -225,7 +219,7 @@ describe('Test AP cleaner', function () { { const query = `UPDATE "accountVideoRate" SET url = url || 'stan'` - await updateQuery(servers[1].internalServerNumber, query) + await servers[1].sqlCommand.updateQuery(query) await wait(5000) await waitJobs(servers) @@ -242,7 +236,7 @@ describe('Test AP cleaner', function () { const query = `SELECT "videoId", "videoComment".url, uuid as "videoUUID" FROM "videoComment" ` + `INNER JOIN video ON "videoComment"."videoId" = video.id AND remote IS ${remote} WHERE "videoComment"."url" LIKE '${like}'` - const res = await selectQuery(servers[0].internalServerNumber, query) + const res = await servers[0].sqlCommand.selectQuery(query) for (const comment of res) { const matcher = new RegExp(`${ofServerUrl}/videos/watch/${comment.videoUUID}/comments/\\d+${urlSuffix}`) @@ -268,7 +262,7 @@ describe('Test AP cleaner', function () { { const query = `UPDATE "videoComment" SET url = url || 'kyle'` - await updateQuery(servers[1].internalServerNumber, query) + await servers[1].sqlCommand.updateQuery(query) await wait(5000) await waitJobs(servers) @@ -280,7 +274,5 @@ describe('Test AP cleaner', function () { after(async function () { await cleanupTests(servers) - - await closeAllSequelize(servers) }) }) -- cgit v1.2.3 From d23dd9fbfc4d26026352c10f81d2795ceaf2908a Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 15 Jul 2021 10:02:54 +0200 Subject: Introduce videos command --- server/tests/api/activitypub/cleaner.ts | 50 ++++++++++++++++----------------- 1 file changed, 24 insertions(+), 26 deletions(-) (limited to 'server/tests/api/activitypub/cleaner.ts') diff --git a/server/tests/api/activitypub/cleaner.ts b/server/tests/api/activitypub/cleaner.ts index 5b08880bf..dcf758711 100644 --- a/server/tests/api/activitypub/cleaner.ts +++ b/server/tests/api/activitypub/cleaner.ts @@ -6,11 +6,8 @@ import { cleanupTests, doubleFollow, flushAndRunMultipleServers, - getVideo, - rateVideo, ServerInfo, setAccessTokensToServers, - uploadVideoAndGetId, wait, waitJobs } from '@shared/extra-utils' @@ -49,9 +46,9 @@ describe('Test AP cleaner', function () { // Create 1 comment per video // Update 1 remote URL and 1 local URL on - videoUUID1 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'server 1' })).uuid - videoUUID2 = (await uploadVideoAndGetId({ server: servers[1], videoName: 'server 2' })).uuid - videoUUID3 = (await uploadVideoAndGetId({ server: servers[2], videoName: 'server 3' })).uuid + videoUUID1 = (await servers[0].videosCommand.quickUpload({ name: 'server 1' })).uuid + videoUUID2 = (await servers[1].videosCommand.quickUpload({ name: 'server 2' })).uuid + videoUUID3 = (await servers[2].videosCommand.quickUpload({ name: 'server 3' })).uuid videoUUIDs = [ videoUUID1, videoUUID2, videoUUID3 ] @@ -59,7 +56,7 @@ describe('Test AP cleaner', function () { for (const server of servers) { for (const uuid of videoUUIDs) { - await rateVideo(server.url, server.accessToken, uuid, 'like') + await server.videosCommand.rate({ id: uuid, rating: 'like' }) await server.commentsCommand.createThread({ videoId: uuid, text: 'comment' }) } } @@ -70,9 +67,10 @@ describe('Test AP cleaner', function () { it('Should have the correct likes', async function () { for (const server of servers) { for (const uuid of videoUUIDs) { - const res = await getVideo(server.url, uuid) - expect(res.body.likes).to.equal(3) - expect(res.body.dislikes).to.equal(0) + const video = await server.videosCommand.get({ id: uuid }) + + expect(video.likes).to.equal(3) + expect(video.dislikes).to.equal(0) } } }) @@ -90,16 +88,16 @@ describe('Test AP cleaner', function () { // Updated rates of my video { - const res = await getVideo(servers[0].url, videoUUID1) - expect(res.body.likes).to.equal(2) - expect(res.body.dislikes).to.equal(0) + const video = await servers[0].videosCommand.get({ id: videoUUID1 }) + expect(video.likes).to.equal(2) + expect(video.dislikes).to.equal(0) } // Did not update rates of a remote video { - const res = await getVideo(servers[0].url, videoUUID2) - expect(res.body.likes).to.equal(3) - expect(res.body.dislikes).to.equal(0) + const video = await servers[0].videosCommand.get({ id: videoUUID2 }) + expect(video.likes).to.equal(3) + expect(video.dislikes).to.equal(0) } }) @@ -108,7 +106,7 @@ describe('Test AP cleaner', function () { for (const server of servers) { for (const uuid of videoUUIDs) { - await rateVideo(server.url, server.accessToken, uuid, 'dislike') + await server.videosCommand.rate({ id: uuid, rating: 'dislike' }) } } @@ -116,9 +114,9 @@ describe('Test AP cleaner', function () { for (const server of servers) { for (const uuid of videoUUIDs) { - const res = await getVideo(server.url, uuid) - expect(res.body.likes).to.equal(0) - expect(res.body.dislikes).to.equal(3) + const video = await server.videosCommand.get({ id: uuid }) + expect(video.likes).to.equal(0) + expect(video.dislikes).to.equal(3) } } }) @@ -137,16 +135,16 @@ describe('Test AP cleaner', function () { // Updated rates of my video { - const res = await getVideo(servers[0].url, videoUUID1) - expect(res.body.likes).to.equal(0) - expect(res.body.dislikes).to.equal(2) + const video = await servers[0].videosCommand.get({ id: videoUUID1 }) + expect(video.likes).to.equal(0) + expect(video.dislikes).to.equal(2) } // Did not update rates of a remote video { - const res = await getVideo(servers[0].url, videoUUID2) - expect(res.body.likes).to.equal(0) - expect(res.body.dislikes).to.equal(3) + const video = await servers[0].videosCommand.get({ id: videoUUID2 }) + expect(video.likes).to.equal(0) + expect(video.dislikes).to.equal(3) } }) -- cgit v1.2.3 From 89d241a79c262b9775c233b73cff080043ebb5e6 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 16 Jul 2021 09:04:35 +0200 Subject: Shorter server command names --- server/tests/api/activitypub/cleaner.ts | 52 ++++++++++++++++----------------- 1 file changed, 26 insertions(+), 26 deletions(-) (limited to 'server/tests/api/activitypub/cleaner.ts') diff --git a/server/tests/api/activitypub/cleaner.ts b/server/tests/api/activitypub/cleaner.ts index dcf758711..1421824da 100644 --- a/server/tests/api/activitypub/cleaner.ts +++ b/server/tests/api/activitypub/cleaner.ts @@ -46,9 +46,9 @@ describe('Test AP cleaner', function () { // Create 1 comment per video // Update 1 remote URL and 1 local URL on - videoUUID1 = (await servers[0].videosCommand.quickUpload({ name: 'server 1' })).uuid - videoUUID2 = (await servers[1].videosCommand.quickUpload({ name: 'server 2' })).uuid - videoUUID3 = (await servers[2].videosCommand.quickUpload({ name: 'server 3' })).uuid + videoUUID1 = (await servers[0].videos.quickUpload({ name: 'server 1' })).uuid + videoUUID2 = (await servers[1].videos.quickUpload({ name: 'server 2' })).uuid + videoUUID3 = (await servers[2].videos.quickUpload({ name: 'server 3' })).uuid videoUUIDs = [ videoUUID1, videoUUID2, videoUUID3 ] @@ -56,8 +56,8 @@ describe('Test AP cleaner', function () { for (const server of servers) { for (const uuid of videoUUIDs) { - await server.videosCommand.rate({ id: uuid, rating: 'like' }) - await server.commentsCommand.createThread({ videoId: uuid, text: 'comment' }) + await server.videos.rate({ id: uuid, rating: 'like' }) + await server.comments.createThread({ videoId: uuid, text: 'comment' }) } } @@ -67,7 +67,7 @@ describe('Test AP cleaner', function () { it('Should have the correct likes', async function () { for (const server of servers) { for (const uuid of videoUUIDs) { - const video = await server.videosCommand.get({ id: uuid }) + const video = await server.videos.get({ id: uuid }) expect(video.likes).to.equal(3) expect(video.dislikes).to.equal(0) @@ -78,9 +78,9 @@ describe('Test AP cleaner', function () { it('Should destroy server 3 internal likes and correctly clean them', async function () { this.timeout(20000) - await servers[2].sqlCommand.deleteAll('accountVideoRate') + await servers[2].sql.deleteAll('accountVideoRate') for (const uuid of videoUUIDs) { - await servers[2].sqlCommand.setVideoField(uuid, 'likes', '0') + await servers[2].sql.setVideoField(uuid, 'likes', '0') } await wait(5000) @@ -88,14 +88,14 @@ describe('Test AP cleaner', function () { // Updated rates of my video { - const video = await servers[0].videosCommand.get({ id: videoUUID1 }) + const video = await servers[0].videos.get({ id: videoUUID1 }) expect(video.likes).to.equal(2) expect(video.dislikes).to.equal(0) } // Did not update rates of a remote video { - const video = await servers[0].videosCommand.get({ id: videoUUID2 }) + const video = await servers[0].videos.get({ id: videoUUID2 }) expect(video.likes).to.equal(3) expect(video.dislikes).to.equal(0) } @@ -106,7 +106,7 @@ describe('Test AP cleaner', function () { for (const server of servers) { for (const uuid of videoUUIDs) { - await server.videosCommand.rate({ id: uuid, rating: 'dislike' }) + await server.videos.rate({ id: uuid, rating: 'dislike' }) } } @@ -114,7 +114,7 @@ describe('Test AP cleaner', function () { for (const server of servers) { for (const uuid of videoUUIDs) { - const video = await server.videosCommand.get({ id: uuid }) + const video = await server.videos.get({ id: uuid }) expect(video.likes).to.equal(0) expect(video.dislikes).to.equal(3) } @@ -124,10 +124,10 @@ describe('Test AP cleaner', function () { it('Should destroy server 3 internal dislikes and correctly clean them', async function () { this.timeout(20000) - await servers[2].sqlCommand.deleteAll('accountVideoRate') + await servers[2].sql.deleteAll('accountVideoRate') for (const uuid of videoUUIDs) { - await servers[2].sqlCommand.setVideoField(uuid, 'dislikes', '0') + await servers[2].sql.setVideoField(uuid, 'dislikes', '0') } await wait(5000) @@ -135,14 +135,14 @@ describe('Test AP cleaner', function () { // Updated rates of my video { - const video = await servers[0].videosCommand.get({ id: videoUUID1 }) + const video = await servers[0].videos.get({ id: videoUUID1 }) expect(video.likes).to.equal(0) expect(video.dislikes).to.equal(2) } // Did not update rates of a remote video { - const video = await servers[0].videosCommand.get({ id: videoUUID2 }) + const video = await servers[0].videos.get({ id: videoUUID2 }) expect(video.likes).to.equal(0) expect(video.dislikes).to.equal(3) } @@ -151,15 +151,15 @@ describe('Test AP cleaner', function () { it('Should destroy server 3 internal shares and correctly clean them', async function () { this.timeout(20000) - const preCount = await servers[0].sqlCommand.getCount('videoShare') + const preCount = await servers[0].sql.getCount('videoShare') expect(preCount).to.equal(6) - await servers[2].sqlCommand.deleteAll('videoShare') + await servers[2].sql.deleteAll('videoShare') await wait(5000) await waitJobs(servers) // Still 6 because we don't have remote shares on local videos - const postCount = await servers[0].sqlCommand.getCount('videoShare') + const postCount = await servers[0].sql.getCount('videoShare') expect(postCount).to.equal(6) }) @@ -167,17 +167,17 @@ describe('Test AP cleaner', function () { this.timeout(20000) { - const { total } = await servers[0].commentsCommand.listThreads({ videoId: videoUUID1 }) + const { total } = await servers[0].comments.listThreads({ videoId: videoUUID1 }) expect(total).to.equal(3) } - await servers[2].sqlCommand.deleteAll('videoComment') + await servers[2].sql.deleteAll('videoComment') await wait(5000) await waitJobs(servers) { - const { total } = await servers[0].commentsCommand.listThreads({ videoId: videoUUID1 }) + const { total } = await servers[0].comments.listThreads({ videoId: videoUUID1 }) expect(total).to.equal(2) } }) @@ -188,7 +188,7 @@ describe('Test AP cleaner', function () { async function check (like: string, ofServerUrl: string, urlSuffix: string, remote: 'true' | 'false') { const query = `SELECT "videoId", "accountVideoRate".url FROM "accountVideoRate" ` + `INNER JOIN video ON "accountVideoRate"."videoId" = video.id AND remote IS ${remote} WHERE "accountVideoRate"."url" LIKE '${like}'` - const res = await servers[0].sqlCommand.selectQuery(query) + const res = await servers[0].sql.selectQuery(query) for (const rate of res) { const matcher = new RegExp(`^${ofServerUrl}/accounts/root/dislikes/\\d+${urlSuffix}$`) @@ -217,7 +217,7 @@ describe('Test AP cleaner', function () { { const query = `UPDATE "accountVideoRate" SET url = url || 'stan'` - await servers[1].sqlCommand.updateQuery(query) + await servers[1].sql.updateQuery(query) await wait(5000) await waitJobs(servers) @@ -234,7 +234,7 @@ describe('Test AP cleaner', function () { const query = `SELECT "videoId", "videoComment".url, uuid as "videoUUID" FROM "videoComment" ` + `INNER JOIN video ON "videoComment"."videoId" = video.id AND remote IS ${remote} WHERE "videoComment"."url" LIKE '${like}'` - const res = await servers[0].sqlCommand.selectQuery(query) + const res = await servers[0].sql.selectQuery(query) for (const comment of res) { const matcher = new RegExp(`${ofServerUrl}/videos/watch/${comment.videoUUID}/comments/\\d+${urlSuffix}`) @@ -260,7 +260,7 @@ describe('Test AP cleaner', function () { { const query = `UPDATE "videoComment" SET url = url || 'kyle'` - await servers[1].sqlCommand.updateQuery(query) + await servers[1].sql.updateQuery(query) await wait(5000) await waitJobs(servers) -- cgit v1.2.3 From 254d3579f5338f5fd775c17d15cdfc37078bcfb4 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 16 Jul 2021 09:47:51 +0200 Subject: Use an object to represent a server --- server/tests/api/activitypub/cleaner.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'server/tests/api/activitypub/cleaner.ts') diff --git a/server/tests/api/activitypub/cleaner.ts b/server/tests/api/activitypub/cleaner.ts index 1421824da..a5ce449f3 100644 --- a/server/tests/api/activitypub/cleaner.ts +++ b/server/tests/api/activitypub/cleaner.ts @@ -5,8 +5,8 @@ import * as chai from 'chai' import { cleanupTests, doubleFollow, - flushAndRunMultipleServers, - ServerInfo, + createMultipleServers, + PeerTubeServer, setAccessTokensToServers, wait, waitJobs @@ -15,7 +15,7 @@ import { const expect = chai.expect describe('Test AP cleaner', function () { - let servers: ServerInfo[] = [] + let servers: PeerTubeServer[] = [] let videoUUID1: string let videoUUID2: string let videoUUID3: string @@ -30,7 +30,7 @@ describe('Test AP cleaner', function () { videos: { cleanup_remote_interactions: true } } } - servers = await flushAndRunMultipleServers(3, config) + servers = await createMultipleServers(3, config) // Get the access tokens await setAccessTokensToServers(servers) -- cgit v1.2.3 From 4c7e60bc17ee5830399bac4aa273356903421b4c Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 16 Jul 2021 14:27:30 +0200 Subject: Reorganize imports --- server/tests/api/activitypub/cleaner.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'server/tests/api/activitypub/cleaner.ts') diff --git a/server/tests/api/activitypub/cleaner.ts b/server/tests/api/activitypub/cleaner.ts index a5ce449f3..51cf6e599 100644 --- a/server/tests/api/activitypub/cleaner.ts +++ b/server/tests/api/activitypub/cleaner.ts @@ -4,8 +4,8 @@ import 'mocha' import * as chai from 'chai' import { cleanupTests, - doubleFollow, createMultipleServers, + doubleFollow, PeerTubeServer, setAccessTokensToServers, wait, -- cgit v1.2.3