You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: onboarding/src/main/kotlin/io/homeassistant/companion/android/onboarding/connection/ConnectionViewModel.kt
+6-2Lines changed: 6 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -134,8 +134,12 @@ internal class ConnectionViewModel @VisibleForTesting constructor(
Copy file name to clipboardExpand all lines: onboarding/src/test/kotlin/io/homeassistant/companion/android/onboarding/connection/ConnectionViewModelTest.kt
+25-29Lines changed: 25 additions & 29 deletions
Original file line number
Diff line number
Diff line change
@@ -51,6 +51,8 @@ class ConnectionViewModelTest {
51
51
funsetup() {
52
52
Timber.plant(ConsoleLogTree)
53
53
ConsoleLogTree.verbose =true
54
+
55
+
mockkStatic(Uri::class)
54
56
}
55
57
56
58
@ParameterizedTest
@@ -127,11 +129,7 @@ class ConnectionViewModelTest {
127
129
@ValueSource(booleans = [true, false])
128
130
fun`Given auth callback uri with code when shouldRedirect then emits Authenticated event with mTLS status and returns true`(requireMTLS:Boolean) = runTest {
129
131
val authCode ="test_auth_code"
130
-
val callbackUri = mockk<Uri> {
131
-
every { scheme } returns "homeassistant"
132
-
every { host } returns "auth-callback"
133
-
every { getQueryParameter("code") } returns authCode
134
-
}
132
+
val stringUri = mockAuthCodeUri(scheme ="homeassistant", host ="auth-callback", authCode = authCode)
135
133
136
134
val viewModel =ConnectionViewModel("http://homeassistant.local:8123", keyChainRepository)
137
135
@@ -145,9 +143,7 @@ class ConnectionViewModelTest {
145
143
146
144
val result = viewModel.webViewClient.shouldOverrideUrlLoading(
147
145
null,
148
-
mockk<WebResourceRequest> {
149
-
every { url } returns callbackUri
150
-
},
146
+
stringUri,
151
147
)
152
148
153
149
assertTrue(result)
@@ -162,13 +158,7 @@ class ConnectionViewModelTest {
162
158
163
159
@Test
164
160
fun`Given auth callback uri without code when shouldRedirect then no event and returns false`() = runTest {
165
-
val callbackUri = mockk<Uri> {
166
-
every { scheme } returns "homeassistant"
167
-
every { host } returns "auth-callback"
168
-
every { getQueryParameter("code") } returns null
169
-
}
170
-
171
-
mockUriParse()
161
+
val stringUri = mockAuthCodeUri(scheme ="homeassistant", host ="auth-callback", authCode =null)
172
162
173
163
val viewModel =ConnectionViewModel("http://homeassistant.local:8123", keyChainRepository)
174
164
@@ -180,9 +170,7 @@ class ConnectionViewModelTest {
180
170
181
171
val result = viewModel.webViewClient.shouldOverrideUrlLoading(
182
172
null,
183
-
mockk<WebResourceRequest> {
184
-
every { url } returns callbackUri
185
-
},
173
+
stringUri,
186
174
)
187
175
188
176
assertFalse(result)
@@ -193,15 +181,12 @@ class ConnectionViewModelTest {
193
181
194
182
@Test
195
183
fun`Given unmatching uri and webview not null when shouldRedirect is invoked then open in external browser and return true`() = runTest {
196
-
val callbackUri = mockk<Uri> {
197
-
every { scheme } returns "http"
198
-
every { host } returns "google"
199
-
every { getQueryParameter("code") } returns "not_related_code"
200
-
}
184
+
val viewModel =ConnectionViewModel("http://homeassistant.local:8123", keyChainRepository)
201
185
186
+
// Used to parse the rawUrl given in the constructor of ConnectionViewModel
0 commit comments