summaryrefslogtreecommitdiff
path: root/packages/anastasis-core/src/policy-suggestion.test.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/anastasis-core/src/policy-suggestion.test.ts')
-rw-r--r--packages/anastasis-core/src/policy-suggestion.test.ts44
1 files changed, 44 insertions, 0 deletions
diff --git a/packages/anastasis-core/src/policy-suggestion.test.ts b/packages/anastasis-core/src/policy-suggestion.test.ts
new file mode 100644
index 000000000..fd42b708f
--- /dev/null
+++ b/packages/anastasis-core/src/policy-suggestion.test.ts
@@ -0,0 +1,44 @@
+import { AmountString, j2s } from "@gnu-taler/taler-util";
+import test from "ava";
+import { ProviderInfo, suggestPolicies } from "./policy-suggestion.js";
+
+test("policy suggestion", async (t) => {
+ const methods = [
+ {
+ challenge: "XXX",
+ instructions: "SMS to 123",
+ type: "sms",
+ },
+ {
+ challenge: "XXX",
+ instructions: "What is the meaning of life?",
+ type: "question",
+ },
+ {
+ challenge: "XXX",
+ instructions: "email to foo@bar.com",
+ type: "email",
+ },
+ ];
+ const providers: ProviderInfo[] = [
+ {
+ methodCost: {
+ sms: "KUDOS:1" as AmountString,
+ },
+ url: "prov1",
+ },
+ {
+ methodCost: {
+ question: "KUDOS:1" as AmountString,
+ },
+ url: "prov2",
+ },
+ ];
+ const res1 = suggestPolicies(methods, providers);
+ t.assert(res1.policies.length === 1);
+ const res2 = suggestPolicies([...methods].reverse(), providers);
+ t.assert(res2.policies.length === 1);
+
+ const res3 = suggestPolicies(methods, [...providers].reverse());
+ t.assert(res3.policies.length === 1);
+});