aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared/utils/miscs
diff options
context:
space:
mode:
Diffstat (limited to 'shared/utils/miscs')
-rw-r--r--shared/utils/miscs/miscs.ts8
-rw-r--r--shared/utils/miscs/sql.ts38
-rw-r--r--shared/utils/miscs/stubs.ts14
3 files changed, 56 insertions, 4 deletions
diff --git a/shared/utils/miscs/miscs.ts b/shared/utils/miscs/miscs.ts
index 589daa420..91a93b631 100644
--- a/shared/utils/miscs/miscs.ts
+++ b/shared/utils/miscs/miscs.ts
@@ -33,8 +33,8 @@ function webtorrentAdd (torrent: string, refreshWebTorrent = false) {
33} 33}
34 34
35function root () { 35function root () {
36 // We are in server/tests/utils/miscs 36 // We are in /shared/utils/miscs
37 return join(__dirname, '..', '..', '..', '..') 37 return join(__dirname, '..', '..', '..')
38} 38}
39 39
40async function testImage (url: string, imageName: string, imagePath: string, extension = '.jpg') { 40async function testImage (url: string, imageName: string, imagePath: string, extension = '.jpg') {
@@ -44,7 +44,7 @@ async function testImage (url: string, imageName: string, imagePath: string, ext
44 44
45 const body = res.body 45 const body = res.body
46 46
47 const data = await readFile(join(__dirname, '..', '..', 'fixtures', imageName + extension)) 47 const data = await readFile(join(root(), 'server', 'tests', 'fixtures', imageName + extension))
48 const minLength = body.length - ((20 * body.length) / 100) 48 const minLength = body.length - ((20 * body.length) / 100)
49 const maxLength = body.length + ((20 * body.length) / 100) 49 const maxLength = body.length + ((20 * body.length) / 100)
50 50
@@ -59,7 +59,7 @@ function buildAbsoluteFixturePath (path: string, customTravisPath = false) {
59 59
60 if (customTravisPath && process.env.TRAVIS) return join(process.env.HOME, 'fixtures', path) 60 if (customTravisPath && process.env.TRAVIS) return join(process.env.HOME, 'fixtures', path)
61 61
62 return join(__dirname, '..', '..', 'fixtures', path) 62 return join(root(), 'server', 'tests', 'fixtures', path)
63} 63}
64 64
65async function generateHighBitrateVideo () { 65async function generateHighBitrateVideo () {
diff --git a/shared/utils/miscs/sql.ts b/shared/utils/miscs/sql.ts
new file mode 100644
index 000000000..027f78131
--- /dev/null
+++ b/shared/utils/miscs/sql.ts
@@ -0,0 +1,38 @@
1import * as Sequelize from 'sequelize'
2
3function getSequelize (serverNumber: number) {
4 const dbname = 'peertube_test' + serverNumber
5 const username = 'peertube'
6 const password = 'peertube'
7 const host = 'localhost'
8 const port = 5432
9
10 return new Sequelize(dbname, username, password, {
11 dialect: 'postgres',
12 host,
13 port,
14 operatorsAliases: false,
15 logging: false
16 })
17}
18
19function setActorField (serverNumber: number, to: string, field: string, value: string) {
20 const seq = getSequelize(serverNumber)
21
22 const options = { type: Sequelize.QueryTypes.UPDATE }
23
24 return seq.query(`UPDATE actor SET "${field}" = '${value}' WHERE url = '${to}'`, options)
25}
26
27function setVideoField (serverNumber: number, uuid: string, field: string, value: string) {
28 const seq = getSequelize(serverNumber)
29
30 const options = { type: Sequelize.QueryTypes.UPDATE }
31
32 return seq.query(`UPDATE video SET "${field}" = '${value}' WHERE uuid = '${uuid}'`, options)
33}
34
35export {
36 setVideoField,
37 setActorField
38}
diff --git a/shared/utils/miscs/stubs.ts b/shared/utils/miscs/stubs.ts
new file mode 100644
index 000000000..d1eb0e3b2
--- /dev/null
+++ b/shared/utils/miscs/stubs.ts
@@ -0,0 +1,14 @@
1function buildRequestStub (): any {
2 return { }
3}
4
5function buildResponseStub (): any {
6 return {
7 locals: {}
8 }
9}
10
11export {
12 buildResponseStub,
13 buildRequestStub
14}