@@ -24,12 +24,15 @@ import org.wordpress.android.fluxc.action.TaxonomyAction
2424import  org.wordpress.android.fluxc.annotations.action.Action 
2525import  org.wordpress.android.fluxc.model.SiteModel 
2626import  org.wordpress.android.fluxc.network.rest.wpapi.rs.WpApiClientProvider 
27+ import  org.wordpress.android.fluxc.model.TermModel 
2728import  org.wordpress.android.fluxc.store.TaxonomyStore.FetchTermsResponsePayload 
29+ import  org.wordpress.android.fluxc.store.TaxonomyStore.RemoteTermPayload 
2830import  org.wordpress.android.fluxc.store.TaxonomyStore.TaxonomyErrorType 
2931import  org.wordpress.android.fluxc.utils.AppLogWrapper 
3032import  rs.wordpress.api.kotlin.WpApiClient 
3133import  rs.wordpress.api.kotlin.WpRequestResult 
3234import  uniffi.wp_api.CategoryWithEditContext 
35+ import  uniffi.wp_api.CategoriesRequestCreateResponse 
3336import  uniffi.wp_api.CategoriesRequestListWithEditContextResponse 
3437import  uniffi.wp_api.TagWithEditContext 
3538import  uniffi.wp_api.TagsRequestListWithEditContextResponse 
@@ -56,6 +59,18 @@ class TaxonomyRsApiRestClientTest {
5659        url =  " https://test.wordpress.com" 
5760    }
5861
62+     private  val  testTermModel =  TermModel (
63+         1 , //  id
64+         123 , //  localSiteId
65+         2L , //  remoteTermId
66+         " category"  , //  taxonomy
67+         " Test Category"  , //  name
68+         " test-category"  , //  slug
69+         " Test category description"  , //  description
70+         0L , //  parentRemoteId
71+         0  //  postCount
72+     )
73+ 
5974    private  val  testTagTaxonomyName =  " post_tag" 
6075    private  val  testCategoryTaxonomyName =  " category" 
6176
@@ -199,6 +214,70 @@ class TaxonomyRsApiRestClientTest {
199214        assertNull(payload.error)
200215    }
201216
217+     @Test
218+     fun  `createPostCategory with error response dispatches error action`  () =  runTest {
219+         //  Use a concrete error type that we can create - UnknownError requires statusCode and response
220+         val  errorResponse =  WpRequestResult .UnknownError <Any >(
221+             statusCode =  500u ,
222+             response =  " Internal Server Error" 
223+         )
224+ 
225+         whenever(wpApiClient.request<Any >(any())).thenReturn(errorResponse)
226+ 
227+         taxonomyClient.createPostCategory(testSite, testTermModel)
228+ 
229+         //  Verify dispatcher was called with error action
230+         val  actionCaptor =  ArgumentCaptor .forClass(Action ::class .java)
231+         verify(dispatcher).dispatch(actionCaptor.capture())
232+ 
233+         val  capturedAction =  actionCaptor.value
234+         val  payload =  capturedAction.payload as  RemoteTermPayload 
235+         assertEquals(capturedAction.type, TaxonomyAction .PUSHED_TERM )
236+         assertEquals(testSite, payload.site)
237+         assertEquals(testTermModel, payload.term)
238+         assertNotNull(payload.error)
239+         assertEquals(TaxonomyErrorType .GENERIC_ERROR , payload.error?.type)
240+     }
241+ 
242+     @Test
243+     fun  `createPostCategory with success response dispatches success action`  () =  runTest {
244+         val  categoryWithEditContext =  createTestCategoryWithEditContext()
245+ 
246+         //  Create the correct response structure following the MediaRSApiRestClientTest pattern
247+         val  categoryResponse =  CategoriesRequestCreateResponse (
248+             categoryWithEditContext,
249+             mock<WpNetworkHeaderMap >()
250+         )
251+ 
252+         val  successResponse:  WpRequestResult <CategoriesRequestCreateResponse > =  WpRequestResult .Success (
253+             response =  categoryResponse
254+         )
255+ 
256+         whenever(wpApiClient.request<CategoriesRequestCreateResponse >(any())).thenReturn(successResponse)
257+ 
258+         taxonomyClient.createPostCategory(testSite, testTermModel)
259+ 
260+         //  Verify dispatcher was called with success action
261+         val  actionCaptor =  ArgumentCaptor .forClass(Action ::class .java)
262+         verify(dispatcher).dispatch(actionCaptor.capture())
263+ 
264+         val  capturedAction =  actionCaptor.value
265+         val  payload =  capturedAction.payload as  RemoteTermPayload 
266+         assertEquals(capturedAction.type, TaxonomyAction .PUSHED_TERM )
267+         assertEquals(testSite, payload.site)
268+         assertNotNull(payload.term)
269+         //  Verify the created term has the correct properties
270+         assertEquals(categoryWithEditContext.id.toInt(), payload.term.id)
271+         assertEquals(testSite.id, payload.term.localSiteId)
272+         assertEquals(categoryWithEditContext.id, payload.term.remoteTermId)
273+         assertEquals(testCategoryTaxonomyName, payload.term.taxonomy)
274+         assertEquals(categoryWithEditContext.name, payload.term.name)
275+         assertEquals(categoryWithEditContext.slug, payload.term.slug)
276+         assertEquals(categoryWithEditContext.description, payload.term.description)
277+         assertEquals(categoryWithEditContext.count.toInt(), payload.term.postCount)
278+         assertNull(payload.error)
279+     }
280+ 
202281    private  fun  createTestCategoryWithEditContext (): CategoryWithEditContext  {
203282        return  CategoryWithEditContext (
204283            id =  2L ,
0 commit comments