summaryrefslogtreecommitdiff
path: root/packages/anastasis-core/src/policy-suggestion.test.ts
blob: fd42b708fd4de993c5591f787e77aadfc9f7e6bb (plain)
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
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);
});