diff options
author | Florian Dold <florian@dold.me> | 2021-11-08 15:51:39 +0100 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2021-11-08 15:52:21 +0100 |
commit | 8da58bd4943cc0dc407acd62a168412301b07717 (patch) | |
tree | 5d3953d03ae26782f8fa79f8c5c5042618a4d28f /packages/anastasis-core/src/policy-suggestion.test.ts | |
parent | 6d7fffc24233ad1005dde89247d387a7090626f6 (diff) | |
download | wallet-core-8da58bd4943cc0dc407acd62a168412301b07717.tar.xz |
anastasis-core: fix policy suggestion and add test case
Diffstat (limited to 'packages/anastasis-core/src/policy-suggestion.test.ts')
-rw-r--r-- | packages/anastasis-core/src/policy-suggestion.test.ts | 44 |
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..6370825da --- /dev/null +++ b/packages/anastasis-core/src/policy-suggestion.test.ts @@ -0,0 +1,44 @@ +import { 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", + }, + url: "prov1", + }, + { + methodCost: { + question: "KUDOS:1", + }, + 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); +}); |