Fix the list related tests to change the updatable list back
Otherwise every odd number of test runs, there will be a change in test/lists/updatable.list for Git.
This commit is contained in:
parent
7d056b5008
commit
4f622923fd
|
@ -0,0 +1,3 @@
|
||||||
|
[development]
|
||||||
|
address = "0.0.0.0"
|
||||||
|
port = 3000
|
|
@ -112,13 +112,11 @@ mod tests {
|
||||||
let mut res = client.get("/lists/updatable").header(Accept::JSON).dispatch();
|
let mut res = client.get("/lists/updatable").header(Accept::JSON).dispatch();
|
||||||
let body = res.body_string().unwrap();
|
let body = res.body_string().unwrap();
|
||||||
let list = serde_json::from_str::<List>(body.as_str()).unwrap();
|
let list = serde_json::from_str::<List>(body.as_str()).unwrap();
|
||||||
// Switch contentA with contentB and vice versa
|
assert_eq!(list.data, "Some content");
|
||||||
let new_data = if list.data == "contentA" {
|
|
||||||
"contentB"
|
// Try to change the list data, then verify it was changed
|
||||||
} else {
|
let new_data = "New content";
|
||||||
"contentA"
|
let mut new_json: serde_json::Value = json!({
|
||||||
};
|
|
||||||
let new_json = json!({
|
|
||||||
"id": "updatable",
|
"id": "updatable",
|
||||||
"index": 1,
|
"index": 1,
|
||||||
"data": new_data,
|
"data": new_data,
|
||||||
|
@ -129,8 +127,6 @@ mod tests {
|
||||||
"name": "Updatable",
|
"name": "Updatable",
|
||||||
"path": "test/lists/updatablelist"
|
"path": "test/lists/updatablelist"
|
||||||
});
|
});
|
||||||
|
|
||||||
// Try to change the list data, then verify it was changed
|
|
||||||
let res = client.put("/lists/updatable")
|
let res = client.put("/lists/updatable")
|
||||||
.header(ContentType::JSON)
|
.header(ContentType::JSON)
|
||||||
.body(new_json.to_string())
|
.body(new_json.to_string())
|
||||||
|
@ -144,6 +140,14 @@ mod tests {
|
||||||
let list = serde_json::from_str::<List>(body.as_str()).unwrap();
|
let list = serde_json::from_str::<List>(body.as_str()).unwrap();
|
||||||
assert_eq!(list.data, new_data);
|
assert_eq!(list.data, new_data);
|
||||||
|
|
||||||
|
// ... and change it back
|
||||||
|
*new_json.get_mut("data").unwrap() = json!("Some content");
|
||||||
|
let res = client.put("/lists/updatable")
|
||||||
|
.header(ContentType::JSON)
|
||||||
|
.body(new_json.to_string())
|
||||||
|
.dispatch();
|
||||||
|
assert_eq!(res.status(), Status::Ok);
|
||||||
|
|
||||||
// Try to change a list that doesn't exist
|
// Try to change a list that doesn't exist
|
||||||
let res = client.put("/lists/doesntexit")
|
let res = client.put("/lists/doesntexit")
|
||||||
.header(ContentType::JSON)
|
.header(ContentType::JSON)
|
||||||
|
|
|
@ -116,20 +116,22 @@ mod tests {
|
||||||
let list = lists.iter_mut()
|
let list = lists.iter_mut()
|
||||||
.find(|list| list.id == "updatable")
|
.find(|list| list.id == "updatable")
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
assert_eq!(list.data, "Some content");
|
||||||
|
|
||||||
let new_data = match list.data.as_ref() {
|
// Update the data van verify it has changed
|
||||||
"contentA" => "contentB",
|
let new_data = "New content";
|
||||||
_ => "contentA"
|
|
||||||
};
|
|
||||||
list.update_data(&String::from(new_data));
|
list.update_data(&String::from(new_data));
|
||||||
assert_eq!(list.data, new_data);
|
assert_eq!(list.data, new_data);
|
||||||
|
|
||||||
// Verify that the data is written to the file of the list by
|
// Verify that the data is written to the file of the list by
|
||||||
// loading them again
|
// loading them again
|
||||||
let lists = List::load_all(Some("test"));
|
let mut lists = List::load_all(Some("test"));
|
||||||
let list = lists.iter()
|
let list = lists.iter_mut()
|
||||||
.find(|list| list.id == "updatable")
|
.find(|list| list.id == "updatable")
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(list.data, new_data);
|
assert_eq!(list.data, new_data);
|
||||||
|
|
||||||
|
// ... and change it back again
|
||||||
|
list.update_data(&String::from("Some content"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
contentB
|
Some content
|
Loading…
Reference in New Issue