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