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