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