-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresponse-generators.ts
More file actions
101 lines (93 loc) · 2.3 KB
/
response-generators.ts
File metadata and controls
101 lines (93 loc) · 2.3 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import {
FeedResponse,
FollowResponse,
OwnUser,
OwnUserResponse,
UserResponse,
} from '../gen/models';
import { humanId } from 'human-id';
export const getHumanId = () => humanId({ capitalize: false, separator: '-' });
export const generateUserResponse = (
overrides: Partial<UserResponse> = {},
): UserResponse => ({
id: `user-${getHumanId()}`,
name: humanId({ separator: ' ' }),
created_at: new Date(),
updated_at: new Date(),
banned: false,
language: 'en',
online: false,
role: 'user',
blocked_user_ids: [],
teams: [],
custom: {},
...overrides,
});
export const generateOwnUserResponse = (
overrides: Partial<OwnUserResponse> = {},
): OwnUserResponse => ({
...generateUserResponse({
id: `own-user-${getHumanId()}`,
}),
invisible: false,
total_unread_count: 0,
unread_channels: 0,
unread_count: 0,
unread_threads: 0,
channel_mutes: [],
devices: [],
mutes: [],
...overrides,
});
export const generateOwnUser = (overrides: Partial<OwnUser> = {}): OwnUser => ({
...generateOwnUserResponse(),
devices: [],
mutes: [],
total_unread_count_by_team: {},
...overrides,
});
export const generateFeedResponse = (
overrides: Omit<Partial<FeedResponse>, 'created_by' | 'fid'> & {
created_by?: Partial<UserResponse>;
} = {},
): FeedResponse => {
const id = overrides.id || `feed-${getHumanId()}`;
const groupId = overrides.group_id || 'user';
const fid = `${groupId}:${id}`;
return {
id,
group_id: groupId,
created_at: new Date(),
updated_at: new Date(),
description: humanId({
addAdverb: true,
adjectiveCount: 4,
separator: ' ',
}),
follower_count: 0,
following_count: 0,
member_count: 0,
name: humanId({ separator: ' ' }),
pin_count: 0,
custom: {},
...overrides,
fid,
created_by: generateUserResponse(overrides.created_by),
};
};
export const generateFollowResponse = (
overrides: Partial<FollowResponse> = {},
): FollowResponse => {
const sourceFeedResponse = generateFeedResponse();
const targetFeedResponse = generateFeedResponse();
return {
created_at: new Date(),
updated_at: new Date(),
follower_role: 'user',
push_preference: 'all',
status: 'accepted',
source_feed: sourceFeedResponse,
target_feed: targetFeedResponse,
...overrides,
};
};