diff options
author | Chocobozzz <me@florianbigard.com> | 2017-12-28 14:29:57 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2017-12-28 14:29:57 +0100 |
commit | eec63bbc0f4fdb39e56f37127b35c449f90a135f (patch) | |
tree | 2403f5efea3e281698ae4a6b550fea9dfc52e390 /server/tests/api/check-params/follows.ts | |
parent | c5d31dba56d669c0df0209761c43c5a6ac7cec4a (diff) | |
download | PeerTube-eec63bbc0f4fdb39e56f37127b35c449f90a135f.tar.gz PeerTube-eec63bbc0f4fdb39e56f37127b35c449f90a135f.tar.zst PeerTube-eec63bbc0f4fdb39e56f37127b35c449f90a135f.zip |
Improve check follow params tests
Diffstat (limited to 'server/tests/api/check-params/follows.ts')
-rw-r--r-- | server/tests/api/check-params/follows.ts | 196 |
1 files changed, 91 insertions, 105 deletions
diff --git a/server/tests/api/check-params/follows.ts b/server/tests/api/check-params/follows.ts index cdd2783df..d5fcb7477 100644 --- a/server/tests/api/check-params/follows.ts +++ b/server/tests/api/check-params/follows.ts | |||
@@ -4,14 +4,10 @@ import 'mocha' | |||
4 | import * as request from 'supertest' | 4 | import * as request from 'supertest' |
5 | 5 | ||
6 | import { | 6 | import { |
7 | createUser, | 7 | createUser, flushTests, killallServers, makeDeleteRequest, makePostBodyRequest, runServer, ServerInfo, setAccessTokensToServers, |
8 | flushTests, | 8 | userLogin |
9 | killallServers, | ||
10 | loginAndGetAccessToken, | ||
11 | runServer, | ||
12 | ServerInfo, | ||
13 | setAccessTokensToServers | ||
14 | } from '../../utils' | 9 | } from '../../utils' |
10 | import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params' | ||
15 | 11 | ||
16 | describe('Test server follows API validators', function () { | 12 | describe('Test server follows API validators', function () { |
17 | let server: ServerInfo | 13 | let server: ServerInfo |
@@ -19,7 +15,7 @@ describe('Test server follows API validators', function () { | |||
19 | // --------------------------------------------------------------- | 15 | // --------------------------------------------------------------- |
20 | 16 | ||
21 | before(async function () { | 17 | before(async function () { |
22 | this.timeout(45000) | 18 | this.timeout(20000) |
23 | 19 | ||
24 | await flushTests() | 20 | await flushTests() |
25 | server = await runServer(1) | 21 | server = await runServer(1) |
@@ -31,81 +27,85 @@ describe('Test server follows API validators', function () { | |||
31 | let userAccessToken = null | 27 | let userAccessToken = null |
32 | 28 | ||
33 | before(async function () { | 29 | before(async function () { |
34 | await createUser(server.url, server.accessToken, 'user1', 'password') | 30 | const user = { |
35 | server.user = { | ||
36 | username: 'user1', | 31 | username: 'user1', |
37 | password: 'password' | 32 | password: 'password' |
38 | } | 33 | } |
39 | 34 | ||
40 | userAccessToken = await loginAndGetAccessToken(server) | 35 | await createUser(server.url, server.accessToken, user.username, user.password) |
36 | userAccessToken = await userLogin(server, user) | ||
41 | }) | 37 | }) |
42 | 38 | ||
43 | describe('When adding follows', function () { | 39 | describe('When adding follows', function () { |
44 | const path = '/api/v1/server/following' | 40 | const path = '/api/v1/server/following' |
45 | const body = { | ||
46 | hosts: [ 'localhost:9002' ] | ||
47 | } | ||
48 | 41 | ||
49 | it('Should fail without hosts', async function () { | 42 | it('Should fail without hosts', async function () { |
50 | await request(server.url) | 43 | await makePostBodyRequest({ |
51 | .post(path) | 44 | url: server.url, |
52 | .set('Authorization', 'Bearer ' + server.accessToken) | 45 | path, |
53 | .set('Accept', 'application/json') | 46 | token: server.accessToken, |
54 | .expect(400) | 47 | statusCodeExpected: 400 |
48 | }) | ||
55 | }) | 49 | }) |
56 | 50 | ||
57 | it('Should fail if hosts is not an array', async function () { | 51 | it('Should fail if hosts is not an array', async function () { |
58 | await request(server.url) | 52 | await makePostBodyRequest({ |
59 | .post(path) | 53 | url: server.url, |
60 | .send({ hosts: 'localhost:9002' }) | 54 | path, |
61 | .set('Authorization', 'Bearer ' + server.accessToken) | 55 | token: server.accessToken, |
62 | .set('Accept', 'application/json') | 56 | fields: { hosts: 'localhost:9002' }, |
63 | .expect(400) | 57 | statusCodeExpected: 400 |
58 | }) | ||
64 | }) | 59 | }) |
65 | 60 | ||
66 | it('Should fail if the array is not composed by hosts', async function () { | 61 | it('Should fail if the array is not composed by hosts', async function () { |
67 | await request(server.url) | 62 | await makePostBodyRequest({ |
68 | .post(path) | 63 | url: server.url, |
69 | .send({ hosts: [ 'localhost:9002', 'localhost:coucou' ] }) | 64 | path, |
70 | .set('Authorization', 'Bearer ' + server.accessToken) | 65 | fields: { hosts: [ 'localhost:9002', 'localhost:coucou' ] }, |
71 | .set('Accept', 'application/json') | 66 | token: server.accessToken, |
72 | .expect(400) | 67 | statusCodeExpected: 400 |
68 | }) | ||
73 | }) | 69 | }) |
74 | 70 | ||
75 | it('Should fail if the array is composed with http schemes', async function () { | 71 | it('Should fail if the array is composed with http schemes', async function () { |
76 | await request(server.url) | 72 | await makePostBodyRequest({ |
77 | .post(path) | 73 | url: server.url, |
78 | .send({ hosts: [ 'localhost:9002', 'http://localhost:9003' ] }) | 74 | path, |
79 | .set('Authorization', 'Bearer ' + server.accessToken) | 75 | fields: { hosts: [ 'localhost:9002', 'http://localhost:9003' ] }, |
80 | .set('Accept', 'application/json') | 76 | token: server.accessToken, |
81 | .expect(400) | 77 | statusCodeExpected: 400 |
78 | }) | ||
82 | }) | 79 | }) |
83 | 80 | ||
84 | it('Should fail if hosts are not unique', async function () { | 81 | it('Should fail if hosts are not unique', async function () { |
85 | await request(server.url) | 82 | await makePostBodyRequest({ |
86 | .post(path) | 83 | url: server.url, |
87 | .send({ urls: [ 'localhost:9002', 'localhost:9002' ] }) | 84 | path, |
88 | .set('Authorization', 'Bearer ' + server.accessToken) | 85 | fields: { urls: [ 'localhost:9002', 'localhost:9002' ] }, |
89 | .set('Accept', 'application/json') | 86 | token: server.accessToken, |
90 | .expect(400) | 87 | statusCodeExpected: 400 |
88 | }) | ||
91 | }) | 89 | }) |
92 | 90 | ||
93 | it('Should fail with an invalid token', async function () { | 91 | it('Should fail with an invalid token', async function () { |
94 | await request(server.url) | 92 | await makePostBodyRequest({ |
95 | .post(path) | 93 | url: server.url, |
96 | .send(body) | 94 | path, |
97 | .set('Authorization', 'Bearer fake_token') | 95 | fields: { hosts: [ 'localhost:9002' ] }, |
98 | .set('Accept', 'application/json') | 96 | token: 'fake_token', |
99 | .expect(401) | 97 | statusCodeExpected: 401 |
98 | }) | ||
100 | }) | 99 | }) |
101 | 100 | ||
102 | it('Should fail if the user is not an administrator', async function () { | 101 | it('Should fail if the user is not an administrator', async function () { |
103 | await request(server.url) | 102 | await makePostBodyRequest({ |
104 | .post(path) | 103 | url: server.url, |
105 | .send(body) | 104 | path, |
106 | .set('Authorization', 'Bearer ' + userAccessToken) | 105 | fields: { hosts: [ 'localhost:9002' ] }, |
107 | .set('Accept', 'application/json') | 106 | token: userAccessToken, |
108 | .expect(403) | 107 | statusCodeExpected: 403 |
108 | }) | ||
109 | }) | 109 | }) |
110 | }) | 110 | }) |
111 | 111 | ||
@@ -113,27 +113,15 @@ describe('Test server follows API validators', function () { | |||
113 | const path = '/api/v1/server/following' | 113 | const path = '/api/v1/server/following' |
114 | 114 | ||
115 | it('Should fail with a bad start pagination', async function () { | 115 | it('Should fail with a bad start pagination', async function () { |
116 | await request(server.url) | 116 | await checkBadStartPagination(server.url, path) |
117 | .get(path) | ||
118 | .query({ start: 'hello' }) | ||
119 | .set('Accept', 'application/json') | ||
120 | .expect(400) | ||
121 | }) | 117 | }) |
122 | 118 | ||
123 | it('Should fail with a bad count pagination', async function () { | 119 | it('Should fail with a bad count pagination', async function () { |
124 | await request(server.url) | 120 | await checkBadCountPagination(server.url, path) |
125 | .get(path) | ||
126 | .query({ count: 'hello' }) | ||
127 | .set('Accept', 'application/json') | ||
128 | .expect(400) | ||
129 | }) | 121 | }) |
130 | 122 | ||
131 | it('Should fail with an incorrect sort', async function () { | 123 | it('Should fail with an incorrect sort', async function () { |
132 | await request(server.url) | 124 | await checkBadSortPagination(server.url, path) |
133 | .get(path) | ||
134 | .query({ sort: 'hello' }) | ||
135 | .set('Accept', 'application/json') | ||
136 | .expect(400) | ||
137 | }) | 125 | }) |
138 | }) | 126 | }) |
139 | 127 | ||
@@ -141,27 +129,15 @@ describe('Test server follows API validators', function () { | |||
141 | const path = '/api/v1/server/followers' | 129 | const path = '/api/v1/server/followers' |
142 | 130 | ||
143 | it('Should fail with a bad start pagination', async function () { | 131 | it('Should fail with a bad start pagination', async function () { |
144 | await request(server.url) | 132 | await checkBadStartPagination(server.url, path) |
145 | .get(path) | ||
146 | .query({ start: 'hello' }) | ||
147 | .set('Accept', 'application/json') | ||
148 | .expect(400) | ||
149 | }) | 133 | }) |
150 | 134 | ||
151 | it('Should fail with a bad count pagination', async function () { | 135 | it('Should fail with a bad count pagination', async function () { |
152 | await request(server.url) | 136 | await checkBadCountPagination(server.url, path) |
153 | .get(path) | ||
154 | .query({ count: 'hello' }) | ||
155 | .set('Accept', 'application/json') | ||
156 | .expect(400) | ||
157 | }) | 137 | }) |
158 | 138 | ||
159 | it('Should fail with an incorrect sort', async function () { | 139 | it('Should fail with an incorrect sort', async function () { |
160 | await request(server.url) | 140 | await checkBadSortPagination(server.url, path) |
161 | .get(path) | ||
162 | .query({ sort: 'hello' }) | ||
163 | .set('Accept', 'application/json') | ||
164 | .expect(400) | ||
165 | }) | 141 | }) |
166 | }) | 142 | }) |
167 | 143 | ||
@@ -169,30 +145,40 @@ describe('Test server follows API validators', function () { | |||
169 | const path = '/api/v1/server/following' | 145 | const path = '/api/v1/server/following' |
170 | 146 | ||
171 | it('Should fail with an invalid token', async function () { | 147 | it('Should fail with an invalid token', async function () { |
172 | await request(server.url) | 148 | await makeDeleteRequest({ |
173 | .delete(path + '/1') | 149 | url: server.url, |
174 | .set('Authorization', 'Bearer faketoken') | 150 | path: path + '/localhost:9002', |
175 | .set('Accept', 'application/json') | 151 | token: 'fake_token', |
176 | .expect(401) | 152 | statusCodeExpected: 401 |
153 | }) | ||
177 | }) | 154 | }) |
178 | 155 | ||
179 | it('Should fail if the user is not an administrator', async function () { | 156 | it('Should fail if the user is not an administrator', async function () { |
180 | await request(server.url) | 157 | await makeDeleteRequest({ |
181 | .delete(path + '/1') | 158 | url: server.url, |
182 | .set('Authorization', 'Bearer ' + userAccessToken) | 159 | path: path + '/localhost:9002', |
183 | .set('Accept', 'application/json') | 160 | token: userAccessToken, |
184 | .expect(403) | 161 | statusCodeExpected: 403 |
185 | }) | 162 | }) |
186 | 163 | }) | |
187 | it('Should fail we do not follow this server', async function () { | 164 | |
188 | await request(server.url) | 165 | it('Should fail if we do not follow this server', async function () { |
189 | .delete(path + '/example.com') | 166 | await makeDeleteRequest({ |
190 | .set('Authorization', 'Bearer ' + server.accessToken) | 167 | url: server.url, |
191 | .set('Accept', 'application/json') | 168 | path: path + '/example.com', |
192 | .expect(404) | 169 | token: server.accessToken, |
170 | statusCodeExpected: 404 | ||
171 | }) | ||
172 | }) | ||
173 | |||
174 | it('Should succeed with the correct parameters', async function () { | ||
175 | await makeDeleteRequest({ | ||
176 | url: server.url, | ||
177 | path: path + '/localhost:9002', | ||
178 | token: server.accessToken, | ||
179 | statusCodeExpected: 404 | ||
180 | }) | ||
193 | }) | 181 | }) |
194 | |||
195 | it('Should succeed with the correct parameters') | ||
196 | }) | 182 | }) |
197 | }) | 183 | }) |
198 | 184 | ||