aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/utils/miscs
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/utils/miscs')
-rw-r--r--server/tests/utils/miscs/email.ts25
-rw-r--r--server/tests/utils/miscs/miscs.ts72
2 files changed, 0 insertions, 97 deletions
diff --git a/server/tests/utils/miscs/email.ts b/server/tests/utils/miscs/email.ts
deleted file mode 100644
index 21accd09d..000000000
--- a/server/tests/utils/miscs/email.ts
+++ /dev/null
@@ -1,25 +0,0 @@
1import * as MailDev from 'maildev'
2
3function mockSmtpServer (emailsCollection: object[]) {
4 const maildev = new MailDev({
5 ip: '127.0.0.1',
6 smtp: 1025,
7 disableWeb: true,
8 silent: true
9 })
10 maildev.on('new', email => emailsCollection.push(email))
11
12 return new Promise((res, rej) => {
13 maildev.listen(err => {
14 if (err) return rej(err)
15
16 return res()
17 })
18 })
19}
20
21// ---------------------------------------------------------------------------
22
23export {
24 mockSmtpServer
25}
diff --git a/server/tests/utils/miscs/miscs.ts b/server/tests/utils/miscs/miscs.ts
deleted file mode 100644
index b2f80e9b1..000000000
--- a/server/tests/utils/miscs/miscs.ts
+++ /dev/null
@@ -1,72 +0,0 @@
1/* tslint:disable:no-unused-expression */
2
3import * as chai from 'chai'
4import { isAbsolute, join } from 'path'
5import * as request from 'supertest'
6import * as WebTorrent from 'webtorrent'
7import { readFile } from 'fs-extra'
8
9const expect = chai.expect
10let webtorrent = new WebTorrent()
11
12function immutableAssign <T, U> (target: T, source: U) {
13 return Object.assign<{}, T, U>({}, target, source)
14}
15
16 // Default interval -> 5 minutes
17function dateIsValid (dateString: string, interval = 300000) {
18 const dateToCheck = new Date(dateString)
19 const now = new Date()
20
21 return Math.abs(now.getTime() - dateToCheck.getTime()) <= interval
22}
23
24function wait (milliseconds: number) {
25 return new Promise(resolve => setTimeout(resolve, milliseconds))
26}
27
28function webtorrentAdd (torrent: string, refreshWebTorrent = false) {
29 if (refreshWebTorrent === true) webtorrent = new WebTorrent()
30
31 return new Promise<WebTorrent.Torrent>(res => webtorrent.add(torrent, res))
32}
33
34function root () {
35 // We are in server/tests/utils/miscs
36 return join(__dirname, '..', '..', '..', '..')
37}
38
39async function testImage (url: string, imageName: string, imagePath: string, extension = '.jpg') {
40 const res = await request(url)
41 .get(imagePath)
42 .expect(200)
43
44 const body = res.body
45
46 const data = await readFile(join(__dirname, '..', '..', 'fixtures', imageName + extension))
47 const minLength = body.length - ((20 * body.length) / 100)
48 const maxLength = body.length + ((20 * body.length) / 100)
49
50 expect(data.length).to.be.above(minLength)
51 expect(data.length).to.be.below(maxLength)
52}
53
54function buildAbsoluteFixturePath (path: string) {
55 if (isAbsolute(path)) {
56 return path
57 }
58
59 return join(__dirname, '..', '..', 'fixtures', path)
60}
61
62// ---------------------------------------------------------------------------
63
64export {
65 dateIsValid,
66 wait,
67 webtorrentAdd,
68 immutableAssign,
69 testImage,
70 buildAbsoluteFixturePath,
71 root
72}