@@ -29,6 +29,8 @@ import org.wordpress.android.fluxc.store.TaxonomyStore.TaxonomyErrorType
29
29
import org.wordpress.android.fluxc.utils.AppLogWrapper
30
30
import rs.wordpress.api.kotlin.WpApiClient
31
31
import rs.wordpress.api.kotlin.WpRequestResult
32
+ import uniffi.wp_api.CategoryWithEditContext
33
+ import uniffi.wp_api.CategoriesRequestListWithEditContextResponse
32
34
import uniffi.wp_api.TagWithEditContext
33
35
import uniffi.wp_api.TagsRequestListWithEditContextResponse
34
36
import uniffi.wp_api.TaxonomyType
@@ -54,7 +56,8 @@ class TaxonomyRsApiRestClientTest {
54
56
url = " https://test.wordpress.com"
55
57
}
56
58
57
- private val testTaxonomyName = " post_tag"
59
+ private val testTagTaxonomyName = " post_tag"
60
+ private val testCategoryTaxonomyName = " category"
58
61
59
62
@Before
60
63
fun setUp () {
@@ -84,7 +87,7 @@ class TaxonomyRsApiRestClientTest {
84
87
85
88
whenever(wpApiClient.request<Any >(any())).thenReturn(errorResponse)
86
89
87
- taxonomyClient.fetchPostTags(testSite, testTaxonomyName )
90
+ taxonomyClient.fetchPostTags(testSite)
88
91
89
92
// Verify dispatcher was called with error action
90
93
val actionCaptor = ArgumentCaptor .forClass(Action ::class .java)
@@ -93,7 +96,7 @@ class TaxonomyRsApiRestClientTest {
93
96
val capturedAction = actionCaptor.value
94
97
val payload = capturedAction.payload as FetchTermsResponsePayload
95
98
assertEquals(capturedAction.type, TaxonomyAction .FETCHED_TERMS )
96
- assertEquals(testTaxonomyName , payload.taxonomy)
99
+ assertEquals(testTagTaxonomyName , payload.taxonomy)
97
100
assertNotNull(payload.error)
98
101
assertEquals(TaxonomyErrorType .GENERIC_ERROR , payload.error?.type)
99
102
}
@@ -119,7 +122,7 @@ class TaxonomyRsApiRestClientTest {
119
122
120
123
whenever(wpApiClient.request<TagsRequestListWithEditContextResponse >(any())).thenReturn(successResponse)
121
124
122
- taxonomyClient.fetchPostTags(testSite, testTaxonomyName )
125
+ taxonomyClient.fetchPostTags(testSite)
123
126
124
127
// Verify dispatcher was called with success action
125
128
val actionCaptor = ArgumentCaptor .forClass(Action ::class .java)
@@ -128,13 +131,87 @@ class TaxonomyRsApiRestClientTest {
128
131
val capturedAction = actionCaptor.value
129
132
val payload = capturedAction.payload as FetchTermsResponsePayload
130
133
assertEquals(capturedAction.type, TaxonomyAction .FETCHED_TERMS )
131
- assertEquals(testTaxonomyName , payload.taxonomy)
134
+ assertEquals(testTagTaxonomyName , payload.taxonomy)
132
135
assertEquals(testSite, payload.site)
133
136
assertNotNull(payload.terms)
134
137
assertEquals(2 , payload.terms.terms.size)
135
138
assertNull(payload.error)
136
139
}
137
140
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
+
138
215
private fun createTestTagWithEditContext (): TagWithEditContext {
139
216
return TagWithEditContext (
140
217
id = 1L ,
0 commit comments