-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPaymentMethodsSpec.scala
70 lines (57 loc) · 1.9 KB
/
PaymentMethodsSpec.scala
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
package io.flow.reference
import io.flow.reference.v0.models.PaymentMethodType
import org.scalatest.funspec.AnyFunSpec
import org.scalatest.matchers.should.Matchers
class PaymentMethodsSpec extends AnyFunSpec with Matchers {
it("be unique") {
data.PaymentMethods.all.groupBy(_.name).filter { _._2.size > 1 }.keys should be(Set())
data.PaymentMethods.all.groupBy(_.id).filter { _._2.size > 1 }.keys should be(Set())
}
it("have no blanks") {
data.PaymentMethods.all.find(_.name.trim.isEmpty) should be(None)
data.PaymentMethods.all.find(_.id.trim.isEmpty) should be(None)
}
it("codes in use are defined") {
val all = Seq(
"visa",
"mastercard",
"american_express",
"paypal",
)
all.filter { id =>
PaymentMethods.find(id).isEmpty
} should be(Nil)
}
it("have common PaymentMethods are defined") {
val visa = data.PaymentMethods.all.find(_.id == "visa").getOrElse {
sys.error("visa missing")
}
visa.id should be("visa")
visa.name should be("VISA")
visa.`type` should be(PaymentMethodType.Card)
val paypal = data.PaymentMethods.all.find(_.id == "paypal").getOrElse {
sys.error("paypal missing")
}
paypal.id should be("paypal")
paypal.name should be("PayPal")
paypal.`type` should be(PaymentMethodType.Online)
}
it("find") {
Seq("visa", "VISA", " visa ").foreach { name =>
PaymentMethods.find(name).getOrElse {
sys.error(s"$name missing")
}
}
PaymentMethods.find("other") should be(None)
}
it("mustFind") {
Seq("visa", "VISA", " visa ").foreach { name =>
PaymentMethods.mustFind(name).id should be("visa")
}
intercept[Throwable] {
PaymentMethods.mustFind("other")
}.getMessage should be(
"The following payment method is invalid: [other]. See https://api.flow.io/reference/payment-methods for a list of all valid payment methods.",
)
}
}