Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

/themes endpoint #477

Draft
wants to merge 2 commits into
base: categories
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package rs.wordpress.api.kotlin

import kotlinx.coroutines.test.runTest
import org.junit.jupiter.api.Test
import uniffi.wp_api.PostListParams
import uniffi.wp_api.SparseCategoryFieldWithEditContext
import uniffi.wp_api.CategoryCreateParams
import uniffi.wp_api.CategoryListParams
Expand Down Expand Up @@ -48,7 +47,7 @@ class CategoriesEndpointTest {
}

@Test
fun testRetrieveMediaRequest() = runTest {
fun testRetrieveCategoryRequest() = runTest {
val category = client.request { requestBuilder ->
requestBuilder.categories().retrieveWithEditContext(CATEGORY_ID_59)
}.assertSuccessAndRetrieveData().data
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package rs.wordpress.api.kotlin

import kotlinx.coroutines.test.runTest
import org.junit.jupiter.api.Test
import uniffi.wp_api.SparseThemeFieldWithEditContext
import uniffi.wp_api.ThemeListParams
import uniffi.wp_api.ThemeStylesheet
import uniffi.wp_api.WpErrorCode
import uniffi.wp_api.wpAuthenticationFromUsernameAndPassword
import kotlin.test.assertNotNull
import kotlin.test.assertNull

private const val THEME_TWENTY_TWENTY_FIVE: String = "twentytwentyfive"

class ThemesEndpointTest {
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 testThemeListRequest() = runTest {
val themeList = client.request { requestBuilder ->
requestBuilder.themes().listWithEditContext(params = ThemeListParams())
}.assertSuccessAndRetrieveData().data
assert(themeList.isNotEmpty())
}

@Test
fun testFilterThemeListRequest() = runTest {
val themeList = client.request { requestBuilder ->
requestBuilder.themes().filterListWithEditContext(
params = ThemeListParams(),
fields = listOf(
SparseThemeFieldWithEditContext.NAME,
SparseThemeFieldWithEditContext.AUTHOR
)
)
}.assertSuccessAndRetrieveData().data
assert(themeList.isNotEmpty())
assertNull(themeList.first().description)
}

@Test
fun testRetrieveThemeRequest() = runTest {
val theme = client.request { requestBuilder ->
requestBuilder.themes()
.retrieveWithEditContext(ThemeStylesheet(THEME_TWENTY_TWENTY_FIVE))
}.assertSuccessAndRetrieveData().data
assertNotNull(theme)
}

@Test
fun testFilterRetrieveThemeRequest() = runTest {
val theme = client.request { requestBuilder ->
requestBuilder.themes().filterRetrieveWithEditContext(
ThemeStylesheet(THEME_TWENTY_TWENTY_FIVE),
fields = listOf(
SparseThemeFieldWithEditContext.NAME,
SparseThemeFieldWithEditContext.STYLESHEET
)
)
}.assertSuccessAndRetrieveData().data
assertNull(theme.description)
}

@Test
fun testErrorThemeNotFound() = runTest {
val result =
client.request { requestBuilder ->
requestBuilder.themes()
.retrieveWithEditContext(ThemeStylesheet("invalid_stylesheet"))
}
assert(result.wpErrorCode() is WpErrorCode.ThemeNotFound)
}
}
6 changes: 6 additions & 0 deletions wp_api/src/api_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use crate::request::{
site_settings_endpoint::{SiteSettingsRequestBuilder, SiteSettingsRequestExecutor},
tags_endpoint::{TagsRequestBuilder, TagsRequestExecutor},
taxonomies_endpoint::{TaxonomiesRequestBuilder, TaxonomiesRequestExecutor},
themes_endpoint::{ThemesRequestBuilder, ThemesRequestExecutor},
users_endpoint::{UsersRequestBuilder, UsersRequestExecutor},
wp_site_health_tests_endpoint::{
WpSiteHealthTestsRequestBuilder, WpSiteHealthTestsRequestExecutor,
Expand Down Expand Up @@ -53,6 +54,7 @@ pub struct WpApiRequestBuilder {
site_settings: Arc<SiteSettingsRequestBuilder>,
tags: Arc<TagsRequestBuilder>,
taxonomies: Arc<TaxonomiesRequestBuilder>,
themes: Arc<ThemesRequestBuilder>,
users: Arc<UsersRequestBuilder>,
wp_site_health_tests: Arc<WpSiteHealthTestsRequestBuilder>,
}
Expand All @@ -73,6 +75,7 @@ impl WpApiRequestBuilder {
site_settings,
tags,
taxonomies,
themes,
users,
wp_site_health_tests
)
Expand Down Expand Up @@ -110,6 +113,7 @@ pub struct WpApiClient {
site_settings: Arc<SiteSettingsRequestExecutor>,
tags: Arc<TagsRequestExecutor>,
taxonomies: Arc<TaxonomiesRequestExecutor>,
themes: Arc<ThemesRequestExecutor>,
users: Arc<UsersRequestExecutor>,
wp_site_health_tests: Arc<WpSiteHealthTestsRequestExecutor>,
}
Expand All @@ -136,6 +140,7 @@ impl WpApiClient {
site_settings,
tags,
taxonomies,
themes,
users,
wp_site_health_tests
)
Expand All @@ -152,6 +157,7 @@ api_client_generate_endpoint_impl!(WpApi, posts);
api_client_generate_endpoint_impl!(WpApi, site_settings);
api_client_generate_endpoint_impl!(WpApi, tags);
api_client_generate_endpoint_impl!(WpApi, taxonomies);
api_client_generate_endpoint_impl!(WpApi, themes);
api_client_generate_endpoint_impl!(WpApi, users);
api_client_generate_endpoint_impl!(WpApi, wp_site_health_tests);

Expand Down
6 changes: 6 additions & 0 deletions wp_api/src/api_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,14 @@ pub enum WpErrorCode {
CannotUpdate,
#[serde(rename = "rest_cannot_view")]
CannotView,
#[serde(rename = "rest_cannot_view_active_theme")]
CannotViewActiveTheme,
#[serde(rename = "rest_cannot_view_plugin")]
CannotViewPlugin,
#[serde(rename = "rest_cannot_view_plugins")]
CannotViewPlugins,
#[serde(rename = "rest_cannot_view_themes")]
CannotViewThemes,
#[serde(rename = "comment_author_column_length")]
CommentAuthorColumnLength,
#[serde(rename = "rest_comment_author_data_required")]
Expand Down Expand Up @@ -217,6 +221,8 @@ pub enum WpErrorCode {
TaxonomyInvalid,
#[serde(rename = "rest_term_invalid")]
TermInvalid,
#[serde(rename = "rest_theme_not_found")]
ThemeNotFound,
#[serde(rename = "rest_type_invalid")]
TypeInvalid,
#[serde(rename = "rest_not_logged_in")]
Expand Down
8 changes: 8 additions & 0 deletions wp_api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub mod request;
pub mod site_settings;
pub mod tags;
pub mod taxonomies;
pub mod themes;
pub mod url_query;
pub mod users;
pub mod wordpress_org;
Expand Down Expand Up @@ -189,6 +190,13 @@ pub enum BoolOrString {
String(String),
}

#[derive(Debug, Serialize, Deserialize, uniffi::Enum)]
#[serde(untagged)]
pub enum BoolOrVecString {
Bool(bool),
VecString(Vec<String>),
}

#[macro_export]
macro_rules! generate {
($type_name:ident) => {
Expand Down
1 change: 1 addition & 0 deletions wp_api/src/request/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub mod posts_endpoint;
pub mod site_settings_endpoint;
pub mod tags_endpoint;
pub mod taxonomies_endpoint;
pub mod themes_endpoint;
pub mod users_endpoint;
pub mod wp_site_health_tests_endpoint;

Expand Down
Loading
Loading