aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2017-12-22 12:10:40 +0100
committerChocobozzz <me@florianbigard.com>2017-12-22 12:12:33 +0100
commitd3ea89759104e6c14b00443526f2c2a0a13aeb97 (patch)
treee30dc7025f284c163a450cb08f7060875e368e6c /server/tests/api
parentbf1f650817dadfd5eeee9e5e0b6b6938c136e25d (diff)
downloadPeerTube-d3ea89759104e6c14b00443526f2c2a0a13aeb97.tar.gz
PeerTube-d3ea89759104e6c14b00443526f2c2a0a13aeb97.tar.zst
PeerTube-d3ea89759104e6c14b00443526f2c2a0a13aeb97.zip
Begin unit tests
Diffstat (limited to 'server/tests/api')
-rw-r--r--server/tests/api/index-slow.ts1
-rw-r--r--server/tests/api/video-comments.ts135
2 files changed, 136 insertions, 0 deletions
diff --git a/server/tests/api/index-slow.ts b/server/tests/api/index-slow.ts
index 4cd5b09a2..b525d6f01 100644
--- a/server/tests/api/index-slow.ts
+++ b/server/tests/api/index-slow.ts
@@ -4,3 +4,4 @@ import './video-transcoder'
4import './multiple-servers' 4import './multiple-servers'
5import './follows' 5import './follows'
6import './jobs' 6import './jobs'
7import './video-comments'
diff --git a/server/tests/api/video-comments.ts b/server/tests/api/video-comments.ts
new file mode 100644
index 000000000..fbc1a0a20
--- /dev/null
+++ b/server/tests/api/video-comments.ts
@@ -0,0 +1,135 @@
1/* tslint:disable:no-unused-expression */
2
3import * as chai from 'chai'
4import 'mocha'
5import { VideoComment, VideoCommentThreadTree } from '../../../shared/models/videos/video-comment.model'
6import { dateIsValid, flushTests, killallServers, runServer, ServerInfo, setAccessTokensToServers, uploadVideo } from '../utils'
7import { addVideoCommentReply, addVideoCommentThread, getVideoCommentThreads, getVideoThreadComments } from '../utils/video-comments'
8
9const expect = chai.expect
10
11describe('Test a video comments', function () {
12 let server: ServerInfo
13 let videoId
14 let videoUUID
15 let threadId
16
17 before(async function () {
18 this.timeout(10000)
19
20 await flushTests()
21
22 server = await runServer(1)
23
24 await setAccessTokensToServers([ server ])
25
26 const res = await uploadVideo(server.url, server.accessToken, {})
27 videoUUID = res.body.video.uuid
28 videoId = res.body.video.id
29 })
30
31 it('Should not have threads on this video', async function () {
32 const res = await getVideoCommentThreads(server.url, videoUUID, 0, 5)
33
34 expect(res.body.total).to.equal(0)
35 expect(res.body.data).to.be.an('array')
36 expect(res.body.data).to.have.lengthOf(0)
37 })
38
39 it('Should create a thread in this video', async function () {
40 const text = 'my super first comment'
41
42 await addVideoCommentThread(server.url, server.accessToken, videoUUID, text)
43 })
44
45 it('Should list threads of this video', async function () {
46 const res = await getVideoCommentThreads(server.url, videoUUID, 0, 5)
47
48 expect(res.body.total).to.equal(1)
49 expect(res.body.data).to.be.an('array')
50 expect(res.body.data).to.have.lengthOf(1)
51
52 const comment: VideoComment = res.body.data[0]
53 expect(comment.inReplyToCommentId).to.be.null
54 expect(comment.text).equal('my super first comment')
55 expect(comment.videoId).to.equal(videoId)
56 expect(comment.id).to.equal(comment.threadId)
57 expect(comment.account.name).to.equal('root')
58 expect(dateIsValid(comment.createdAt as string)).to.be.true
59 expect(dateIsValid(comment.updatedAt as string)).to.be.true
60
61 threadId = comment.threadId
62 })
63
64 it('Should get all the thread created', async function () {
65 const res = await getVideoThreadComments(server.url, videoUUID, threadId)
66
67 const rootComment = res.body.comment
68 expect(rootComment.inReplyToCommentId).to.be.null
69 expect(rootComment.text).equal('my super first comment')
70 expect(rootComment.videoId).to.equal(videoId)
71 expect(dateIsValid(rootComment.createdAt as string)).to.be.true
72 expect(dateIsValid(rootComment.updatedAt as string)).to.be.true
73 })
74
75 it('Should create multiple replies in this thread', async function () {
76 const text1 = 'my super answer to thread 1'
77 const childCommentRes = await addVideoCommentReply(server.url, server.accessToken, videoId, threadId, text1)
78 const childCommentId = childCommentRes.body.comment.id
79
80 const text2 = 'my super answer to answer of thread 1'
81 await addVideoCommentReply(server.url, server.accessToken, videoId, childCommentId, text2)
82
83 const text3 = 'my second answer to thread 1'
84 await addVideoCommentReply(server.url, server.accessToken, videoId, threadId, text3)
85 })
86
87 it('Should get correctly the replies', async function () {
88 const res = await getVideoThreadComments(server.url, videoUUID, threadId)
89
90 const tree: VideoCommentThreadTree = res.body
91 expect(tree.comment.text).equal('my super first comment')
92 expect(tree.children).to.have.lengthOf(2)
93
94 const firstChild = tree.children[0]
95 expect(firstChild.comment.text).to.equal('my super answer to thread 1')
96 expect(firstChild.children).to.have.lengthOf(1)
97
98 const childOfFirstChild = firstChild.children[0]
99 expect(childOfFirstChild.comment.text).to.equal('my super answer to answer of thread 1')
100 expect(childOfFirstChild.children).to.have.lengthOf(0)
101
102 const secondChild = tree.children[1]
103 expect(secondChild.comment.text).to.equal('my second answer to thread 1')
104 expect(secondChild.children).to.have.lengthOf(0)
105 })
106
107 it('Should create other threads', async function () {
108 const text1 = 'super thread 2'
109 await addVideoCommentThread(server.url, server.accessToken, videoUUID, text1)
110
111 const text2 = 'super thread 3'
112 await addVideoCommentThread(server.url, server.accessToken, videoUUID, text2)
113 })
114
115 it('Should list the threads', async function () {
116 const res = await getVideoCommentThreads(server.url, videoUUID, 0, 5, 'createdAt')
117
118 expect(res.body.total).to.equal(3)
119 expect(res.body.data).to.be.an('array')
120 expect(res.body.data).to.have.lengthOf(3)
121
122 expect(res.body.data[0].text).to.equal('my super first comment')
123 expect(res.body.data[1].text).to.equal('super thread 2')
124 expect(res.body.data[2].text).to.equal('super thread 3')
125 })
126
127 after(async function () {
128 killallServers([ server ])
129
130 // Keep the logs if the test failed
131 if (this['ok']) {
132 await flushTests()
133 }
134 })
135})