-
Notifications
You must be signed in to change notification settings - Fork 2
/
e2e_test.js
334 lines (302 loc) · 10.9 KB
/
e2e_test.js
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
/*global Feature */
/*global Scenario */
require("dotenv").config();
const { MailSlurp } = require("../../node_modules/mailslurp-client");
const mailslurp = new MailSlurp({ apiKey: process.env.MAILSLURP_KEY });
const chai = require("chai");
chai.use(require("chai-json-schema-ajv"));
const expect = chai.expect;
const API_LOG = 1;
const MAX_LAG = 1000;
const url = process.env.TEST_URL;
console.log("e2e_test.js url: ", url);
const timeSince = start => process.hrtime(start)[1] / 1000000;
Feature("API");
// Scenario("0. /hello", async I => {
// const helloStart = process.hrtime();
// const helloResponse = await I.sendGetRequest("/hello");
// expect(timeSince(helloStart)).to.be.lessThan(MAX_LAG);
// expect(helloResponse.status).to.equal(200);
// expect(helloResponse.data).to.equal("Hello World!");
// });
Scenario("1. /admin/migrate", async I => {
// const migrateStart = process.hrtime();
const migrationResponse = await I.sendPostRequest("/admin/migrate", {
password: process.env.ADMIN_PASSWORD
});
console.log(
"migrationResponse",
migrationResponse.status,
migrationResponse.data
);
// expect(timeSince(migrateStart)).to.be.lessThan(MAX_LAG);
expect(migrationResponse.status).to.equal(200);
});
// Scenario("2. /admin/pingdb", async I => {
// // const pingDbStart = process.hrtime();
// const pingDbResponse = await I.sendPostRequest("/admin/pingdb");
// console.log(">>>>> RES", pingDbResponse.status, pingDbResponse.data);
// // expect(timeSince(pingDbStart)).to.be.lessThan(MAX_LAG);
// expect(pingDbResponse.status).to.equal(200);
// });
// Scenario("2. /users", async I => {
// // ALLOW SIGN UP WITH VALID EMAILS
// const inbox = await mailslurp.createInbox();
// const password = "TestP@$$w3rd!";
// const display_name = "testuser";
// const signUpStart = process.hrtime();
// const signUpResponse = await I.sendPostRequest("/users", {
// email: inbox.emailAddress,
// display_name,
// password
// });
// if (API_LOG) console.log(signUpResponse);
// expect(timeSince(signUpStart)).to.be.lessThan(MAX_LAG);
// expect(signUpResponse.status).to.equal(200);
// // GET EMAIL WITH CODE
// const verifyEmail = await mailslurp.waitForLatestEmail(id);
// expect(timeSince(signUpStart)).to.be.lessThan(5000); // Emails within 5 seconds
// expect(verifyEmail.body).to.match(/Verify with Bit Pharma using code:/);
// const verifyCode = /([0-9]{6})$/.exec(verifyEmail.body)[1];
// expect(verifyCode).to.exist.and.to.have.lengthOf(6);
// // REJECT INCORRECT VERIFICATION CODES
// const incorrectCodeStart = process.hrtime();
// const incorrectCodeResponse = await I.sendPostRequest(
// `/users/${display_name}/verify`,
// {
// code: "probably_incorrect"
// }
// );
// expect(timeSince(incorrectCodeStart)).to.be.lessThan(MAX_LAG);
// expect(incorrectCodeResponse.status).to.equal(400);
// // VERIFY EMAIL WITH CORRECT CODE
// const verifyStart = process.hrtime();
// const verifyResponse = await I.sendPostRequest(
// `/users/${display_name}/verify`,
// {
// code: verifyCode
// }
// );
// expect(timeSince(verifyStart)).to.be.lessThan(MAX_LAG);
// expect(verifyResponse.status).to.equal(200);
// mailslurp.deleteEmail(verifyEmail.id);
// // REJECT EMAILS ALREADY SIGNED UP
// const emailInUseStart = process.hrtime();
// const emailInUseResponse = await I.sendPostRequest("/users", {
// display_name: "testuser2",
// email: inbox.emailAddress,
// password
// });
// expect(timeSince(emailInUseStart)).to.be.lessThan(MAX_LAG);
// expect(emailInUseResponse.statusCode).to.equal(400);
// // REJECT DISPLAY_NAMES ALREADY SIGNED UP
// const nameInUseStart = process.hrtime();
// const nameInUseResponse = await I.sendPostRequest("/users", {
// email: "bob@bob.com",
// display_name,
// password
// });
// expect(timeSince(nameInUseStart)).to.be.lessThan(MAX_LAG);
// expect(nameInUseResponse.statusCode).to.equal(400);
// // REJECT NON-EMAIL EMAILS
// const notAnEmailStart = process.hrtime();
// const notAnEmailResponse = await I.sendPostRequest("/users", {
// display_name: "testuser3",
// email: "notAnEmail",
// password
// });
// expect(timeSince(notAnEmailStart)).to.be.lessThan(MAX_LAG);
// expect(notAnEmailResponse.statusCode).to.equal(400);
// // REJECT BAD PASSWORDS
// const badPwStart = process.hrtime();
// const badPwResponse = await I.sendPostRequest("/users", {
// display_name: "testuser3",
// email: "bob@bob.com",
// password: ""
// });
// expect(timeSince(badPwStart)).to.be.lessThan(MAX_LAG);
// expect(badPwResponse.statusCode).to.equal(400);
// // REJECT SIGN IN WITH WRONG PASSWORD
// const incorrectPasswordStart = process.hrtime();
// const incorrectPasswordResponse = await I.sendPostRequest(
// `/users/${display_name}/signin`,
// {
// email: emailAddress,
// password: "WRONG_PASSWORD!!1"
// }
// );
// expect(timeSince(incorrectPasswordStart)).to.be.lessThan(MAX_LAG);
// expect(incorrectPasswordResponse.status).to.equal(400);
// // SIGN IN WORKS
// const signInStart = process.hrtine();
// const signInResponse = await I.sendPostRequest(
// `/users/${display_name}/signin`,
// {
// email: emailAddress,
// password
// }
// );
// expect(timeSince(signInStart)).to.be.lessThan(MAX_LAG);
// expect(signInResponse.status).to.equal(200);
// I.seeCookie("session");
// // REJECT INCORRECT PASSWORD IN CHANGE PASSWORD
// const newPassword = "NewP@$$w3rd!";
// const failedChangeStart = process.hrtime();
// const failedChangeResponse = await I.sendPostRequest(
// `/users/${display_name}/password`,
// {
// password: "WRONG_PASSWORD!!1",
// newPassword
// }
// );
// expect(timeSince(failedChangeStart)).to.be.lessThan(MAX_LAG);
// expect(failedChangeResponse.status).to.equal(400);
// // CHANGE PASSWORDS
// const changePasswordStart = process.hrtime();
// const changeResponse = await I.sendPostRequest(
// `/users/${display_name}/password`,
// {
// password,
// newPassword
// }
// );
// expect(timeSince(changePasswordStart)).to.be.lessThan(MAX_LAG);
// expect(changeResponse.status).to.equal(200);
// // SIGN IN WORKS WITH NEW PASSWORD
// const newPasswordSignInStart = process.hrtime();
// const newPasswordSignInResponse = await I.sendPostRequest(
// `/users/${display_name}/signin`,
// {
// email: emailAddress,
// password: newPassword
// }
// );
// expect(timeSince(newPasswordSignInStart)).to.be.lessThan(MAX_LAG);
// expect(newPasswordSignInResponse.status).to.equal(200);
// // FORGOT PASSWORDS
// const forgotStart = process.hrtime();
// const forgotResponse = await I.sendPostRequest(
// `/users/${display_name}/forgot`
// );
// expect(timeSince(forgotStart)).to.be.lessThan(MAX_LAG);
// expect(forgotResponse.status).to.equal(200);
// const forgotEmail = await mailslurp.waitForLatestEmail(id);
// expect(timeSince(forgotStart)).to.be.lessThan(5000); // Emails within 5 seconds
// expect(forgotEmail.body).to.match(
// /Reset your Bit Pharma password with code:/
// );
// const resetCode = /([0-9]{6})$/.exec(forgotEmail.body)[1];
// const resetPassword = "ResetP@$$w3rd!";
// const resetStart = process.hrtime();
// const resetResponse = await I.sendPostRequest(
// `/users/${display_name}/reset`,
// {
// code: resetCode,
// newPassword: resetPassword
// }
// );
// expect(timeSince(resetStart)).to.be.lessThan(MAX_LAG);
// expect(resetResponse.status).to.equal(200);
// mailslurp.deleteEmail(forgotEmail.id);
// // REJECT USED RESET CODES
// const resetAgainStart = process.hrtime();
// const resetAgainResponse = await I.sendPostRequest(
// `/users/${display_name}/reset`,
// {
// code: resetCode,
// newPassword: "ANOTHER P@$SWORD!"
// }
// );
// expect(timeSince(resetAgainStart)).to.be.lessThan(MAX_LAG);
// expect(resetAgainResponse.status).to.equal(400);
// // REJECT INCORRECT RESET CODE
// const incorrectResetCodeStart = process.hrtime();
// const incorrectResetCodeResponse = await I.sendPostRequest(
// `/users/${display_name}/reset`,
// {
// code: "good news, everyone!",
// newPassword: ""
// }
// );
// expect(timeSince(incorrectResetCodeStart)).to.be.lessThan(MAX_LAG);
// expect(incorrectResetCodeResponse.status).to.equal(400);
// // SIGN IN WORKS WITH RESET PASSWORD
// const resetPasswordSignInStart = process.hrtime();
// const resetPasswordSignInResponse = await I.sendPostRequest(
// `/users/${display_name}/signin`,
// {
// email: emailAddress,
// password: resetPassword
// }
// );
// expect(timeSince(resetPasswordSignInStart)).to.be.lessThan(MAX_LAG);
// expect(resetPasswordSignInResponse.status).to.equal(200);
// // REJECT ACCOUNT REMOVAL WITH WRONG PASSWORD
// const badPwDeleteStart = process.hrtime();
// const badPwDeleteResponse = await I.sendDeleteRequest(
// `/users/${display_name}`,
// {
// email: emailAddress,
// password: "BENDER_B_RODRIGUEZ"
// }
// );
// expect(timeSince(badPwDeleteStart)).to.be.lessThan(MAX_LAG);
// expect(badPwDeleteResponse.status).to.equal(400);
// // DELETE ACCOUNT WORKS
// const deleteStart = process.hrtime();
// const deleteResponse = await I.sendDeleteRequest(`/users/${display_name}`, {
// email: emailAddress,
// password: resetPassword
// });
// expect(timeSince(deleteStart)).to.be.lessThan(MAX_LAG);
// expect(deleteResponse.status).to.equal(200);
// // CLEAN UP
// mailslurp.deleteInbox(inbox.id);
// });
// Scenario("3. /teams", async I => {
// HOW DO I TEST TEAMS?
// Create - public, private
// Retrieve - public, private
// Update - admins, viewers
// Delete - only superadmins
// List
// });
// Scenario("4. /items", async I => {});
// Scenario("5. /index", async I => {});
// Scenario("6. /orders", async I => {});
// Scenario("6. /events", async I => {});
// Feature("Search");
// Scenario("visit the site", async I => {
// I.amOnPage(url);
// I.see("Search");
// });
// Feature("Contact");
// Scenario("check the contact link", async I => {
// I.amOnPage(url);
// const contactHref = await I.grabAttributeFrom("#contact-link", "href");
// expect(contactHref).to.equal("mailto:bion@bitpharma.com");
// });
// Feature("Blog");
// Scenario("visit the blog", async I => {
// I.amOnPage(url);
// I.click("#blog-link");
// I.see("Blog");
// });
// Feature("Feedback");
// Scenario("give feedback", async I => {
// I.amOnPage(url);
// I.see("Feedback");
// I.click("#feedback-link");
// I.see("Leave a comment");
// });
// Feature("Docs");
// Scenario("skim the docs", async I => {
// I.amOnPage(url);
// I.see("Docs");
// I.click("#docs-link");
// I.see("Table of Contents");
// I.see("Quick Start");
// I.see("API");
// I.see("Deep Dive");
// I.see("FAQ");
// });