mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-04-25 15:16:07 +00:00
Test /read endpoint for single partition case
This commit is contained in:
@@ -9,6 +9,7 @@ use test_util::*;
|
|||||||
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
use std::borrow::Cow;
|
||||||
|
|
||||||
use librojo::{
|
use librojo::{
|
||||||
session::Session,
|
session::Session,
|
||||||
@@ -86,7 +87,7 @@ fn one_partition() {
|
|||||||
assert_eq!(response.partitions, partitions);
|
assert_eq!(response.partitions, partitions);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
let check_base_read_all = || {
|
||||||
let body = server.get_string("/api/read_all");
|
let body = server.get_string("/api/read_all");
|
||||||
let response = serde_json::from_str::<ReadAllResponse>(&body).unwrap();
|
let response = serde_json::from_str::<ReadAllResponse>(&body).unwrap();
|
||||||
|
|
||||||
@@ -96,18 +97,18 @@ fn one_partition() {
|
|||||||
assert_eq!(response.message_cursor, -1);
|
assert_eq!(response.message_cursor, -1);
|
||||||
assert_eq!(response.instances.len(), 4); // root and three children
|
assert_eq!(response.instances.len(), 4); // root and three children
|
||||||
|
|
||||||
let mut found_root = false;
|
let mut root_id = None;
|
||||||
let mut found_module = false;
|
let mut module_id = None;
|
||||||
let mut found_client = false;
|
let mut client_id = None;
|
||||||
let mut found_server = false;
|
let mut server_id = None;
|
||||||
|
|
||||||
for (id, instance) in response.instances.iter() {
|
for (id, instance) in response.instances.iter() {
|
||||||
match instance.class_name.as_str() {
|
match instance.class_name.as_str() {
|
||||||
// TOOD: Should partition roots (and other directories) be some
|
// TOOD: Should partition roots (and other directories) be some
|
||||||
// magical object instead of Folder?
|
// magical object instead of Folder?
|
||||||
"Folder" => {
|
"Folder" => {
|
||||||
assert!(!found_root);
|
assert!(root_id.is_none());
|
||||||
found_root = true;
|
root_id = Some(*id);
|
||||||
|
|
||||||
assert_eq!(*id, partition_id);
|
assert_eq!(*id, partition_id);
|
||||||
|
|
||||||
@@ -118,10 +119,17 @@ fn one_partition() {
|
|||||||
assert_eq!(instance.properties.len(), 0);
|
assert_eq!(instance.properties.len(), 0);
|
||||||
assert_eq!(instance.parent, None);
|
assert_eq!(instance.parent, None);
|
||||||
assert_eq!(instance.children.len(), 3);
|
assert_eq!(instance.children.len(), 3);
|
||||||
|
|
||||||
|
let single_body = server.get_string(&format!("/api/read/{}", id));
|
||||||
|
let single_response = serde_json::from_str::<ReadResponse>(&single_body).unwrap();
|
||||||
|
|
||||||
|
let single_instance = single_response.instances.get(id).unwrap();
|
||||||
|
|
||||||
|
assert_eq!(single_instance, &Cow::Borrowed(instance));
|
||||||
},
|
},
|
||||||
"ModuleScript" => {
|
"ModuleScript" => {
|
||||||
assert!(!found_module);
|
assert!(module_id.is_none());
|
||||||
found_module = true;
|
module_id = Some(*id);
|
||||||
|
|
||||||
let mut properties = HashMap::new();
|
let mut properties = HashMap::new();
|
||||||
properties.insert("Source".to_string(), "-- a.lua".to_string());
|
properties.insert("Source".to_string(), "-- a.lua".to_string());
|
||||||
@@ -130,10 +138,17 @@ fn one_partition() {
|
|||||||
assert_eq!(instance.properties, properties);
|
assert_eq!(instance.properties, properties);
|
||||||
assert_eq!(instance.parent, Some(partition_id));
|
assert_eq!(instance.parent, Some(partition_id));
|
||||||
assert_eq!(instance.children.len(), 0);
|
assert_eq!(instance.children.len(), 0);
|
||||||
|
|
||||||
|
let single_body = server.get_string(&format!("/api/read/{}", id));
|
||||||
|
let single_response = serde_json::from_str::<ReadResponse>(&single_body).unwrap();
|
||||||
|
|
||||||
|
let single_instance = single_response.instances.get(id).unwrap();
|
||||||
|
|
||||||
|
assert_eq!(single_instance, &Cow::Borrowed(instance));
|
||||||
},
|
},
|
||||||
"LocalScript" => {
|
"LocalScript" => {
|
||||||
assert!(!found_client);
|
assert!(client_id.is_none());
|
||||||
found_client = true;
|
client_id = Some(*id);
|
||||||
|
|
||||||
let mut properties = HashMap::new();
|
let mut properties = HashMap::new();
|
||||||
properties.insert("Source".to_string(), "-- b.client.lua".to_string());
|
properties.insert("Source".to_string(), "-- b.client.lua".to_string());
|
||||||
@@ -142,10 +157,17 @@ fn one_partition() {
|
|||||||
assert_eq!(instance.properties, properties);
|
assert_eq!(instance.properties, properties);
|
||||||
assert_eq!(instance.parent, Some(partition_id));
|
assert_eq!(instance.parent, Some(partition_id));
|
||||||
assert_eq!(instance.children.len(), 0);
|
assert_eq!(instance.children.len(), 0);
|
||||||
|
|
||||||
|
let single_body = server.get_string(&format!("/api/read/{}", id));
|
||||||
|
let single_response = serde_json::from_str::<ReadResponse>(&single_body).unwrap();
|
||||||
|
|
||||||
|
let single_instance = single_response.instances.get(id).unwrap();
|
||||||
|
|
||||||
|
assert_eq!(single_instance, &Cow::Borrowed(instance));
|
||||||
},
|
},
|
||||||
"Script" => {
|
"Script" => {
|
||||||
assert!(!found_server);
|
assert!(server_id.is_none());
|
||||||
found_server = true;
|
server_id = Some(*id);
|
||||||
|
|
||||||
let mut properties = HashMap::new();
|
let mut properties = HashMap::new();
|
||||||
properties.insert("Source".to_string(), "-- a.server.lua".to_string());
|
properties.insert("Source".to_string(), "-- a.server.lua".to_string());
|
||||||
@@ -154,17 +176,26 @@ fn one_partition() {
|
|||||||
assert_eq!(instance.properties, properties);
|
assert_eq!(instance.properties, properties);
|
||||||
assert_eq!(instance.parent, Some(partition_id));
|
assert_eq!(instance.parent, Some(partition_id));
|
||||||
assert_eq!(instance.children.len(), 0);
|
assert_eq!(instance.children.len(), 0);
|
||||||
|
|
||||||
|
let single_body = server.get_string(&format!("/api/read/{}", id));
|
||||||
|
let single_response = serde_json::from_str::<ReadResponse>(&single_body).unwrap();
|
||||||
|
|
||||||
|
let single_instance = single_response.instances.get(id).unwrap();
|
||||||
|
|
||||||
|
assert_eq!(single_instance, &Cow::Borrowed(instance));
|
||||||
},
|
},
|
||||||
_ => panic!("Unexpected instance!"),
|
_ => panic!("Unexpected instance!"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
assert!(found_root);
|
module_id.unwrap();
|
||||||
assert!(found_module);
|
client_id.unwrap();
|
||||||
assert!(found_client);
|
server_id.unwrap();
|
||||||
assert!(found_server);
|
|
||||||
}
|
root_id.unwrap()
|
||||||
|
};
|
||||||
|
|
||||||
|
check_base_read_all();
|
||||||
|
|
||||||
// TODO: Test /read
|
|
||||||
// TODO: Test /subscribe
|
// TODO: Test /subscribe
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user