]>
Commit | Line | Data |
---|---|---|
0883b324 C |
1 | /* tslint:disable:no-unused-expression */ |
2 | ||
3 | import * as chai from 'chai' | |
4 | import 'mocha' | |
5 | import { flushTests, getVideosList, killallServers, ServerInfo, setAccessTokensToServers, uploadVideo } from '../../utils/index' | |
6 | import { userLogin } from '../../utils/users/login' | |
7 | import { createUser } from '../../utils/users/users' | |
8 | import { getMyVideos } from '../../utils/videos/videos' | |
9 | import { | |
6b738c7a | 10 | getAccountVideos, |
3cd0734f C |
11 | getConfig, |
12 | getCustomConfig, | |
13 | getMyUserInformation, | |
14 | getVideoChannelVideos, | |
0883b324 C |
15 | getVideosListWithToken, |
16 | runServer, | |
17 | searchVideo, | |
3cd0734f C |
18 | searchVideoWithToken, |
19 | updateCustomConfig, | |
0883b324 C |
20 | updateMyUser |
21 | } from '../../utils' | |
22 | import { ServerConfig } from '../../../../shared/models' | |
23 | import { CustomConfig } from '../../../../shared/models/server/custom-config.model' | |
6b738c7a | 24 | import { User } from '../../../../shared/models/users' |
0883b324 C |
25 | |
26 | const expect = chai.expect | |
27 | ||
28 | describe('Test video NSFW policy', function () { | |
29 | let server: ServerInfo | |
30 | let userAccessToken: string | |
31 | let customConfig: CustomConfig | |
32 | ||
6b738c7a C |
33 | function getVideosFunctions (token?: string) { |
34 | return getMyUserInformation(server.url, server.accessToken) | |
35 | .then(res => { | |
36 | const user: User = res.body | |
37 | const videoChannelUUID = user.videoChannels[0].uuid | |
ad9e39fb | 38 | const accountName = user.account.name + '@' + user.account.host |
6b738c7a C |
39 | |
40 | if (token) { | |
41 | return Promise.all([ | |
42 | getVideosListWithToken(server.url, token), | |
43 | searchVideoWithToken(server.url, 'n', token), | |
ad9e39fb | 44 | getAccountVideos(server.url, token, accountName, 0, 5), |
cc918ac3 | 45 | getVideoChannelVideos(server.url, token, videoChannelUUID, 0, 5) |
6b738c7a C |
46 | ]) |
47 | } | |
48 | ||
49 | return Promise.all([ | |
50 | getVideosList(server.url), | |
51 | searchVideo(server.url, 'n'), | |
ad9e39fb | 52 | getAccountVideos(server.url, undefined, accountName, 0, 5), |
cc918ac3 | 53 | getVideoChannelVideos(server.url, undefined, videoChannelUUID, 0, 5) |
6b738c7a C |
54 | ]) |
55 | }) | |
56 | } | |
57 | ||
0883b324 C |
58 | before(async function () { |
59 | this.timeout(50000) | |
60 | ||
61 | await flushTests() | |
62 | server = await runServer(1) | |
63 | ||
64 | // Get the access tokens | |
65 | await setAccessTokensToServers([ server ]) | |
66 | ||
67 | { | |
68 | const attributes = { name: 'nsfw', nsfw: true } | |
69 | await uploadVideo(server.url, server.accessToken, attributes) | |
70 | } | |
71 | ||
72 | { | |
73 | const attributes = { name: 'normal', nsfw: false } | |
74 | await uploadVideo(server.url, server.accessToken, attributes) | |
75 | } | |
76 | ||
77 | { | |
78 | const res = await getCustomConfig(server.url, server.accessToken) | |
79 | customConfig = res.body | |
80 | } | |
81 | }) | |
82 | ||
83 | describe('Instance default NSFW policy', function () { | |
84 | it('Should display NSFW videos with display default NSFW policy', async function () { | |
85 | const resConfig = await getConfig(server.url) | |
86 | const serverConfig: ServerConfig = resConfig.body | |
87 | expect(serverConfig.instance.defaultNSFWPolicy).to.equal('display') | |
88 | ||
6b738c7a | 89 | for (const res of await getVideosFunctions()) { |
0883b324 C |
90 | expect(res.body.total).to.equal(2) |
91 | ||
92 | const videos = res.body.data | |
93 | expect(videos).to.have.lengthOf(2) | |
94 | expect(videos[ 0 ].name).to.equal('normal') | |
95 | expect(videos[ 1 ].name).to.equal('nsfw') | |
96 | } | |
97 | }) | |
98 | ||
99 | it('Should not display NSFW videos with do_not_list default NSFW policy', async function () { | |
100 | customConfig.instance.defaultNSFWPolicy = 'do_not_list' | |
101 | await updateCustomConfig(server.url, server.accessToken, customConfig) | |
102 | ||
103 | const resConfig = await getConfig(server.url) | |
104 | const serverConfig: ServerConfig = resConfig.body | |
105 | expect(serverConfig.instance.defaultNSFWPolicy).to.equal('do_not_list') | |
106 | ||
6b738c7a | 107 | for (const res of await getVideosFunctions()) { |
0883b324 C |
108 | expect(res.body.total).to.equal(1) |
109 | ||
110 | const videos = res.body.data | |
111 | expect(videos).to.have.lengthOf(1) | |
112 | expect(videos[ 0 ].name).to.equal('normal') | |
113 | } | |
114 | }) | |
115 | ||
116 | it('Should display NSFW videos with blur default NSFW policy', async function () { | |
117 | customConfig.instance.defaultNSFWPolicy = 'blur' | |
118 | await updateCustomConfig(server.url, server.accessToken, customConfig) | |
119 | ||
120 | const resConfig = await getConfig(server.url) | |
121 | const serverConfig: ServerConfig = resConfig.body | |
122 | expect(serverConfig.instance.defaultNSFWPolicy).to.equal('blur') | |
123 | ||
6b738c7a | 124 | for (const res of await getVideosFunctions()) { |
0883b324 C |
125 | expect(res.body.total).to.equal(2) |
126 | ||
127 | const videos = res.body.data | |
128 | expect(videos).to.have.lengthOf(2) | |
129 | expect(videos[ 0 ].name).to.equal('normal') | |
130 | expect(videos[ 1 ].name).to.equal('nsfw') | |
131 | } | |
132 | }) | |
133 | }) | |
134 | ||
135 | describe('User NSFW policy', function () { | |
136 | ||
137 | it('Should create a user having the default nsfw policy', async function () { | |
138 | const username = 'user1' | |
139 | const password = 'my super password' | |
140 | await createUser(server.url, server.accessToken, username, password) | |
141 | ||
142 | userAccessToken = await userLogin(server, { username, password }) | |
143 | ||
144 | const res = await getMyUserInformation(server.url, userAccessToken) | |
145 | const user = res.body | |
146 | ||
147 | expect(user.nsfwPolicy).to.equal('blur') | |
148 | }) | |
149 | ||
150 | it('Should display NSFW videos with blur user NSFW policy', async function () { | |
6b738c7a | 151 | for (const res of await getVideosFunctions(userAccessToken)) { |
0883b324 C |
152 | expect(res.body.total).to.equal(2) |
153 | ||
154 | const videos = res.body.data | |
155 | expect(videos).to.have.lengthOf(2) | |
156 | expect(videos[ 0 ].name).to.equal('normal') | |
157 | expect(videos[ 1 ].name).to.equal('nsfw') | |
158 | } | |
159 | }) | |
160 | ||
161 | it('Should display NSFW videos with display user NSFW policy', async function () { | |
162 | await updateMyUser({ | |
163 | url: server.url, | |
164 | accessToken: server.accessToken, | |
165 | nsfwPolicy: 'display' | |
166 | }) | |
167 | ||
6b738c7a | 168 | for (const res of await getVideosFunctions(server.accessToken)) { |
0883b324 C |
169 | expect(res.body.total).to.equal(2) |
170 | ||
171 | const videos = res.body.data | |
172 | expect(videos).to.have.lengthOf(2) | |
173 | expect(videos[ 0 ].name).to.equal('normal') | |
174 | expect(videos[ 1 ].name).to.equal('nsfw') | |
175 | } | |
176 | }) | |
177 | ||
178 | it('Should not display NSFW videos with do_not_list user NSFW policy', async function () { | |
179 | await updateMyUser({ | |
180 | url: server.url, | |
181 | accessToken: server.accessToken, | |
182 | nsfwPolicy: 'do_not_list' | |
183 | }) | |
184 | ||
6b738c7a | 185 | for (const res of await getVideosFunctions(server.accessToken)) { |
0883b324 C |
186 | expect(res.body.total).to.equal(1) |
187 | ||
188 | const videos = res.body.data | |
189 | expect(videos).to.have.lengthOf(1) | |
190 | expect(videos[ 0 ].name).to.equal('normal') | |
191 | } | |
192 | }) | |
193 | ||
194 | it('Should be able to see my NSFW videos even with do_not_list user NSFW policy', async function () { | |
195 | const res = await getMyVideos(server.url, server.accessToken, 0, 5) | |
196 | expect(res.body.total).to.equal(2) | |
197 | ||
198 | const videos = res.body.data | |
199 | expect(videos).to.have.lengthOf(2) | |
200 | expect(videos[ 0 ].name).to.equal('normal') | |
201 | expect(videos[ 1 ].name).to.equal('nsfw') | |
202 | }) | |
203 | }) | |
204 | ||
205 | after(async function () { | |
206 | killallServers([ server ]) | |
0883b324 C |
207 | }) |
208 | }) |