@@ -29,6 +29,8 @@ import org.wordpress.android.fluxc.store.TaxonomyStore.TaxonomyErrorType
2929import org.wordpress.android.fluxc.utils.AppLogWrapper
3030import rs.wordpress.api.kotlin.WpApiClient
3131import rs.wordpress.api.kotlin.WpRequestResult
32+ import uniffi.wp_api.CategoryWithEditContext
33+ import uniffi.wp_api.CategoriesRequestListWithEditContextResponse
3234import uniffi.wp_api.TagWithEditContext
3335import uniffi.wp_api.TagsRequestListWithEditContextResponse
3436import uniffi.wp_api.TaxonomyType
@@ -54,7 +56,8 @@ class TaxonomyRsApiRestClientTest {
5456 url = " https://test.wordpress.com"
5557 }
5658
57- private val testTaxonomyName = " post_tag"
59+ private val testTagTaxonomyName = " post_tag"
60+ private val testCategoryTaxonomyName = " category"
5861
5962 @Before
6063 fun setUp () {
@@ -84,7 +87,7 @@ class TaxonomyRsApiRestClientTest {
8487
8588 whenever(wpApiClient.request<Any >(any())).thenReturn(errorResponse)
8689
87- taxonomyClient.fetchPostTags(testSite, testTaxonomyName )
90+ taxonomyClient.fetchPostTags(testSite)
8891
8992 // Verify dispatcher was called with error action
9093 val actionCaptor = ArgumentCaptor .forClass(Action ::class .java)
@@ -93,7 +96,7 @@ class TaxonomyRsApiRestClientTest {
9396 val capturedAction = actionCaptor.value
9497 val payload = capturedAction.payload as FetchTermsResponsePayload
9598 assertEquals(capturedAction.type, TaxonomyAction .FETCHED_TERMS )
96- assertEquals(testTaxonomyName , payload.taxonomy)
99+ assertEquals(testTagTaxonomyName , payload.taxonomy)
97100 assertNotNull(payload.error)
98101 assertEquals(TaxonomyErrorType .GENERIC_ERROR , payload.error?.type)
99102 }
@@ -119,7 +122,7 @@ class TaxonomyRsApiRestClientTest {
119122
120123 whenever(wpApiClient.request<TagsRequestListWithEditContextResponse >(any())).thenReturn(successResponse)
121124
122- taxonomyClient.fetchPostTags(testSite, testTaxonomyName )
125+ taxonomyClient.fetchPostTags(testSite)
123126
124127 // Verify dispatcher was called with success action
125128 val actionCaptor = ArgumentCaptor .forClass(Action ::class .java)
@@ -128,13 +131,87 @@ class TaxonomyRsApiRestClientTest {
128131 val capturedAction = actionCaptor.value
129132 val payload = capturedAction.payload as FetchTermsResponsePayload
130133 assertEquals(capturedAction.type, TaxonomyAction .FETCHED_TERMS )
131- assertEquals(testTaxonomyName , payload.taxonomy)
134+ assertEquals(testTagTaxonomyName , payload.taxonomy)
132135 assertEquals(testSite, payload.site)
133136 assertNotNull(payload.terms)
134137 assertEquals(2 , payload.terms.terms.size)
135138 assertNull(payload.error)
136139 }
137140
141+ @Test
142+ fun `fetchPostCategories with error response dispatches error action` () = runTest {
143+ // Use a concrete error type that we can create - UnknownError requires statusCode and response
144+ val errorResponse = WpRequestResult .UnknownError <Any >(
145+ statusCode = 500u ,
146+ response = " Internal Server Error"
147+ )
148+
149+ whenever(wpApiClient.request<Any >(any())).thenReturn(errorResponse)
150+
151+ taxonomyClient.fetchPostCategories(testSite)
152+
153+ // Verify dispatcher was called with error action
154+ val actionCaptor = ArgumentCaptor .forClass(Action ::class .java)
155+ verify(dispatcher).dispatch(actionCaptor.capture())
156+
157+ val capturedAction = actionCaptor.value
158+ val payload = capturedAction.payload as FetchTermsResponsePayload
159+ assertEquals(capturedAction.type, TaxonomyAction .FETCHED_TERMS )
160+ assertEquals(testCategoryTaxonomyName, payload.taxonomy)
161+ assertNotNull(payload.error)
162+ assertEquals(TaxonomyErrorType .GENERIC_ERROR , payload.error?.type)
163+ }
164+
165+ @Test
166+ fun `fetchPostCategories with success response dispatches success action` () = runTest {
167+ val categoryWithEditContext = listOf (
168+ createTestCategoryWithEditContext(),
169+ createTestCategoryWithEditContext()
170+ )
171+
172+ // Create the correct response structure following the MediaRSApiRestClientTest pattern
173+ val categoryResponse = CategoriesRequestListWithEditContextResponse (
174+ categoryWithEditContext,
175+ mock<WpNetworkHeaderMap >(),
176+ null ,
177+ null
178+ )
179+
180+ val successResponse: WpRequestResult <CategoriesRequestListWithEditContextResponse > = WpRequestResult .Success (
181+ response = categoryResponse
182+ )
183+
184+ whenever(wpApiClient.request<CategoriesRequestListWithEditContextResponse >(any())).thenReturn(successResponse)
185+
186+ taxonomyClient.fetchPostCategories(testSite)
187+
188+ // Verify dispatcher was called with success action
189+ val actionCaptor = ArgumentCaptor .forClass(Action ::class .java)
190+ verify(dispatcher).dispatch(actionCaptor.capture())
191+
192+ val capturedAction = actionCaptor.value
193+ val payload = capturedAction.payload as FetchTermsResponsePayload
194+ assertEquals(capturedAction.type, TaxonomyAction .FETCHED_TERMS )
195+ assertEquals(testCategoryTaxonomyName, payload.taxonomy)
196+ assertEquals(testSite, payload.site)
197+ assertNotNull(payload.terms)
198+ assertEquals(2 , payload.terms.terms.size)
199+ assertNull(payload.error)
200+ }
201+
202+ private fun createTestCategoryWithEditContext (): CategoryWithEditContext {
203+ return CategoryWithEditContext (
204+ id = 2L ,
205+ count = 3L ,
206+ description = " Test category description" ,
207+ link = " https://example.com/category/test" ,
208+ name = " Test Category" ,
209+ slug = " test-category" ,
210+ taxonomy = TaxonomyType .Category ,
211+ parent = 0L
212+ )
213+ }
214+
138215 private fun createTestTagWithEditContext (): TagWithEditContext {
139216 return TagWithEditContext (
140217 id = 1L ,
0 commit comments