-
Notifications
You must be signed in to change notification settings - Fork 629
/
LpmRepositoryTest.kt
158 lines (144 loc) · 4.83 KB
/
LpmRepositoryTest.kt
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
package com.stripe.android.ui.core.forms.resources
import android.app.Application
import androidx.test.core.app.ApplicationProvider
import com.google.common.truth.Truth.assertThat
import com.stripe.android.payments.financialconnections.IsFinancialConnectionsAvailable
import com.stripe.android.paymentsheet.forms.Delayed
import com.stripe.android.ui.core.elements.EmptyFormSpec
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
@RunWith(RobolectricTestRunner::class)
class LpmRepositoryTest {
private val lpmRepository = LpmRepository(
ApplicationProvider.getApplicationContext<Application>().resources,
object : IsFinancialConnectionsAvailable {
override fun invoke(): Boolean {
return true
}
}
)
@Test
fun `Verify no fields in the default json are ignored`() {
// If this test fails, check to make sure the spec's serializer is added to
// FormItemSpecSerializer
LpmRepository.exposedPaymentMethods.forEach { code ->
if (!hasEmptyForm(code)) {
assertThat(
lpmRepository.fromCode(code)!!.formSpec.items
.filter {
it is EmptyFormSpec && !hasEmptyForm(code)
}
).isEmpty()
}
}
}
private fun hasEmptyForm(code: String) =
(code == "paypal" || code == "us_bank_account") &&
lpmRepository.fromCode(code)!!.formSpec.items.size == 1 &&
lpmRepository.fromCode(code)!!.formSpec.items.first() == EmptyFormSpec
@Test
fun `Verify the repository only shows card if in lpms json`() {
assertThat(lpmRepository.fromCode("card")).isNotNull()
lpmRepository.initialize(
"""
[
{
"type": "affirm",
"async": false,
"fields": [
{
"type": "affirm_header"
}
]
}
]
""".trimIndent().byteInputStream()
)
assertThat(lpmRepository.fromCode("card")).isNull()
}
// TODO(michelleb): Once we have the server implemented in production we can do filtering there instead
// of in code here.
@Test
fun `Verify that unknown LPMs are not shown because not listed as exposed`() {
lpmRepository.initialize(
"""
[
{
"type": "affirm",
"async": false,
"fields": [
{
"type": "affirm_header"
}
]
},
{
"type": "unknown_lpm",
"async": false,
"fields": [
{
"type": "affirm_header"
}
]
}
]
""".trimIndent().byteInputStream()
)
assertThat(lpmRepository.fromCode("unknown_lpm")).isNull()
}
@Test
fun `Verify that payment methods hardcoded to delayed remain regardless of json`() {
assertThat(
lpmRepository.fromCode("sofort")?.requirement?.piRequirements
).contains(Delayed)
lpmRepository.initialize(
"""
[
{
"type": "sofort",
"async": false,
"fields": []
}
]
""".trimIndent().byteInputStream()
)
assertThat(
lpmRepository.fromCode("sofort")?.requirement?.piRequirements
).contains(Delayed)
}
@Test
fun `Verify that us_bank_account is supported when financial connections sdk available`() {
lpmRepository.initialize(
"""
[
{
"type": "us_bank_account"
}
]
""".trimIndent().byteInputStream()
)
assertThat(lpmRepository.fromCode("us_bank_account")).isNotNull()
}
@Test
fun `Verify that us_bank_account not supported when financial connections sdk not available`() {
val lpmRepository = LpmRepository(
ApplicationProvider.getApplicationContext<Application>().resources,
object : IsFinancialConnectionsAvailable {
override fun invoke(): Boolean {
return false
}
}
)
lpmRepository.initialize(
"""
[
{
"type": "us_bank_account"
}
]
""".trimIndent().byteInputStream()
)
assertThat(lpmRepository.fromCode("us_bank_account")).isNull()
}
}