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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
|
// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
import Client from 'client/client.jsx';
import jqd from 'jquery-deferred';
class TestHelperClass {
basicClient = () => {
return this.basicc;
}
basicTeam = () => {
return this.basict;
}
basicUser = () => {
return this.basicu;
}
basicChannel = () => {
return this.basicch;
}
basicPost = () => {
return this.basicp;
}
generateId = () => {
// implementation taken from http://stackoverflow.com/a/2117523
var id = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx';
id = id.replace(/[xy]/g, function replaceRandom(c) {
var r = Math.floor(Math.random() * 16);
var v;
if (c === 'x') {
v = r;
} else {
v = (r & 0x3) | 0x8;
}
return v.toString(16);
});
return 'uid' + id;
}
createClient() {
var c = new Client();
c.setUrl('http://localhost:8065');
c.useHeaderToken();
c.enableLogErrorsToConsole(true);
return c;
}
fakeEmail = () => {
return 'success' + this.generateId() + '@simulator.amazonses.com';
}
fakeUser = () => {
var user = {};
user.email = this.fakeEmail();
user.allow_marketing = true;
user.password = 'password1';
user.username = this.generateId();
return user;
}
fakeTeam = () => {
var team = {};
team.name = this.generateId();
team.display_name = `Unit Test ${team.name}`;
team.type = 'O';
team.email = this.fakeEmail();
team.allowed_domains = '';
return team;
}
fakeChannel = () => {
var channel = {};
channel.name = this.generateId();
channel.display_name = `Unit Test ${channel.name}`;
channel.type = 'O'; // open channel
return channel;
}
fakePost = () => {
var post = {};
post.message = `Unit Test ${this.generateId()}`;
return post;
}
initBasic = (callback) => {
this.basicc = this.createClient();
var d1 = jqd.Deferred();
var email = this.fakeEmail();
var outer = this; // eslint-disable-line consistent-this
this.basicClient().signupTeam(
email,
function(rsignUp) {
var teamSignup = {};
teamSignup.invites = [];
teamSignup.data = decodeURIComponent(rsignUp.follow_link.split('&h=')[0].replace('/signup_team_complete/?d=', ''));
teamSignup.hash = decodeURIComponent(rsignUp.follow_link.split('&h=')[1]);
teamSignup.user = outer.fakeUser();
teamSignup.team = outer.fakeTeam();
teamSignup.team.email = email;
teamSignup.user.email = email;
var password = teamSignup.user.password;
outer.basicClient().createTeamFromSignup(
teamSignup,
function(rteamSignup) {
outer.basict = rteamSignup.team;
outer.basicu = rteamSignup.user;
outer.basicu.password = password;
outer.basicClient().setTeamId(outer.basict.id);
outer.basicClient().login(
rteamSignup.user.email,
password,
null,
function() {
outer.basicClient().useHeaderToken();
var channel = outer.fakeChannel();
channel.team_id = outer.basicTeam().id;
outer.basicClient().createChannel(
channel,
function(rchannel) {
outer.basicch = rchannel;
var post = outer.fakePost();
post.channel_id = rchannel.id;
outer.basicClient().createPost(
post,
function(rpost) {
outer.basicp = rpost;
d1.resolve();
},
function(err) {
throw err;
}
);
},
function(err) {
throw err;
}
);
},
function(err) {
throw err;
}
);
},
function(err) {
throw err;
}
);
},
function(err) {
throw err;
}
);
jqd.when(d1).done(() => {
callback();
});
}
}
var TestHelper = new TestHelperClass();
export default TestHelper;
|