]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Add AP fetch tests
authorChocobozzz <me@florianbigard.com>
Wed, 14 Nov 2018 15:32:12 +0000 (16:32 +0100)
committerChocobozzz <me@florianbigard.com>
Wed, 14 Nov 2018 15:32:28 +0000 (16:32 +0100)
server/tests/api/activitypub/fetch.ts [new file with mode: 0644]
server/tests/api/activitypub/index.ts
server/tests/utils/miscs/sql.ts

diff --git a/server/tests/api/activitypub/fetch.ts b/server/tests/api/activitypub/fetch.ts
new file mode 100644 (file)
index 0000000..a42c606
--- /dev/null
@@ -0,0 +1,86 @@
+/* tslint:disable:no-unused-expression */
+
+import 'mocha'
+
+import {
+  createUser,
+  doubleFollow,
+  flushAndRunMultipleServers,
+  flushTests,
+  getVideosListSort,
+  killallServers,
+  ServerInfo,
+  setAccessTokensToServers,
+  uploadVideo,
+  userLogin
+} from '../../utils'
+import * as chai from 'chai'
+import { setActorField, setVideoField } from '../../utils/miscs/sql'
+import { waitJobs } from '../../utils/server/jobs'
+import { Video } from '../../../../shared/models/videos'
+
+const expect = chai.expect
+
+describe('Test ActivityPub fetcher', function () {
+  let servers: ServerInfo[]
+
+  // ---------------------------------------------------------------
+
+  before(async function () {
+    this.timeout(60000)
+
+    servers = await flushAndRunMultipleServers(3)
+
+    // Get the access tokens
+    await setAccessTokensToServers(servers)
+
+    const user = { username: 'user1', password: 'password' }
+    for (const server of servers) {
+      await createUser(server.url, server.accessToken, user.username, user.password)
+    }
+
+    const userAccessToken = await userLogin(servers[0], user)
+
+    await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video root' })
+    const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'bad video root' })
+    const badVideoUUID = res.body.video.uuid
+    await uploadVideo(servers[0].url, userAccessToken, { name: 'video user' })
+
+    await setActorField(1, 'http://localhost:9001/accounts/user1', 'url', 'http://localhost:9002/accounts/user1')
+    await setVideoField(1, badVideoUUID, 'url', 'http://localhost:9003/videos/watch/' + badVideoUUID)
+  })
+
+  it('Should add only the video with a valid actor URL', async function () {
+    this.timeout(60000)
+
+    await doubleFollow(servers[0], servers[1])
+    await waitJobs(servers)
+
+    {
+      const res = await getVideosListSort(servers[0].url, 'createdAt')
+      expect(res.body.total).to.equal(3)
+
+      const data: Video[] = res.body.data
+      expect(data[0].name).to.equal('video root')
+      expect(data[1].name).to.equal('bad video root')
+      expect(data[2].name).to.equal('video user')
+    }
+
+    {
+      const res = await getVideosListSort(servers[1].url, 'createdAt')
+      expect(res.body.total).to.equal(1)
+
+      const data: Video[] = res.body.data
+      expect(data[0].name).to.equal('video root')
+    }
+  })
+
+  after(async function () {
+    killallServers(servers)
+
+    // Keep the logs if the test failed
+    if (this['ok']) {
+      await flushTests()
+    }
+  })
+})
index de8a599788138b88da780ad10ed4e63e3421589b..e748f32e9c1faad2c07b015269f036647e9e10d5 100644 (file)
@@ -1,3 +1,4 @@
 import './client'
+import './fetch'
 import './helpers'
 import './security'
index 204ff5163f463e316c647479837cdc869af5149d..027f781318cec2d3b69f79f7812b44001a095017 100644 (file)
@@ -24,6 +24,15 @@ function setActorField (serverNumber: number, to: string, field: string, value:
   return seq.query(`UPDATE actor SET "${field}" = '${value}' WHERE url = '${to}'`, options)
 }
 
+function setVideoField (serverNumber: number, uuid: string, field: string, value: string) {
+  const seq = getSequelize(serverNumber)
+
+  const options = { type: Sequelize.QueryTypes.UPDATE }
+
+  return seq.query(`UPDATE video SET "${field}" = '${value}' WHERE uuid = '${uuid}'`, options)
+}
+
 export {
+  setVideoField,
   setActorField
 }