]>
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 () { | |
23 | this.timeout(30000) | |
24 | ||
254d3579 | 25 | server = await createSingleServer(1) |
fa47956e | 26 | remoteServer = await createSingleServer(2, { transcoding: { enabled: false } }) |
3521ab8f | 27 | |
fa47956e | 28 | await setAccessTokensToServers([ server, remoteServer ]) |
3521ab8f C |
29 | |
30 | { | |
fa47956e | 31 | await server.users.create({ username: 'user1' }) |
3521ab8f C |
32 | const channel = { |
33 | name: 'squall_channel', | |
34 | displayName: 'Squall channel' | |
35 | } | |
89d241a7 | 36 | await server.channels.create({ attributes: channel }) |
3521ab8f | 37 | } |
af971e06 | 38 | |
fa47956e C |
39 | { |
40 | await remoteServer.users.create({ username: 'user1' }) | |
41 | const channel = { | |
42 | name: 'zell_channel', | |
43 | displayName: 'Zell channel' | |
44 | } | |
45 | const { id } = await remoteServer.channels.create({ attributes: channel }) | |
46 | ||
47 | await remoteServer.videos.upload({ attributes: { channelId: id } }) | |
48 | } | |
49 | ||
50 | await doubleFollow(server, remoteServer) | |
51 | ||
89d241a7 | 52 | command = server.search |
3521ab8f C |
53 | }) |
54 | ||
55 | it('Should make a simple search and not have results', async function () { | |
af971e06 | 56 | const body = await command.searchChannels({ search: 'abc' }) |
3521ab8f | 57 | |
af971e06 C |
58 | expect(body.total).to.equal(0) |
59 | expect(body.data).to.have.lengthOf(0) | |
3521ab8f C |
60 | }) |
61 | ||
62 | it('Should make a search and have results', async function () { | |
63 | { | |
64 | const search = { | |
65 | search: 'Squall', | |
66 | start: 0, | |
67 | count: 1 | |
68 | } | |
af971e06 C |
69 | const body = await command.advancedChannelSearch({ search }) |
70 | expect(body.total).to.equal(1) | |
71 | expect(body.data).to.have.lengthOf(1) | |
3521ab8f | 72 | |
af971e06 | 73 | const channel: VideoChannel = body.data[0] |
3521ab8f C |
74 | expect(channel.name).to.equal('squall_channel') |
75 | expect(channel.displayName).to.equal('Squall channel') | |
76 | } | |
77 | ||
78 | { | |
79 | const search = { | |
80 | search: 'Squall', | |
81 | start: 1, | |
82 | count: 1 | |
83 | } | |
84 | ||
af971e06 C |
85 | const body = await command.advancedChannelSearch({ search }) |
86 | expect(body.total).to.equal(1) | |
87 | expect(body.data).to.have.lengthOf(0) | |
3521ab8f C |
88 | } |
89 | }) | |
90 | ||
fa47956e C |
91 | it('Should filter by host', async function () { |
92 | { | |
93 | const search = { search: 'channel', host: remoteServer.host } | |
94 | ||
95 | const body = await command.advancedChannelSearch({ search }) | |
96 | expect(body.total).to.equal(1) | |
97 | expect(body.data).to.have.lengthOf(1) | |
98 | expect(body.data[0].displayName).to.equal('Zell channel') | |
99 | } | |
100 | ||
101 | { | |
102 | const search = { search: 'Sq', host: server.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('Squall channel') | |
108 | } | |
109 | ||
110 | { | |
111 | const search = { search: 'Squall', host: 'example.com' } | |
112 | ||
113 | const body = await command.advancedChannelSearch({ search }) | |
114 | expect(body.total).to.equal(0) | |
115 | expect(body.data).to.have.lengthOf(0) | |
116 | } | |
117 | }) | |
118 | ||
3521ab8f C |
119 | after(async function () { |
120 | await cleanupTests([ server ]) | |
121 | }) | |
122 | }) |