@reventlessdev/reventless-registration 1.0.0-alpha.49 → 1.0.0-alpha.50
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/README.md +77 -2
- package/conformance/Registration/InboundTranslation/CompleteRegistration_Conformance_GWT.res +65 -0
- package/conformance/Registration/InboundTranslation/CompleteRegistration_Conformance_GWT.res.mjs +123 -0
- package/conformance/Registration/InboundTranslation/SignUp_Conformance_GWT.res +136 -0
- package/conformance/Registration/InboundTranslation/SignUp_Conformance_GWT.res.mjs +212 -0
- package/conformance/Registration/OutboundTranslation/CreateRegisteredPrincipal_Conformance_GWT.res +102 -0
- package/conformance/Registration/OutboundTranslation/CreateRegisteredPrincipal_Conformance_GWT.res.mjs +179 -0
- package/conformance/Registration/OutboundTranslation/SendRegistrationChallenge_Conformance_GWT.res +312 -0
- package/conformance/Registration/OutboundTranslation/SendRegistrationChallenge_Conformance_GWT.res.mjs +360 -0
- package/conformance/Registration/Registration_Conformance_Examples.res +58 -0
- package/conformance/Registration/Registration_Conformance_Examples.res.mjs +106 -0
- package/conformance/Registration/StateChange/RegistrationPolicy_Conformance_GWT.res +108 -0
- package/conformance/Registration/StateChange/RegistrationPolicy_Conformance_GWT.res.mjs +161 -0
- package/conformance/Registration/StateChange/RegistrationsByInvitation_Conformance_GWT.res +155 -0
- package/conformance/Registration/StateChange/RegistrationsByInvitation_Conformance_GWT.res.mjs +216 -0
- package/conformance/Registration/StateChange/Registrations_Conformance_GWT.res +469 -0
- package/conformance/Registration/StateChange/Registrations_Conformance_GWT.res.mjs +512 -0
- package/conformance/Registration/StateViewStream/RegistrationWindows_Conformance_GWT.res +33 -0
- package/conformance/Registration/StateViewStream/RegistrationWindows_Conformance_GWT.res.mjs +87 -0
- package/package.json +7 -4
- package/rescript.json +6 -1
package/README.md
CHANGED
|
@@ -38,6 +38,59 @@ dependencies. The generator composes the slices as the plugin's own, under the
|
|
|
38
38
|
A closed role, a role no visitor may have, a taken address and a fresh one all answer
|
|
39
39
|
an anonymous caller alike; only what arrives at the address differs.
|
|
40
40
|
|
|
41
|
+
## The ledger
|
|
42
|
+
|
|
43
|
+
`Registrations` keeps one claim per address, keyed by `emailId`, the address's keyed
|
|
44
|
+
fingerprint. The claim is at one of four stages:
|
|
45
|
+
|
|
46
|
+
- **Unclaimed**: nobody holds the address.
|
|
47
|
+
- **Pending**: a visitor or an inviter claimed it. A code may be out, and wrong attempts
|
|
48
|
+
are counted.
|
|
49
|
+
- **Verified**: the proof settled, and the account is being made.
|
|
50
|
+
- **Completed**: the account exists.
|
|
51
|
+
|
|
52
|
+
What each command records, and when. Every case the table leaves out records nothing
|
|
53
|
+
and answers `Ok`, so a door relayed for an anonymous caller cannot be used to learn
|
|
54
|
+
whether an address is registered.
|
|
55
|
+
|
|
56
|
+
| Command | Reached by | Records | When |
|
|
57
|
+
|---|---|---|---|
|
|
58
|
+
| `Register` | `SignUp` | `RegistrationRequested` | Unclaimed, and the policy admits the role |
|
|
59
|
+
| | | `RegistrationExpired`, `RegistrationRequested` | Pending, but the claim has lapsed |
|
|
60
|
+
| | | `RegistrationAttemptedOnTakenAddress` | Completed, at most once an hour |
|
|
61
|
+
| `Invite` | an invitation door the app provides | `RegistrationInvited` | Unclaimed |
|
|
62
|
+
| | | `RegistrationExpired`, `RegistrationInvited` | Pending, but the claim has lapsed |
|
|
63
|
+
| | | error `NotByInvitation` or `NoRoleToGrant` | a role not declared by invitation, or no role |
|
|
64
|
+
| `IssueRegistrationChallenge` | `SendRegistrationChallenge` | `RegistrationChallengeIssued` | Pending, with no code out |
|
|
65
|
+
| `ReissueRegistrationChallenge` | a "send me a new code" door | `RegistrationChallengeReissued` | Pending, a code out, past the resend cooldown |
|
|
66
|
+
| `SubmitRegistrationProof` | `CompleteRegistration` | `RegistrationProofAccepted` | Pending, the proof matches, in time, attempts left |
|
|
67
|
+
| | | `RegistrationProofRefused` | Pending with a code out, and any of those fails |
|
|
68
|
+
| `RecordRegistrationCompleted` | `CreateRegisteredPrincipal` | `RegistrationCompleted` | Verified |
|
|
69
|
+
| `WithdrawRegistration` | an administrator's door | `RegistrationWithdrawn` | Pending |
|
|
70
|
+
| `ReleaseRegistration` | the erasure workflow | `RegistrationReleased` | Completed |
|
|
71
|
+
|
|
72
|
+
## An example run
|
|
73
|
+
|
|
74
|
+
A visitor signs up as a shopper, mistypes the code once, then gets it right. Each step
|
|
75
|
+
names the scenario of `conformance/…/Registrations_Conformance_GWT.res` that pins it.
|
|
76
|
+
|
|
77
|
+
1. The visitor gives their address on the sign-up form. `SignUp` relays `Register`, and
|
|
78
|
+
the ledger records `RegistrationRequested`: the address is claimed. *"a self-service
|
|
79
|
+
role claims the address before anything is recorded"*
|
|
80
|
+
2. `SendRegistrationChallenge` sends a code to the address and relays
|
|
81
|
+
`IssueRegistrationChallenge` with the code's hash, never the code. The ledger records
|
|
82
|
+
`RegistrationChallengeIssued`. *"a pending registration opens a challenge against a
|
|
83
|
+
hash"*
|
|
84
|
+
3. The visitor types a wrong code. `CompleteRegistration` relays the hash of what they
|
|
85
|
+
typed, and the ledger records `RegistrationProofRefused` with `ProofMismatch`. One of
|
|
86
|
+
five attempts is spent. *"a wrong proof is counted, not settled"*
|
|
87
|
+
4. The visitor types the right code, within the day the code holds. The ledger records
|
|
88
|
+
`RegistrationProofAccepted`: the address is verified. *"the right proof settles the
|
|
89
|
+
registration"*
|
|
90
|
+
5. `CreateRegisteredPrincipal` makes the account in the shopper role's group and relays
|
|
91
|
+
`RecordRegistrationCompleted`. The ledger records `RegistrationCompleted`. *"an account
|
|
92
|
+
made for a settled proof completes the registration"*
|
|
93
|
+
|
|
41
94
|
The package ships the doors a visitor uses and no invitation door. A plugin that
|
|
42
95
|
provides one lists it beside these slices, marks it `let admissionDoor =
|
|
43
96
|
Reventless.Admission.Invite`, checks the inviter's roles, and relays `Invite` to the
|
|
@@ -54,8 +107,30 @@ where the deployment offers it, unless the address already holds an account, who
|
|
|
54
107
|
own language wins. The ledger records the language and the key of the mail each code
|
|
55
108
|
went out in.
|
|
56
109
|
|
|
57
|
-
|
|
58
|
-
|
|
110
|
+
## Testing the slices against your table
|
|
111
|
+
|
|
112
|
+
The package ships its scenarios as suites under `conformance/`, one per component, each a
|
|
113
|
+
functor over your admission table. Add one test file to the plugin that lists the package:
|
|
114
|
+
|
|
115
|
+
```rescript
|
|
116
|
+
// tests/Registration_Conformance_GWT.res
|
|
117
|
+
module Ledger = Registrations_Conformance_GWT.Make(Admission)
|
|
118
|
+
module ByInvitation = RegistrationsByInvitation_Conformance_GWT.Make(Admission)
|
|
119
|
+
module Policy = RegistrationPolicy_Conformance_GWT.Make(Admission)
|
|
120
|
+
module Windows = RegistrationWindows_Conformance_GWT.Make(Admission)
|
|
121
|
+
module SignUpDoor = SignUp_Conformance_GWT.Make(Admission)
|
|
122
|
+
module CompletionDoor = CompleteRegistration_Conformance_GWT.Make(Admission)
|
|
123
|
+
module Mail = SendRegistrationChallenge_Conformance_GWT.Make(Admission)
|
|
124
|
+
module Account = CreateRegisteredPrincipal_Conformance_GWT.Make(Admission)
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
The plugin compiles with `-open ReventlessRegistration` and depends on
|
|
128
|
+
`@reventlessdev/reventless-gwt`. A scenario that needs a kind of role your table does not
|
|
129
|
+
declare (one by invitation, or one a visitor may not have) is listed as a todo that says so.
|
|
130
|
+
`check-lifecycle` reads these suites for every plugin that lists the package, so the ledger's
|
|
131
|
+
commands take part in your plugin's lifecycle model. The example host in this repository,
|
|
132
|
+
`examples/online-shop-hybrid/registration`, runs them under its own table and under one that
|
|
133
|
+
admits staff by invitation.
|
|
59
134
|
|
|
60
135
|
The doors admit anonymous callers, which only the local platform does today, so a
|
|
61
136
|
plugin listing these slices is hosted by the local platform only.
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// The door a registration ends at. The password goes into the stash under the proof's hash, and
|
|
2
|
+
// only the hash travels on: nothing that would answer the challenge, and nothing that would sign
|
|
3
|
+
// in, reaches the command. It reads no table; `App` keeps it applied like the other suites.
|
|
4
|
+
|
|
5
|
+
module Make = (App: Reventless.Admission.Declaration) => {
|
|
6
|
+
open CompleteRegistration
|
|
7
|
+
open CompleteRegistration_Translation
|
|
8
|
+
include ReventlessGwt.InboundTranslation_GWT.FromSlice(
|
|
9
|
+
CompleteRegistration,
|
|
10
|
+
CompleteRegistration_Translation,
|
|
11
|
+
)
|
|
12
|
+
open Registration_Conformance_Examples
|
|
13
|
+
|
|
14
|
+
module Outcome = ReventlessGwt.Outcome
|
|
15
|
+
|
|
16
|
+
let password = goodPassword
|
|
17
|
+
|
|
18
|
+
let thenSubmits = async (pending, expected) =>
|
|
19
|
+
switch (await pending).outcome {
|
|
20
|
+
| Translated([(id, SubmitRegistrationProof({emailId, proofHash, _}))]) =>
|
|
21
|
+
let actual = `${id}|${emailId->ContactAddressId.toString}|${proofHash}`
|
|
22
|
+
actual == expected
|
|
23
|
+
? Outcome.pass
|
|
24
|
+
: Outcome.fail(TranslateError({expected, actual: Some(actual)}))
|
|
25
|
+
| _ => Outcome.fail(TranslateError({expected, actual: None}))
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
describe("CompleteRegistration InboundTranslationSlice", () => {
|
|
29
|
+
// scenario-id: 06245209-d526-44a9-8b8e-aac5ab65355b
|
|
30
|
+
test("the proof travels as its hash", () =>
|
|
31
|
+
whenInput({email: "Alice@Example.com", proof: "the-secret", password})->thenSubmits(
|
|
32
|
+
`${aliceId}|${aliceId}|hash:the-secret`,
|
|
33
|
+
)
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
// 🚨 The password is held for the slice that may act on it, under the key that slice will
|
|
37
|
+
// be handed, and for minutes rather than for ever.
|
|
38
|
+
// scenario-id: a79e5f26-5f82-4094-aa7c-0b9d74a1b6cd
|
|
39
|
+
test("the password is stashed under the proof's hash", () =>
|
|
40
|
+
whenInput({email: aliceAddress, proof: "the-secret", password})->thenSent([
|
|
41
|
+
Hashed({input: "the-secret"}),
|
|
42
|
+
Stashed({key: "hash:the-secret", value: password, ttl: passwordTtl}),
|
|
43
|
+
])
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
// Checked here, before the proof is spent, so a pool's policy cannot refuse the account
|
|
47
|
+
// after the challenge has settled.
|
|
48
|
+
// scenario-id: 9634063c-c36d-4cef-83c3-aaa27a86d5dc
|
|
49
|
+
test("a short password is not understood, and nothing is held", () =>
|
|
50
|
+
whenInput({
|
|
51
|
+
email: "alice@example.com",
|
|
52
|
+
proof: "the-secret",
|
|
53
|
+
password: "short",
|
|
54
|
+
})->thenNothingSent
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
// scenario-id: be4234e6-996b-4d3d-a365-dd42635d6d1e
|
|
58
|
+
test("with no stash, the proof is not relayed", () =>
|
|
59
|
+
whenInput(
|
|
60
|
+
{email: "alice@example.com", proof: "the-secret", password},
|
|
61
|
+
~fakes=fakes(~stash=Reventless.Stash.unavailable(~reason="none here"), ()),
|
|
62
|
+
)->thenNotUnderstood("cannot hold the password: none here")
|
|
63
|
+
)
|
|
64
|
+
})
|
|
65
|
+
}
|
package/conformance/Registration/InboundTranslation/CompleteRegistration_Conformance_GWT.res.mjs
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
|
+
|
|
3
|
+
import * as Stash$Reventless from "@reventlessdev/reventless-spec/src/semantic/Stash.res.mjs";
|
|
4
|
+
import * as Outcome$ReventlessGwt from "@reventlessdev/reventless-gwt/src/Outcome.res.mjs";
|
|
5
|
+
import * as InboundTranslation_GWT$ReventlessGwt from "@reventlessdev/reventless-gwt/src/InboundTranslation_GWT.res.mjs";
|
|
6
|
+
import * as ContactAddressId$ReventlessRegistration from "../../../src/Registration/ContactAddressId.res.mjs";
|
|
7
|
+
import * as CompleteRegistration$ReventlessRegistration from "../../../src/Registration/InboundTranslation/CompleteRegistration.res.mjs";
|
|
8
|
+
import * as CompleteRegistration_Translation$ReventlessRegistration from "../../../src/Registration/InboundTranslation/CompleteRegistration_Translation.res.mjs";
|
|
9
|
+
import * as Registration_Conformance_Examples$ReventlessRegistration from "../Registration_Conformance_Examples.res.mjs";
|
|
10
|
+
|
|
11
|
+
function Make(App) {
|
|
12
|
+
let include = InboundTranslation_GWT$ReventlessGwt.FromSlice({
|
|
13
|
+
name: CompleteRegistration$ReventlessRegistration.name,
|
|
14
|
+
moduleUrl: CompleteRegistration$ReventlessRegistration.moduleUrl,
|
|
15
|
+
externalInputSchema: CompleteRegistration$ReventlessRegistration.externalInputSchema,
|
|
16
|
+
commandSchema: CompleteRegistration$ReventlessRegistration.commandSchema,
|
|
17
|
+
targetName: CompleteRegistration$ReventlessRegistration.targetName,
|
|
18
|
+
externalSystem: undefined,
|
|
19
|
+
authorizationOf: CompleteRegistration$ReventlessRegistration.authorizationOf,
|
|
20
|
+
endpoint: undefined,
|
|
21
|
+
capabilityNeeds: CompleteRegistration$ReventlessRegistration.capabilityNeeds
|
|
22
|
+
})({
|
|
23
|
+
translate: CompleteRegistration_Translation$ReventlessRegistration.translate,
|
|
24
|
+
moduleUrl: CompleteRegistration_Translation$ReventlessRegistration.moduleUrl
|
|
25
|
+
});
|
|
26
|
+
let describe = include.describe;
|
|
27
|
+
let test = include.test;
|
|
28
|
+
let fakes = include.fakes;
|
|
29
|
+
let whenInput = include.whenInput;
|
|
30
|
+
let thenNotUnderstood = include.thenNotUnderstood;
|
|
31
|
+
let thenSent = include.thenSent;
|
|
32
|
+
let thenNothingSent = include.thenNothingSent;
|
|
33
|
+
let thenSubmits = async (pending, expected) => {
|
|
34
|
+
let match = (await pending).outcome;
|
|
35
|
+
switch (match.TAG) {
|
|
36
|
+
case "Translated" :
|
|
37
|
+
let match$1 = match._0;
|
|
38
|
+
if (match$1.length === 1) {
|
|
39
|
+
let match$2 = match$1[0];
|
|
40
|
+
let match$3 = match$2[1];
|
|
41
|
+
let actual = match$2[0] + `|` + ContactAddressId$ReventlessRegistration.toString(match$3.emailId) + `|` + match$3.proofHash;
|
|
42
|
+
if (actual === expected) {
|
|
43
|
+
return Outcome$ReventlessGwt.pass;
|
|
44
|
+
} else {
|
|
45
|
+
return Outcome$ReventlessGwt.fail({
|
|
46
|
+
TAG: "TranslateError",
|
|
47
|
+
expected: expected,
|
|
48
|
+
actual: actual
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
break;
|
|
53
|
+
case "NotUnderstood" :
|
|
54
|
+
case "InputRefused" :
|
|
55
|
+
break;
|
|
56
|
+
}
|
|
57
|
+
return Outcome$ReventlessGwt.fail({
|
|
58
|
+
TAG: "TranslateError",
|
|
59
|
+
expected: expected,
|
|
60
|
+
actual: undefined
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
describe("CompleteRegistration InboundTranslationSlice", () => {
|
|
64
|
+
test("the proof travels as its hash", undefined, () => thenSubmits(whenInput({
|
|
65
|
+
email: "Alice@Example.com",
|
|
66
|
+
proof: "the-secret",
|
|
67
|
+
password: Registration_Conformance_Examples$ReventlessRegistration.goodPassword
|
|
68
|
+
}, undefined, undefined), Registration_Conformance_Examples$ReventlessRegistration.aliceId + `|` + Registration_Conformance_Examples$ReventlessRegistration.aliceId + `|hash:the-secret`));
|
|
69
|
+
test("the password is stashed under the proof's hash", undefined, () => thenSent(whenInput({
|
|
70
|
+
email: Registration_Conformance_Examples$ReventlessRegistration.aliceAddress,
|
|
71
|
+
proof: "the-secret",
|
|
72
|
+
password: Registration_Conformance_Examples$ReventlessRegistration.goodPassword
|
|
73
|
+
}, undefined, undefined), [
|
|
74
|
+
{
|
|
75
|
+
TAG: "Hashed",
|
|
76
|
+
input: "the-secret"
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
TAG: "Stashed",
|
|
80
|
+
key: "hash:the-secret",
|
|
81
|
+
value: Registration_Conformance_Examples$ReventlessRegistration.goodPassword,
|
|
82
|
+
ttl: CompleteRegistration_Translation$ReventlessRegistration.passwordTtl
|
|
83
|
+
}
|
|
84
|
+
]));
|
|
85
|
+
test("a short password is not understood, and nothing is held", undefined, () => thenNothingSent(whenInput({
|
|
86
|
+
email: "alice@example.com",
|
|
87
|
+
proof: "the-secret",
|
|
88
|
+
password: "short"
|
|
89
|
+
}, undefined, undefined)));
|
|
90
|
+
test("with no stash, the proof is not relayed", undefined, () => thenNotUnderstood(whenInput({
|
|
91
|
+
email: "alice@example.com",
|
|
92
|
+
proof: "the-secret",
|
|
93
|
+
password: Registration_Conformance_Examples$ReventlessRegistration.goodPassword
|
|
94
|
+
}, fakes(undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, Stash$Reventless.unavailable("none here"), undefined, undefined, undefined, undefined, undefined), undefined), "cannot hold the password: none here"));
|
|
95
|
+
});
|
|
96
|
+
return {
|
|
97
|
+
describe: describe,
|
|
98
|
+
test: test,
|
|
99
|
+
fakes: fakes,
|
|
100
|
+
encPairs: include.encPairs,
|
|
101
|
+
errorOf: include.errorOf,
|
|
102
|
+
whenInput: whenInput,
|
|
103
|
+
whenReceived: include.whenReceived,
|
|
104
|
+
describeOther: include.describeOther,
|
|
105
|
+
roundTrips: include.roundTrips,
|
|
106
|
+
thenCommands: include.thenCommands,
|
|
107
|
+
thenCommand: include.thenCommand,
|
|
108
|
+
thenNoCommand: include.thenNoCommand,
|
|
109
|
+
thenNotUnderstood: thenNotUnderstood,
|
|
110
|
+
thenTranslateError: include.thenTranslateError,
|
|
111
|
+
thenRefusedInput: include.thenRefusedInput,
|
|
112
|
+
thenSent: thenSent,
|
|
113
|
+
thenNothingSent: thenNothingSent,
|
|
114
|
+
Outcome: undefined,
|
|
115
|
+
password: Registration_Conformance_Examples$ReventlessRegistration.goodPassword,
|
|
116
|
+
thenSubmits: thenSubmits
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export {
|
|
121
|
+
Make,
|
|
122
|
+
}
|
|
123
|
+
/* InboundTranslation_GWT-ReventlessGwt Not a pure module */
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
// The door a registration starts at, for any admission table. The time on the command is the
|
|
2
|
+
// moment the request arrived, read here at the edge, so it is not compared whole.
|
|
3
|
+
|
|
4
|
+
module Make = (App: Reventless.Admission.Declaration) => {
|
|
5
|
+
module AppSignUp = SignUp_Translation.Make(App)
|
|
6
|
+
open SignUp
|
|
7
|
+
include ReventlessGwt.InboundTranslation_GWT.FromSlice(SignUp, AppSignUp)
|
|
8
|
+
open Registration_Conformance_Examples
|
|
9
|
+
|
|
10
|
+
module Outcome = ReventlessGwt.Outcome
|
|
11
|
+
|
|
12
|
+
let needing = needs =>
|
|
13
|
+
(name, body) =>
|
|
14
|
+
switch unmet(needs) {
|
|
15
|
+
| None => test(name, body)
|
|
16
|
+
| Some(why) => ReventlessGwt.JestBind.todo(`${name} (${why})`)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
let selfServiceRoles = selfService(App.table)
|
|
20
|
+
let roleName = selfServiceRoles->first->nameOf
|
|
21
|
+
|
|
22
|
+
let thenRegisters = async (pending, expected) =>
|
|
23
|
+
switch (await pending).outcome {
|
|
24
|
+
| Translated([(id, Register({emailId, role, _}))]) =>
|
|
25
|
+
let actual = `${id}|${emailId->ContactAddressId.toString}|${(role :> string)}`
|
|
26
|
+
actual == expected
|
|
27
|
+
? Outcome.pass
|
|
28
|
+
: Outcome.fail(TranslateError({expected, actual: Some(actual)}))
|
|
29
|
+
| _ => Outcome.fail(TranslateError({expected, actual: None}))
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// The visitor has no account to say what they read, so the request says it, and the ledger
|
|
33
|
+
// carries it to the mail. A value that is no language tag picks no words.
|
|
34
|
+
let thenLanguage = async (pending, expected) =>
|
|
35
|
+
switch (await pending).outcome {
|
|
36
|
+
| Translated([(_, Register({?language}))]) if language == expected => Outcome.pass
|
|
37
|
+
| Translated([(_, Register({?language}))]) =>
|
|
38
|
+
Outcome.fail(
|
|
39
|
+
TranslateError({
|
|
40
|
+
expected: expected->Option.getOr("(none)"),
|
|
41
|
+
actual: Some(language->Option.getOr("(none)")),
|
|
42
|
+
}),
|
|
43
|
+
)
|
|
44
|
+
| _ => Outcome.fail(TranslateError({expected: "a Register", actual: None}))
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// The deployment checks that a person sent the request before anything is relayed. This
|
|
48
|
+
// check knows one good token.
|
|
49
|
+
let checking = fakes(
|
|
50
|
+
~personCheck={
|
|
51
|
+
verify: async (~token) => token == "person" ? Ok() : Error(Rejected("Turnstile said no")),
|
|
52
|
+
},
|
|
53
|
+
(),
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
describe("SignUp InboundTranslationSlice", () => {
|
|
57
|
+
// One address, however it was typed: the claim is on the address, so two spellings of it
|
|
58
|
+
// must not be two claims.
|
|
59
|
+
// scenario-id: 469fba42-1c66-4548-8014-a5258953e14b
|
|
60
|
+
test("an address registers for the role it names, as one spelling", () =>
|
|
61
|
+
whenInput({email: " Alice@Example.com ", role: roleName})->thenRegisters(
|
|
62
|
+
`${aliceId}|${aliceId}|${roleName}`,
|
|
63
|
+
)
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
// The door relays whatever role it is asked for; the ledger is what answers a role no
|
|
67
|
+
// visitor may have, and it answers it as it answers a closed one.
|
|
68
|
+
// scenario-id: 9e1b7d3f-6a2c-4e8b-b0d4-3c5a7e9f1b2d
|
|
69
|
+
test("a role no visitor may have is relayed, not refused at the door", () => {
|
|
70
|
+
let stranger = App.table->unknownRole->nameOf
|
|
71
|
+
whenInput({email: aliceAddress, role: stranger})->thenRegisters(
|
|
72
|
+
`${aliceId}|${aliceId}|${stranger}`,
|
|
73
|
+
)
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
test("the language the visitor reads in travels with the registration", () =>
|
|
77
|
+
whenInput({email: aliceAddress, role: roleName, language: " de-AT "})->thenLanguage(
|
|
78
|
+
Some("de-AT"),
|
|
79
|
+
)
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
test("a language that is not a tag is dropped, and the registration goes on", () =>
|
|
83
|
+
whenInput({email: aliceAddress, role: roleName, language: "<script>"})->thenLanguage(None)
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
// scenario-id: 2547a470-7044-45b6-b7a0-530595f08567
|
|
87
|
+
test("something that is not an address is not understood", () =>
|
|
88
|
+
whenInput({email: "alice", role: roleName})->thenNotUnderstood("not an email address")
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
// scenario-id: 608df706-9341-480c-9b8f-d86d0520a868
|
|
92
|
+
test("starting a registration reaches no capability", () =>
|
|
93
|
+
whenInput({email: aliceAddress, role: roleName})->thenNothingSent
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
test("a sign-up without the check's token relays nothing", () =>
|
|
97
|
+
whenInput({email: aliceAddress, role: roleName}, ~fakes=checking)->thenNotUnderstood(
|
|
98
|
+
SignUp_Translation.personCheckRejected,
|
|
99
|
+
)
|
|
100
|
+
)
|
|
101
|
+
|
|
102
|
+
test("a sign-up whose token does not pass relays nothing", () =>
|
|
103
|
+
whenInput(
|
|
104
|
+
{email: aliceAddress, role: roleName, personCheck: "script"},
|
|
105
|
+
~fakes=checking,
|
|
106
|
+
)->thenNotUnderstood(SignUp_Translation.personCheckRejected)
|
|
107
|
+
)
|
|
108
|
+
|
|
109
|
+
test("a sign-up whose token passes registers", () =>
|
|
110
|
+
whenInput(
|
|
111
|
+
{email: aliceAddress, role: roleName, personCheck: "person"},
|
|
112
|
+
~fakes=checking,
|
|
113
|
+
)->thenRegisters(`${aliceId}|${aliceId}|${roleName}`)
|
|
114
|
+
)
|
|
115
|
+
|
|
116
|
+
// Refused rather than let through, and said so: a check that is down must not open the door
|
|
117
|
+
// to scripts, nor tell a person to wait for mail that never comes.
|
|
118
|
+
test("a check that cannot be asked relays nothing", () =>
|
|
119
|
+
whenInput(
|
|
120
|
+
{email: aliceAddress, role: roleName, personCheck: "person"},
|
|
121
|
+
~fakes=fakes(
|
|
122
|
+
~personCheck=Reventless.PersonCheck.unavailable(~reason="Turnstile cannot be reached"),
|
|
123
|
+
(),
|
|
124
|
+
),
|
|
125
|
+
)->thenNotUnderstood(SignUp_Translation.personCheckUnavailable)
|
|
126
|
+
)
|
|
127
|
+
|
|
128
|
+
let test = needing([hasOne(selfServiceRoles, ~kind="self-service")])
|
|
129
|
+
|
|
130
|
+
// A table with one self-service role lets a sign-up leave it out.
|
|
131
|
+
// scenario-id: 5a9c3e7b-2d4f-4b6a-8c1e-7f0d2a4b6c8e
|
|
132
|
+
test("a sign-up naming no role asks for the one self-service role", () =>
|
|
133
|
+
whenInput({email: aliceAddress})->thenRegisters(`${aliceId}|${aliceId}|${roleName}`)
|
|
134
|
+
)
|
|
135
|
+
})
|
|
136
|
+
}
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
|
+
|
|
3
|
+
import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
|
|
4
|
+
import * as Primitive_object from "@rescript/runtime/lib/es6/Primitive_object.js";
|
|
5
|
+
import * as Outcome$ReventlessGwt from "@reventlessdev/reventless-gwt/src/Outcome.res.mjs";
|
|
6
|
+
import * as JestBind$ReventlessGwt from "@reventlessdev/reventless-gwt/src/JestBind.res.mjs";
|
|
7
|
+
import * as PersonCheck$Reventless from "@reventlessdev/reventless-spec/src/semantic/PersonCheck.res.mjs";
|
|
8
|
+
import * as SignUp$ReventlessRegistration from "../../../src/Registration/InboundTranslation/SignUp.res.mjs";
|
|
9
|
+
import * as InboundTranslation_GWT$ReventlessGwt from "@reventlessdev/reventless-gwt/src/InboundTranslation_GWT.res.mjs";
|
|
10
|
+
import * as ContactAddressId$ReventlessRegistration from "../../../src/Registration/ContactAddressId.res.mjs";
|
|
11
|
+
import * as SignUp_Translation$ReventlessRegistration from "../../../src/Registration/InboundTranslation/SignUp_Translation.res.mjs";
|
|
12
|
+
import * as Registration_Conformance_Examples$ReventlessRegistration from "../Registration_Conformance_Examples.res.mjs";
|
|
13
|
+
|
|
14
|
+
function Make(App) {
|
|
15
|
+
let AppSignUp = SignUp_Translation$ReventlessRegistration.Make(App);
|
|
16
|
+
let include = InboundTranslation_GWT$ReventlessGwt.FromSlice({
|
|
17
|
+
name: SignUp$ReventlessRegistration.name,
|
|
18
|
+
moduleUrl: SignUp$ReventlessRegistration.moduleUrl,
|
|
19
|
+
externalInputSchema: SignUp$ReventlessRegistration.externalInputSchema,
|
|
20
|
+
commandSchema: SignUp$ReventlessRegistration.commandSchema,
|
|
21
|
+
targetName: SignUp$ReventlessRegistration.targetName,
|
|
22
|
+
externalSystem: undefined,
|
|
23
|
+
authorizationOf: SignUp$ReventlessRegistration.authorizationOf,
|
|
24
|
+
endpoint: undefined,
|
|
25
|
+
capabilityNeeds: SignUp$ReventlessRegistration.capabilityNeeds
|
|
26
|
+
})({
|
|
27
|
+
translate: AppSignUp.translate,
|
|
28
|
+
moduleUrl: AppSignUp.moduleUrl
|
|
29
|
+
});
|
|
30
|
+
let describe = include.describe;
|
|
31
|
+
let test = include.test;
|
|
32
|
+
let fakes = include.fakes;
|
|
33
|
+
let whenInput = include.whenInput;
|
|
34
|
+
let thenNotUnderstood = include.thenNotUnderstood;
|
|
35
|
+
let thenNothingSent = include.thenNothingSent;
|
|
36
|
+
let needing = needs => ((name, body) => {
|
|
37
|
+
let why = Registration_Conformance_Examples$ReventlessRegistration.unmet(needs);
|
|
38
|
+
if (why !== undefined) {
|
|
39
|
+
return JestBind$ReventlessGwt.todo(name + ` (` + why + `)`);
|
|
40
|
+
} else {
|
|
41
|
+
return test(name, undefined, body);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
let selfServiceRoles = Registration_Conformance_Examples$ReventlessRegistration.selfService(App.table);
|
|
45
|
+
let roleName = Registration_Conformance_Examples$ReventlessRegistration.nameOf(Registration_Conformance_Examples$ReventlessRegistration.first(selfServiceRoles));
|
|
46
|
+
let thenRegisters = async (pending, expected) => {
|
|
47
|
+
let match = (await pending).outcome;
|
|
48
|
+
switch (match.TAG) {
|
|
49
|
+
case "Translated" :
|
|
50
|
+
let match$1 = match._0;
|
|
51
|
+
if (match$1.length === 1) {
|
|
52
|
+
let match$2 = match$1[0];
|
|
53
|
+
let match$3 = match$2[1];
|
|
54
|
+
let actual = match$2[0] + `|` + ContactAddressId$ReventlessRegistration.toString(match$3.emailId) + `|` + match$3.role;
|
|
55
|
+
if (actual === expected) {
|
|
56
|
+
return Outcome$ReventlessGwt.pass;
|
|
57
|
+
} else {
|
|
58
|
+
return Outcome$ReventlessGwt.fail({
|
|
59
|
+
TAG: "TranslateError",
|
|
60
|
+
expected: expected,
|
|
61
|
+
actual: actual
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
break;
|
|
66
|
+
case "NotUnderstood" :
|
|
67
|
+
case "InputRefused" :
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
return Outcome$ReventlessGwt.fail({
|
|
71
|
+
TAG: "TranslateError",
|
|
72
|
+
expected: expected,
|
|
73
|
+
actual: undefined
|
|
74
|
+
});
|
|
75
|
+
};
|
|
76
|
+
let thenLanguage = async (pending, expected) => {
|
|
77
|
+
let match = (await pending).outcome;
|
|
78
|
+
switch (match.TAG) {
|
|
79
|
+
case "Translated" :
|
|
80
|
+
let match$1 = match._0;
|
|
81
|
+
if (match$1.length !== 1) {
|
|
82
|
+
return Outcome$ReventlessGwt.fail({
|
|
83
|
+
TAG: "TranslateError",
|
|
84
|
+
expected: "a Register",
|
|
85
|
+
actual: undefined
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
let match$2 = match$1[0];
|
|
89
|
+
let language = match$2[1].language;
|
|
90
|
+
if (Primitive_object.equal(language, expected)) {
|
|
91
|
+
return Outcome$ReventlessGwt.pass;
|
|
92
|
+
} else {
|
|
93
|
+
return Outcome$ReventlessGwt.fail({
|
|
94
|
+
TAG: "TranslateError",
|
|
95
|
+
expected: Stdlib_Option.getOr(expected, "(none)"),
|
|
96
|
+
actual: Stdlib_Option.getOr(language, "(none)")
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
case "NotUnderstood" :
|
|
100
|
+
case "InputRefused" :
|
|
101
|
+
return Outcome$ReventlessGwt.fail({
|
|
102
|
+
TAG: "TranslateError",
|
|
103
|
+
expected: "a Register",
|
|
104
|
+
actual: undefined
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
let checking = fakes(undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, {
|
|
109
|
+
verify: async token => {
|
|
110
|
+
if (token === "person") {
|
|
111
|
+
return {
|
|
112
|
+
TAG: "Ok",
|
|
113
|
+
_0: undefined
|
|
114
|
+
};
|
|
115
|
+
} else {
|
|
116
|
+
return {
|
|
117
|
+
TAG: "Error",
|
|
118
|
+
_0: {
|
|
119
|
+
TAG: "Rejected",
|
|
120
|
+
_0: "Turnstile said no"
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}, undefined, undefined);
|
|
126
|
+
describe("SignUp InboundTranslationSlice", () => {
|
|
127
|
+
test("an address registers for the role it names, as one spelling", undefined, () => thenRegisters(whenInput({
|
|
128
|
+
email: " Alice@Example.com ",
|
|
129
|
+
role: roleName
|
|
130
|
+
}, undefined, undefined), Registration_Conformance_Examples$ReventlessRegistration.aliceId + `|` + Registration_Conformance_Examples$ReventlessRegistration.aliceId + `|` + roleName));
|
|
131
|
+
test("a role no visitor may have is relayed, not refused at the door", undefined, () => {
|
|
132
|
+
let stranger = Registration_Conformance_Examples$ReventlessRegistration.nameOf(Registration_Conformance_Examples$ReventlessRegistration.unknownRole(App.table));
|
|
133
|
+
return thenRegisters(whenInput({
|
|
134
|
+
email: Registration_Conformance_Examples$ReventlessRegistration.aliceAddress,
|
|
135
|
+
role: stranger
|
|
136
|
+
}, undefined, undefined), Registration_Conformance_Examples$ReventlessRegistration.aliceId + `|` + Registration_Conformance_Examples$ReventlessRegistration.aliceId + `|` + stranger);
|
|
137
|
+
});
|
|
138
|
+
test("the language the visitor reads in travels with the registration", undefined, () => thenLanguage(whenInput({
|
|
139
|
+
email: Registration_Conformance_Examples$ReventlessRegistration.aliceAddress,
|
|
140
|
+
role: roleName,
|
|
141
|
+
language: " de-AT "
|
|
142
|
+
}, undefined, undefined), "de-AT"));
|
|
143
|
+
test("a language that is not a tag is dropped, and the registration goes on", undefined, () => thenLanguage(whenInput({
|
|
144
|
+
email: Registration_Conformance_Examples$ReventlessRegistration.aliceAddress,
|
|
145
|
+
role: roleName,
|
|
146
|
+
language: "<script>"
|
|
147
|
+
}, undefined, undefined), undefined));
|
|
148
|
+
test("something that is not an address is not understood", undefined, () => thenNotUnderstood(whenInput({
|
|
149
|
+
email: "alice",
|
|
150
|
+
role: roleName
|
|
151
|
+
}, undefined, undefined), "not an email address"));
|
|
152
|
+
test("starting a registration reaches no capability", undefined, () => thenNothingSent(whenInput({
|
|
153
|
+
email: Registration_Conformance_Examples$ReventlessRegistration.aliceAddress,
|
|
154
|
+
role: roleName
|
|
155
|
+
}, undefined, undefined)));
|
|
156
|
+
test("a sign-up without the check's token relays nothing", undefined, () => thenNotUnderstood(whenInput({
|
|
157
|
+
email: Registration_Conformance_Examples$ReventlessRegistration.aliceAddress,
|
|
158
|
+
role: roleName
|
|
159
|
+
}, checking, undefined), SignUp_Translation$ReventlessRegistration.personCheckRejected));
|
|
160
|
+
test("a sign-up whose token does not pass relays nothing", undefined, () => thenNotUnderstood(whenInput({
|
|
161
|
+
email: Registration_Conformance_Examples$ReventlessRegistration.aliceAddress,
|
|
162
|
+
role: roleName,
|
|
163
|
+
personCheck: "script"
|
|
164
|
+
}, checking, undefined), SignUp_Translation$ReventlessRegistration.personCheckRejected));
|
|
165
|
+
test("a sign-up whose token passes registers", undefined, () => thenRegisters(whenInput({
|
|
166
|
+
email: Registration_Conformance_Examples$ReventlessRegistration.aliceAddress,
|
|
167
|
+
role: roleName,
|
|
168
|
+
personCheck: "person"
|
|
169
|
+
}, checking, undefined), Registration_Conformance_Examples$ReventlessRegistration.aliceId + `|` + Registration_Conformance_Examples$ReventlessRegistration.aliceId + `|` + roleName));
|
|
170
|
+
test("a check that cannot be asked relays nothing", undefined, () => thenNotUnderstood(whenInput({
|
|
171
|
+
email: Registration_Conformance_Examples$ReventlessRegistration.aliceAddress,
|
|
172
|
+
role: roleName,
|
|
173
|
+
personCheck: "person"
|
|
174
|
+
}, fakes(undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, PersonCheck$Reventless.unavailable("Turnstile cannot be reached"), undefined, undefined), undefined), SignUp_Translation$ReventlessRegistration.personCheckUnavailable));
|
|
175
|
+
let test$1 = needing([Registration_Conformance_Examples$ReventlessRegistration.hasOne(selfServiceRoles, "self-service")]);
|
|
176
|
+
test$1("a sign-up naming no role asks for the one self-service role", () => thenRegisters(whenInput({
|
|
177
|
+
email: Registration_Conformance_Examples$ReventlessRegistration.aliceAddress
|
|
178
|
+
}, undefined, undefined), Registration_Conformance_Examples$ReventlessRegistration.aliceId + `|` + Registration_Conformance_Examples$ReventlessRegistration.aliceId + `|` + roleName));
|
|
179
|
+
});
|
|
180
|
+
return {
|
|
181
|
+
AppSignUp: AppSignUp,
|
|
182
|
+
describe: describe,
|
|
183
|
+
test: test,
|
|
184
|
+
fakes: fakes,
|
|
185
|
+
encPairs: include.encPairs,
|
|
186
|
+
errorOf: include.errorOf,
|
|
187
|
+
whenInput: whenInput,
|
|
188
|
+
whenReceived: include.whenReceived,
|
|
189
|
+
describeOther: include.describeOther,
|
|
190
|
+
roundTrips: include.roundTrips,
|
|
191
|
+
thenCommands: include.thenCommands,
|
|
192
|
+
thenCommand: include.thenCommand,
|
|
193
|
+
thenNoCommand: include.thenNoCommand,
|
|
194
|
+
thenNotUnderstood: thenNotUnderstood,
|
|
195
|
+
thenTranslateError: include.thenTranslateError,
|
|
196
|
+
thenRefusedInput: include.thenRefusedInput,
|
|
197
|
+
thenSent: include.thenSent,
|
|
198
|
+
thenNothingSent: thenNothingSent,
|
|
199
|
+
Outcome: undefined,
|
|
200
|
+
needing: needing,
|
|
201
|
+
selfServiceRoles: selfServiceRoles,
|
|
202
|
+
roleName: roleName,
|
|
203
|
+
thenRegisters: thenRegisters,
|
|
204
|
+
thenLanguage: thenLanguage,
|
|
205
|
+
checking: checking
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
export {
|
|
210
|
+
Make,
|
|
211
|
+
}
|
|
212
|
+
/* SignUp-ReventlessRegistration Not a pure module */
|