Skip to content

Commit c325465

Browse files
authored
Fix an issue where plugin update checks may fail (#533)
1 parent d5a3d13 commit c325465

File tree

5 files changed

+189
-2
lines changed

5 files changed

+189
-2
lines changed

wp_api/src/wordpress_org/plugin_directory.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,9 @@ pub struct Screenshot {
107107

108108
#[derive(Deserialize, Debug, Eq, PartialEq, Default, uniffi::Record)]
109109
pub struct Banners {
110-
#[serde(deserialize_with = "deserialize_default_values")]
110+
#[serde(deserialize_with = "deserialize_default_values", alias = "1x")]
111111
pub low: String,
112-
#[serde(deserialize_with = "deserialize_default_values")]
112+
#[serde(deserialize_with = "deserialize_default_values", alias = "2x")]
113113
pub high: String,
114114
}
115115

@@ -324,4 +324,12 @@ mod tests {
324324
let parsed = serde_json::from_str::<QueryPluginResponse>(json_string);
325325
assert!(parsed.is_ok(), "Failed to parse JSON: {:?}", parsed.err());
326326
}
327+
328+
#[test]
329+
fn plugin_directory_single_plugin_case_1() {
330+
let json_string =
331+
include_str!("../../tests/plugin-directory/plugin_directory_single_plugin_case_1.json");
332+
let parsed = serde_json::from_str::<PluginInformation>(json_string);
333+
assert!(parsed.is_ok(), "Failed to parse JSON: {:?}", parsed.err());
334+
}
327335
}

wp_api/src/wordpress_org/update_check.rs

+8
Original file line numberDiff line numberDiff line change
@@ -304,4 +304,12 @@ mod tests {
304304

305305
assert_eq!(body_map.get("all").unwrap(), "true");
306306
}
307+
308+
#[test]
309+
fn plugin_directory_single_plugin_case_1() {
310+
let json_string =
311+
include_str!("../../tests/plugin-directory/plugin_update_check_case_1.json");
312+
let parsed = serde_json::from_str::<UpdateCheckResponse>(json_string);
313+
assert!(parsed.is_ok(), "Failed to parse JSON: {:?}", parsed.err());
314+
}
307315
}

wp_api/tests/plugin-directory/plugin_directory_single_plugin_case_1.json

+87
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
{
2+
"plugins": {
3+
"akismet\/akismet.php": {
4+
"id": "w.org\/plugins\/akismet",
5+
"slug": "akismet",
6+
"plugin": "akismet\/akismet.php",
7+
"new_version": "5.3.6",
8+
"url": "https:\/\/wordpress.org\/plugins\/akismet\/",
9+
"package": "https:\/\/downloads.wordpress.org\/plugin\/akismet.5.3.6.zip",
10+
"icons": {
11+
"2x": "https:\/\/ps.w.org\/akismet\/assets\/icon-256x256.png?rev=2818463",
12+
"1x": "https:\/\/ps.w.org\/akismet\/assets\/icon-128x128.png?rev=2818463"
13+
},
14+
"banners": {
15+
"2x": "https:\/\/ps.w.org\/akismet\/assets\/banner-1544x500.png?rev=2900731",
16+
"1x": "https:\/\/ps.w.org\/akismet\/assets\/banner-772x250.png?rev=2900731"
17+
},
18+
"banners_rtl": [],
19+
"requires": "5.8",
20+
"tested": "6.7.1",
21+
"requires_php": "5.6.20",
22+
"requires_plugins": [],
23+
"compatibility": []
24+
}
25+
},
26+
"translations": [],
27+
"no_update": {
28+
"classic-editor\/classic-editor.php": {
29+
"id": "w.org\/plugins\/classic-editor",
30+
"slug": "classic-editor",
31+
"plugin": "classic-editor\/classic-editor.php",
32+
"new_version": "1.6.7",
33+
"url": "https:\/\/wordpress.org\/plugins\/classic-editor\/",
34+
"package": "https:\/\/downloads.wordpress.org\/plugin\/classic-editor.1.6.7.zip",
35+
"icons": {
36+
"2x": "https:\/\/ps.w.org\/classic-editor\/assets\/icon-256x256.png?rev=1998671",
37+
"1x": "https:\/\/ps.w.org\/classic-editor\/assets\/icon-128x128.png?rev=1998671"
38+
},
39+
"banners": {
40+
"2x": "https:\/\/ps.w.org\/classic-editor\/assets\/banner-1544x500.png?rev=1998671",
41+
"1x": "https:\/\/ps.w.org\/classic-editor\/assets\/banner-772x250.png?rev=1998676"
42+
},
43+
"banners_rtl": [],
44+
"requires": "4.9"
45+
},
46+
"hello.php": {
47+
"id": "w.org\/plugins\/hello-dolly",
48+
"slug": "hello-dolly",
49+
"plugin": "hello.php",
50+
"new_version": "1.7.2",
51+
"url": "https:\/\/wordpress.org\/plugins\/hello-dolly\/",
52+
"package": "https:\/\/downloads.wordpress.org\/plugin\/hello-dolly.1.7.3.zip",
53+
"icons": {
54+
"2x": "https:\/\/ps.w.org\/hello-dolly\/assets\/icon-256x256.jpg?rev=2052855",
55+
"1x": "https:\/\/ps.w.org\/hello-dolly\/assets\/icon-128x128.jpg?rev=2052855"
56+
},
57+
"banners": {
58+
"2x": "https:\/\/ps.w.org\/hello-dolly\/assets\/banner-1544x500.jpg?rev=2645582",
59+
"1x": "https:\/\/ps.w.org\/hello-dolly\/assets\/banner-772x250.jpg?rev=2052855"
60+
},
61+
"banners_rtl": [],
62+
"requires": "4.6"
63+
},
64+
"hello-dolly\/hello.php": {
65+
"id": "w.org\/plugins\/hello-dolly",
66+
"slug": "hello-dolly",
67+
"plugin": "hello-dolly\/hello.php",
68+
"new_version": "1.7.2",
69+
"url": "https:\/\/wordpress.org\/plugins\/hello-dolly\/",
70+
"package": "https:\/\/downloads.wordpress.org\/plugin\/hello-dolly.1.7.3.zip",
71+
"icons": {
72+
"2x": "https:\/\/ps.w.org\/hello-dolly\/assets\/icon-256x256.jpg?rev=2052855",
73+
"1x": "https:\/\/ps.w.org\/hello-dolly\/assets\/icon-128x128.jpg?rev=2052855"
74+
},
75+
"banners": {
76+
"2x": "https:\/\/ps.w.org\/hello-dolly\/assets\/banner-1544x500.jpg?rev=2645582",
77+
"1x": "https:\/\/ps.w.org\/hello-dolly\/assets\/banner-772x250.jpg?rev=2052855"
78+
},
79+
"banners_rtl": [],
80+
"requires": "4.6"
81+
}
82+
}
83+
}

wp_api_integration_tests/tests/test_plugin_directory.rs

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use wp_api::wordpress_org::{
66
},
77
plugin_directory::PluginInformation,
88
};
9+
910
use wp_api_integration_tests::AsyncWpNetworking;
1011

1112
const FETCH_PLUGIN_INFORMATION_RETRY_COUNT: usize = 5;

0 commit comments

Comments
 (0)