aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/config.js
blob: f2c00f85a94254f223a56ef3ab5807eb9a5a6fdd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/* eslint-disable no-unused-expressions */

'use strict'

const chai = require('chai')
const expect = chai.expect
const series = require('async/series')

const serversUtils = require('../utils/servers')
const configUtils = require('../utils/config')
const usersUtils = require('../utils/users')

describe('Test config', function () {
  let server = null

  before(function (done) {
    this.timeout(120000)

    series([
      function (next) {
        serversUtils.flushTests(next)
      },
      function (next) {
        serversUtils.runServer(1, function (server1) {
          server = server1
          next()
        })
      }
    ], done)
  })

  it('Should have a correct config on a server with registration enabled', function (done) {
    configUtils.getConfig(server.url, function (err, res) {
      if (err) throw err

      const data = res.body

      expect(data.signup.allowed).to.be.truthy

      done()
    })
  })

  it('Should have a correct config on a server with registration enabled and a users limit', function (done) {
    series([
      function (next) {
        usersUtils.registerUser(server.url, 'user1', 'super password', done)
      },

      function (next) {
        usersUtils.registerUser(server.url, 'user2', 'super password', done)
      },

      function (next) {
        usersUtils.registerUser(server.url, 'user3', 'super password', done)
      },

      function (next) {
        usersUtils.registerUser(server.url, 'user4', 'super password', done)
      }

    ], function (err) {
      if (err) throw err

      configUtils.getConfig(server.url, function (err, res) {
        if (err) throw err

        const data = res.body

        expect(data.signup.allowed).to.be.truthy

        done()
      })
    })
  })

  after(function (done) {
    process.kill(-server.app.pid)

    // Keep the logs if the test failed
    if (this.ok) {
      serversUtils.flushTests(done)
    } else {
      done()
    }
  })
})