-
Notifications
You must be signed in to change notification settings - Fork 56
/
generate.js
96 lines (88 loc) · 2.43 KB
/
generate.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
import faker from "faker";
import compose from "lodash/fp/compose";
import map from "lodash/fp/map";
import times from "lodash/fp/times";
import * as pki from "../../pki";
export function User({
isadmin = false,
userid,
email,
username,
paywalladdress,
proposalcredits,
paywalltxid,
publickey,
totpverified = false
} = {}) {
this.isadmin = isadmin;
this.userid = userid || faker.datatype.uuid();
this.email = email || faker.internet.email();
this.username = username || faker.internet.userName();
this.proposalcredits = proposalcredits || faker.datatype.number(100);
this.paywalladdress = paywalladdress || `Ts${faker.datatype.hexaDecimal(33)}`;
this.paywalltxid =
paywalltxid || faker.datatype.hexaDecimal(64, false, /[0-9a-z]/);
this.publickey = publickey || pki.toHex(faker.datatype.hexaDecimal(64));
this.paywallamount = 10000000;
this.paywalltxnotbefore = Date.now() / 1000 - 3600;
this.lastlogintime = faker.time.recent() / 1000;
this.sessionmaxage = 86400; // 1 day
this.totpverified = totpverified;
}
export function UserAdmin(props = {}) {
return new User({ ...props, isadmin: true });
}
export function UserUnpaid(props = {}) {
return new User({
...props,
paywallamount: 0,
paywalladdress: "",
paywalltxid: ""
});
}
export function UserNoCredits(props = {}) {
return new User({ ...props, proposalcredits: 0 });
}
export function UserTotp(props = {}) {
return new User({ ...props, totpverified: true });
}
export function userByType(userType, props) {
switch (userType) {
case "admin":
return UserAdmin(props);
case "noCredits":
return UserNoCredits(props);
case "unpaid":
return UserUnpaid(props);
case "user":
return new User(props);
case "totp":
return UserTotp(props);
case "noLogin":
return {};
default:
return new User(props);
}
}
export function PaymentCredits({ spent = 0, unspent = 0 } = {}) {
const makeCredits = compose(
map(() => ({
paywallid: 0,
price: 0,
datepurchased: Date.now() / 1000,
txid: "created_by_e2e_mock_api"
})),
times
);
this.spentcredits = makeCredits(spent);
this.unspentcredits = makeCredits(unspent);
}
export function Identity({ userid, publickey }) {
return pki.generateKeys().then((keys) => {
const stringKeys = {
secretKey: pki.toHex(keys.secretKey),
publicKey: publickey
};
pki.importKeys(userid, stringKeys);
});
}