diff options
Diffstat (limited to 'server/tests/api/search/search-channels.ts')
-rw-r--r-- | server/tests/api/search/search-channels.ts | 116 |
1 files changed, 93 insertions, 23 deletions
diff --git a/server/tests/api/search/search-channels.ts b/server/tests/api/search/search-channels.ts index daca2aebe..8a01aff90 100644 --- a/server/tests/api/search/search-channels.ts +++ b/server/tests/api/search/search-channels.ts | |||
@@ -2,44 +2,65 @@ | |||
2 | 2 | ||
3 | import 'mocha' | 3 | import 'mocha' |
4 | import * as chai from 'chai' | 4 | import * as chai from 'chai' |
5 | import { searchVideoChannel, advancedVideoChannelSearch } from '@shared/extra-utils/search/video-channels' | ||
6 | import { | 5 | import { |
7 | addVideoChannel, | ||
8 | cleanupTests, | 6 | cleanupTests, |
9 | createUser, | 7 | createSingleServer, |
10 | flushAndRunServer, | 8 | doubleFollow, |
11 | ServerInfo, | 9 | PeerTubeServer, |
10 | SearchCommand, | ||
12 | setAccessTokensToServers | 11 | setAccessTokensToServers |
13 | } from '../../../../shared/extra-utils' | 12 | } from '@shared/extra-utils' |
14 | import { VideoChannel } from '@shared/models' | 13 | import { VideoChannel } from '@shared/models' |
15 | 14 | ||
16 | const expect = chai.expect | 15 | const expect = chai.expect |
17 | 16 | ||
18 | describe('Test channels search', function () { | 17 | describe('Test channels search', function () { |
19 | let server: ServerInfo = null | 18 | let server: PeerTubeServer |
19 | let remoteServer: PeerTubeServer | ||
20 | let command: SearchCommand | ||
20 | 21 | ||
21 | before(async function () { | 22 | before(async function () { |
22 | this.timeout(30000) | 23 | this.timeout(120000) |
23 | 24 | ||
24 | server = await flushAndRunServer(1) | 25 | const servers = await Promise.all([ |
26 | createSingleServer(1), | ||
27 | createSingleServer(2, { transcoding: { enabled: false } }) | ||
28 | ]) | ||
29 | server = servers[0] | ||
30 | remoteServer = servers[1] | ||
25 | 31 | ||
26 | await setAccessTokensToServers([ server ]) | 32 | await setAccessTokensToServers([ server, remoteServer ]) |
27 | 33 | ||
28 | { | 34 | { |
29 | await createUser({ url: server.url, accessToken: server.accessToken, username: 'user1', password: 'password' }) | 35 | await server.users.create({ username: 'user1' }) |
30 | const channel = { | 36 | const channel = { |
31 | name: 'squall_channel', | 37 | name: 'squall_channel', |
32 | displayName: 'Squall channel' | 38 | displayName: 'Squall channel' |
33 | } | 39 | } |
34 | await addVideoChannel(server.url, server.accessToken, channel) | 40 | await server.channels.create({ attributes: channel }) |
35 | } | 41 | } |
42 | |||
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 | |||
56 | command = server.search | ||
36 | }) | 57 | }) |
37 | 58 | ||
38 | it('Should make a simple search and not have results', async function () { | 59 | it('Should make a simple search and not have results', async function () { |
39 | const res = await searchVideoChannel(server.url, 'abc') | 60 | const body = await command.searchChannels({ search: 'abc' }) |
40 | 61 | ||
41 | expect(res.body.total).to.equal(0) | 62 | expect(body.total).to.equal(0) |
42 | expect(res.body.data).to.have.lengthOf(0) | 63 | expect(body.data).to.have.lengthOf(0) |
43 | }) | 64 | }) |
44 | 65 | ||
45 | it('Should make a search and have results', async function () { | 66 | it('Should make a search and have results', async function () { |
@@ -49,11 +70,11 @@ describe('Test channels search', function () { | |||
49 | start: 0, | 70 | start: 0, |
50 | count: 1 | 71 | count: 1 |
51 | } | 72 | } |
52 | const res = await advancedVideoChannelSearch(server.url, search) | 73 | const body = await command.advancedChannelSearch({ search }) |
53 | expect(res.body.total).to.equal(1) | 74 | expect(body.total).to.equal(1) |
54 | expect(res.body.data).to.have.lengthOf(1) | 75 | expect(body.data).to.have.lengthOf(1) |
55 | 76 | ||
56 | const channel: VideoChannel = res.body.data[0] | 77 | const channel: VideoChannel = body.data[0] |
57 | expect(channel.name).to.equal('squall_channel') | 78 | expect(channel.name).to.equal('squall_channel') |
58 | expect(channel.displayName).to.equal('Squall channel') | 79 | expect(channel.displayName).to.equal('Squall channel') |
59 | } | 80 | } |
@@ -65,15 +86,64 @@ describe('Test channels search', function () { | |||
65 | count: 1 | 86 | count: 1 |
66 | } | 87 | } |
67 | 88 | ||
68 | const res = await advancedVideoChannelSearch(server.url, search) | 89 | const body = await command.advancedChannelSearch({ search }) |
90 | expect(body.total).to.equal(1) | ||
91 | expect(body.data).to.have.lengthOf(0) | ||
92 | } | ||
93 | }) | ||
94 | |||
95 | it('Should filter by host', async function () { | ||
96 | { | ||
97 | const search = { search: 'channel', host: remoteServer.host } | ||
69 | 98 | ||
70 | expect(res.body.total).to.equal(1) | 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 } | ||
71 | 107 | ||
72 | expect(res.body.data).to.have.lengthOf(0) | 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 | |||
123 | it('Should filter by names', async function () { | ||
124 | { | ||
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) | ||
128 | expect(body.data[0].displayName).to.equal('Squall channel') | ||
129 | } | ||
130 | |||
131 | { | ||
132 | const body = await command.advancedChannelSearch({ search: { handles: [ 'chocobozzz_channel' ] } }) | ||
133 | expect(body.total).to.equal(0) | ||
134 | expect(body.data).to.have.lengthOf(0) | ||
135 | } | ||
136 | |||
137 | { | ||
138 | const body = await command.advancedChannelSearch({ search: { handles: [ 'squall_channel', 'zell_channel@' + remoteServer.host ] } }) | ||
139 | expect(body.total).to.equal(2) | ||
140 | expect(body.data).to.have.lengthOf(2) | ||
141 | expect(body.data[0].displayName).to.equal('Squall channel') | ||
142 | expect(body.data[1].displayName).to.equal('Zell channel') | ||
73 | } | 143 | } |
74 | }) | 144 | }) |
75 | 145 | ||
76 | after(async function () { | 146 | after(async function () { |
77 | await cleanupTests([ server ]) | 147 | await cleanupTests([ server, remoteServer ]) |
78 | }) | 148 | }) |
79 | }) | 149 | }) |