]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/utils/users/accounts.ts
Set sort refractoring
[github/Chocobozzz/PeerTube.git] / server / tests / utils / users / accounts.ts
1 import { expect } from 'chai'
2 import { Account } from '../../../../shared/models/actors'
3 import { makeGetRequest } from '../requests/requests'
4
5 function getAccountsList (url: string, sort = '-createdAt', statusCodeExpected = 200) {
6 const path = '/api/v1/accounts'
7
8 return makeGetRequest({
9 url,
10 query: { sort },
11 path,
12 statusCodeExpected
13 })
14 }
15
16 function getAccount (url: string, accountId: number | string, statusCodeExpected = 200) {
17 const path = '/api/v1/accounts/' + accountId
18
19 return makeGetRequest({
20 url,
21 path,
22 statusCodeExpected
23 })
24 }
25
26 async function expectAccountFollows (url: string, nameWithDomain: string, followersCount: number, followingCount: number) {
27 const res = await getAccountsList(url)
28 const account = res.body.data.find((a: Account) => a.name + '@' + a.host === nameWithDomain)
29
30 const message = `${nameWithDomain} on ${url}`
31 expect(account.followersCount).to.equal(followersCount, message)
32 expect(account.followingCount).to.equal(followingCount, message)
33 }
34
35 // ---------------------------------------------------------------------------
36
37 export {
38 getAccount,
39 expectAccountFollows,
40 getAccountsList
41 }