]>
Commit | Line | Data |
---|---|---|
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | |
2 | ||
3 | import 'mocha' | |
4 | import * as chai from 'chai' | |
5 | import { VideoChannel } from '@shared/models' | |
6 | import { | |
7 | cleanupTests, | |
8 | createSingleServer, | |
9 | doubleFollow, | |
10 | PeerTubeServer, | |
11 | SearchCommand, | |
12 | setAccessTokensToServers, | |
13 | setDefaultAccountAvatar, | |
14 | setDefaultChannelAvatar | |
15 | } from '@shared/server-commands' | |
16 | ||
17 | const expect = chai.expect | |
18 | ||
19 | describe('Test channels search', function () { | |
20 | let server: PeerTubeServer | |
21 | let remoteServer: PeerTubeServer | |
22 | let command: SearchCommand | |
23 | ||
24 | before(async function () { | |
25 | this.timeout(120000) | |
26 | ||
27 | const servers = await Promise.all([ | |
28 | createSingleServer(1), | |
29 | createSingleServer(2) | |
30 | ]) | |
31 | server = servers[0] | |
32 | remoteServer = servers[1] | |
33 | ||
34 | await setAccessTokensToServers([ server, remoteServer ]) | |
35 | await setDefaultChannelAvatar(server) | |
36 | await setDefaultAccountAvatar(server) | |
37 | ||
38 | await servers[1].config.disableTranscoding() | |
39 | ||
40 | { | |
41 | await server.users.create({ username: 'user1' }) | |
42 | const channel = { | |
43 | name: 'squall_channel', | |
44 | displayName: 'Squall channel' | |
45 | } | |
46 | await server.channels.create({ attributes: channel }) | |
47 | } | |
48 | ||
49 | { | |
50 | await remoteServer.users.create({ username: 'user1' }) | |
51 | const channel = { | |
52 | name: 'zell_channel', | |
53 | displayName: 'Zell channel' | |
54 | } | |
55 | const { id } = await remoteServer.channels.create({ attributes: channel }) | |
56 | ||
57 | await remoteServer.videos.upload({ attributes: { channelId: id } }) | |
58 | } | |
59 | ||
60 | await doubleFollow(server, remoteServer) | |
61 | ||
62 | command = server.search | |
63 | }) | |
64 | ||
65 | it('Should make a simple search and not have results', async function () { | |
66 | const body = await command.searchChannels({ search: 'abc' }) | |
67 | ||
68 | expect(body.total).to.equal(0) | |
69 | expect(body.data).to.have.lengthOf(0) | |
70 | }) | |
71 | ||
72 | it('Should make a search and have results', async function () { | |
73 | { | |
74 | const search = { | |
75 | search: 'Squall', | |
76 | start: 0, | |
77 | count: 1 | |
78 | } | |
79 | const body = await command.advancedChannelSearch({ search }) | |
80 | expect(body.total).to.equal(1) | |
81 | expect(body.data).to.have.lengthOf(1) | |
82 | ||
83 | const channel: VideoChannel = body.data[0] | |
84 | expect(channel.name).to.equal('squall_channel') | |
85 | expect(channel.displayName).to.equal('Squall channel') | |
86 | } | |
87 | ||
88 | { | |
89 | const search = { | |
90 | search: 'Squall', | |
91 | start: 1, | |
92 | count: 1 | |
93 | } | |
94 | ||
95 | const body = await command.advancedChannelSearch({ search }) | |
96 | expect(body.total).to.equal(1) | |
97 | expect(body.data).to.have.lengthOf(0) | |
98 | } | |
99 | }) | |
100 | ||
101 | it('Should filter by host', async function () { | |
102 | { | |
103 | const search = { search: 'channel', host: remoteServer.host } | |
104 | ||
105 | const body = await command.advancedChannelSearch({ search }) | |
106 | expect(body.total).to.equal(1) | |
107 | expect(body.data).to.have.lengthOf(1) | |
108 | expect(body.data[0].displayName).to.equal('Zell channel') | |
109 | } | |
110 | ||
111 | { | |
112 | const search = { search: 'Sq', host: server.host } | |
113 | ||
114 | const body = await command.advancedChannelSearch({ search }) | |
115 | expect(body.total).to.equal(1) | |
116 | expect(body.data).to.have.lengthOf(1) | |
117 | expect(body.data[0].displayName).to.equal('Squall channel') | |
118 | } | |
119 | ||
120 | { | |
121 | const search = { search: 'Squall', host: 'example.com' } | |
122 | ||
123 | const body = await command.advancedChannelSearch({ search }) | |
124 | expect(body.total).to.equal(0) | |
125 | expect(body.data).to.have.lengthOf(0) | |
126 | } | |
127 | }) | |
128 | ||
129 | it('Should filter by names', async function () { | |
130 | { | |
131 | const body = await command.advancedChannelSearch({ search: { handles: [ 'squall_channel', 'zell_channel' ] } }) | |
132 | expect(body.total).to.equal(1) | |
133 | expect(body.data).to.have.lengthOf(1) | |
134 | expect(body.data[0].displayName).to.equal('Squall channel') | |
135 | } | |
136 | ||
137 | { | |
138 | const body = await command.advancedChannelSearch({ search: { handles: [ 'squall_channel@' + server.host ] } }) | |
139 | expect(body.total).to.equal(1) | |
140 | expect(body.data).to.have.lengthOf(1) | |
141 | expect(body.data[0].displayName).to.equal('Squall channel') | |
142 | } | |
143 | ||
144 | { | |
145 | const body = await command.advancedChannelSearch({ search: { handles: [ 'chocobozzz_channel' ] } }) | |
146 | expect(body.total).to.equal(0) | |
147 | expect(body.data).to.have.lengthOf(0) | |
148 | } | |
149 | ||
150 | { | |
151 | const body = await command.advancedChannelSearch({ search: { handles: [ 'squall_channel', 'zell_channel@' + remoteServer.host ] } }) | |
152 | expect(body.total).to.equal(2) | |
153 | expect(body.data).to.have.lengthOf(2) | |
154 | expect(body.data[0].displayName).to.equal('Squall channel') | |
155 | expect(body.data[1].displayName).to.equal('Zell channel') | |
156 | } | |
157 | }) | |
158 | ||
159 | after(async function () { | |
160 | await cleanupTests([ server, remoteServer ]) | |
161 | }) | |
162 | }) |