]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/search/search-channels.ts
Introduce channels command
[github/Chocobozzz/PeerTube.git] / server / tests / api / search / search-channels.ts
CommitLineData
3521ab8f
C
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3import 'mocha'
4import * as chai from 'chai'
a5461888 5import { cleanupTests, createUser, flushAndRunServer, SearchCommand, ServerInfo, setAccessTokensToServers } from '@shared/extra-utils'
3521ab8f
C
6import { VideoChannel } from '@shared/models'
7
8const expect = chai.expect
9
10describe('Test channels search', function () {
11 let server: ServerInfo = null
af971e06 12 let command: SearchCommand
3521ab8f
C
13
14 before(async function () {
15 this.timeout(30000)
16
17 server = await flushAndRunServer(1)
18
19 await setAccessTokensToServers([ server ])
20
21 {
22 await createUser({ url: server.url, accessToken: server.accessToken, username: 'user1', password: 'password' })
23 const channel = {
24 name: 'squall_channel',
25 displayName: 'Squall channel'
26 }
a5461888 27 await server.channelsCommand.create({ attributes: channel })
3521ab8f 28 }
af971e06
C
29
30 command = server.searchCommand
3521ab8f
C
31 })
32
33 it('Should make a simple search and not have results', async function () {
af971e06 34 const body = await command.searchChannels({ search: 'abc' })
3521ab8f 35
af971e06
C
36 expect(body.total).to.equal(0)
37 expect(body.data).to.have.lengthOf(0)
3521ab8f
C
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 }
af971e06
C
47 const body = await command.advancedChannelSearch({ search })
48 expect(body.total).to.equal(1)
49 expect(body.data).to.have.lengthOf(1)
3521ab8f 50
af971e06 51 const channel: VideoChannel = body.data[0]
3521ab8f
C
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
af971e06
C
63 const body = await command.advancedChannelSearch({ search })
64 expect(body.total).to.equal(1)
65 expect(body.data).to.have.lengthOf(0)
3521ab8f
C
66 }
67 })
68
69 after(async function () {
70 await cleanupTests([ server ])
71 })
72})