-
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.
- Loading branch information
Showing
11 changed files
with
651 additions
and
2 deletions.
There are no files selected for viewing
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
78 changes: 78 additions & 0 deletions
78
native/kotlin/api/kotlin/src/integrationTest/kotlin/ThemesEndpointTest.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,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) | ||
} | ||
} |
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 crate::themes::{ | ||
SparseThemeFieldWithEditContext, SparseThemeFieldWithEmbedContext, | ||
SparseThemeFieldWithViewContext, ThemeStylesheet, | ||
}; | ||
use crate::SparseField; | ||
use wp_derive_request_builder::WpDerivedRequest; | ||
|
||
use super::{AsNamespace, DerivedRequest, WpNamespace}; | ||
#[derive(WpDerivedRequest)] | ||
enum ThemesRequest { | ||
#[contextual_get(url = "/themes", params = &crate::themes::ThemeListParams, output = Vec<crate::themes::SparseTheme>, filter_by = crate::themes::SparseThemeField)] | ||
List, | ||
#[contextual_get(url = "/themes/<theme_stylesheet>", output = crate::themes::SparseTheme, filter_by = crate::themes::SparseThemeField)] | ||
Retrieve, | ||
} | ||
|
||
impl DerivedRequest for ThemesRequest { | ||
fn namespace() -> impl AsNamespace { | ||
WpNamespace::WpV2 | ||
} | ||
} | ||
|
||
super::macros::default_sparse_field_implementation_from_field_name!( | ||
SparseThemeFieldWithEditContext | ||
); | ||
super::macros::default_sparse_field_implementation_from_field_name!( | ||
SparseThemeFieldWithEmbedContext | ||
); | ||
super::macros::default_sparse_field_implementation_from_field_name!( | ||
SparseThemeFieldWithViewContext | ||
); |
Oops, something went wrong.