aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/users.js
blob: 9ab5083a0501df7db62582f78e02c40ccf2a2f2c (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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
'use strict'

const async = require('async')
const chai = require('chai')
const expect = chai.expect
const pathUtils = require('path')

const webtorrent = require(pathUtils.join(__dirname, '../../lib/webtorrent'))
webtorrent.silent = true

const utils = require('./utils')

describe('Test users', function () {
  let server = null
  let accessToken = null
  let videoId

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

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

  it('Should create a new client')

  it('Should return the first client')

  it('Should remove the last client')

  it('Should not login with an invalid client id', function (done) {
    const client = { id: 'client', password: server.client.secret }
    utils.login(server.url, client, server.user, 400, function (err, res) {
      if (err) throw err

      expect(res.body.error).to.equal('invalid_client')
      done()
    })
  })

  it('Should not login with an invalid client password', function (done) {
    const client = { id: server.client.id, password: 'coucou' }
    utils.login(server.url, client, server.user, 400, function (err, res) {
      if (err) throw err

      expect(res.body.error).to.equal('invalid_client')
      done()
    })
  })

  it('Should not login with an invalid username', function (done) {
    const user = { username: 'captain crochet', password: server.user.password }
    utils.login(server.url, server.client, user, 400, function (err, res) {
      if (err) throw err

      expect(res.body.error).to.equal('invalid_grant')
      done()
    })
  })

  it('Should not login with an invalid password', function (done) {
    const user = { username: server.user.username, password: 'mewthree' }
    utils.login(server.url, server.client, user, 400, function (err, res) {
      if (err) throw err

      expect(res.body.error).to.equal('invalid_grant')
      done()
    })
  })

  it('Should not be able to upload a video', function (done) {
    accessToken = 'mysupertoken'
    utils.uploadVideo(server.url, accessToken, 'my super name', 'my super description', 'video_short.webm', 401, done)
  })

  it('Should not be able to make friends', function (done) {
    accessToken = 'mysupertoken'
    utils.makeFriends(server.url, accessToken, 401, done)
  })

  it('Should not be able to quit friends', function (done) {
    accessToken = 'mysupertoken'
    utils.quitFriends(server.url, accessToken, 401, done)
  })

  it('Should be able to login', function (done) {
    utils.login(server.url, server.client, server.user, 200, function (err, res) {
      if (err) throw err

      accessToken = res.body.access_token
      done()
    })
  })

  it('Should upload the video with the correct token', function (done) {
    utils.uploadVideo(server.url, accessToken, 'my super name', 'my super description', 'video_short.webm', 204, function (err, res) {
      if (err) throw err

      utils.getVideosList(server.url, function (err, res) {
        if (err) throw err

        const video = res.body.data[0]
        expect(video.author).to.equal('root')

        videoId = video.id
        done()
      })
    })
  })

  it('Should upload the video again with the correct token', function (done) {
    utils.uploadVideo(server.url, accessToken, 'my super name 2', 'my super description 2', 'video_short.webm', 204, done)
  })

  it('Should not be able to remove the video with an incorrect token', function (done) {
    utils.removeVideo(server.url, 'bad_token', videoId, 401, done)
  })

  it('Should not be able to remove the video with the token of another account')

  it('Should be able to remove the video with the correct token', function (done) {
    utils.removeVideo(server.url, accessToken, videoId, done)
  })

  it('Should logout')

  it('Should not be able to upload a video')

  it('Should not be able to remove a video')

  it('Should be able to login again')

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

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