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