aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/utils/follows.ts
blob: 9ad1ca7f4e2f47c4045cc1dd1191d1b135bc7fb0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import * as request from 'supertest'

import { wait } from './miscs'

function getFollowersListPaginationAndSort (url: string, start: number, count: number, sort: string) {
  const path = '/api/v1/servers/followers'

  return request(url)
    .get(path)
    .query({ start })
    .query({ count })
    .query({ sort })
    .set('Accept', 'application/json')
    .expect(200)
    .expect('Content-Type', /json/)
}

function getFollowingListPaginationAndSort (url: string, start: number, count: number, sort: string) {
  const path = '/api/v1/servers/following'

  return request(url)
    .get(path)
    .query({ start })
    .query({ count })
    .query({ sort })
    .set('Accept', 'application/json')
    .expect(200)
    .expect('Content-Type', /json/)
}

async function follow (follower: string, following: string[], accessToken: string, expectedStatus = 204) {
  const path = '/api/v1/servers/follow'

  const res = await request(follower)
    .post(path)
    .set('Accept', 'application/json')
    .set('Authorization', 'Bearer ' + accessToken)
    .send({ 'hosts': following })
    .expect(expectedStatus)

  // Wait request propagation
  await wait(1000)

  return res
}

// ---------------------------------------------------------------------------

export {
  getFollowersListPaginationAndSort,
  getFollowingListPaginationAndSort,
  follow
}