]>
Commit | Line | Data |
---|---|---|
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | |
2 | ||
3 | import 'mocha' | |
4 | import * as chai from 'chai' | |
5 | import { cleanupTests, createSingleServer, PeerTubeServer, SearchCommand, setAccessTokensToServers } from '@shared/extra-utils' | |
6 | import { VideoChannel } from '@shared/models' | |
7 | ||
8 | const expect = chai.expect | |
9 | ||
10 | describe('Test channels search', function () { | |
11 | let server: PeerTubeServer = null | |
12 | let command: SearchCommand | |
13 | ||
14 | before(async function () { | |
15 | this.timeout(30000) | |
16 | ||
17 | server = await createSingleServer(1) | |
18 | ||
19 | await setAccessTokensToServers([ server ]) | |
20 | ||
21 | { | |
22 | await server.users.create({ username: 'user1', password: 'password' }) | |
23 | const channel = { | |
24 | name: 'squall_channel', | |
25 | displayName: 'Squall channel' | |
26 | } | |
27 | await server.channels.create({ attributes: channel }) | |
28 | } | |
29 | ||
30 | command = server.search | |
31 | }) | |
32 | ||
33 | it('Should make a simple search and not have results', async function () { | |
34 | const body = await command.searchChannels({ search: 'abc' }) | |
35 | ||
36 | expect(body.total).to.equal(0) | |
37 | expect(body.data).to.have.lengthOf(0) | |
38 | }) | |
39 | ||
40 | it('Should make a search and have results', async function () { | |
41 | { | |
42 | const search = { | |
43 | search: 'Squall', | |
44 | start: 0, | |
45 | count: 1 | |
46 | } | |
47 | const body = await command.advancedChannelSearch({ search }) | |
48 | expect(body.total).to.equal(1) | |
49 | expect(body.data).to.have.lengthOf(1) | |
50 | ||
51 | const channel: VideoChannel = body.data[0] | |
52 | expect(channel.name).to.equal('squall_channel') | |
53 | expect(channel.displayName).to.equal('Squall channel') | |
54 | } | |
55 | ||
56 | { | |
57 | const search = { | |
58 | search: 'Squall', | |
59 | start: 1, | |
60 | count: 1 | |
61 | } | |
62 | ||
63 | const body = await command.advancedChannelSearch({ search }) | |
64 | expect(body.total).to.equal(1) | |
65 | expect(body.data).to.have.lengthOf(0) | |
66 | } | |
67 | }) | |
68 | ||
69 | after(async function () { | |
70 | await cleanupTests([ server ]) | |
71 | }) | |
72 | }) |