Skip to content

Commit 76f7aa6

Browse files
committed
Replace PostTypeSupportsValue with JsonValue directly
Simplify post type supports by using JsonValue directly instead of the PostTypeSupportsValue wrapper type. Tests now use the supports method on PostTypeSupportsMap to check feature support. Changes: - Change PostTypeSupportsMap.map from HashMap<_, Arc<PostTypeSupportsValue>> to HashMap<_, JsonValue> - Remove PostTypeSupportsValue struct and its impl block - Update Rust test to use supports method directly - Update Kotlin test to use postTypeSupports helper
1 parent 1f1b288 commit 76f7aa6

File tree

3 files changed

+4
-32
lines changed

3 files changed

+4
-32
lines changed

native/kotlin/api/kotlin/src/integrationTest/kotlin/PostTypesEndpointTest.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import uniffi.wp_api.PostType
66
import uniffi.wp_api.PostTypeCapabilities
77
import uniffi.wp_api.PostTypeSupports
88
import uniffi.wp_api.WpErrorCode
9+
import uniffi.wp_api.postTypeSupports
910
import kotlin.test.assertEquals
1011
import kotlin.test.assertFalse
1112
import kotlin.test.assertNull
@@ -26,7 +27,7 @@ class PostTypesEndpointTest {
2627
val postTypesPost = client.request { requestBuilder ->
2728
requestBuilder.postTypes().retrieveWithEditContext(PostType.Post)
2829
}.assertSuccessAndRetrieveData().data
29-
assert(postTypesPost.supports.map[PostTypeSupports.Title]!!.asJsonBool()!!)
30+
assert(postTypeSupports(postTypesPost.supports, PostTypeSupports.Title))
3031
assertFalse(postTypesPost.capabilities[PostTypeCapabilities.EditPosts]!!.isEmpty())
3132
}
3233

wp_api/src/post_types.rs

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use crate::{JsonValue, impl_as_query_value_from_to_string};
22
use serde::{Deserialize, Serialize};
33
use std::collections::HashMap;
44
use std::str::FromStr;
5-
use std::sync::Arc;
65
use wp_contextual::WpContextual;
76
use wp_serde_helper::deserialize_empty_array_or_hashmap;
87

@@ -98,7 +97,7 @@ pub struct PostTypeSupportsMap {
9897
#[serde(deserialize_with = "deserialize_empty_array_or_hashmap")]
9998
#[serde(flatten)]
10099
#[serde(rename = "supports")]
101-
pub map: HashMap<PostTypeSupports, Arc<PostTypeSupportsValue>>,
100+
pub map: HashMap<PostTypeSupports, JsonValue>,
102101
}
103102

104103
impl PostTypeSupportsMap {
@@ -123,27 +122,6 @@ fn post_type_supports(supports_map: &PostTypeSupportsMap, feature: PostTypeSuppo
123122
supports_map.supports(&feature)
124123
}
125124

126-
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, uniffi::Object)]
127-
#[serde(transparent)]
128-
pub struct PostTypeSupportsValue {
129-
#[serde(flatten)]
130-
pub json_value: JsonValue,
131-
}
132-
133-
#[uniffi::export]
134-
impl PostTypeSupportsValue {
135-
fn as_json_value(&self) -> JsonValue {
136-
self.json_value.clone()
137-
}
138-
139-
pub fn as_json_bool(&self) -> Option<bool> {
140-
match self.json_value {
141-
JsonValue::Bool(b) => Some(b),
142-
_ => None,
143-
}
144-
}
145-
}
146-
147125
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize, uniffi::Record)]
148126
pub struct PostTypeLabels {
149127
pub name: String,

wp_api_integration_tests/tests/test_post_types_immut.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,7 @@ async fn retrieve_post_types_with_edit_context(
9292
// It's possible that we might have more test sites in the future and some of their
9393
// post types might not support `Title` in which case it's perfectly fine to completely
9494
// remove this assertion.
95-
assert_eq!(
96-
post_type
97-
.supports
98-
.map
99-
.get(&PostTypeSupports::Title)
100-
.and_then(|v| v.as_json_bool()),
101-
Some(true)
102-
);
95+
assert!(post_type.supports.supports(&PostTypeSupports::Title));
10396
// All post types in our current testing sites have `EditPost` capability, so we use this
10497
// assertion to verify that we are able to parse `capabilities` field properly.
10598
//

0 commit comments

Comments
 (0)