@live-change/user-frontend 0.9.196 → 0.9.197

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/e2e/steps_file.js DELETED
@@ -1,156 +0,0 @@
1
- const App = require('@live-change/framework')
2
- const app = App.app()
3
-
4
- const randomProfile = require('random-profile-generator')
5
- const passwordGenerator = require('generate-password')
6
-
7
- const steps = {
8
-
9
- async haveUser(name, email, password, user = app.generateUid(), roles = []) {
10
- const I = this
11
-
12
- if(!password) password = passwordGenerator.generate({
13
- length: 10,
14
- numbers: true
15
- })
16
- if(!name) {
17
- name = randomProfile.profile().firstName
18
- }
19
- if(!email) {
20
- email = name.split(' ')[0].toLowerCase() + (Math.random()*100).toFixed() + '@test.com'
21
- }
22
-
23
- const PasswordAuthentication = await I.haveModel("passwordAuthentication", "PasswordAuthentication")
24
- const User = await I.haveModel("user", "User")
25
- const Email = await I.haveModel("email", "Email")
26
- const Identification = await I.haveModel("userIdentification", "Identification")
27
-
28
- const passwordHash = PasswordAuthentication.definition.properties.passwordHash.preFilter(password)
29
- await User.create({ id: user, roles })
30
- await PasswordAuthentication.create({ id: user, user, passwordHash })
31
- await Email.create({ id: email, email, user })
32
- await Identification.create({
33
- id: App.encodeIdentifier(['user_User', user]), sessionOrUserType: 'user_User', sessionOrUser: user,
34
- name
35
- })
36
- return {
37
- id: user,
38
- name,
39
- email,
40
- password
41
- }
42
- },
43
-
44
- async useEmailLink(email, prefix = '/link/') {
45
- const I = this
46
- const MessageAuthentication = await I.haveModel('messageAuthentication', 'Authentication')
47
- const authentication =
48
- await MessageAuthentication.indexObjectGet('byContact', ['email', email], { reverse: true, limit: 1 })
49
- const Link = await I.haveModel('secretLink', 'Link')
50
- let link = await Link.indexObjectGet('byAuthentication', authentication)
51
- I.amOnPage(prefix + link.secretCode)
52
- await I.wait(0.1)
53
- return { authentication, link }
54
- },
55
-
56
- async amLoggedIn(user) {
57
- const I = this
58
- console.log("USER", user)
59
- const AuthenticatedUser = await I.haveModel("user", "AuthenticatedUser")
60
- const session = await I.executeScript(() => window.api.client.value.session)
61
- console.log("AUTHENTICATE SESSION", session)
62
- await AuthenticatedUser.create({ id: session, session, user: user.id })
63
- },
64
-
65
- async amLoggedOut() {
66
- const I = this
67
- const AuthenticatedUser = await I.haveModel("user", "AuthenticatedUser")
68
- const session = await I.executeScript(() => window.api.client.value.session)
69
- await AuthenticatedUser.delete(session)
70
- },
71
-
72
- async useSecretCode(authentication, happyPath) {
73
- const I = this
74
- const Code = await I.haveModel('secretCode', 'Code')
75
- let codeData = await Code.indexObjectGet('byAuthentication', authentication)
76
- console.log("CODE DATA", codeData)
77
- I.assert(!!codeData, true, 'code created')
78
-
79
- if(!happyPath) {
80
- const wrongCode = codeData.secretCode == '123456' ? '654321' : '123456'
81
- I.fillField('input#code', wrongCode)
82
- I.fillField('input#code', wrongCode) /// twice because it can fail once with this type of field
83
- I.click('button[type=submit]')
84
- I.seeElement('#code-help.p-error')
85
- }
86
-
87
- if(!happyPath) {
88
- await I.wait(0.2)
89
- await Code.update(codeData.id, { expire: new Date() }) // expire now
90
- I.fillField('input#code', codeData.secretCode)
91
- I.fillField('input#code', codeData.secretCode) /// twice because it can fail once with this type of field
92
- I.click('button[type=submit]')
93
- I.seeElement('#code-help.p-error')
94
-
95
- I.click('Resend')
96
- I.seeInCurrentUrl('/sent/')
97
-
98
- await I.wait(0.2)
99
- const newCodeData = await Code.indexRangeGet('byAuthentication', authentication)
100
- newCodeData.sort((a,b) => new Date(b.expire).getTime() - new Date(a.expire).getTime())
101
- const oldCodeData = codeData
102
- codeData = newCodeData[0]
103
- I.assert(!!codeData, true, 'code exists')
104
- I.assert(oldCodeData.id != codeData.id, true, 'code is different from previous code')
105
- }
106
-
107
- I.fillField('input#code', codeData.secretCode)
108
- I.fillField('input#code', codeData.secretCode) /// twice because it can fail once with this type of field
109
- I.click('button[type=submit]')
110
- await I.wait(0.1)
111
- },
112
-
113
- async useSecretLink(authentication, happyPath, prefix = '') {
114
- const I = this
115
- const Link = await I.haveModel('secretLink', 'Link')
116
- let linkData = await Link.indexObjectGet('byAuthentication', authentication)
117
- console.log("LINK DATA", linkData)
118
- I.assert(!!linkData, true, 'link created')
119
-
120
- if(!happyPath) {
121
- I.amOnPage(prefix + '/link/[badSecret]')
122
- I.see('Unknown link')
123
- }
124
-
125
- if(!happyPath) {
126
- await I.wait(0.2)
127
- await Link.update(linkData.id, { expire: new Date() }) // expire now
128
- I.amOnPage(prefix + '/link/' + linkData.secretCode)
129
- I.see('Link expired')
130
-
131
- I.click('Resend')
132
- I.seeInCurrentUrl(prefix + '/sent/')
133
-
134
- await I.wait(0.2)
135
- const newLinksData = await Link.indexRangeGet('byAuthentication', authentication)
136
- newLinksData.sort((a,b) => new Date(b.expire).getTime() - new Date(a.expire).getTime())
137
- const oldLinkData = linkData
138
- linkData = newLinksData[0]
139
- I.assert(!!linkData, true, 'link exists')
140
- I.assert(oldLinkData.id != linkData.id, true, 'link is different from previous link')
141
- }
142
-
143
- console.log("LINK RIGHT", prefix + '/link/' + linkData.secretCode)
144
- I.amOnPage(prefix + '/link/'+linkData.secretCode)
145
- await I.wait(0.1)
146
-
147
- return linkData
148
- }
149
-
150
- }
151
-
152
- module.exports = function() {
153
- return actor(steps)
154
- }
155
-
156
- module.exports.steps = steps