diff options
author | Chocobozzz <me@florianbigard.com> | 2019-04-15 15:26:15 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-04-24 16:25:52 +0200 |
commit | 94565d52bb2883e09f16d1363170ac9c0dccb7a1 (patch) | |
tree | 3dcd20cd7b5a5cca80bce32b655cdbfaddf7aa59 /shared/extra-utils/users/accounts.ts | |
parent | 4ee7a4c9ac9280cda930a281c2d5a9a4c409cc14 (diff) | |
download | PeerTube-94565d52bb2883e09f16d1363170ac9c0dccb7a1.tar.gz PeerTube-94565d52bb2883e09f16d1363170ac9c0dccb7a1.tar.zst PeerTube-94565d52bb2883e09f16d1363170ac9c0dccb7a1.zip |
Shared utils -> extra-utils
Because they need dev dependencies
Diffstat (limited to 'shared/extra-utils/users/accounts.ts')
-rw-r--r-- | shared/extra-utils/users/accounts.ts | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/shared/extra-utils/users/accounts.ts b/shared/extra-utils/users/accounts.ts new file mode 100644 index 000000000..f64a2dbad --- /dev/null +++ b/shared/extra-utils/users/accounts.ts | |||
@@ -0,0 +1,80 @@ | |||
1 | /* tslint:disable:no-unused-expression */ | ||
2 | |||
3 | import * as request from 'supertest' | ||
4 | import { expect } from 'chai' | ||
5 | import { existsSync, readdir } from 'fs-extra' | ||
6 | import { join } from 'path' | ||
7 | import { Account } from '../../models/actors' | ||
8 | import { root } from '../miscs/miscs' | ||
9 | import { makeGetRequest } from '../requests/requests' | ||
10 | import { VideoRateType } from '../../models/videos' | ||
11 | |||
12 | function getAccountsList (url: string, sort = '-createdAt', statusCodeExpected = 200) { | ||
13 | const path = '/api/v1/accounts' | ||
14 | |||
15 | return makeGetRequest({ | ||
16 | url, | ||
17 | query: { sort }, | ||
18 | path, | ||
19 | statusCodeExpected | ||
20 | }) | ||
21 | } | ||
22 | |||
23 | function getAccount (url: string, accountName: string, statusCodeExpected = 200) { | ||
24 | const path = '/api/v1/accounts/' + accountName | ||
25 | |||
26 | return makeGetRequest({ | ||
27 | url, | ||
28 | path, | ||
29 | statusCodeExpected | ||
30 | }) | ||
31 | } | ||
32 | |||
33 | async function expectAccountFollows (url: string, nameWithDomain: string, followersCount: number, followingCount: number) { | ||
34 | const res = await getAccountsList(url) | ||
35 | const account = res.body.data.find((a: Account) => a.name + '@' + a.host === nameWithDomain) | ||
36 | |||
37 | const message = `${nameWithDomain} on ${url}` | ||
38 | expect(account.followersCount).to.equal(followersCount, message) | ||
39 | expect(account.followingCount).to.equal(followingCount, message) | ||
40 | } | ||
41 | |||
42 | async function checkActorFilesWereRemoved (actorUUID: string, serverNumber: number) { | ||
43 | const testDirectory = 'test' + serverNumber | ||
44 | |||
45 | for (const directory of [ 'avatars' ]) { | ||
46 | const directoryPath = join(root(), testDirectory, directory) | ||
47 | |||
48 | const directoryExists = existsSync(directoryPath) | ||
49 | expect(directoryExists).to.be.true | ||
50 | |||
51 | const files = await readdir(directoryPath) | ||
52 | for (const file of files) { | ||
53 | expect(file).to.not.contain(actorUUID) | ||
54 | } | ||
55 | } | ||
56 | } | ||
57 | |||
58 | function getAccountRatings (url: string, accountName: string, accessToken: string, rating?: VideoRateType, statusCodeExpected = 200) { | ||
59 | const path = '/api/v1/accounts/' + accountName + '/ratings' | ||
60 | |||
61 | const query = rating ? { rating } : {} | ||
62 | |||
63 | return request(url) | ||
64 | .get(path) | ||
65 | .query(query) | ||
66 | .set('Accept', 'application/json') | ||
67 | .set('Authorization', 'Bearer ' + accessToken) | ||
68 | .expect(statusCodeExpected) | ||
69 | .expect('Content-Type', /json/) | ||
70 | } | ||
71 | |||
72 | // --------------------------------------------------------------------------- | ||
73 | |||
74 | export { | ||
75 | getAccount, | ||
76 | expectAccountFollows, | ||
77 | getAccountsList, | ||
78 | checkActorFilesWereRemoved, | ||
79 | getAccountRatings | ||
80 | } | ||