-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
List & retrieve
/taxonomies
endpoint (#456)
* List & retrieve `/taxonomies` endpoint * Add nav_menu_item & wp_block post type tests to list taxonomies * Implement FromStr for PostType::Custom * Address clippy warning to use unwrap_or_else over expect with format! * Replace FromStr error types with Infallible where possible
- Loading branch information
Showing
15 changed files
with
540 additions
and
20 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
native/kotlin/api/kotlin/src/integrationTest/kotlin/TaxonomiesEndpointTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package rs.wordpress.api.kotlin | ||
|
||
import kotlinx.coroutines.test.runTest | ||
import org.junit.jupiter.api.Test | ||
import uniffi.wp_api.TaxonomyListParams | ||
import uniffi.wp_api.TaxonomyType | ||
import uniffi.wp_api.wpAuthenticationFromUsernameAndPassword | ||
import kotlin.test.assertEquals | ||
|
||
class TaxonomiesEndpointTest { | ||
private val testCredentials = TestCredentials.INSTANCE | ||
private val siteUrl = testCredentials.parsedSiteUrl | ||
private val authentication = wpAuthenticationFromUsernameAndPassword( | ||
username = testCredentials.adminUsername, password = testCredentials.adminPassword | ||
) | ||
private val client = WpApiClient(siteUrl, authentication) | ||
|
||
@Test | ||
fun testTaxonomyListRequest() = runTest { | ||
val taxonomyList = client.request { requestBuilder -> | ||
requestBuilder.taxonomies().listWithEditContext(params = TaxonomyListParams()) | ||
}.assertSuccessAndRetrieveData().data | ||
assert(taxonomyList.taxonomyTypes.isNotEmpty()) | ||
} | ||
|
||
@Test | ||
fun testRetrieveCategoryTaxonomyRequest() = runTest { | ||
val taxonomy = client.request { requestBuilder -> | ||
requestBuilder.taxonomies().retrieveWithEditContext(TaxonomyType.Category) | ||
}.assertSuccessAndRetrieveData().data | ||
assertEquals("Categories", taxonomy.name) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use super::{AsNamespace, DerivedRequest, WpNamespace}; | ||
use crate::taxonomies::{ | ||
SparseTaxonomyTypeDetailsFieldWithEditContext, SparseTaxonomyTypeDetailsFieldWithEmbedContext, | ||
SparseTaxonomyTypeDetailsFieldWithViewContext, TaxonomyListParams, TaxonomyType, | ||
}; | ||
use crate::SparseField; | ||
use wp_derive_request_builder::WpDerivedRequest; | ||
|
||
#[derive(WpDerivedRequest)] | ||
enum TaxonomiesRequest { | ||
#[contextual_get(url = "/taxonomies", params = &TaxonomyListParams, output = crate::taxonomies::SparseTaxonomyTypesResponse)] | ||
List, | ||
#[contextual_get(url = "/taxonomies/<taxonomy_type>", output = crate::taxonomies::SparseTaxonomyTypeDetails, filter_by = crate::taxonomies::SparseTaxonomyTypeDetailsField)] | ||
Retrieve, | ||
} | ||
|
||
impl DerivedRequest for TaxonomiesRequest { | ||
fn namespace() -> impl AsNamespace { | ||
WpNamespace::WpV2 | ||
} | ||
} | ||
|
||
super::macros::default_sparse_field_implementation_from_field_name!( | ||
SparseTaxonomyTypeDetailsFieldWithEditContext | ||
); | ||
super::macros::default_sparse_field_implementation_from_field_name!( | ||
SparseTaxonomyTypeDetailsFieldWithEmbedContext | ||
); | ||
super::macros::default_sparse_field_implementation_from_field_name!( | ||
SparseTaxonomyTypeDetailsFieldWithViewContext | ||
); |
Oops, something went wrong.