From 28f7d2020fe3ffbe5ba8a0083386f616b0186a91 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 15 Aug 2016 18:44:30 +0200 Subject: Server: test filenames with hyphens --- server/tests/api/check-params.js | 660 +++++++++++++++++++++++++++++++++++ server/tests/api/checkParams.js | 660 ----------------------------------- server/tests/api/friends-advanced.js | 284 +++++++++++++++ server/tests/api/friends-basic.js | 192 ++++++++++ server/tests/api/friendsAdvanced.js | 284 --------------- server/tests/api/friendsBasic.js | 192 ---------- server/tests/api/index.js | 10 +- server/tests/api/multiple-pods.js | 427 ++++++++++++++++++++++ server/tests/api/multiplePods.js | 427 ---------------------- server/tests/api/single-pod.js | 508 +++++++++++++++++++++++++++ server/tests/api/singlePod.js | 508 --------------------------- 11 files changed, 2076 insertions(+), 2076 deletions(-) create mode 100644 server/tests/api/check-params.js delete mode 100644 server/tests/api/checkParams.js create mode 100644 server/tests/api/friends-advanced.js create mode 100644 server/tests/api/friends-basic.js delete mode 100644 server/tests/api/friendsAdvanced.js delete mode 100644 server/tests/api/friendsBasic.js create mode 100644 server/tests/api/multiple-pods.js delete mode 100644 server/tests/api/multiplePods.js create mode 100644 server/tests/api/single-pod.js delete mode 100644 server/tests/api/singlePod.js (limited to 'server') diff --git a/server/tests/api/check-params.js b/server/tests/api/check-params.js new file mode 100644 index 000000000..882948fac --- /dev/null +++ b/server/tests/api/check-params.js @@ -0,0 +1,660 @@ +'use strict' + +const chai = require('chai') +const expect = chai.expect +const pathUtils = require('path') +const request = require('supertest') +const series = require('async/series') + +const loginUtils = require('../utils/login') +const requestsUtils = require('../utils/requests') +const serversUtils = require('../utils/servers') +const usersUtils = require('../utils/users') + +describe('Test parameters validator', function () { + let server = null + + // --------------------------------------------------------------- + + before(function (done) { + this.timeout(20000) + + series([ + function (next) { + serversUtils.flushTests(next) + }, + function (next) { + serversUtils.runServer(1, function (server1) { + server = server1 + + next() + }) + }, + function (next) { + loginUtils.loginAndGetAccessToken(server, function (err, token) { + if (err) throw err + server.accessToken = token + + next() + }) + } + ], done) + }) + + describe('Of the pods API', function () { + const path = '/api/v1/pods/' + + describe('When adding a pod', function () { + it('Should fail with nothing', function (done) { + const data = {} + requestsUtils.makePostBodyRequest(server.url, path, null, data, done) + }) + + it('Should fail without public key', function (done) { + const data = { + url: 'http://coucou.com' + } + requestsUtils.makePostBodyRequest(server.url, path, null, data, done) + }) + + it('Should fail without an url', function (done) { + const data = { + publicKey: 'mysuperpublickey' + } + requestsUtils.makePostBodyRequest(server.url, path, null, data, done) + }) + + it('Should fail with an incorrect url', function (done) { + const data = { + url: 'coucou.com', + publicKey: 'mysuperpublickey' + } + requestsUtils.makePostBodyRequest(server.url, path, null, data, function () { + data.url = 'http://coucou' + requestsUtils.makePostBodyRequest(server.url, path, null, data, function () { + data.url = 'coucou' + requestsUtils.makePostBodyRequest(server.url, path, null, data, done) + }) + }) + }) + + it('Should succeed with the correct parameters', function (done) { + const data = { + url: 'http://coucou.com', + publicKey: 'mysuperpublickey' + } + requestsUtils.makePostBodyRequest(server.url, path, null, data, done, 200) + }) + }) + + describe('For the friends API', function () { + let userAccessToken = null + + before(function (done) { + usersUtils.createUser(server.url, server.accessToken, 'user1', 'password', function () { + server.user = { + username: 'user1', + password: 'password' + } + + loginUtils.loginAndGetAccessToken(server, function (err, accessToken) { + if (err) throw err + + userAccessToken = accessToken + + done() + }) + }) + }) + + describe('When making friends', function () { + it('Should fail with a invalid token', function (done) { + request(server.url) + .get(path + '/makefriends') + .query({ start: 'hello' }) + .set('Authorization', 'Bearer faketoken') + .set('Accept', 'application/json') + .expect(401, done) + }) + + it('Should fail if the user is not an administrator', function (done) { + request(server.url) + .get(path + '/makefriends') + .query({ start: 'hello' }) + .set('Authorization', 'Bearer ' + userAccessToken) + .set('Accept', 'application/json') + .expect(403, done) + }) + }) + + describe('When quitting friends', function () { + it('Should fail with a invalid token', function (done) { + request(server.url) + .get(path + '/quitfriends') + .query({ start: 'hello' }) + .set('Authorization', 'Bearer faketoken') + .set('Accept', 'application/json') + .expect(401, done) + }) + + it('Should fail if the user is not an administrator', function (done) { + request(server.url) + .get(path + '/quitfriends') + .query({ start: 'hello' }) + .set('Authorization', 'Bearer ' + userAccessToken) + .set('Accept', 'application/json') + .expect(403, done) + }) + }) + }) + }) + + describe('Of the videos API', function () { + const path = '/api/v1/videos/' + + describe('When listing a video', function () { + it('Should fail with a bad start pagination', function (done) { + request(server.url) + .get(path) + .query({ start: 'hello' }) + .set('Accept', 'application/json') + .expect(400, done) + }) + + it('Should fail with a bad count pagination', function (done) { + request(server.url) + .get(path) + .query({ count: 'hello' }) + .set('Accept', 'application/json') + .expect(400, done) + }) + + it('Should fail with an incorrect sort', function (done) { + request(server.url) + .get(path) + .query({ sort: 'hello' }) + .set('Accept', 'application/json') + .expect(400, done) + }) + }) + + describe('When searching a video', function () { + it('Should fail with nothing', function (done) { + request(server.url) + .get(pathUtils.join(path, 'search')) + .set('Accept', 'application/json') + .expect(400, done) + }) + + it('Should fail with a bad start pagination', function (done) { + request(server.url) + .get(pathUtils.join(path, 'search', 'test')) + .query({ start: 'hello' }) + .set('Accept', 'application/json') + .expect(400, done) + }) + + it('Should fail with a bad count pagination', function (done) { + request(server.url) + .get(pathUtils.join(path, 'search', 'test')) + .query({ count: 'hello' }) + .set('Accept', 'application/json') + .expect(400, done) + }) + + it('Should fail with an incorrect sort', function (done) { + request(server.url) + .get(pathUtils.join(path, 'search', 'test')) + .query({ sort: 'hello' }) + .set('Accept', 'application/json') + .expect(400, done) + }) + }) + + describe('When adding a video', function () { + it('Should fail with nothing', function (done) { + const data = {} + const attach = {} + requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) + }) + + it('Should fail without name', function (done) { + const data = { + description: 'my super description', + tags: [ 'tag1', 'tag2' ] + } + const attach = { + 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') + } + requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) + }) + + it('Should fail with a long name', function (done) { + const data = { + name: 'My very very very very very very very very very very very very very very very very long name', + description: 'my super description', + tags: [ 'tag1', 'tag2' ] + } + const attach = { + 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') + } + requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) + }) + + it('Should fail without description', function (done) { + const data = { + name: 'my super name', + tags: [ 'tag1', 'tag2' ] + } + const attach = { + 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') + } + requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) + }) + + it('Should fail with a long description', function (done) { + const data = { + name: 'my super name', + description: 'my super description which is very very very very very very very very very very very very very very' + + 'very very very very very very very very very very very very very very very very very very very very very' + + 'very very very very very very very very very very very very very very very long', + tags: [ 'tag1', 'tag2' ] + } + const attach = { + 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') + } + requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) + }) + + it('Should fail without tags', function (done) { + const data = { + name: 'my super name', + description: 'my super description' + } + const attach = { + 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') + } + requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) + }) + + it('Should fail with too many tags', function (done) { + const data = { + name: 'my super name', + description: 'my super description', + tags: [ 'tag1', 'tag2', 'tag3', 'tag4' ] + } + const attach = { + 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') + } + requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) + }) + + it('Should fail with not enough tags', function (done) { + const data = { + name: 'my super name', + description: 'my super description', + tags: [ ] + } + const attach = { + 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') + } + requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) + }) + + it('Should fail with a tag length too low', function (done) { + const data = { + name: 'my super name', + description: 'my super description', + tags: [ 'tag1', 't' ] + } + const attach = { + 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') + } + requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) + }) + + it('Should fail with a tag length too big', function (done) { + const data = { + name: 'my super name', + description: 'my super description', + tags: [ 'mysupertagtoolong', 'tag1' ] + } + const attach = { + 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') + } + requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) + }) + + it('Should fail with malformed tags', function (done) { + const data = { + name: 'my super name', + description: 'my super description', + tags: [ 'my tag' ] + } + const attach = { + 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') + } + requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) + }) + + it('Should fail without an input file', function (done) { + const data = { + name: 'my super name', + description: 'my super description', + tags: [ 'tag1', 'tag2' ] + } + const attach = {} + requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) + }) + + it('Should fail without an incorrect input file', function (done) { + const data = { + name: 'my super name', + description: 'my super description', + tags: [ 'tag1', 'tag2' ] + } + const attach = { + 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short_fake.webm') + } + requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) + }) + + it('Should fail with a too big duration', function (done) { + const data = { + name: 'my super name', + description: 'my super description', + tags: [ 'tag1', 'tag2' ] + } + const attach = { + 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_too_long.webm') + } + requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) + }) + + it('Should succeed with the correct parameters', function (done) { + const data = { + name: 'my super name', + description: 'my super description', + tags: [ 'tag1', 'tag2' ] + } + const attach = { + 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') + } + requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, function () { + attach.videofile = pathUtils.join(__dirname, 'fixtures', 'video_short.mp4') + requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, function () { + attach.videofile = pathUtils.join(__dirname, 'fixtures', 'video_short.ogv') + requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done, 204) + }, false) + }, false) + }) + }) + + describe('When getting a video', function () { + it('Should return the list of the videos with nothing', function (done) { + request(server.url) + .get(path) + .set('Accept', 'application/json') + .expect(200) + .expect('Content-Type', /json/) + .end(function (err, res) { + if (err) throw err + + expect(res.body.data).to.be.an('array') + expect(res.body.data.length).to.equal(3) + + done() + }) + }) + + it('Should fail without a mongodb id', function (done) { + request(server.url) + .get(path + 'coucou') + .set('Accept', 'application/json') + .expect(400, done) + }) + + it('Should return 404 with an incorrect video', function (done) { + request(server.url) + .get(path + '123456789012345678901234') + .set('Accept', 'application/json') + .expect(404, done) + }) + + it('Should succeed with the correct parameters') + }) + + describe('When removing a video', function () { + it('Should have 404 with nothing', function (done) { + request(server.url) + .delete(path) + .set('Authorization', 'Bearer ' + server.accessToken) + .expect(400, done) + }) + + it('Should fail without a mongodb id', function (done) { + request(server.url) + .delete(path + 'hello') + .set('Authorization', 'Bearer ' + server.accessToken) + .expect(400, done) + }) + + it('Should fail with a video which does not exist', function (done) { + request(server.url) + .delete(path + '123456789012345678901234') + .set('Authorization', 'Bearer ' + server.accessToken) + .expect(404, done) + }) + + it('Should fail with a video of another user') + + it('Should fail with a video of another pod') + + it('Should succeed with the correct parameters') + }) + }) + + describe('Of the users API', function () { + const path = '/api/v1/users/' + let userId = null + let userAccessToken = null + + describe('When adding a new user', function () { + it('Should fail with a too small username', function (done) { + const data = { + username: 'ji', + password: 'mysuperpassword' + } + + requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done) + }) + + it('Should fail with a too long username', function (done) { + const data = { + username: 'mysuperusernamewhichisverylong', + password: 'mysuperpassword' + } + + requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done) + }) + + it('Should fail with an incorrect username', function (done) { + const data = { + username: 'my username', + password: 'mysuperpassword' + } + + requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done) + }) + + it('Should fail with a too small password', function (done) { + const data = { + username: 'myusername', + password: 'bla' + } + + requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done) + }) + + it('Should fail with a too long password', function (done) { + const data = { + username: 'myusername', + password: 'my super long password which is very very very very very very very very very very very very very very' + + 'very very very very very very very very very very very very very very very veryv very very very very' + + 'very very very very very very very very very very very very very very very very very very very very long' + } + + requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done) + }) + + it('Should fail with an non authenticated user', function (done) { + const data = { + username: 'myusername', + password: 'my super password' + } + + requestsUtils.makePostBodyRequest(server.url, path, 'super token', data, done, 401) + }) + + it('Should succeed with the correct params', function (done) { + const data = { + username: 'user1', + password: 'my super password' + } + + requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done, 204) + }) + + it('Should fail with a non admin user', function (done) { + server.user = { + username: 'user1', + password: 'my super password' + } + + loginUtils.loginAndGetAccessToken(server, function (err, accessToken) { + if (err) throw err + + userAccessToken = accessToken + + const data = { + username: 'user2', + password: 'my super password' + } + + requestsUtils.makePostBodyRequest(server.url, path, userAccessToken, data, done, 403) + }) + }) + }) + + describe('When updating a user', function () { + before(function (done) { + usersUtils.getUsersList(server.url, function (err, res) { + if (err) throw err + + userId = res.body.data[1].id + done() + }) + }) + + it('Should fail with a too small password', function (done) { + const data = { + password: 'bla' + } + + requestsUtils.makePutBodyRequest(server.url, path + userId, userAccessToken, data, done) + }) + + it('Should fail with a too long password', function (done) { + const data = { + password: 'my super long password which is very very very very very very very very very very very very very very' + + 'very very very very very very very very very very very very very very very veryv very very very very' + + 'very very very very very very very very very very very very very very very very very very very very long' + } + + requestsUtils.makePutBodyRequest(server.url, path + userId, userAccessToken, data, done) + }) + + it('Should fail with an non authenticated user', function (done) { + const data = { + password: 'my super password' + } + + requestsUtils.makePutBodyRequest(server.url, path + userId, 'super token', data, done, 401) + }) + + it('Should succeed with the correct params', function (done) { + const data = { + password: 'my super password' + } + + requestsUtils.makePutBodyRequest(server.url, path + userId, userAccessToken, data, done, 204) + }) + }) + + describe('When getting my information', function () { + it('Should fail with a non authenticated user', function (done) { + request(server.url) + .get(path + 'me') + .set('Authorization', 'Bearer faketoken') + .set('Accept', 'application/json') + .expect(401, done) + }) + + it('Should success with the correct parameters', function (done) { + request(server.url) + .get(path + 'me') + .set('Authorization', 'Bearer ' + userAccessToken) + .set('Accept', 'application/json') + .expect(200, done) + }) + }) + + describe('When removing an user', function () { + it('Should fail with an incorrect id', function (done) { + request(server.url) + .delete(path + 'bla-bla') + .set('Authorization', 'Bearer ' + server.accessToken) + .expect(400, done) + }) + + it('Should return 404 with a non existing id', function (done) { + request(server.url) + .delete(path + '579f982228c99c221d8092b8') + .set('Authorization', 'Bearer ' + server.accessToken) + .expect(404, done) + }) + + it('Should success with the correct parameters', function (done) { + request(server.url) + .delete(path + userId) + .set('Authorization', 'Bearer ' + server.accessToken) + .expect(204, done) + }) + }) + }) + + describe('Of the remote videos API', function () { + describe('When making a secure request', function () { + it('Should check a secure request') + }) + + describe('When adding a video', function () { + it('Should check when adding a video') + }) + + describe('When removing a video', function () { + it('Should check when removing a video') + }) + }) + + after(function (done) { + process.kill(-server.app.pid) + + // Keep the logs if the test failed + if (this.ok) { + serversUtils.flushTests(done) + } else { + done() + } + }) +}) diff --git a/server/tests/api/checkParams.js b/server/tests/api/checkParams.js deleted file mode 100644 index 882948fac..000000000 --- a/server/tests/api/checkParams.js +++ /dev/null @@ -1,660 +0,0 @@ -'use strict' - -const chai = require('chai') -const expect = chai.expect -const pathUtils = require('path') -const request = require('supertest') -const series = require('async/series') - -const loginUtils = require('../utils/login') -const requestsUtils = require('../utils/requests') -const serversUtils = require('../utils/servers') -const usersUtils = require('../utils/users') - -describe('Test parameters validator', function () { - let server = null - - // --------------------------------------------------------------- - - before(function (done) { - this.timeout(20000) - - series([ - function (next) { - serversUtils.flushTests(next) - }, - function (next) { - serversUtils.runServer(1, function (server1) { - server = server1 - - next() - }) - }, - function (next) { - loginUtils.loginAndGetAccessToken(server, function (err, token) { - if (err) throw err - server.accessToken = token - - next() - }) - } - ], done) - }) - - describe('Of the pods API', function () { - const path = '/api/v1/pods/' - - describe('When adding a pod', function () { - it('Should fail with nothing', function (done) { - const data = {} - requestsUtils.makePostBodyRequest(server.url, path, null, data, done) - }) - - it('Should fail without public key', function (done) { - const data = { - url: 'http://coucou.com' - } - requestsUtils.makePostBodyRequest(server.url, path, null, data, done) - }) - - it('Should fail without an url', function (done) { - const data = { - publicKey: 'mysuperpublickey' - } - requestsUtils.makePostBodyRequest(server.url, path, null, data, done) - }) - - it('Should fail with an incorrect url', function (done) { - const data = { - url: 'coucou.com', - publicKey: 'mysuperpublickey' - } - requestsUtils.makePostBodyRequest(server.url, path, null, data, function () { - data.url = 'http://coucou' - requestsUtils.makePostBodyRequest(server.url, path, null, data, function () { - data.url = 'coucou' - requestsUtils.makePostBodyRequest(server.url, path, null, data, done) - }) - }) - }) - - it('Should succeed with the correct parameters', function (done) { - const data = { - url: 'http://coucou.com', - publicKey: 'mysuperpublickey' - } - requestsUtils.makePostBodyRequest(server.url, path, null, data, done, 200) - }) - }) - - describe('For the friends API', function () { - let userAccessToken = null - - before(function (done) { - usersUtils.createUser(server.url, server.accessToken, 'user1', 'password', function () { - server.user = { - username: 'user1', - password: 'password' - } - - loginUtils.loginAndGetAccessToken(server, function (err, accessToken) { - if (err) throw err - - userAccessToken = accessToken - - done() - }) - }) - }) - - describe('When making friends', function () { - it('Should fail with a invalid token', function (done) { - request(server.url) - .get(path + '/makefriends') - .query({ start: 'hello' }) - .set('Authorization', 'Bearer faketoken') - .set('Accept', 'application/json') - .expect(401, done) - }) - - it('Should fail if the user is not an administrator', function (done) { - request(server.url) - .get(path + '/makefriends') - .query({ start: 'hello' }) - .set('Authorization', 'Bearer ' + userAccessToken) - .set('Accept', 'application/json') - .expect(403, done) - }) - }) - - describe('When quitting friends', function () { - it('Should fail with a invalid token', function (done) { - request(server.url) - .get(path + '/quitfriends') - .query({ start: 'hello' }) - .set('Authorization', 'Bearer faketoken') - .set('Accept', 'application/json') - .expect(401, done) - }) - - it('Should fail if the user is not an administrator', function (done) { - request(server.url) - .get(path + '/quitfriends') - .query({ start: 'hello' }) - .set('Authorization', 'Bearer ' + userAccessToken) - .set('Accept', 'application/json') - .expect(403, done) - }) - }) - }) - }) - - describe('Of the videos API', function () { - const path = '/api/v1/videos/' - - describe('When listing a video', function () { - it('Should fail with a bad start pagination', function (done) { - request(server.url) - .get(path) - .query({ start: 'hello' }) - .set('Accept', 'application/json') - .expect(400, done) - }) - - it('Should fail with a bad count pagination', function (done) { - request(server.url) - .get(path) - .query({ count: 'hello' }) - .set('Accept', 'application/json') - .expect(400, done) - }) - - it('Should fail with an incorrect sort', function (done) { - request(server.url) - .get(path) - .query({ sort: 'hello' }) - .set('Accept', 'application/json') - .expect(400, done) - }) - }) - - describe('When searching a video', function () { - it('Should fail with nothing', function (done) { - request(server.url) - .get(pathUtils.join(path, 'search')) - .set('Accept', 'application/json') - .expect(400, done) - }) - - it('Should fail with a bad start pagination', function (done) { - request(server.url) - .get(pathUtils.join(path, 'search', 'test')) - .query({ start: 'hello' }) - .set('Accept', 'application/json') - .expect(400, done) - }) - - it('Should fail with a bad count pagination', function (done) { - request(server.url) - .get(pathUtils.join(path, 'search', 'test')) - .query({ count: 'hello' }) - .set('Accept', 'application/json') - .expect(400, done) - }) - - it('Should fail with an incorrect sort', function (done) { - request(server.url) - .get(pathUtils.join(path, 'search', 'test')) - .query({ sort: 'hello' }) - .set('Accept', 'application/json') - .expect(400, done) - }) - }) - - describe('When adding a video', function () { - it('Should fail with nothing', function (done) { - const data = {} - const attach = {} - requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) - }) - - it('Should fail without name', function (done) { - const data = { - description: 'my super description', - tags: [ 'tag1', 'tag2' ] - } - const attach = { - 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') - } - requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) - }) - - it('Should fail with a long name', function (done) { - const data = { - name: 'My very very very very very very very very very very very very very very very very long name', - description: 'my super description', - tags: [ 'tag1', 'tag2' ] - } - const attach = { - 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') - } - requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) - }) - - it('Should fail without description', function (done) { - const data = { - name: 'my super name', - tags: [ 'tag1', 'tag2' ] - } - const attach = { - 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') - } - requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) - }) - - it('Should fail with a long description', function (done) { - const data = { - name: 'my super name', - description: 'my super description which is very very very very very very very very very very very very very very' + - 'very very very very very very very very very very very very very very very very very very very very very' + - 'very very very very very very very very very very very very very very very long', - tags: [ 'tag1', 'tag2' ] - } - const attach = { - 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') - } - requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) - }) - - it('Should fail without tags', function (done) { - const data = { - name: 'my super name', - description: 'my super description' - } - const attach = { - 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') - } - requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) - }) - - it('Should fail with too many tags', function (done) { - const data = { - name: 'my super name', - description: 'my super description', - tags: [ 'tag1', 'tag2', 'tag3', 'tag4' ] - } - const attach = { - 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') - } - requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) - }) - - it('Should fail with not enough tags', function (done) { - const data = { - name: 'my super name', - description: 'my super description', - tags: [ ] - } - const attach = { - 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') - } - requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) - }) - - it('Should fail with a tag length too low', function (done) { - const data = { - name: 'my super name', - description: 'my super description', - tags: [ 'tag1', 't' ] - } - const attach = { - 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') - } - requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) - }) - - it('Should fail with a tag length too big', function (done) { - const data = { - name: 'my super name', - description: 'my super description', - tags: [ 'mysupertagtoolong', 'tag1' ] - } - const attach = { - 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') - } - requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) - }) - - it('Should fail with malformed tags', function (done) { - const data = { - name: 'my super name', - description: 'my super description', - tags: [ 'my tag' ] - } - const attach = { - 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') - } - requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) - }) - - it('Should fail without an input file', function (done) { - const data = { - name: 'my super name', - description: 'my super description', - tags: [ 'tag1', 'tag2' ] - } - const attach = {} - requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) - }) - - it('Should fail without an incorrect input file', function (done) { - const data = { - name: 'my super name', - description: 'my super description', - tags: [ 'tag1', 'tag2' ] - } - const attach = { - 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short_fake.webm') - } - requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) - }) - - it('Should fail with a too big duration', function (done) { - const data = { - name: 'my super name', - description: 'my super description', - tags: [ 'tag1', 'tag2' ] - } - const attach = { - 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_too_long.webm') - } - requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) - }) - - it('Should succeed with the correct parameters', function (done) { - const data = { - name: 'my super name', - description: 'my super description', - tags: [ 'tag1', 'tag2' ] - } - const attach = { - 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') - } - requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, function () { - attach.videofile = pathUtils.join(__dirname, 'fixtures', 'video_short.mp4') - requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, function () { - attach.videofile = pathUtils.join(__dirname, 'fixtures', 'video_short.ogv') - requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done, 204) - }, false) - }, false) - }) - }) - - describe('When getting a video', function () { - it('Should return the list of the videos with nothing', function (done) { - request(server.url) - .get(path) - .set('Accept', 'application/json') - .expect(200) - .expect('Content-Type', /json/) - .end(function (err, res) { - if (err) throw err - - expect(res.body.data).to.be.an('array') - expect(res.body.data.length).to.equal(3) - - done() - }) - }) - - it('Should fail without a mongodb id', function (done) { - request(server.url) - .get(path + 'coucou') - .set('Accept', 'application/json') - .expect(400, done) - }) - - it('Should return 404 with an incorrect video', function (done) { - request(server.url) - .get(path + '123456789012345678901234') - .set('Accept', 'application/json') - .expect(404, done) - }) - - it('Should succeed with the correct parameters') - }) - - describe('When removing a video', function () { - it('Should have 404 with nothing', function (done) { - request(server.url) - .delete(path) - .set('Authorization', 'Bearer ' + server.accessToken) - .expect(400, done) - }) - - it('Should fail without a mongodb id', function (done) { - request(server.url) - .delete(path + 'hello') - .set('Authorization', 'Bearer ' + server.accessToken) - .expect(400, done) - }) - - it('Should fail with a video which does not exist', function (done) { - request(server.url) - .delete(path + '123456789012345678901234') - .set('Authorization', 'Bearer ' + server.accessToken) - .expect(404, done) - }) - - it('Should fail with a video of another user') - - it('Should fail with a video of another pod') - - it('Should succeed with the correct parameters') - }) - }) - - describe('Of the users API', function () { - const path = '/api/v1/users/' - let userId = null - let userAccessToken = null - - describe('When adding a new user', function () { - it('Should fail with a too small username', function (done) { - const data = { - username: 'ji', - password: 'mysuperpassword' - } - - requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done) - }) - - it('Should fail with a too long username', function (done) { - const data = { - username: 'mysuperusernamewhichisverylong', - password: 'mysuperpassword' - } - - requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done) - }) - - it('Should fail with an incorrect username', function (done) { - const data = { - username: 'my username', - password: 'mysuperpassword' - } - - requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done) - }) - - it('Should fail with a too small password', function (done) { - const data = { - username: 'myusername', - password: 'bla' - } - - requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done) - }) - - it('Should fail with a too long password', function (done) { - const data = { - username: 'myusername', - password: 'my super long password which is very very very very very very very very very very very very very very' + - 'very very very very very very very very very very very very very very very veryv very very very very' + - 'very very very very very very very very very very very very very very very very very very very very long' - } - - requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done) - }) - - it('Should fail with an non authenticated user', function (done) { - const data = { - username: 'myusername', - password: 'my super password' - } - - requestsUtils.makePostBodyRequest(server.url, path, 'super token', data, done, 401) - }) - - it('Should succeed with the correct params', function (done) { - const data = { - username: 'user1', - password: 'my super password' - } - - requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done, 204) - }) - - it('Should fail with a non admin user', function (done) { - server.user = { - username: 'user1', - password: 'my super password' - } - - loginUtils.loginAndGetAccessToken(server, function (err, accessToken) { - if (err) throw err - - userAccessToken = accessToken - - const data = { - username: 'user2', - password: 'my super password' - } - - requestsUtils.makePostBodyRequest(server.url, path, userAccessToken, data, done, 403) - }) - }) - }) - - describe('When updating a user', function () { - before(function (done) { - usersUtils.getUsersList(server.url, function (err, res) { - if (err) throw err - - userId = res.body.data[1].id - done() - }) - }) - - it('Should fail with a too small password', function (done) { - const data = { - password: 'bla' - } - - requestsUtils.makePutBodyRequest(server.url, path + userId, userAccessToken, data, done) - }) - - it('Should fail with a too long password', function (done) { - const data = { - password: 'my super long password which is very very very very very very very very very very very very very very' + - 'very very very very very very very very very very very very very very very veryv very very very very' + - 'very very very very very very very very very very very very very very very very very very very very long' - } - - requestsUtils.makePutBodyRequest(server.url, path + userId, userAccessToken, data, done) - }) - - it('Should fail with an non authenticated user', function (done) { - const data = { - password: 'my super password' - } - - requestsUtils.makePutBodyRequest(server.url, path + userId, 'super token', data, done, 401) - }) - - it('Should succeed with the correct params', function (done) { - const data = { - password: 'my super password' - } - - requestsUtils.makePutBodyRequest(server.url, path + userId, userAccessToken, data, done, 204) - }) - }) - - describe('When getting my information', function () { - it('Should fail with a non authenticated user', function (done) { - request(server.url) - .get(path + 'me') - .set('Authorization', 'Bearer faketoken') - .set('Accept', 'application/json') - .expect(401, done) - }) - - it('Should success with the correct parameters', function (done) { - request(server.url) - .get(path + 'me') - .set('Authorization', 'Bearer ' + userAccessToken) - .set('Accept', 'application/json') - .expect(200, done) - }) - }) - - describe('When removing an user', function () { - it('Should fail with an incorrect id', function (done) { - request(server.url) - .delete(path + 'bla-bla') - .set('Authorization', 'Bearer ' + server.accessToken) - .expect(400, done) - }) - - it('Should return 404 with a non existing id', function (done) { - request(server.url) - .delete(path + '579f982228c99c221d8092b8') - .set('Authorization', 'Bearer ' + server.accessToken) - .expect(404, done) - }) - - it('Should success with the correct parameters', function (done) { - request(server.url) - .delete(path + userId) - .set('Authorization', 'Bearer ' + server.accessToken) - .expect(204, done) - }) - }) - }) - - describe('Of the remote videos API', function () { - describe('When making a secure request', function () { - it('Should check a secure request') - }) - - describe('When adding a video', function () { - it('Should check when adding a video') - }) - - describe('When removing a video', function () { - it('Should check when removing a video') - }) - }) - - after(function (done) { - process.kill(-server.app.pid) - - // Keep the logs if the test failed - if (this.ok) { - serversUtils.flushTests(done) - } else { - done() - } - }) -}) diff --git a/server/tests/api/friends-advanced.js b/server/tests/api/friends-advanced.js new file mode 100644 index 000000000..0d24481ef --- /dev/null +++ b/server/tests/api/friends-advanced.js @@ -0,0 +1,284 @@ +'use strict' + +const chai = require('chai') +const each = require('async/each') +const expect = chai.expect +const series = require('async/series') + +const loginUtils = require('../utils/login') +const podsUtils = require('../utils/pods') +const serversUtils = require('../utils/servers') +const videosUtils = require('../utils/videos') + +describe('Test advanced friends', function () { + let servers = [] + + function makeFriends (podNumber, callback) { + const server = servers[podNumber - 1] + return podsUtils.makeFriends(server.url, server.accessToken, callback) + } + + function quitFriends (podNumber, callback) { + const server = servers[podNumber - 1] + return podsUtils.quitFriends(server.url, server.accessToken, callback) + } + + function getFriendsList (podNumber, end) { + const server = servers[podNumber - 1] + return podsUtils.getFriendsList(server.url, end) + } + + function uploadVideo (podNumber, callback) { + const name = 'my super video' + const description = 'my super description' + const tags = [ 'tag1', 'tag2' ] + const fixture = 'video_short.webm' + const server = servers[podNumber - 1] + + return videosUtils.uploadVideo(server.url, server.accessToken, name, description, tags, fixture, callback) + } + + function getVideos (podNumber, callback) { + return videosUtils.getVideosList(servers[podNumber - 1].url, callback) + } + + // --------------------------------------------------------------- + + before(function (done) { + this.timeout(30000) + serversUtils.flushAndRunMultipleServers(6, function (serversRun, urlsRun) { + servers = serversRun + + each(servers, function (server, callbackEach) { + loginUtils.loginAndGetAccessToken(server, function (err, accessToken) { + if (err) return callbackEach(err) + + server.accessToken = accessToken + callbackEach() + }) + }, done) + }) + }) + + it('Should make friends with two pod each in a different group', function (done) { + this.timeout(20000) + + series([ + // Pod 3 makes friend with the first one + function (next) { + makeFriends(3, next) + }, + // Pod 4 makes friend with the second one + function (next) { + makeFriends(4, next) + }, + // Now if the fifth wants to make friends with the third et the first + function (next) { + makeFriends(5, next) + }, + function (next) { + setTimeout(next, 11000) + }], + function (err) { + if (err) throw err + + // It should have 0 friends + getFriendsList(5, function (err, res) { + if (err) throw err + + expect(res.body.length).to.equal(0) + + done() + }) + } + ) + }) + + it('Should quit all friends', function (done) { + this.timeout(10000) + + series([ + function (next) { + quitFriends(1, next) + }, + function (next) { + quitFriends(2, next) + }], + function (err) { + if (err) throw err + + each([ 1, 2, 3, 4, 5, 6 ], function (i, callback) { + getFriendsList(i, function (err, res) { + if (err) throw err + + expect(res.body.length).to.equal(0) + + callback() + }) + }, done) + } + ) + }) + + it('Should make friends with the pods 1, 2, 3', function (done) { + this.timeout(150000) + + series([ + // Pods 1, 2, 3 and 4 become friends + function (next) { + makeFriends(2, next) + }, + function (next) { + makeFriends(1, next) + }, + function (next) { + makeFriends(4, next) + }, + // Check the pods 1, 2, 3 and 4 are friends + function (next) { + each([ 1, 2, 3, 4 ], function (i, callback) { + getFriendsList(i, function (err, res) { + if (err) throw err + + expect(res.body.length).to.equal(3) + + callback() + }) + }, next) + }, + // Kill pod 4 + function (next) { + servers[3].app.kill() + next() + }, + // Expulse pod 4 from pod 1 and 2 + function (next) { + uploadVideo(1, next) + }, + function (next) { + uploadVideo(2, next) + }, + function (next) { + setTimeout(next, 11000) + }, + function (next) { + uploadVideo(1, next) + }, + function (next) { + uploadVideo(2, next) + }, + function (next) { + setTimeout(next, 11000) + }, + // Rerun server 4 + function (next) { + serversUtils.runServer(4, function (server) { + servers[3].app = server.app + next() + }) + }, + function (next) { + getFriendsList(4, function (err, res) { + if (err) throw err + + // Pod 4 didn't know pod 1 and 2 removed it + expect(res.body.length).to.equal(3) + next() + }) + }, + // Pod 6 ask pod 1, 2 and 3 + function (next) { + makeFriends(6, next) + }, + function (next) { + setTimeout(next, 11000) + }], + function (err) { + if (err) throw err + + getFriendsList(6, function (err, res) { + if (err) throw err + + // Pod 4 should not be our friend + const result = res.body + expect(result.length).to.equal(3) + for (const pod of result) { + expect(pod.url).not.equal(servers[3].url) + } + + done() + }) + } + ) + }) + + it('Should pod 1 quit friends', function (done) { + this.timeout(25000) + + series([ + // Upload a video on server 3 for aditionnal tests + function (next) { + uploadVideo(3, next) + }, + function (next) { + setTimeout(next, 15000) + }, + function (next) { + quitFriends(1, next) + }, + // Remove pod 1 from pod 2 + function (next) { + getVideos(1, function (err, res) { + if (err) throw err + + const videos = res.body.data + expect(videos).to.be.an('array') + expect(videos.length).to.equal(2) + + next() + }) + }], + function (err) { + if (err) throw err + + getVideos(2, function (err, res) { + if (err) throw err + + const videos = res.body.data + expect(videos).to.be.an('array') + expect(videos.length).to.equal(3) + done() + }) + } + ) + }) + + it('Should make friends between pod 1 and 2 and exchange their videos', function (done) { + this.timeout(20000) + makeFriends(1, function () { + setTimeout(function () { + getVideos(1, function (err, res) { + if (err) throw err + + const videos = res.body.data + expect(videos).to.be.an('array') + expect(videos.length).to.equal(5) + + done() + }) + }, 11000) + }) + }) + + after(function (done) { + servers.forEach(function (server) { + process.kill(-server.app.pid) + }) + + if (this.ok) { + serversUtils.flushTests(done) + } else { + done() + } + }) +}) diff --git a/server/tests/api/friends-basic.js b/server/tests/api/friends-basic.js new file mode 100644 index 000000000..2a6883acb --- /dev/null +++ b/server/tests/api/friends-basic.js @@ -0,0 +1,192 @@ +'use strict' + +const chai = require('chai') +const each = require('async/each') +const expect = chai.expect +const series = require('async/series') + +const loginUtils = require('../utils/login') +const podsUtils = require('../utils/pods') +const serversUtils = require('../utils/servers') + +describe('Test basic friends', function () { + let servers = [] + + function makeFriends (podNumber, callback) { + const server = servers[podNumber - 1] + return podsUtils.makeFriends(server.url, server.accessToken, callback) + } + + function testMadeFriends (servers, serverToTest, callback) { + const friends = [] + for (let i = 0; i < servers.length; i++) { + if (servers[i].url === serverToTest.url) continue + friends.push(servers[i].url) + } + + podsUtils.getFriendsList(serverToTest.url, function (err, res) { + if (err) throw err + + const result = res.body + expect(result).to.be.an('array') + expect(result.length).to.equal(2) + + const resultUrls = [ result[0].url, result[1].url ] + expect(resultUrls[0]).to.not.equal(resultUrls[1]) + + const errorString = 'Friends url do not correspond for ' + serverToTest.url + expect(friends).to.contain(resultUrls[0], errorString) + expect(friends).to.contain(resultUrls[1], errorString) + callback() + }) + } + + // --------------------------------------------------------------- + + before(function (done) { + this.timeout(20000) + serversUtils.flushAndRunMultipleServers(3, function (serversRun, urlsRun) { + servers = serversRun + + each(servers, function (server, callbackEach) { + loginUtils.loginAndGetAccessToken(server, function (err, accessToken) { + if (err) return callbackEach(err) + + server.accessToken = accessToken + callbackEach() + }) + }, done) + }) + }) + + it('Should not have friends', function (done) { + each(servers, function (server, callback) { + podsUtils.getFriendsList(server.url, function (err, res) { + if (err) throw err + + const result = res.body + expect(result).to.be.an('array') + expect(result.length).to.equal(0) + callback() + }) + }, done) + }) + + it('Should make friends', function (done) { + this.timeout(10000) + + series([ + // The second pod make friend with the third + function (next) { + makeFriends(2, next) + }, + // Wait for the request between pods + function (next) { + setTimeout(next, 1000) + }, + // The second pod should have the third as a friend + function (next) { + podsUtils.getFriendsList(servers[1].url, function (err, res) { + if (err) throw err + + const result = res.body + expect(result).to.be.an('array') + expect(result.length).to.equal(1) + expect(result[0].url).to.be.equal(servers[2].url) + + next() + }) + }, + // Same here, the third pod should have the second pod as a friend + function (next) { + podsUtils.getFriendsList(servers[2].url, function (err, res) { + if (err) throw err + + const result = res.body + expect(result).to.be.an('array') + expect(result.length).to.equal(1) + expect(result[0].url).to.be.equal(servers[1].url) + + next() + }) + }, + // Finally the first pod make friend with the second pod + function (next) { + makeFriends(1, next) + }, + // Wait for the request between pods + function (next) { + setTimeout(next, 1000) + } + ], + // Now each pod should be friend with the other ones + function (err) { + if (err) throw err + each(servers, function (server, callback) { + testMadeFriends(servers, server, callback) + }, done) + }) + }) + + it('Should not be allowed to make friend again', function (done) { + const server = servers[1] + podsUtils.makeFriends(server.url, server.accessToken, 409, done) + }) + + it('Should quit friends of pod 2', function (done) { + series([ + // Pod 1 quit friends + function (next) { + const server = servers[1] + podsUtils.quitFriends(server.url, server.accessToken, next) + }, + // Pod 1 should not have friends anymore + function (next) { + podsUtils.getFriendsList(servers[1].url, function (err, res) { + if (err) throw err + + const result = res.body + expect(result).to.be.an('array') + expect(result.length).to.equal(0) + + next() + }) + }, + // Other pods shouldn't have pod 1 too + function (next) { + each([ servers[0].url, servers[2].url ], function (url, callback) { + podsUtils.getFriendsList(url, function (err, res) { + if (err) throw err + + const result = res.body + expect(result).to.be.an('array') + expect(result.length).to.equal(1) + expect(result[0].url).not.to.be.equal(servers[1].url) + callback() + }) + }, next) + } + ], done) + }) + + it('Should allow pod 2 to make friend again', function (done) { + const server = servers[1] + podsUtils.makeFriends(server.url, server.accessToken, function () { + each(servers, function (server, callback) { + testMadeFriends(servers, server, callback) + }, done) + }) + }) + + after(function (done) { + servers.forEach(function (server) { + process.kill(-server.app.pid) + }) + + if (this.ok) { + serversUtils.flushTests(done) + } else { + done() + } + }) +}) diff --git a/server/tests/api/friendsAdvanced.js b/server/tests/api/friendsAdvanced.js deleted file mode 100644 index 0d24481ef..000000000 --- a/server/tests/api/friendsAdvanced.js +++ /dev/null @@ -1,284 +0,0 @@ -'use strict' - -const chai = require('chai') -const each = require('async/each') -const expect = chai.expect -const series = require('async/series') - -const loginUtils = require('../utils/login') -const podsUtils = require('../utils/pods') -const serversUtils = require('../utils/servers') -const videosUtils = require('../utils/videos') - -describe('Test advanced friends', function () { - let servers = [] - - function makeFriends (podNumber, callback) { - const server = servers[podNumber - 1] - return podsUtils.makeFriends(server.url, server.accessToken, callback) - } - - function quitFriends (podNumber, callback) { - const server = servers[podNumber - 1] - return podsUtils.quitFriends(server.url, server.accessToken, callback) - } - - function getFriendsList (podNumber, end) { - const server = servers[podNumber - 1] - return podsUtils.getFriendsList(server.url, end) - } - - function uploadVideo (podNumber, callback) { - const name = 'my super video' - const description = 'my super description' - const tags = [ 'tag1', 'tag2' ] - const fixture = 'video_short.webm' - const server = servers[podNumber - 1] - - return videosUtils.uploadVideo(server.url, server.accessToken, name, description, tags, fixture, callback) - } - - function getVideos (podNumber, callback) { - return videosUtils.getVideosList(servers[podNumber - 1].url, callback) - } - - // --------------------------------------------------------------- - - before(function (done) { - this.timeout(30000) - serversUtils.flushAndRunMultipleServers(6, function (serversRun, urlsRun) { - servers = serversRun - - each(servers, function (server, callbackEach) { - loginUtils.loginAndGetAccessToken(server, function (err, accessToken) { - if (err) return callbackEach(err) - - server.accessToken = accessToken - callbackEach() - }) - }, done) - }) - }) - - it('Should make friends with two pod each in a different group', function (done) { - this.timeout(20000) - - series([ - // Pod 3 makes friend with the first one - function (next) { - makeFriends(3, next) - }, - // Pod 4 makes friend with the second one - function (next) { - makeFriends(4, next) - }, - // Now if the fifth wants to make friends with the third et the first - function (next) { - makeFriends(5, next) - }, - function (next) { - setTimeout(next, 11000) - }], - function (err) { - if (err) throw err - - // It should have 0 friends - getFriendsList(5, function (err, res) { - if (err) throw err - - expect(res.body.length).to.equal(0) - - done() - }) - } - ) - }) - - it('Should quit all friends', function (done) { - this.timeout(10000) - - series([ - function (next) { - quitFriends(1, next) - }, - function (next) { - quitFriends(2, next) - }], - function (err) { - if (err) throw err - - each([ 1, 2, 3, 4, 5, 6 ], function (i, callback) { - getFriendsList(i, function (err, res) { - if (err) throw err - - expect(res.body.length).to.equal(0) - - callback() - }) - }, done) - } - ) - }) - - it('Should make friends with the pods 1, 2, 3', function (done) { - this.timeout(150000) - - series([ - // Pods 1, 2, 3 and 4 become friends - function (next) { - makeFriends(2, next) - }, - function (next) { - makeFriends(1, next) - }, - function (next) { - makeFriends(4, next) - }, - // Check the pods 1, 2, 3 and 4 are friends - function (next) { - each([ 1, 2, 3, 4 ], function (i, callback) { - getFriendsList(i, function (err, res) { - if (err) throw err - - expect(res.body.length).to.equal(3) - - callback() - }) - }, next) - }, - // Kill pod 4 - function (next) { - servers[3].app.kill() - next() - }, - // Expulse pod 4 from pod 1 and 2 - function (next) { - uploadVideo(1, next) - }, - function (next) { - uploadVideo(2, next) - }, - function (next) { - setTimeout(next, 11000) - }, - function (next) { - uploadVideo(1, next) - }, - function (next) { - uploadVideo(2, next) - }, - function (next) { - setTimeout(next, 11000) - }, - // Rerun server 4 - function (next) { - serversUtils.runServer(4, function (server) { - servers[3].app = server.app - next() - }) - }, - function (next) { - getFriendsList(4, function (err, res) { - if (err) throw err - - // Pod 4 didn't know pod 1 and 2 removed it - expect(res.body.length).to.equal(3) - next() - }) - }, - // Pod 6 ask pod 1, 2 and 3 - function (next) { - makeFriends(6, next) - }, - function (next) { - setTimeout(next, 11000) - }], - function (err) { - if (err) throw err - - getFriendsList(6, function (err, res) { - if (err) throw err - - // Pod 4 should not be our friend - const result = res.body - expect(result.length).to.equal(3) - for (const pod of result) { - expect(pod.url).not.equal(servers[3].url) - } - - done() - }) - } - ) - }) - - it('Should pod 1 quit friends', function (done) { - this.timeout(25000) - - series([ - // Upload a video on server 3 for aditionnal tests - function (next) { - uploadVideo(3, next) - }, - function (next) { - setTimeout(next, 15000) - }, - function (next) { - quitFriends(1, next) - }, - // Remove pod 1 from pod 2 - function (next) { - getVideos(1, function (err, res) { - if (err) throw err - - const videos = res.body.data - expect(videos).to.be.an('array') - expect(videos.length).to.equal(2) - - next() - }) - }], - function (err) { - if (err) throw err - - getVideos(2, function (err, res) { - if (err) throw err - - const videos = res.body.data - expect(videos).to.be.an('array') - expect(videos.length).to.equal(3) - done() - }) - } - ) - }) - - it('Should make friends between pod 1 and 2 and exchange their videos', function (done) { - this.timeout(20000) - makeFriends(1, function () { - setTimeout(function () { - getVideos(1, function (err, res) { - if (err) throw err - - const videos = res.body.data - expect(videos).to.be.an('array') - expect(videos.length).to.equal(5) - - done() - }) - }, 11000) - }) - }) - - after(function (done) { - servers.forEach(function (server) { - process.kill(-server.app.pid) - }) - - if (this.ok) { - serversUtils.flushTests(done) - } else { - done() - } - }) -}) diff --git a/server/tests/api/friendsBasic.js b/server/tests/api/friendsBasic.js deleted file mode 100644 index 2a6883acb..000000000 --- a/server/tests/api/friendsBasic.js +++ /dev/null @@ -1,192 +0,0 @@ -'use strict' - -const chai = require('chai') -const each = require('async/each') -const expect = chai.expect -const series = require('async/series') - -const loginUtils = require('../utils/login') -const podsUtils = require('../utils/pods') -const serversUtils = require('../utils/servers') - -describe('Test basic friends', function () { - let servers = [] - - function makeFriends (podNumber, callback) { - const server = servers[podNumber - 1] - return podsUtils.makeFriends(server.url, server.accessToken, callback) - } - - function testMadeFriends (servers, serverToTest, callback) { - const friends = [] - for (let i = 0; i < servers.length; i++) { - if (servers[i].url === serverToTest.url) continue - friends.push(servers[i].url) - } - - podsUtils.getFriendsList(serverToTest.url, function (err, res) { - if (err) throw err - - const result = res.body - expect(result).to.be.an('array') - expect(result.length).to.equal(2) - - const resultUrls = [ result[0].url, result[1].url ] - expect(resultUrls[0]).to.not.equal(resultUrls[1]) - - const errorString = 'Friends url do not correspond for ' + serverToTest.url - expect(friends).to.contain(resultUrls[0], errorString) - expect(friends).to.contain(resultUrls[1], errorString) - callback() - }) - } - - // --------------------------------------------------------------- - - before(function (done) { - this.timeout(20000) - serversUtils.flushAndRunMultipleServers(3, function (serversRun, urlsRun) { - servers = serversRun - - each(servers, function (server, callbackEach) { - loginUtils.loginAndGetAccessToken(server, function (err, accessToken) { - if (err) return callbackEach(err) - - server.accessToken = accessToken - callbackEach() - }) - }, done) - }) - }) - - it('Should not have friends', function (done) { - each(servers, function (server, callback) { - podsUtils.getFriendsList(server.url, function (err, res) { - if (err) throw err - - const result = res.body - expect(result).to.be.an('array') - expect(result.length).to.equal(0) - callback() - }) - }, done) - }) - - it('Should make friends', function (done) { - this.timeout(10000) - - series([ - // The second pod make friend with the third - function (next) { - makeFriends(2, next) - }, - // Wait for the request between pods - function (next) { - setTimeout(next, 1000) - }, - // The second pod should have the third as a friend - function (next) { - podsUtils.getFriendsList(servers[1].url, function (err, res) { - if (err) throw err - - const result = res.body - expect(result).to.be.an('array') - expect(result.length).to.equal(1) - expect(result[0].url).to.be.equal(servers[2].url) - - next() - }) - }, - // Same here, the third pod should have the second pod as a friend - function (next) { - podsUtils.getFriendsList(servers[2].url, function (err, res) { - if (err) throw err - - const result = res.body - expect(result).to.be.an('array') - expect(result.length).to.equal(1) - expect(result[0].url).to.be.equal(servers[1].url) - - next() - }) - }, - // Finally the first pod make friend with the second pod - function (next) { - makeFriends(1, next) - }, - // Wait for the request between pods - function (next) { - setTimeout(next, 1000) - } - ], - // Now each pod should be friend with the other ones - function (err) { - if (err) throw err - each(servers, function (server, callback) { - testMadeFriends(servers, server, callback) - }, done) - }) - }) - - it('Should not be allowed to make friend again', function (done) { - const server = servers[1] - podsUtils.makeFriends(server.url, server.accessToken, 409, done) - }) - - it('Should quit friends of pod 2', function (done) { - series([ - // Pod 1 quit friends - function (next) { - const server = servers[1] - podsUtils.quitFriends(server.url, server.accessToken, next) - }, - // Pod 1 should not have friends anymore - function (next) { - podsUtils.getFriendsList(servers[1].url, function (err, res) { - if (err) throw err - - const result = res.body - expect(result).to.be.an('array') - expect(result.length).to.equal(0) - - next() - }) - }, - // Other pods shouldn't have pod 1 too - function (next) { - each([ servers[0].url, servers[2].url ], function (url, callback) { - podsUtils.getFriendsList(url, function (err, res) { - if (err) throw err - - const result = res.body - expect(result).to.be.an('array') - expect(result.length).to.equal(1) - expect(result[0].url).not.to.be.equal(servers[1].url) - callback() - }) - }, next) - } - ], done) - }) - - it('Should allow pod 2 to make friend again', function (done) { - const server = servers[1] - podsUtils.makeFriends(server.url, server.accessToken, function () { - each(servers, function (server, callback) { - testMadeFriends(servers, server, callback) - }, done) - }) - }) - - after(function (done) { - servers.forEach(function (server) { - process.kill(-server.app.pid) - }) - - if (this.ok) { - serversUtils.flushTests(done) - } else { - done() - } - }) -}) diff --git a/server/tests/api/index.js b/server/tests/api/index.js index 61c9a7aca..11f49e1e2 100644 --- a/server/tests/api/index.js +++ b/server/tests/api/index.js @@ -1,9 +1,9 @@ 'use strict' // Order of the tests we want to execute -require('./checkParams') -require('./friendsBasic') +require('./check-params') +require('./friends-basic') require('./users') -require('./singlePod') -require('./multiplePods') -require('./friendsAdvanced') +require('./single-pod') +require('./multiple-pods') +require('./friends-advanced') diff --git a/server/tests/api/multiple-pods.js b/server/tests/api/multiple-pods.js new file mode 100644 index 000000000..b86f88c22 --- /dev/null +++ b/server/tests/api/multiple-pods.js @@ -0,0 +1,427 @@ +'use strict' + +const chai = require('chai') +const each = require('async/each') +const expect = chai.expect +const pathUtils = require('path') +const series = require('async/series') + +const loginUtils = require('../utils/login') +const miscsUtils = require('../utils/miscs') +const podsUtils = require('../utils/pods') +const serversUtils = require('../utils/servers') +const videosUtils = require('../utils/videos') +const webtorrent = require(pathUtils.join(__dirname, '../../lib/webtorrent')) +webtorrent.silent = true + +describe('Test multiple pods', function () { + let servers = [] + const toRemove = [] + + before(function (done) { + this.timeout(30000) + + series([ + // Run servers + function (next) { + serversUtils.flushAndRunMultipleServers(3, function (serversRun) { + servers = serversRun + next() + }) + }, + // Get the access tokens + function (next) { + each(servers, function (server, callbackEach) { + loginUtils.loginAndGetAccessToken(server, function (err, accessToken) { + if (err) return callbackEach(err) + + server.accessToken = accessToken + callbackEach() + }) + }, next) + }, + // The second pod make friend with the third + function (next) { + const server = servers[1] + podsUtils.makeFriends(server.url, server.accessToken, next) + }, + // Wait for the request between pods + function (next) { + setTimeout(next, 10000) + }, + // Pod 1 make friends too + function (next) { + const server = servers[0] + podsUtils.makeFriends(server.url, server.accessToken, next) + }, + function (next) { + webtorrent.create({ host: 'client', port: '1' }, next) + } + ], done) + }) + + it('Should not have videos for all pods', function (done) { + each(servers, function (server, callback) { + videosUtils.getVideosList(server.url, function (err, res) { + if (err) throw err + + const videos = res.body.data + expect(videos).to.be.an('array') + expect(videos.length).to.equal(0) + + callback() + }) + }, done) + }) + + describe('Should upload the video and propagate on each pod', function () { + it('Should upload the video on pod 1 and propagate on each pod', function (done) { + this.timeout(15000) + + series([ + function (next) { + const name = 'my super name for pod 1' + const description = 'my super description for pod 1' + const tags = [ 'tag1p1', 'tag2p1' ] + const file = 'video_short1.webm' + videosUtils.uploadVideo(servers[0].url, servers[0].accessToken, name, description, tags, file, next) + }, + function (next) { + setTimeout(next, 11000) + }], + // All pods should have this video + function (err) { + if (err) throw err + + each(servers, function (server, callback) { + let baseMagnet = null + + videosUtils.getVideosList(server.url, function (err, res) { + if (err) throw err + + const videos = res.body.data + expect(videos).to.be.an('array') + expect(videos.length).to.equal(1) + const video = videos[0] + expect(video.name).to.equal('my super name for pod 1') + expect(video.description).to.equal('my super description for pod 1') + expect(video.podUrl).to.equal('localhost:9001') + expect(video.magnetUri).to.exist + expect(video.duration).to.equal(10) + expect(video.tags).to.deep.equal([ 'tag1p1', 'tag2p1' ]) + expect(miscsUtils.dateIsValid(video.createdDate)).to.be.true + expect(video.author).to.equal('root') + + if (server.url !== 'http://localhost:9001') { + expect(video.isLocal).to.be.false + } else { + expect(video.isLocal).to.be.true + } + + // All pods should have the same magnet Uri + if (baseMagnet === null) { + baseMagnet = video.magnetUri + } else { + expect(video.magnetUri).to.equal.magnetUri + } + + videosUtils.testVideoImage(server.url, 'video_short1.webm', video.thumbnailPath, function (err, test) { + if (err) throw err + expect(test).to.equal(true) + + callback() + }) + }) + }, done) + } + ) + }) + + it('Should upload the video on pod 2 and propagate on each pod', function (done) { + this.timeout(15000) + + series([ + function (next) { + const name = 'my super name for pod 2' + const description = 'my super description for pod 2' + const tags = [ 'tag1p2', 'tag2p2', 'tag3p2' ] + const file = 'video_short2.webm' + videosUtils.uploadVideo(servers[1].url, servers[1].accessToken, name, description, tags, file, next) + }, + function (next) { + setTimeout(next, 11000) + }], + // All pods should have this video + function (err) { + if (err) throw err + + each(servers, function (server, callback) { + let baseMagnet = null + + videosUtils.getVideosList(server.url, function (err, res) { + if (err) throw err + + const videos = res.body.data + expect(videos).to.be.an('array') + expect(videos.length).to.equal(2) + const video = videos[1] + expect(video.name).to.equal('my super name for pod 2') + expect(video.description).to.equal('my super description for pod 2') + expect(video.podUrl).to.equal('localhost:9002') + expect(video.magnetUri).to.exist + expect(video.duration).to.equal(5) + expect(video.tags).to.deep.equal([ 'tag1p2', 'tag2p2', 'tag3p2' ]) + expect(miscsUtils.dateIsValid(video.createdDate)).to.be.true + expect(video.author).to.equal('root') + + if (server.url !== 'http://localhost:9002') { + expect(video.isLocal).to.be.false + } else { + expect(video.isLocal).to.be.true + } + + // All pods should have the same magnet Uri + if (baseMagnet === null) { + baseMagnet = video.magnetUri + } else { + expect(video.magnetUri).to.equal.magnetUri + } + + videosUtils.testVideoImage(server.url, 'video_short2.webm', video.thumbnailPath, function (err, test) { + if (err) throw err + expect(test).to.equal(true) + + callback() + }) + }) + }, done) + } + ) + }) + + it('Should upload two videos on pod 3 and propagate on each pod', function (done) { + this.timeout(30000) + + series([ + function (next) { + const name = 'my super name for pod 3' + const description = 'my super description for pod 3' + const tags = [ 'tag1p3' ] + const file = 'video_short3.webm' + videosUtils.uploadVideo(servers[2].url, servers[2].accessToken, name, description, tags, file, next) + }, + function (next) { + const name = 'my super name for pod 3-2' + const description = 'my super description for pod 3-2' + const tags = [ 'tag2p3', 'tag3p3', 'tag4p3' ] + const file = 'video_short.webm' + videosUtils.uploadVideo(servers[2].url, servers[2].accessToken, name, description, tags, file, next) + }, + function (next) { + setTimeout(next, 22000) + }], + function (err) { + if (err) throw err + + let baseMagnet = null + // All pods should have this video + each(servers, function (server, callback) { + videosUtils.getVideosList(server.url, function (err, res) { + if (err) throw err + + const videos = res.body.data + expect(videos).to.be.an('array') + expect(videos.length).to.equal(4) + + // We not sure about the order of the two last uploads + let video1 = null + let video2 = null + if (videos[2].name === 'my super name for pod 3') { + video1 = videos[2] + video2 = videos[3] + } else { + video1 = videos[3] + video2 = videos[2] + } + + expect(video1.name).to.equal('my super name for pod 3') + expect(video1.description).to.equal('my super description for pod 3') + expect(video1.podUrl).to.equal('localhost:9003') + expect(video1.magnetUri).to.exist + expect(video1.duration).to.equal(5) + expect(video1.tags).to.deep.equal([ 'tag1p3' ]) + expect(video1.author).to.equal('root') + expect(miscsUtils.dateIsValid(video1.createdDate)).to.be.true + + expect(video2.name).to.equal('my super name for pod 3-2') + expect(video2.description).to.equal('my super description for pod 3-2') + expect(video2.podUrl).to.equal('localhost:9003') + expect(video2.magnetUri).to.exist + expect(video2.duration).to.equal(5) + expect(video2.tags).to.deep.equal([ 'tag2p3', 'tag3p3', 'tag4p3' ]) + expect(video2.author).to.equal('root') + expect(miscsUtils.dateIsValid(video2.createdDate)).to.be.true + + if (server.url !== 'http://localhost:9003') { + expect(video1.isLocal).to.be.false + expect(video2.isLocal).to.be.false + } else { + expect(video1.isLocal).to.be.true + expect(video2.isLocal).to.be.true + } + + // All pods should have the same magnet Uri + if (baseMagnet === null) { + baseMagnet = video2.magnetUri + } else { + expect(video2.magnetUri).to.equal.magnetUri + } + + videosUtils.testVideoImage(server.url, 'video_short3.webm', video1.thumbnailPath, function (err, test) { + if (err) throw err + expect(test).to.equal(true) + + videosUtils.testVideoImage(server.url, 'video_short.webm', video2.thumbnailPath, function (err, test) { + if (err) throw err + expect(test).to.equal(true) + + callback() + }) + }) + }) + }, done) + } + ) + }) + }) + + describe('Should seed the uploaded video', function () { + it('Should add the file 1 by asking pod 3', function (done) { + // Yes, this could be long + this.timeout(200000) + + videosUtils.getVideosList(servers[2].url, function (err, res) { + if (err) throw err + + const video = res.body.data[0] + toRemove.push(res.body.data[2].id) + toRemove.push(res.body.data[3].id) + + webtorrent.add(video.magnetUri, function (torrent) { + expect(torrent.files).to.exist + expect(torrent.files.length).to.equal(1) + expect(torrent.files[0].path).to.exist.and.to.not.equal('') + + done() + }) + }) + }) + + it('Should add the file 2 by asking pod 1', function (done) { + // Yes, this could be long + this.timeout(200000) + + videosUtils.getVideosList(servers[0].url, function (err, res) { + if (err) throw err + + const video = res.body.data[1] + + webtorrent.add(video.magnetUri, function (torrent) { + expect(torrent.files).to.exist + expect(torrent.files.length).to.equal(1) + expect(torrent.files[0].path).to.exist.and.to.not.equal('') + + done() + }) + }) + }) + + it('Should add the file 3 by asking pod 2', function (done) { + // Yes, this could be long + this.timeout(200000) + + videosUtils.getVideosList(servers[1].url, function (err, res) { + if (err) throw err + + const video = res.body.data[2] + + webtorrent.add(video.magnetUri, function (torrent) { + expect(torrent.files).to.exist + expect(torrent.files.length).to.equal(1) + expect(torrent.files[0].path).to.exist.and.to.not.equal('') + + webtorrent.remove(video.magnetUri, done) + }) + }) + }) + + it('Should add the file 3-2 by asking pod 1', function (done) { + // Yes, this could be long + this.timeout(200000) + + videosUtils.getVideosList(servers[0].url, function (err, res) { + if (err) throw err + + const video = res.body.data[3] + + webtorrent.add(video.magnetUri, function (torrent) { + expect(torrent.files).to.exist + expect(torrent.files.length).to.equal(1) + expect(torrent.files[0].path).to.exist.and.to.not.equal('') + + done() + }) + }) + }) + + it('Should remove the file 3 and 3-2 by asking pod 3', function (done) { + this.timeout(15000) + + series([ + function (next) { + videosUtils.removeVideo(servers[2].url, servers[2].accessToken, toRemove[0], next) + }, + function (next) { + videosUtils.removeVideo(servers[2].url, servers[2].accessToken, toRemove[1], next) + }], + function (err) { + if (err) throw err + setTimeout(done, 11000) + } + ) + }) + + it('Should have videos 1 and 3 on each pod', function (done) { + each(servers, function (server, callback) { + videosUtils.getVideosList(server.url, function (err, res) { + if (err) throw err + + const videos = res.body.data + expect(videos).to.be.an('array') + expect(videos.length).to.equal(2) + expect(videos[0].id).not.to.equal(videos[1].id) + expect(videos[0].id).not.to.equal(toRemove[0]) + expect(videos[1].id).not.to.equal(toRemove[0]) + expect(videos[0].id).not.to.equal(toRemove[1]) + expect(videos[1].id).not.to.equal(toRemove[1]) + + callback() + }) + }, done) + }) + }) + + after(function (done) { + servers.forEach(function (server) { + process.kill(-server.app.pid) + }) + process.kill(-webtorrent.app.pid) + + // Keep the logs if the test failed + if (this.ok) { + serversUtils.flushTests(done) + } else { + done() + } + }) +}) diff --git a/server/tests/api/multiplePods.js b/server/tests/api/multiplePods.js deleted file mode 100644 index b86f88c22..000000000 --- a/server/tests/api/multiplePods.js +++ /dev/null @@ -1,427 +0,0 @@ -'use strict' - -const chai = require('chai') -const each = require('async/each') -const expect = chai.expect -const pathUtils = require('path') -const series = require('async/series') - -const loginUtils = require('../utils/login') -const miscsUtils = require('../utils/miscs') -const podsUtils = require('../utils/pods') -const serversUtils = require('../utils/servers') -const videosUtils = require('../utils/videos') -const webtorrent = require(pathUtils.join(__dirname, '../../lib/webtorrent')) -webtorrent.silent = true - -describe('Test multiple pods', function () { - let servers = [] - const toRemove = [] - - before(function (done) { - this.timeout(30000) - - series([ - // Run servers - function (next) { - serversUtils.flushAndRunMultipleServers(3, function (serversRun) { - servers = serversRun - next() - }) - }, - // Get the access tokens - function (next) { - each(servers, function (server, callbackEach) { - loginUtils.loginAndGetAccessToken(server, function (err, accessToken) { - if (err) return callbackEach(err) - - server.accessToken = accessToken - callbackEach() - }) - }, next) - }, - // The second pod make friend with the third - function (next) { - const server = servers[1] - podsUtils.makeFriends(server.url, server.accessToken, next) - }, - // Wait for the request between pods - function (next) { - setTimeout(next, 10000) - }, - // Pod 1 make friends too - function (next) { - const server = servers[0] - podsUtils.makeFriends(server.url, server.accessToken, next) - }, - function (next) { - webtorrent.create({ host: 'client', port: '1' }, next) - } - ], done) - }) - - it('Should not have videos for all pods', function (done) { - each(servers, function (server, callback) { - videosUtils.getVideosList(server.url, function (err, res) { - if (err) throw err - - const videos = res.body.data - expect(videos).to.be.an('array') - expect(videos.length).to.equal(0) - - callback() - }) - }, done) - }) - - describe('Should upload the video and propagate on each pod', function () { - it('Should upload the video on pod 1 and propagate on each pod', function (done) { - this.timeout(15000) - - series([ - function (next) { - const name = 'my super name for pod 1' - const description = 'my super description for pod 1' - const tags = [ 'tag1p1', 'tag2p1' ] - const file = 'video_short1.webm' - videosUtils.uploadVideo(servers[0].url, servers[0].accessToken, name, description, tags, file, next) - }, - function (next) { - setTimeout(next, 11000) - }], - // All pods should have this video - function (err) { - if (err) throw err - - each(servers, function (server, callback) { - let baseMagnet = null - - videosUtils.getVideosList(server.url, function (err, res) { - if (err) throw err - - const videos = res.body.data - expect(videos).to.be.an('array') - expect(videos.length).to.equal(1) - const video = videos[0] - expect(video.name).to.equal('my super name for pod 1') - expect(video.description).to.equal('my super description for pod 1') - expect(video.podUrl).to.equal('localhost:9001') - expect(video.magnetUri).to.exist - expect(video.duration).to.equal(10) - expect(video.tags).to.deep.equal([ 'tag1p1', 'tag2p1' ]) - expect(miscsUtils.dateIsValid(video.createdDate)).to.be.true - expect(video.author).to.equal('root') - - if (server.url !== 'http://localhost:9001') { - expect(video.isLocal).to.be.false - } else { - expect(video.isLocal).to.be.true - } - - // All pods should have the same magnet Uri - if (baseMagnet === null) { - baseMagnet = video.magnetUri - } else { - expect(video.magnetUri).to.equal.magnetUri - } - - videosUtils.testVideoImage(server.url, 'video_short1.webm', video.thumbnailPath, function (err, test) { - if (err) throw err - expect(test).to.equal(true) - - callback() - }) - }) - }, done) - } - ) - }) - - it('Should upload the video on pod 2 and propagate on each pod', function (done) { - this.timeout(15000) - - series([ - function (next) { - const name = 'my super name for pod 2' - const description = 'my super description for pod 2' - const tags = [ 'tag1p2', 'tag2p2', 'tag3p2' ] - const file = 'video_short2.webm' - videosUtils.uploadVideo(servers[1].url, servers[1].accessToken, name, description, tags, file, next) - }, - function (next) { - setTimeout(next, 11000) - }], - // All pods should have this video - function (err) { - if (err) throw err - - each(servers, function (server, callback) { - let baseMagnet = null - - videosUtils.getVideosList(server.url, function (err, res) { - if (err) throw err - - const videos = res.body.data - expect(videos).to.be.an('array') - expect(videos.length).to.equal(2) - const video = videos[1] - expect(video.name).to.equal('my super name for pod 2') - expect(video.description).to.equal('my super description for pod 2') - expect(video.podUrl).to.equal('localhost:9002') - expect(video.magnetUri).to.exist - expect(video.duration).to.equal(5) - expect(video.tags).to.deep.equal([ 'tag1p2', 'tag2p2', 'tag3p2' ]) - expect(miscsUtils.dateIsValid(video.createdDate)).to.be.true - expect(video.author).to.equal('root') - - if (server.url !== 'http://localhost:9002') { - expect(video.isLocal).to.be.false - } else { - expect(video.isLocal).to.be.true - } - - // All pods should have the same magnet Uri - if (baseMagnet === null) { - baseMagnet = video.magnetUri - } else { - expect(video.magnetUri).to.equal.magnetUri - } - - videosUtils.testVideoImage(server.url, 'video_short2.webm', video.thumbnailPath, function (err, test) { - if (err) throw err - expect(test).to.equal(true) - - callback() - }) - }) - }, done) - } - ) - }) - - it('Should upload two videos on pod 3 and propagate on each pod', function (done) { - this.timeout(30000) - - series([ - function (next) { - const name = 'my super name for pod 3' - const description = 'my super description for pod 3' - const tags = [ 'tag1p3' ] - const file = 'video_short3.webm' - videosUtils.uploadVideo(servers[2].url, servers[2].accessToken, name, description, tags, file, next) - }, - function (next) { - const name = 'my super name for pod 3-2' - const description = 'my super description for pod 3-2' - const tags = [ 'tag2p3', 'tag3p3', 'tag4p3' ] - const file = 'video_short.webm' - videosUtils.uploadVideo(servers[2].url, servers[2].accessToken, name, description, tags, file, next) - }, - function (next) { - setTimeout(next, 22000) - }], - function (err) { - if (err) throw err - - let baseMagnet = null - // All pods should have this video - each(servers, function (server, callback) { - videosUtils.getVideosList(server.url, function (err, res) { - if (err) throw err - - const videos = res.body.data - expect(videos).to.be.an('array') - expect(videos.length).to.equal(4) - - // We not sure about the order of the two last uploads - let video1 = null - let video2 = null - if (videos[2].name === 'my super name for pod 3') { - video1 = videos[2] - video2 = videos[3] - } else { - video1 = videos[3] - video2 = videos[2] - } - - expect(video1.name).to.equal('my super name for pod 3') - expect(video1.description).to.equal('my super description for pod 3') - expect(video1.podUrl).to.equal('localhost:9003') - expect(video1.magnetUri).to.exist - expect(video1.duration).to.equal(5) - expect(video1.tags).to.deep.equal([ 'tag1p3' ]) - expect(video1.author).to.equal('root') - expect(miscsUtils.dateIsValid(video1.createdDate)).to.be.true - - expect(video2.name).to.equal('my super name for pod 3-2') - expect(video2.description).to.equal('my super description for pod 3-2') - expect(video2.podUrl).to.equal('localhost:9003') - expect(video2.magnetUri).to.exist - expect(video2.duration).to.equal(5) - expect(video2.tags).to.deep.equal([ 'tag2p3', 'tag3p3', 'tag4p3' ]) - expect(video2.author).to.equal('root') - expect(miscsUtils.dateIsValid(video2.createdDate)).to.be.true - - if (server.url !== 'http://localhost:9003') { - expect(video1.isLocal).to.be.false - expect(video2.isLocal).to.be.false - } else { - expect(video1.isLocal).to.be.true - expect(video2.isLocal).to.be.true - } - - // All pods should have the same magnet Uri - if (baseMagnet === null) { - baseMagnet = video2.magnetUri - } else { - expect(video2.magnetUri).to.equal.magnetUri - } - - videosUtils.testVideoImage(server.url, 'video_short3.webm', video1.thumbnailPath, function (err, test) { - if (err) throw err - expect(test).to.equal(true) - - videosUtils.testVideoImage(server.url, 'video_short.webm', video2.thumbnailPath, function (err, test) { - if (err) throw err - expect(test).to.equal(true) - - callback() - }) - }) - }) - }, done) - } - ) - }) - }) - - describe('Should seed the uploaded video', function () { - it('Should add the file 1 by asking pod 3', function (done) { - // Yes, this could be long - this.timeout(200000) - - videosUtils.getVideosList(servers[2].url, function (err, res) { - if (err) throw err - - const video = res.body.data[0] - toRemove.push(res.body.data[2].id) - toRemove.push(res.body.data[3].id) - - webtorrent.add(video.magnetUri, function (torrent) { - expect(torrent.files).to.exist - expect(torrent.files.length).to.equal(1) - expect(torrent.files[0].path).to.exist.and.to.not.equal('') - - done() - }) - }) - }) - - it('Should add the file 2 by asking pod 1', function (done) { - // Yes, this could be long - this.timeout(200000) - - videosUtils.getVideosList(servers[0].url, function (err, res) { - if (err) throw err - - const video = res.body.data[1] - - webtorrent.add(video.magnetUri, function (torrent) { - expect(torrent.files).to.exist - expect(torrent.files.length).to.equal(1) - expect(torrent.files[0].path).to.exist.and.to.not.equal('') - - done() - }) - }) - }) - - it('Should add the file 3 by asking pod 2', function (done) { - // Yes, this could be long - this.timeout(200000) - - videosUtils.getVideosList(servers[1].url, function (err, res) { - if (err) throw err - - const video = res.body.data[2] - - webtorrent.add(video.magnetUri, function (torrent) { - expect(torrent.files).to.exist - expect(torrent.files.length).to.equal(1) - expect(torrent.files[0].path).to.exist.and.to.not.equal('') - - webtorrent.remove(video.magnetUri, done) - }) - }) - }) - - it('Should add the file 3-2 by asking pod 1', function (done) { - // Yes, this could be long - this.timeout(200000) - - videosUtils.getVideosList(servers[0].url, function (err, res) { - if (err) throw err - - const video = res.body.data[3] - - webtorrent.add(video.magnetUri, function (torrent) { - expect(torrent.files).to.exist - expect(torrent.files.length).to.equal(1) - expect(torrent.files[0].path).to.exist.and.to.not.equal('') - - done() - }) - }) - }) - - it('Should remove the file 3 and 3-2 by asking pod 3', function (done) { - this.timeout(15000) - - series([ - function (next) { - videosUtils.removeVideo(servers[2].url, servers[2].accessToken, toRemove[0], next) - }, - function (next) { - videosUtils.removeVideo(servers[2].url, servers[2].accessToken, toRemove[1], next) - }], - function (err) { - if (err) throw err - setTimeout(done, 11000) - } - ) - }) - - it('Should have videos 1 and 3 on each pod', function (done) { - each(servers, function (server, callback) { - videosUtils.getVideosList(server.url, function (err, res) { - if (err) throw err - - const videos = res.body.data - expect(videos).to.be.an('array') - expect(videos.length).to.equal(2) - expect(videos[0].id).not.to.equal(videos[1].id) - expect(videos[0].id).not.to.equal(toRemove[0]) - expect(videos[1].id).not.to.equal(toRemove[0]) - expect(videos[0].id).not.to.equal(toRemove[1]) - expect(videos[1].id).not.to.equal(toRemove[1]) - - callback() - }) - }, done) - }) - }) - - after(function (done) { - servers.forEach(function (server) { - process.kill(-server.app.pid) - }) - process.kill(-webtorrent.app.pid) - - // Keep the logs if the test failed - if (this.ok) { - serversUtils.flushTests(done) - } else { - done() - } - }) -}) diff --git a/server/tests/api/single-pod.js b/server/tests/api/single-pod.js new file mode 100644 index 000000000..bdaaee46c --- /dev/null +++ b/server/tests/api/single-pod.js @@ -0,0 +1,508 @@ +'use strict' + +const chai = require('chai') +const each = require('async/each') +const expect = chai.expect +const fs = require('fs') +const keyBy = require('lodash/keyBy') +const pathUtils = require('path') +const series = require('async/series') + +const loginUtils = require('../utils/login') +const miscsUtils = require('../utils/miscs') +const serversUtils = require('../utils/servers') +const videosUtils = require('../utils/videos') +const webtorrent = require(pathUtils.join(__dirname, '../../lib/webtorrent')) +webtorrent.silent = true + +describe('Test a single pod', function () { + let server = null + let videoId = -1 + let videosListBase = null + + before(function (done) { + this.timeout(20000) + + series([ + function (next) { + serversUtils.flushTests(next) + }, + function (next) { + serversUtils.runServer(1, function (server1) { + server = server1 + next() + }) + }, + function (next) { + loginUtils.loginAndGetAccessToken(server, function (err, token) { + if (err) throw err + server.accessToken = token + next() + }) + }, + function (next) { + webtorrent.create({ host: 'client', port: '1' }, next) + } + ], done) + }) + + it('Should not have videos', function (done) { + videosUtils.getVideosList(server.url, function (err, res) { + if (err) throw err + + expect(res.body.total).to.equal(0) + expect(res.body.data).to.be.an('array') + expect(res.body.data.length).to.equal(0) + + done() + }) + }) + + it('Should upload the video', function (done) { + this.timeout(5000) + const name = 'my super name' + const description = 'my super description' + const tags = [ 'tag1', 'tag2', 'tag3' ] + const file = 'video_short.webm' + videosUtils.uploadVideo(server.url, server.accessToken, name, description, tags, file, done) + }) + + it('Should seed the uploaded video', function (done) { + // Yes, this could be long + this.timeout(60000) + + videosUtils.getVideosList(server.url, function (err, res) { + if (err) throw err + + expect(res.body.total).to.equal(1) + expect(res.body.data).to.be.an('array') + expect(res.body.data.length).to.equal(1) + + const video = res.body.data[0] + expect(video.name).to.equal('my super name') + expect(video.description).to.equal('my super description') + expect(video.podUrl).to.equal('localhost:9001') + expect(video.magnetUri).to.exist + expect(video.author).to.equal('root') + expect(video.isLocal).to.be.true + expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ]) + expect(miscsUtils.dateIsValid(video.createdDate)).to.be.true + + videosUtils.testVideoImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) { + if (err) throw err + expect(test).to.equal(true) + + videoId = video.id + + webtorrent.add(video.magnetUri, function (torrent) { + expect(torrent.files).to.exist + expect(torrent.files.length).to.equal(1) + expect(torrent.files[0].path).to.exist.and.to.not.equal('') + + done() + }) + }) + }) + }) + + it('Should get the video', function (done) { + // Yes, this could be long + this.timeout(60000) + + videosUtils.getVideo(server.url, videoId, function (err, res) { + if (err) throw err + + const video = res.body + expect(video.name).to.equal('my super name') + expect(video.description).to.equal('my super description') + expect(video.podUrl).to.equal('localhost:9001') + expect(video.magnetUri).to.exist + expect(video.author).to.equal('root') + expect(video.isLocal).to.be.true + expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ]) + expect(miscsUtils.dateIsValid(video.createdDate)).to.be.true + + videosUtils.testVideoImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) { + if (err) throw err + expect(test).to.equal(true) + + done() + }) + }) + }) + + it('Should search the video by name by default', function (done) { + videosUtils.searchVideo(server.url, 'my', function (err, res) { + if (err) throw err + + expect(res.body.total).to.equal(1) + expect(res.body.data).to.be.an('array') + expect(res.body.data.length).to.equal(1) + + const video = res.body.data[0] + expect(video.name).to.equal('my super name') + expect(video.description).to.equal('my super description') + expect(video.podUrl).to.equal('localhost:9001') + expect(video.author).to.equal('root') + expect(video.isLocal).to.be.true + expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ]) + expect(miscsUtils.dateIsValid(video.createdDate)).to.be.true + + videosUtils.testVideoImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) { + if (err) throw err + expect(test).to.equal(true) + + done() + }) + }) + }) + + it('Should search the video by podUrl', function (done) { + videosUtils.searchVideo(server.url, '9001', 'podUrl', function (err, res) { + if (err) throw err + + expect(res.body.total).to.equal(1) + expect(res.body.data).to.be.an('array') + expect(res.body.data.length).to.equal(1) + + const video = res.body.data[0] + expect(video.name).to.equal('my super name') + expect(video.description).to.equal('my super description') + expect(video.podUrl).to.equal('localhost:9001') + expect(video.author).to.equal('root') + expect(video.isLocal).to.be.true + expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ]) + expect(miscsUtils.dateIsValid(video.createdDate)).to.be.true + + videosUtils.testVideoImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) { + if (err) throw err + expect(test).to.equal(true) + + done() + }) + }) + }) + + it('Should search the video by tag', function (done) { + videosUtils.searchVideo(server.url, 'tag1', 'tags', function (err, res) { + if (err) throw err + + expect(res.body.total).to.equal(1) + expect(res.body.data).to.be.an('array') + expect(res.body.data.length).to.equal(1) + + const video = res.body.data[0] + expect(video.name).to.equal('my super name') + expect(video.description).to.equal('my super description') + expect(video.podUrl).to.equal('localhost:9001') + expect(video.author).to.equal('root') + expect(video.isLocal).to.be.true + expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ]) + expect(miscsUtils.dateIsValid(video.createdDate)).to.be.true + + videosUtils.testVideoImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) { + if (err) throw err + expect(test).to.equal(true) + + done() + }) + }) + }) + + it('Should not find a search by name by default', function (done) { + videosUtils.searchVideo(server.url, 'hello', function (err, res) { + if (err) throw err + + expect(res.body.total).to.equal(0) + expect(res.body.data).to.be.an('array') + expect(res.body.data.length).to.equal(0) + + done() + }) + }) + + it('Should not find a search by author', function (done) { + videosUtils.searchVideo(server.url, 'hello', 'author', function (err, res) { + if (err) throw err + + expect(res.body.total).to.equal(0) + expect(res.body.data).to.be.an('array') + expect(res.body.data.length).to.equal(0) + + done() + }) + }) + + it('Should not find a search by tag', function (done) { + videosUtils.searchVideo(server.url, 'tag', 'tags', function (err, res) { + if (err) throw err + + expect(res.body.total).to.equal(0) + expect(res.body.data).to.be.an('array') + expect(res.body.data.length).to.equal(0) + + done() + }) + }) + + it('Should remove the video', function (done) { + videosUtils.removeVideo(server.url, server.accessToken, videoId, function (err) { + if (err) throw err + + fs.readdir(pathUtils.join(__dirname, '../../../test1/uploads/'), function (err, files) { + if (err) throw err + + expect(files.length).to.equal(0) + done() + }) + }) + }) + + it('Should not have videos', function (done) { + videosUtils.getVideosList(server.url, function (err, res) { + if (err) throw err + + expect(res.body.total).to.equal(0) + expect(res.body.data).to.be.an('array') + expect(res.body.data.length).to.equal(0) + + done() + }) + }) + + it('Should upload 6 videos', function (done) { + this.timeout(25000) + const videos = [ + 'video_short.mp4', 'video_short.ogv', 'video_short.webm', + 'video_short1.webm', 'video_short2.webm', 'video_short3.webm' + ] + each(videos, function (video, callbackEach) { + const name = video + ' name' + const description = video + ' description' + const tags = [ 'tag1', 'tag2', 'tag3' ] + + videosUtils.uploadVideo(server.url, server.accessToken, name, description, tags, video, callbackEach) + }, done) + }) + + it('Should have the correct durations', function (done) { + videosUtils.getVideosList(server.url, function (err, res) { + if (err) throw err + + expect(res.body.total).to.equal(6) + const videos = res.body.data + expect(videos).to.be.an('array') + expect(videos.length).to.equal(6) + + const videosByName = keyBy(videos, 'name') + expect(videosByName['video_short.mp4 name'].duration).to.equal(5) + expect(videosByName['video_short.ogv name'].duration).to.equal(5) + expect(videosByName['video_short.webm name'].duration).to.equal(5) + expect(videosByName['video_short1.webm name'].duration).to.equal(10) + expect(videosByName['video_short2.webm name'].duration).to.equal(5) + expect(videosByName['video_short3.webm name'].duration).to.equal(5) + + done() + }) + }) + + it('Should have the correct thumbnails', function (done) { + videosUtils.getVideosList(server.url, function (err, res) { + if (err) throw err + + const videos = res.body.data + // For the next test + videosListBase = videos + + each(videos, function (video, callbackEach) { + if (err) throw err + const videoName = video.name.replace(' name', '') + + videosUtils.testVideoImage(server.url, videoName, video.thumbnailPath, function (err, test) { + if (err) throw err + + expect(test).to.equal(true) + callbackEach() + }) + }, done) + }) + }) + + it('Should list only the two first videos', function (done) { + videosUtils.getVideosListPagination(server.url, 0, 2, function (err, res) { + if (err) throw err + + const videos = res.body.data + expect(res.body.total).to.equal(6) + expect(videos.length).to.equal(2) + expect(videos[0].name === videosListBase[0].name) + expect(videos[1].name === videosListBase[1].name) + + done() + }) + }) + + it('Should list only the next three videos', function (done) { + videosUtils.getVideosListPagination(server.url, 2, 3, function (err, res) { + if (err) throw err + + const videos = res.body.data + expect(res.body.total).to.equal(6) + expect(videos.length).to.equal(3) + expect(videos[0].name === videosListBase[2].name) + expect(videos[1].name === videosListBase[3].name) + expect(videos[2].name === videosListBase[4].name) + + done() + }) + }) + + it('Should list the last video', function (done) { + videosUtils.getVideosListPagination(server.url, 5, 6, function (err, res) { + if (err) throw err + + const videos = res.body.data + expect(res.body.total).to.equal(6) + expect(videos.length).to.equal(1) + expect(videos[0].name === videosListBase[5].name) + + done() + }) + }) + + it('Should search the first video', function (done) { + videosUtils.searchVideoWithPagination(server.url, 'webm', 'name', 0, 1, function (err, res) { + if (err) throw err + + const videos = res.body.data + expect(res.body.total).to.equal(4) + expect(videos.length).to.equal(1) + expect(videos[0].name === 'video_short.webm name') + + done() + }) + }) + + it('Should search the last two videos', function (done) { + videosUtils.searchVideoWithPagination(server.url, 'webm', 'name', 2, 2, function (err, res) { + if (err) throw err + + const videos = res.body.data + expect(res.body.total).to.equal(4) + expect(videos.length).to.equal(2) + expect(videos[0].name === 'video_short2.webm name') + expect(videos[1].name === 'video_short3.webm name') + + done() + }) + }) + + it('Should search all the webm videos', function (done) { + videosUtils.searchVideoWithPagination(server.url, 'webm', 'name', 0, 15, function (err, res) { + if (err) throw err + + const videos = res.body.data + expect(res.body.total).to.equal(4) + expect(videos.length).to.equal(4) + + done() + }) + }) + + it('Should search all the root author videos', function (done) { + videosUtils.searchVideoWithPagination(server.url, 'root', 'author', 0, 15, function (err, res) { + if (err) throw err + + const videos = res.body.data + expect(res.body.total).to.equal(6) + expect(videos.length).to.equal(6) + + done() + }) + }) + + it('Should search all the 9001 port videos', function (done) { + videosUtils.searchVideoWithPagination(server.url, '9001', 'podUrl', 0, 15, function (err, res) { + if (err) throw err + + const videos = res.body.data + expect(res.body.total).to.equal(6) + expect(videos.length).to.equal(6) + + done() + }) + }) + + it('Should search all the localhost videos', function (done) { + videosUtils.searchVideoWithPagination(server.url, 'localhost', 'podUrl', 0, 15, function (err, res) { + if (err) throw err + + const videos = res.body.data + expect(res.body.total).to.equal(6) + expect(videos.length).to.equal(6) + + done() + }) + }) + + it('Should search the good magnetUri video', function (done) { + const video = videosListBase[0] + videosUtils.searchVideoWithPagination(server.url, encodeURIComponent(video.magnetUri), 'magnetUri', 0, 15, function (err, res) { + if (err) throw err + + const videos = res.body.data + expect(res.body.total).to.equal(1) + expect(videos.length).to.equal(1) + expect(videos[0].name).to.equal(video.name) + + done() + }) + }) + + it('Should list and sort by name in descending order', function (done) { + videosUtils.getVideosListSort(server.url, '-name', function (err, res) { + if (err) throw err + + const videos = res.body.data + expect(res.body.total).to.equal(6) + expect(videos.length).to.equal(6) + expect(videos[5].name === 'video_short.mp4 name') + expect(videos[4].name === 'video_short.ogv name') + expect(videos[3].name === 'video_short.webm name') + expect(videos[2].name === 'video_short1.webm name') + expect(videos[1].name === 'video_short2.webm name') + expect(videos[0].name === 'video_short3.webm name') + + done() + }) + }) + + it('Should search and sort by name in ascending order', function (done) { + videosUtils.searchVideoWithSort(server.url, 'webm', 'name', function (err, res) { + if (err) throw err + + const videos = res.body.data + expect(res.body.total).to.equal(4) + expect(videos.length).to.equal(4) + + expect(videos[0].name === 'video_short.webm name') + expect(videos[1].name === 'video_short1.webm name') + expect(videos[2].name === 'video_short2.webm name') + expect(videos[3].name === 'video_short3.webm name') + + done() + }) + }) + + after(function (done) { + process.kill(-server.app.pid) + process.kill(-webtorrent.app.pid) + + // Keep the logs if the test failed + if (this.ok) { + serversUtils.flushTests(done) + } else { + done() + } + }) +}) diff --git a/server/tests/api/singlePod.js b/server/tests/api/singlePod.js deleted file mode 100644 index bdaaee46c..000000000 --- a/server/tests/api/singlePod.js +++ /dev/null @@ -1,508 +0,0 @@ -'use strict' - -const chai = require('chai') -const each = require('async/each') -const expect = chai.expect -const fs = require('fs') -const keyBy = require('lodash/keyBy') -const pathUtils = require('path') -const series = require('async/series') - -const loginUtils = require('../utils/login') -const miscsUtils = require('../utils/miscs') -const serversUtils = require('../utils/servers') -const videosUtils = require('../utils/videos') -const webtorrent = require(pathUtils.join(__dirname, '../../lib/webtorrent')) -webtorrent.silent = true - -describe('Test a single pod', function () { - let server = null - let videoId = -1 - let videosListBase = null - - before(function (done) { - this.timeout(20000) - - series([ - function (next) { - serversUtils.flushTests(next) - }, - function (next) { - serversUtils.runServer(1, function (server1) { - server = server1 - next() - }) - }, - function (next) { - loginUtils.loginAndGetAccessToken(server, function (err, token) { - if (err) throw err - server.accessToken = token - next() - }) - }, - function (next) { - webtorrent.create({ host: 'client', port: '1' }, next) - } - ], done) - }) - - it('Should not have videos', function (done) { - videosUtils.getVideosList(server.url, function (err, res) { - if (err) throw err - - expect(res.body.total).to.equal(0) - expect(res.body.data).to.be.an('array') - expect(res.body.data.length).to.equal(0) - - done() - }) - }) - - it('Should upload the video', function (done) { - this.timeout(5000) - const name = 'my super name' - const description = 'my super description' - const tags = [ 'tag1', 'tag2', 'tag3' ] - const file = 'video_short.webm' - videosUtils.uploadVideo(server.url, server.accessToken, name, description, tags, file, done) - }) - - it('Should seed the uploaded video', function (done) { - // Yes, this could be long - this.timeout(60000) - - videosUtils.getVideosList(server.url, function (err, res) { - if (err) throw err - - expect(res.body.total).to.equal(1) - expect(res.body.data).to.be.an('array') - expect(res.body.data.length).to.equal(1) - - const video = res.body.data[0] - expect(video.name).to.equal('my super name') - expect(video.description).to.equal('my super description') - expect(video.podUrl).to.equal('localhost:9001') - expect(video.magnetUri).to.exist - expect(video.author).to.equal('root') - expect(video.isLocal).to.be.true - expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ]) - expect(miscsUtils.dateIsValid(video.createdDate)).to.be.true - - videosUtils.testVideoImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) { - if (err) throw err - expect(test).to.equal(true) - - videoId = video.id - - webtorrent.add(video.magnetUri, function (torrent) { - expect(torrent.files).to.exist - expect(torrent.files.length).to.equal(1) - expect(torrent.files[0].path).to.exist.and.to.not.equal('') - - done() - }) - }) - }) - }) - - it('Should get the video', function (done) { - // Yes, this could be long - this.timeout(60000) - - videosUtils.getVideo(server.url, videoId, function (err, res) { - if (err) throw err - - const video = res.body - expect(video.name).to.equal('my super name') - expect(video.description).to.equal('my super description') - expect(video.podUrl).to.equal('localhost:9001') - expect(video.magnetUri).to.exist - expect(video.author).to.equal('root') - expect(video.isLocal).to.be.true - expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ]) - expect(miscsUtils.dateIsValid(video.createdDate)).to.be.true - - videosUtils.testVideoImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) { - if (err) throw err - expect(test).to.equal(true) - - done() - }) - }) - }) - - it('Should search the video by name by default', function (done) { - videosUtils.searchVideo(server.url, 'my', function (err, res) { - if (err) throw err - - expect(res.body.total).to.equal(1) - expect(res.body.data).to.be.an('array') - expect(res.body.data.length).to.equal(1) - - const video = res.body.data[0] - expect(video.name).to.equal('my super name') - expect(video.description).to.equal('my super description') - expect(video.podUrl).to.equal('localhost:9001') - expect(video.author).to.equal('root') - expect(video.isLocal).to.be.true - expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ]) - expect(miscsUtils.dateIsValid(video.createdDate)).to.be.true - - videosUtils.testVideoImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) { - if (err) throw err - expect(test).to.equal(true) - - done() - }) - }) - }) - - it('Should search the video by podUrl', function (done) { - videosUtils.searchVideo(server.url, '9001', 'podUrl', function (err, res) { - if (err) throw err - - expect(res.body.total).to.equal(1) - expect(res.body.data).to.be.an('array') - expect(res.body.data.length).to.equal(1) - - const video = res.body.data[0] - expect(video.name).to.equal('my super name') - expect(video.description).to.equal('my super description') - expect(video.podUrl).to.equal('localhost:9001') - expect(video.author).to.equal('root') - expect(video.isLocal).to.be.true - expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ]) - expect(miscsUtils.dateIsValid(video.createdDate)).to.be.true - - videosUtils.testVideoImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) { - if (err) throw err - expect(test).to.equal(true) - - done() - }) - }) - }) - - it('Should search the video by tag', function (done) { - videosUtils.searchVideo(server.url, 'tag1', 'tags', function (err, res) { - if (err) throw err - - expect(res.body.total).to.equal(1) - expect(res.body.data).to.be.an('array') - expect(res.body.data.length).to.equal(1) - - const video = res.body.data[0] - expect(video.name).to.equal('my super name') - expect(video.description).to.equal('my super description') - expect(video.podUrl).to.equal('localhost:9001') - expect(video.author).to.equal('root') - expect(video.isLocal).to.be.true - expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ]) - expect(miscsUtils.dateIsValid(video.createdDate)).to.be.true - - videosUtils.testVideoImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) { - if (err) throw err - expect(test).to.equal(true) - - done() - }) - }) - }) - - it('Should not find a search by name by default', function (done) { - videosUtils.searchVideo(server.url, 'hello', function (err, res) { - if (err) throw err - - expect(res.body.total).to.equal(0) - expect(res.body.data).to.be.an('array') - expect(res.body.data.length).to.equal(0) - - done() - }) - }) - - it('Should not find a search by author', function (done) { - videosUtils.searchVideo(server.url, 'hello', 'author', function (err, res) { - if (err) throw err - - expect(res.body.total).to.equal(0) - expect(res.body.data).to.be.an('array') - expect(res.body.data.length).to.equal(0) - - done() - }) - }) - - it('Should not find a search by tag', function (done) { - videosUtils.searchVideo(server.url, 'tag', 'tags', function (err, res) { - if (err) throw err - - expect(res.body.total).to.equal(0) - expect(res.body.data).to.be.an('array') - expect(res.body.data.length).to.equal(0) - - done() - }) - }) - - it('Should remove the video', function (done) { - videosUtils.removeVideo(server.url, server.accessToken, videoId, function (err) { - if (err) throw err - - fs.readdir(pathUtils.join(__dirname, '../../../test1/uploads/'), function (err, files) { - if (err) throw err - - expect(files.length).to.equal(0) - done() - }) - }) - }) - - it('Should not have videos', function (done) { - videosUtils.getVideosList(server.url, function (err, res) { - if (err) throw err - - expect(res.body.total).to.equal(0) - expect(res.body.data).to.be.an('array') - expect(res.body.data.length).to.equal(0) - - done() - }) - }) - - it('Should upload 6 videos', function (done) { - this.timeout(25000) - const videos = [ - 'video_short.mp4', 'video_short.ogv', 'video_short.webm', - 'video_short1.webm', 'video_short2.webm', 'video_short3.webm' - ] - each(videos, function (video, callbackEach) { - const name = video + ' name' - const description = video + ' description' - const tags = [ 'tag1', 'tag2', 'tag3' ] - - videosUtils.uploadVideo(server.url, server.accessToken, name, description, tags, video, callbackEach) - }, done) - }) - - it('Should have the correct durations', function (done) { - videosUtils.getVideosList(server.url, function (err, res) { - if (err) throw err - - expect(res.body.total).to.equal(6) - const videos = res.body.data - expect(videos).to.be.an('array') - expect(videos.length).to.equal(6) - - const videosByName = keyBy(videos, 'name') - expect(videosByName['video_short.mp4 name'].duration).to.equal(5) - expect(videosByName['video_short.ogv name'].duration).to.equal(5) - expect(videosByName['video_short.webm name'].duration).to.equal(5) - expect(videosByName['video_short1.webm name'].duration).to.equal(10) - expect(videosByName['video_short2.webm name'].duration).to.equal(5) - expect(videosByName['video_short3.webm name'].duration).to.equal(5) - - done() - }) - }) - - it('Should have the correct thumbnails', function (done) { - videosUtils.getVideosList(server.url, function (err, res) { - if (err) throw err - - const videos = res.body.data - // For the next test - videosListBase = videos - - each(videos, function (video, callbackEach) { - if (err) throw err - const videoName = video.name.replace(' name', '') - - videosUtils.testVideoImage(server.url, videoName, video.thumbnailPath, function (err, test) { - if (err) throw err - - expect(test).to.equal(true) - callbackEach() - }) - }, done) - }) - }) - - it('Should list only the two first videos', function (done) { - videosUtils.getVideosListPagination(server.url, 0, 2, function (err, res) { - if (err) throw err - - const videos = res.body.data - expect(res.body.total).to.equal(6) - expect(videos.length).to.equal(2) - expect(videos[0].name === videosListBase[0].name) - expect(videos[1].name === videosListBase[1].name) - - done() - }) - }) - - it('Should list only the next three videos', function (done) { - videosUtils.getVideosListPagination(server.url, 2, 3, function (err, res) { - if (err) throw err - - const videos = res.body.data - expect(res.body.total).to.equal(6) - expect(videos.length).to.equal(3) - expect(videos[0].name === videosListBase[2].name) - expect(videos[1].name === videosListBase[3].name) - expect(videos[2].name === videosListBase[4].name) - - done() - }) - }) - - it('Should list the last video', function (done) { - videosUtils.getVideosListPagination(server.url, 5, 6, function (err, res) { - if (err) throw err - - const videos = res.body.data - expect(res.body.total).to.equal(6) - expect(videos.length).to.equal(1) - expect(videos[0].name === videosListBase[5].name) - - done() - }) - }) - - it('Should search the first video', function (done) { - videosUtils.searchVideoWithPagination(server.url, 'webm', 'name', 0, 1, function (err, res) { - if (err) throw err - - const videos = res.body.data - expect(res.body.total).to.equal(4) - expect(videos.length).to.equal(1) - expect(videos[0].name === 'video_short.webm name') - - done() - }) - }) - - it('Should search the last two videos', function (done) { - videosUtils.searchVideoWithPagination(server.url, 'webm', 'name', 2, 2, function (err, res) { - if (err) throw err - - const videos = res.body.data - expect(res.body.total).to.equal(4) - expect(videos.length).to.equal(2) - expect(videos[0].name === 'video_short2.webm name') - expect(videos[1].name === 'video_short3.webm name') - - done() - }) - }) - - it('Should search all the webm videos', function (done) { - videosUtils.searchVideoWithPagination(server.url, 'webm', 'name', 0, 15, function (err, res) { - if (err) throw err - - const videos = res.body.data - expect(res.body.total).to.equal(4) - expect(videos.length).to.equal(4) - - done() - }) - }) - - it('Should search all the root author videos', function (done) { - videosUtils.searchVideoWithPagination(server.url, 'root', 'author', 0, 15, function (err, res) { - if (err) throw err - - const videos = res.body.data - expect(res.body.total).to.equal(6) - expect(videos.length).to.equal(6) - - done() - }) - }) - - it('Should search all the 9001 port videos', function (done) { - videosUtils.searchVideoWithPagination(server.url, '9001', 'podUrl', 0, 15, function (err, res) { - if (err) throw err - - const videos = res.body.data - expect(res.body.total).to.equal(6) - expect(videos.length).to.equal(6) - - done() - }) - }) - - it('Should search all the localhost videos', function (done) { - videosUtils.searchVideoWithPagination(server.url, 'localhost', 'podUrl', 0, 15, function (err, res) { - if (err) throw err - - const videos = res.body.data - expect(res.body.total).to.equal(6) - expect(videos.length).to.equal(6) - - done() - }) - }) - - it('Should search the good magnetUri video', function (done) { - const video = videosListBase[0] - videosUtils.searchVideoWithPagination(server.url, encodeURIComponent(video.magnetUri), 'magnetUri', 0, 15, function (err, res) { - if (err) throw err - - const videos = res.body.data - expect(res.body.total).to.equal(1) - expect(videos.length).to.equal(1) - expect(videos[0].name).to.equal(video.name) - - done() - }) - }) - - it('Should list and sort by name in descending order', function (done) { - videosUtils.getVideosListSort(server.url, '-name', function (err, res) { - if (err) throw err - - const videos = res.body.data - expect(res.body.total).to.equal(6) - expect(videos.length).to.equal(6) - expect(videos[5].name === 'video_short.mp4 name') - expect(videos[4].name === 'video_short.ogv name') - expect(videos[3].name === 'video_short.webm name') - expect(videos[2].name === 'video_short1.webm name') - expect(videos[1].name === 'video_short2.webm name') - expect(videos[0].name === 'video_short3.webm name') - - done() - }) - }) - - it('Should search and sort by name in ascending order', function (done) { - videosUtils.searchVideoWithSort(server.url, 'webm', 'name', function (err, res) { - if (err) throw err - - const videos = res.body.data - expect(res.body.total).to.equal(4) - expect(videos.length).to.equal(4) - - expect(videos[0].name === 'video_short.webm name') - expect(videos[1].name === 'video_short1.webm name') - expect(videos[2].name === 'video_short2.webm name') - expect(videos[3].name === 'video_short3.webm name') - - done() - }) - }) - - after(function (done) { - process.kill(-server.app.pid) - process.kill(-webtorrent.app.pid) - - // Keep the logs if the test failed - if (this.ok) { - serversUtils.flushTests(done) - } else { - done() - } - }) -}) -- cgit v1.2.3