Side types overhaul (#762)

* side types overhaul

* fixes, fmt clippy

* migration fix for v3 bug

* fixed migration issues

* more tested migration changes

* fmt, clippy

* bump cicd

---------

Co-authored-by: Geometrically <18202329+Geometrically@users.noreply.github.com>
This commit is contained in:
Wyatt Verchere
2023-11-28 10:36:59 -08:00
committed by GitHub
parent fd18185ef0
commit f731c1080d
28 changed files with 957 additions and 555 deletions

View File

@@ -112,7 +112,7 @@ async fn creating_loader_fields() {
Some(
serde_json::from_value(json!([{
"op": "remove",
"path": "/client_side"
"path": "/singleplayer"
}]))
.unwrap(),
),
@@ -183,7 +183,7 @@ async fn creating_loader_fields() {
json!(1),
json!([1]),
json!("1.20.1"),
json!(["client_side"]),
json!(["singleplayer"]),
] {
// TODO: - Create project
// - Create version
@@ -271,12 +271,12 @@ async fn creating_loader_fields() {
"value": ["1.20.1", "1.20.2"]
}, {
"op": "add",
"path": "/client_side",
"value": "optional"
"path": "/singleplayer",
"value": false
}, {
"op": "add",
"path": "/server_side",
"value": "required"
"path": "/server_only",
"value": true
}]))
.unwrap(),
),
@@ -287,16 +287,16 @@ async fn creating_loader_fields() {
v.fields.get("game_versions").unwrap(),
&json!(["1.20.1", "1.20.2"])
);
assert_eq!(v.fields.get("client_side").unwrap(), &json!("optional"));
assert_eq!(v.fields.get("server_side").unwrap(), &json!("required"));
assert_eq!(v.fields.get("singleplayer").unwrap(), &json!(false));
assert_eq!(v.fields.get("server_only").unwrap(), &json!(true));
// - Patch
let resp = api
.edit_version(
alpha_version_id,
json!({
"game_versions": ["1.20.1", "1.20.2"],
"client_side": "optional",
"server_side": "required"
"singleplayer": false,
"server_only": true
}),
USER_USER_PAT,
)
@@ -314,16 +314,13 @@ async fn creating_loader_fields() {
}
#[actix_rt::test]
async fn get_loader_fields() {
async fn get_loader_fields_variants() {
with_test_environment(None, |test_env: TestEnvironment<ApiV3>| async move {
let api = &test_env.api;
let game_versions = api
.get_loader_field_variants_deserialized("game_versions")
.await;
let side_types = api
.get_loader_field_variants_deserialized("client_side")
.await;
// These tests match dummy data and will need to be updated if the dummy data changes
// Versions should be ordered by:
@@ -348,18 +345,64 @@ async fn get_loader_fields() {
"1.20.1"
]
);
let side_type_names = side_types
.into_iter()
.map(|x| x.value)
.collect::<HashSet<_>>();
assert_eq!(
side_type_names,
["unknown", "required", "optional", "unsupported"]
.iter()
.map(|s| s.to_string())
.collect()
);
})
.await
}
#[actix_rt::test]
async fn get_available_loader_fields() {
// Get available loader fields for a given loader
// (ie: which fields are relevant for 'fabric', etc)
with_test_environment(None, |test_env: TestEnvironment<ApiV3>| async move {
let api = &test_env.api;
let loaders = api.get_loaders_deserialized().await;
let fabric_loader_fields = loaders
.iter()
.find(|x| x.name == "fabric")
.unwrap()
.supported_fields
.clone()
.into_iter()
.collect::<HashSet<_>>();
assert_eq!(
fabric_loader_fields,
[
"game_versions",
"singleplayer",
"client_and_server",
"client_only",
"server_only",
"test_fabric_optional" // exists for testing
]
.iter()
.map(|s| s.to_string())
.collect()
);
let mrpack_loader_fields = loaders
.iter()
.find(|x| x.name == "mrpack")
.unwrap()
.supported_fields
.clone()
.into_iter()
.collect::<HashSet<_>>();
assert_eq!(
mrpack_loader_fields,
[
"game_versions",
"singleplayer",
"client_and_server",
"client_only",
"server_only",
// mrpack has all the general fields as well as this
"mrpack_loaders"
]
.iter()
.map(|s| s.to_string())
.collect()
);
})
.await;
}