From 54c4b6cd67c7f8190dc7dfb4da6ad99dc2101c82 Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Wed, 14 Nov 2018 18:52:48 -0800 Subject: 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. --- rust/tests/test_api_server_http.rs | 66 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) (limited to 'rust/tests') 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, + ); +} -- cgit v1.2.3