-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathProvincesSpec.scala
74 lines (56 loc) · 2.14 KB
/
ProvincesSpec.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
71
72
73
74
package io.flow.reference
import io.flow.reference.data.Countries.{Can, Usa}
import org.scalatest.funspec.AnyFunSpec
import org.scalatest.matchers.should.Matchers
import scala.collection.immutable.Nil
class ProvincesSpec extends AnyFunSpec with Matchers {
it("be unique") {
data.Provinces.all.groupBy(_.id).filter { _._2.size > 1 }.keys should be(Set())
}
it("be sorted") {
data.Provinces.all.map(_.id) should be(data.Provinces.all.map(_.id).sortBy { _.toLowerCase })
}
it("id must be join of iso31662 and country") {
data.Provinces.all.map(_.id) should be(data.Provinces.all.map(p => s"${p.country}-${p.iso31662}"))
}
it("have no blanks") {
data.Provinces.all.find(_.id.trim.isEmpty) should be(None)
}
it("find") {
Seq("USA-NY", "usa-ny", "AUS-NSW", "aus-nsw").foreach { id =>
Provinces.find(id).getOrElse {
sys.error(s"$id missing")
}
}
Provinces.find("other") should be(None)
}
it("mustFind") {
Seq("USA-NY", "usa-ny", "UsA-nY").foreach { id =>
Provinces.mustFind(id).id should be("USA-NY")
}
intercept[Throwable] {
Provinces.mustFind("other")
}.getMessage should be(
"The following province is invalid: [other]. See https://api.flow.io/reference/provinces for a list of all valid provinces.",
)
}
it("query") {
Seq("New York", "NY").foreach { q =>
Provinces.query(Some(q), None) should be(Seq(data.Provinces.UsaNy))
}
Seq("New York", "NY").foreach { q =>
Provinces.query(Some(q), Some(Seq("AUS"))) should be(Nil)
}
Seq("New York", "NY").foreach { q =>
Provinces.query(Some(q), Some(Seq("USA"))) should be(Seq(data.Provinces.UsaNy))
}
Provinces.query(None, Some(Seq("USA"))) should contain(data.Provinces.UsaNy)
Provinces.query(None, Some(Seq("foobar"))) should be(Nil)
}
it("findInCountry") {
Provinces.findInCountry(Usa, "New York").get.id shouldBe data.Provinces.UsaNy.id
Provinces.findInCountry(Usa, "NY").get.id shouldBe data.Provinces.UsaNy.id
Provinces.findInCountry(Usa, "quebec") shouldBe None
Provinces.findInCountry(Can, "quebec").get.id shouldBe data.Provinces.CanQc.id
}
}