@@ -15,8 +15,8 @@ import org.mockito.kotlin.verify
1515import org.mockito.kotlin.whenever
1616import org.robolectric.RobolectricTestRunner
1717import org.robolectric.annotation.Config
18- import org.wordpress.android.fluxc.TestSiteSqlUtils
1918import org.wordpress.android.fluxc.model.SiteModel
19+ import org.wordpress.android.fluxc.persistence.SiteSqlUtils
2020import org.wordpress.android.fluxc.network.BaseRequest.GenericErrorType.UNKNOWN
2121import org.wordpress.android.fluxc.network.discovery.DiscoveryWPAPIRestClient
2222import org.wordpress.android.fluxc.network.rest.wpapi.Nonce
@@ -49,9 +49,7 @@ class ReactNativeStoreWPAPITest {
4949 private lateinit var store: ReactNativeStore
5050 private lateinit var site: SiteModel
5151
52- private interface SitePersister : (SiteModel ) -> Int
53-
54- private lateinit var sitePersistenceMock: SitePersister
52+ private val siteSqlUtils = mock<SiteSqlUtils >()
5553
5654 @Before
5755 fun setup () {
@@ -65,16 +63,14 @@ class ReactNativeStoreWPAPITest {
6563
6664 private fun initStore (nonce : Nonce ? ) {
6765 whenever(nonceRestClient.getNonce(any<SiteModel >())).thenReturn(nonce)
68- sitePersistenceMock = mock()
6966 store = ReactNativeStore (
7067 mock(),
7168 wpApiRestClient,
7269 nonceRestClient,
7370 discoveryWPAPIRestClient,
74- TestSiteSqlUtils . siteSqlUtils,
71+ siteSqlUtils,
7572 initCoroutineEngine(),
76- { currentTime },
77- sitePersistenceMock
73+ { currentTime }
7874 )
7975 }
8076
@@ -102,9 +98,9 @@ class ReactNativeStoreWPAPITest {
10298 val actualResponse = store.executeGetRequest(site, restPathWithParams)
10399 assertEquals(callWithSuccess, actualResponse)
104100 assertEquals(restUrl, site.wpApiRestUrl, " site should be updated with rest endpoint used for successful call" )
105- inOrder(discoveryWPAPIRestClient, sitePersistenceMock , wpApiRestClient, nonceRestClient) {
101+ inOrder(discoveryWPAPIRestClient, siteSqlUtils , wpApiRestClient, nonceRestClient) {
106102 verify(discoveryWPAPIRestClient).discoverWPAPIBaseURL(site.url)
107- verify(sitePersistenceMock) (site) // persist site after discovering wpApiRestUrl
103+ verify(siteSqlUtils).updateWpApiRestUrl (site.id, restUrl ) // persist discovered wpApiRestUrl
108104 verify(nonceRestClient).requestNonce(site)
109105 verify(wpApiRestClient).getRequest(fetchUrl, nonce.value)
110106 }
@@ -134,9 +130,9 @@ class ReactNativeStoreWPAPITest {
134130 val actualResponse = store.executePostRequest(site, restPathWithParams, bodyMap)
135131 assertEquals(callWithSuccess, actualResponse)
136132 assertEquals(restUrl, site.wpApiRestUrl, " site should be updated with rest endpoint used for successful call" )
137- inOrder(discoveryWPAPIRestClient, sitePersistenceMock , wpApiRestClient, nonceRestClient) {
133+ inOrder(discoveryWPAPIRestClient, siteSqlUtils , wpApiRestClient, nonceRestClient) {
138134 verify(discoveryWPAPIRestClient).discoverWPAPIBaseURL(site.url)
139- verify(sitePersistenceMock) (site) // persist site after discovering wpApiRestUrl
135+ verify(siteSqlUtils).updateWpApiRestUrl (site.id, restUrl ) // persist discovered wpApiRestUrl
140136 verify(nonceRestClient).requestNonce(site)
141137 verify(wpApiRestClient).postRequest(postURL, nonce.value)
142138 }
@@ -154,7 +150,7 @@ class ReactNativeStoreWPAPITest {
154150 val actualResponse = store.executeGetRequest(site, restPathWithParams)
155151 assertEquals(initialResponseWithSuccess, actualResponse)
156152 verify(wpApiRestClient).getRequest(fetchUrl)
157- verify(sitePersistenceMock , never())( any()) // no wpApiRestUrl updates, so no persistence
153+ verify(siteSqlUtils , never()).updateWpApiRestUrl(any(), any()) // no wpApiRestUrl updates, so no persistence
158154 verify(discoveryWPAPIRestClient, never()).discoverWPAPIBaseURL(any())
159155 }
160156
@@ -177,9 +173,9 @@ class ReactNativeStoreWPAPITest {
177173 val actualResponse = store.executeGetRequest(site, restPathWithParams)
178174 assertEquals(initialResponseWithSuccess, actualResponse)
179175 assertEquals(restUrl, site.wpApiRestUrl, " site should be updated with rest endpoint used for successful call" )
180- inOrder(discoveryWPAPIRestClient, sitePersistenceMock , wpApiRestClient) {
176+ inOrder(discoveryWPAPIRestClient, siteSqlUtils , wpApiRestClient) {
181177 verify(discoveryWPAPIRestClient).discoverWPAPIBaseURL(site.url)
182- verify(sitePersistenceMock) (site) // persist site after discovering wpApiRestUrl
178+ verify(siteSqlUtils).updateWpApiRestUrl (site.id, restUrl ) // persist discovered wpApiRestUrl
183179 verify(wpApiRestClient).getRequest(fetchUrl)
184180 }
185181 }
@@ -206,9 +202,9 @@ class ReactNativeStoreWPAPITest {
206202 fallbackRestUrl, site.wpApiRestUrl,
207203 " site should be updated with rest endpoint used for successful call"
208204 )
209- inOrder(discoveryWPAPIRestClient, sitePersistenceMock , wpApiRestClient) {
205+ inOrder(discoveryWPAPIRestClient, siteSqlUtils , wpApiRestClient) {
210206 verify(discoveryWPAPIRestClient).discoverWPAPIBaseURL(site.url)
211- verify(sitePersistenceMock) (site) // persist default endpoint after failed discovery
207+ verify(siteSqlUtils).updateWpApiRestUrl (site.id, fallbackRestUrl ) // persist fallback endpoint
212208 verify(wpApiRestClient).getRequest(fetchUrl)
213209 }
214210 }
@@ -239,11 +235,10 @@ class ReactNativeStoreWPAPITest {
239235 val actualResponse = store.executeGetRequest(site, restPathWithParams)
240236 assertEquals(secondResponseWithSuccess, actualResponse)
241237 assertEquals(restUrl, site.wpApiRestUrl, " should save rest endpoint used for successful call" )
242- inOrder(discoveryWPAPIRestClient, sitePersistenceMock , wpApiRestClient) {
238+ inOrder(discoveryWPAPIRestClient, siteSqlUtils , wpApiRestClient) {
243239 verify(wpApiRestClient).getRequest(incorrectUrl)
244- verify(sitePersistenceMock)(site) // persist site after clearing wpApiRestUrl that resulted in 404 failure
245240 verify(discoveryWPAPIRestClient).discoverWPAPIBaseURL(site.url)
246- verify(sitePersistenceMock) (site) // persist site after discovering wpApiRestUrl
241+ verify(siteSqlUtils).updateWpApiRestUrl (site.id, restUrl ) // persist discovered wpApiRestUrl
247242 verify(wpApiRestClient).getRequest(correctUrl)
248243 }
249244 }
@@ -268,11 +263,10 @@ class ReactNativeStoreWPAPITest {
268263 val actualResponse = store.executeGetRequest(site, restPathWithParams)
269264 assertEquals(responseWithNotFoundError, actualResponse)
270265 assertNull(site.wpApiRestUrl, " should not update site wpApiRestEndpoint when call fails" )
271- inOrder(discoveryWPAPIRestClient, sitePersistenceMock , wpApiRestClient) {
266+ inOrder(discoveryWPAPIRestClient, siteSqlUtils , wpApiRestClient) {
272267 verify(discoveryWPAPIRestClient).discoverWPAPIBaseURL(site.url)
273- verify(sitePersistenceMock) (site) // persist site after discovering wpApiRestUrl
268+ verify(siteSqlUtils).updateWpApiRestUrl (site.id, restUrl ) // persist discovered wpApiRestUrl
274269 verify(wpApiRestClient).getRequest(fetchUrl)
275- verify(sitePersistenceMock)(site) // persist site after clearing wpApiRestUrl that resulted in 404 failure
276270 }
277271 }
278272
@@ -483,10 +477,9 @@ class ReactNativeStoreWPAPITest {
483477 wpApiRestClient,
484478 nonceRestClient,
485479 discoveryWPAPIRestClient,
486- TestSiteSqlUtils . siteSqlUtils,
480+ siteSqlUtils,
487481 initCoroutineEngine(),
488482 { currentTime },
489- sitePersistenceMock,
490483 uriParser
491484 )
492485
0 commit comments