aboutsummaryrefslogtreecommitdiffstats
path: root/rust/tests
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2018-11-14 18:52:48 -0800
committerBryan Newbold <bnewbold@robocracy.org>2018-11-14 18:52:50 -0800
commit54c4b6cd67c7f8190dc7dfb4da6ad99dc2101c82 (patch)
treef121a1deebef99a639ff82bc241eb44f2d5bc8ef /rust/tests
parent610b0a6550c758529cf6c34587f45e483a240df4 (diff)
downloadfatcat-54c4b6cd67c7f8190dc7dfb4da6ad99dc2101c82.tar.gz
fatcat-54c4b6cd67c7f8190dc7dfb4da6ad99dc2101c82.zip
fix date/datetime confusion on rust/API side
Should have dug in to this earlier; python code was getting confused. This is a breaking API change, from a practical standpoint, as both python and rust code had been hacked to work around this.
Diffstat (limited to 'rust/tests')
-rw-r--r--rust/tests/test_api_server_http.rs66
1 files changed, 66 insertions, 0 deletions
diff --git a/rust/tests/test_api_server_http.rs b/rust/tests/test_api_server_http.rs
index 6266a747..6df616a6 100644
--- a/rust/tests/test_api_server_http.rs
+++ b/rust/tests/test_api_server_http.rs
@@ -416,6 +416,7 @@ fn test_post_release() {
// TODO: target_release_id
r#"{"title": "secret paper",
"release_type": "journal-article",
+ "release_date": "2000-01-02",
"doi": "10.1234/abcde.781231231239",
"pmid": "54321",
"pmcid": "PMC12345",
@@ -1024,3 +1025,68 @@ fn test_post_batch_autoaccept() {
None,
);
}
+
+#[test]
+fn test_release_dates() {
+ let (headers, router, _conn) = setup_http();
+
+ // Ok
+ check_http_response(
+ request::post(
+ "http://localhost:9411/v0/release",
+ headers.clone(),
+ r#"{"title": "secret minimal paper",
+ "release_type": "journal-article",
+ "release_date": "2000-01-02"
+ }"#,
+ &router,
+ ),
+ status::Created,
+ None,
+ );
+
+ // Bad: year/month only
+ check_http_response(
+ request::post(
+ "http://localhost:9411/v0/release",
+ headers.clone(),
+ r#"{"title": "secret minimal paper",
+ "release_type": "journal-article",
+ "release_date": "2000-01"
+ }"#,
+ &router,
+ ),
+ status::BadRequest,
+ None,
+ );
+
+ // Bad: full timestamp
+ check_http_response(
+ request::post(
+ "http://localhost:9411/v0/release",
+ headers.clone(),
+ r#"{"title": "secret minimal paper",
+ "release_type": "journal-article",
+ "release_date": "2005-08-30T00:00:00Z"
+ }"#,
+ &router,
+ ),
+ status::BadRequest,
+ None,
+ );
+
+ // Bad: bogus month/day
+ check_http_response(
+ request::post(
+ "http://localhost:9411/v0/release",
+ headers.clone(),
+ r#"{"title": "secret minimal paper",
+ "release_type": "journal-article",
+ "release_date": "2000-88-99"
+ }"#,
+ &router,
+ ),
+ status::BadRequest,
+ None,
+ );
+}