/* * This file contains API server tests that hit the API by connecting via the Iron client, * essentially doing raw HTTP/JSON requests. * * These tests are relatively simple and don't mutate much database state; they are primarily to * test basic serialization/deserialization, and take advantage of hard-coded example entities. */ extern crate diesel; extern crate fatcat; extern crate fatcat_api_spec; extern crate iron; extern crate iron_test; extern crate uuid; use diesel::prelude::*; use fatcat::api_helpers::*; use fatcat::database_schema::*; use iron::status; use iron_test::request; use uuid::Uuid; mod helpers; use helpers::{check_http_response, setup_http}; #[test] fn test_entity_gets() { let (headers, router, _conn) = setup_http(); check_http_response( request::get( "http://localhost:9411/v0/container/aaaaaaaaaaaaaeiraaaaaaaaai", headers.clone(), &router, ), status::Ok, Some("Trivial Results"), ); // Check revision encoding check_http_response( request::get( "http://localhost:9411/v0/container/aaaaaaaaaaaaaeiraaaaaaaaai", headers.clone(), &router, ), status::Ok, Some("00000000-0000-0000-1111-fff000000002"), ); check_http_response( request::get( "http://localhost:9411/v0/creator/aaaaaaaaaaaaaircaaaaaaaaae", headers.clone(), &router, ), status::Ok, Some("Grace Hopper"), ); check_http_response( request::get( "http://localhost:9411/v0/file/aaaaaaaaaaaaamztaaaaaaaaai", headers.clone(), &router, ), status::Ok, Some("archive.org"), ); check_http_response( request::get( "http://localhost:9411/v0/fileset/aaaaaaaaaaaaaztgaaaaaaaaam", headers.clone(), &router, ), status::Ok, Some(".tar.gz"), ); check_http_response( request::get( "http://localhost:9411/v0/webcapture/aaaaaaaaaaaaa53xaaaaaaaaam", headers.clone(), &router, ), status::Ok, Some("asheesh.org"), ); check_http_response( request::get( "http://localhost:9411/v0/release/aaaaaaaaaaaaarceaaaaaaaaai", headers.clone(), &router, ), status::Ok, Some("bigger example"), ); // expand keyword check_http_response( request::get( "http://localhost:9411/v0/release/aaaaaaaaaaaaarceaaaaaaaaai?expand=container", headers.clone(), &router, ), status::Ok, Some("MySpace Blog"), ); // hide keyword check_http_response( request::get( "http://localhost:9411/v0/release/aaaaaaaaaaaaarceaaaaaaaaai?hide=refs,container", headers.clone(), &router, ), status::Ok, Some("bigger example"), ); check_http_response( request::get( "http://localhost:9411/v0/work/aaaaaaaaaaaaavkvaaaaaaaaai", headers.clone(), &router, ), status::Ok, None, ); } #[test] fn test_entity_404() { let (headers, router, _conn) = setup_http(); check_http_response( request::get( "http://localhost:9411/v0/creator/aaaaaaaaaaaaairceeeeeeeeee", headers.clone(), &router, ), status::NotFound, None, ); } #[test] fn test_entity_history() { let (headers, router, _conn) = setup_http(); check_http_response( request::get( "http://localhost:9411/v0/container/aaaaaaaaaaaaaeiraaaaaaaaai/history", headers.clone(), &router, ), status::Ok, Some("changelog"), ); check_http_response( request::get( "http://localhost:9411/v0/creator/aaaaaaaaaaaaaircaaaaaaaaae/history", headers.clone(), &router, ), status::Ok, Some("changelog"), ); check_http_response( request::get( "http://localhost:9411/v0/file/aaaaaaaaaaaaamztaaaaaaaaam/history", headers.clone(), &router, ), status::Ok, Some("changelog"), ); check_http_response( request::get( "http://localhost:9411/v0/fileset/aaaaaaaaaaaaaztgaaaaaaaaam/history", headers.clone(), &router, ), status::Ok, Some("changelog"), ); check_http_response( request::get( "http://localhost:9411/v0/webcapture/aaaaaaaaaaaaa53xaaaaaaaaam/history", headers.clone(), &router, ), status::Ok, Some("changelog"), ); check_http_response( request::get( "http://localhost:9411/v0/release/aaaaaaaaaaaaarceaaaaaaaaai/history", headers.clone(), &router, ), status::Ok, Some("changelog"), ); check_http_response( request::get( "http://localhost:9411/v0/work/aaaaaaaaaaaaavkvaaaaaaaaai/history", headers.clone(), &router, ), status::Ok, Some("changelog"), ); } #[test] fn test_lookups() { let (headers, router, _conn) = setup_http(); check_http_response( request::get( "http://localhost:9411/v0/container/lookup?issnl=1234-0000", headers.clone(), &router, ), status::NotFound, None, ); check_http_response( request::get( "http://localhost:9411/v0/container/lookup?issnl=1234", headers.clone(), &router, ), status::BadRequest, None, ); check_http_response( request::get( "http://localhost:9411/v0/container/lookup?wikidata_qid=Q84913959359", headers.clone(), &router, ), status::NotFound, None, ); check_http_response( request::get( "http://localhost:9411/v0/container/lookup?wikidata_qid=84913959359", headers.clone(), &router, ), status::BadRequest, None, ); check_http_response( request::get( "http://localhost:9411/v0/container/lookup?wikidata_qid=Q84913959359&issnl=1234-0000", headers.clone(), &router, ), status::BadRequest, None, ); check_http_response( request::get( "http://localhost:9411/v0/creator/lookup?orcid=0000-0003-2088-7465", headers.clone(), &router, ), status::Ok, Some("Christine Moran"), ); check_http_response( request::get( "http://localhost:9411/v0/creator/lookup?wikidata_qid=Q5678", headers.clone(), &router, ), status::Ok, Some("John P. A. Ioannidis"), ); check_http_response( request::get( "http://localhost:9411/v0/creator/lookup?orcid=0000-0003-2088-0000", headers.clone(), &router, ), status::NotFound, None, ); check_http_response( request::get( "http://localhost:9411/v0/file/lookup?md5=00000000000ab9fdc2a128f962faebff", headers.clone(), &router, ), status::NotFound, None, ); check_http_response( request::get( "http://localhost:9411/v0/file/lookup?md5=00000000000ab9fdc2a128f962faebfff", headers.clone(), &router, ), status::BadRequest, None, ); check_http_response( request::get( "http://localhost:9411/v0/file/lookup?md5=f4de91152c7ab9fdc2a128f962faebff", headers.clone(), &router, ), status::Ok, Some("0020124&type=printable"), ); check_http_response( request::get( "http://localhost:9411/v0/file/lookup?sha1=7d97e98f8af710c7e7fe703abc8f639e0ee507c4", headers.clone(), &router, ), status::Ok, Some("robots.txt"), ); check_http_response( request::get( "http://localhost:9411/v0/file/lookup?sha256=ffc1005680cb620eec4c913437dfabbf311b535cfe16cbaeb2faec1f92afc362", headers.clone(), &router, ), status::Ok, Some("0020124&type=printable"), ); check_http_response( request::get( "http://localhost:9411/v0/file/lookup?sha1=00000000000000c7e7fe703abc8f639e0ee507c4", headers.clone(), &router, ), status::NotFound, None, ); // not URL encoded check_http_response( request::get( "http://localhost:9411/v0/release/lookup?doi=10.123/abc", headers.clone(), &router, ), status::Ok, Some("bigger example"), ); // URL encoded check_http_response( request::get( "http://localhost:9411/v0/release/lookup?doi=10.123%2Fabc", headers.clone(), &router, ), status::Ok, Some("bigger example"), ); check_http_response( request::get( "http://localhost:9411/v0/release/lookup?wikidata_qid=Q55555", headers.clone(), &router, ), status::Ok, Some("bigger example"), ); check_http_response( request::get( "http://localhost:9411/v0/release/lookup?pmid=54321", headers.clone(), &router, ), status::Ok, Some("bigger example"), ); check_http_response( request::get( "http://localhost:9411/v0/release/lookup?pmcid=PMC555", headers.clone(), &router, ), status::Ok, Some("bigger example"), ); check_http_response( request::get( "http://localhost:9411/v0/release/lookup?isbn13=978-3-16-148410-0", headers.clone(), &router, ), status::Ok, Some("bigger example"), ); check_http_response( request::get( "http://localhost:9411/v0/release/lookup?core_id=42022773", headers.clone(), &router, ), status::Ok, Some("bigger example"), ); } #[test] fn test_reverse_lookups() { let (headers, router, _conn) = setup_http(); check_http_response( request::get( "http://localhost:9411/v0/creator/aaaaaaaaaaaaaircaaaaaaaaai/releases", headers.clone(), &router, ), status::Ok, Some("bigger example"), ); check_http_response( request::get( "http://localhost:9411/v0/release/aaaaaaaaaaaaarceaaaaaaaaai/files", headers.clone(), &router, ), status::Ok, Some("7d97e98f8af710c7e7fe703abc8f639e0ee507c4"), ); check_http_response( request::get( "http://localhost:9411/v0/release/aaaaaaaaaaaaarceaaaaaaaaai/filesets", headers.clone(), &router, ), status::Ok, Some("README.md"), ); check_http_response( request::get( "http://localhost:9411/v0/release/aaaaaaaaaaaaarceaaaaaaaaai/webcaptures", headers.clone(), &router, ), status::Ok, Some("http://example.org"), ); check_http_response( request::get( "http://localhost:9411/v0/work/aaaaaaaaaaaaavkvaaaaaaaaai/releases", headers.clone(), &router, ), status::Ok, Some("bigger example"), ); } #[test] fn test_post_container() { let (headers, router, _conn) = setup_http(); check_http_response( request::post( "http://localhost:9411/v0/container", headers, r#"{"name": "test journal"}"#, &router, ), status::Created, None, ); // TODO: "test journal" } #[test] fn test_post_batch_container() { let (headers, router, _conn) = setup_http(); check_http_response( request::post( "http://localhost:9411/v0/container/batch", headers, r#"[{"name": "test journal"}, {"name": "another test journal"}]"#, &router, ), status::Created, None, ); // TODO: "test journal" } #[test] fn test_post_creator() { let (headers, router, _conn) = setup_http(); check_http_response( request::post( "http://localhost:9411/v0/creator", headers, r#"{"display_name": "some person"}"#, &router, ), status::Created, None, ); } #[test] fn test_post_file() { let (headers, router, conn) = setup_http(); check_http_response( request::post( "http://localhost:9411/v0/file", headers.clone(), r#"{ }"#, &router, ), status::Created, None, ); check_http_response( request::post( "http://localhost:9411/v0/file", headers.clone(), r#"{"size": 76543, "sha1": "f0000000000000008b7eb2a93e6d0440c1f3e7f8", "md5": "0b6d347b01d437a092be84c2edfce72c", "sha256": "a77e4c11a57f1d757fca5754a8f83b5d4ece49a2d28596889127c1a2f3f28832", "urls": [ {"url": "http://archive.org/asdf.txt", "rel": "web" }, {"url": "http://web.archive.org/2/http://archive.org/asdf.txt", "rel": "webarchive" } ], "mimetype": "application/pdf", "releases": [ "aaaaaaaaaaaaarceaaaaaaaaae", "aaaaaaaaaaaaarceaaaaaaaaai" ], "extra": { "source": "speculation" } }"#, &router, ), status::Created, None, ); let editor_id = Uuid::parse_str("00000000-0000-0000-AAAA-000000000001").unwrap(); let editgroup_id = get_or_create_editgroup(editor_id, &conn).unwrap(); check_http_response( request::post( &format!( "http://localhost:9411/v0/editgroup/{}/accept", uuid2fcid(&editgroup_id) ), headers.clone(), "", &router, ), status::Ok, None, ); check_http_response( request::get( "http://localhost:9411/v0/file/lookup?sha1=f0000000000000008b7eb2a93e6d0440c1f3e7f8", headers.clone(), &router, ), status::Ok, Some("web.archive.org/2/http"), ); } #[test] fn test_post_fileset() { let (headers, router, conn) = setup_http(); check_http_response( request::post( "http://localhost:9411/v0/fileset", headers.clone(), r#"{ }"#, &router, ), status::Created, None, ); check_http_response( request::post( "http://localhost:9411/v0/fileset", headers.clone(), r#"{"manifest": [ {"path": "new_file.txt", "size": 12345, "sha1": "e9dd75237c94b209dc3ccd52722de6931a310ba3" }, {"path": "output/bogus.hdf5", "size": 43210, "sha1": "e9dd75237c94b209dc3ccd52722de6931a310ba3", "extra": {"some": "other value"} } ], "urls": [ {"url": "http://archive.org/download/dataset-0123/", "rel": "archive" }, {"url": "http://homepage.name/dataset/", "rel": "web" } ], "releases": [ "aaaaaaaaaaaaarceaaaaaaaaae", "aaaaaaaaaaaaarceaaaaaaaaai" ], "extra": { "source": "speculation" } }"#, &router, ), status::Created, None, ); let editor_id = Uuid::parse_str("00000000-0000-0000-AAAA-000000000001").unwrap(); let editgroup_id = get_or_create_editgroup(editor_id, &conn).unwrap(); check_http_response( request::post( &format!( "http://localhost:9411/v0/editgroup/{}/accept", uuid2fcid(&editgroup_id) ), headers.clone(), "", &router, ), status::Ok, None, ); // TODO: there is no lookup for filesets } #[test] fn test_post_webcapture() { let (headers, router, conn) = setup_http(); check_http_response( request::post( "http://localhost:9411/v0/webcapture", headers.clone(), r#"{ "original_url": "https://fatcat.wiki", "timestamp": "2018-12-28T11:11:11Z" }"#, &router, ), status::Created, None, ); check_http_response( request::post( "http://localhost:9411/v0/webcapture", headers.clone(), r#"{"original_url": "https://bnewbold.net/", "timestamp": "2018-12-28T05:06:07Z", "cdx": [ {"surt": "org,asheesh,)/robots.txt", "timestamp": 20181228050607, "url": "https://asheesh.org/robots.txt", "status_code": 200, "mimetype": "text/html", "sha1": "e9dd75237c94b209dc3ccd52722de6931a310ba3" } ], "archive_urls": [ {"url": "http://archive.org/download/dataset-0123/", "rel": "archive" }, {"url": "http://homepage.name/dataset/", "rel": "web" } ], "releases": [ "aaaaaaaaaaaaarceaaaaaaaaae", "aaaaaaaaaaaaarceaaaaaaaaai" ], "extra": { "source": "speculation" } }"#, &router, ), status::Created, None, ); let editor_id = Uuid::parse_str("00000000-0000-0000-AAAA-000000000001").unwrap(); let editgroup_id = get_or_create_editgroup(editor_id, &conn).unwrap(); check_http_response( request::post( &format!( "http://localhost:9411/v0/editgroup/{}/accept", uuid2fcid(&editgroup_id) ), headers.clone(), "", &router, ), status::Ok, None, ); // TODO: there is no lookup for filesets } #[test] fn test_post_release() { let (headers, router, _conn) = setup_http(); check_http_response( request::post( "http://localhost:9411/v0/release", headers.clone(), // TODO: target_release_id r#"{"title": "secret minimal paper", "release_type": "article-journal", "work_id": "aaaaaaaaaaaaavkvaaaaaaaaae" }"#, &router, ), status::Created, None, ); // TODO: "secret paper" // No work_id supplied (auto-created) check_http_response( request::post( "http://localhost:9411/v0/release", headers.clone(), // TODO: target_release_id r#"{"title": "secret minimal paper the second", "release_type": "article-journal" }"#, &router, ), status::Created, None, ); check_http_response( request::post( "http://localhost:9411/v0/release", headers.clone(), // TODO: target_release_id r#"{"title": "secret paper", "release_type": "article-journal", "release_date": "2000-01-02", "release_year": 2000, "doi": "10.1234/abcde.781231231239", "pmid": "54321", "pmcid": "PMC12345", "wikidata_qid": "Q12345", "core_id": "7890", "volume": "439", "issue": "IV", "pages": "1-399", "work_id": "aaaaaaaaaaaaavkvaaaaaaaaai", "container_id": "aaaaaaaaaaaaaeiraaaaaaaaae", "refs": [{ "index": 3, "raw": "just a string" },{ "raw": "just a string" }], "contribs": [{ "index": 1, "raw_name": "textual description of contributor (aka, name)", "creator_id": "aaaaaaaaaaaaaircaaaaaaaaae", "role": "author" },{ "raw_name": "shorter" }], "extra": { "source": "speculation" } }"#, &router, ), status::Created, None, ); // TODO: "secret paper" // Bogus non-existant fields /* XXX: doesn't fail check_http_response( request::post( "http://localhost:9411/v0/release", headers.clone(), r#"{"title": "secret minimal paper the second", "asdf123": "lalala" }"#, &router, ), status::BadRequest, None, ); */ } #[test] fn test_post_work() { let (headers, router, _conn) = setup_http(); check_http_response( request::post( "http://localhost:9411/v0/work", headers.clone(), // TODO: target_work_id r#"{ "extra": { "source": "speculation" } }"#, &router, ), status::Created, None, ); } #[test] fn test_update_work() { let (headers, router, conn) = setup_http(); check_http_response( request::post( "http://localhost:9411/v0/work", headers.clone(), r#"{ "extra": { "source": "other speculation" } }"#, &router, ), status::Created, None, ); let editor_id = Uuid::parse_str("00000000-0000-0000-AAAA-000000000001").unwrap(); let editgroup_id = get_or_create_editgroup(editor_id, &conn).unwrap(); check_http_response( request::post( &format!( "http://localhost:9411/v0/editgroup/{}/accept", uuid2fcid(&editgroup_id) ), headers.clone(), "", &router, ), status::Ok, None, ); } #[test] fn test_delete_work() { let (headers, router, conn) = setup_http(); check_http_response( request::delete( "http://localhost:9411/v0/work/aaaaaaaaaaaaavkvaaaaaaaaai", headers.clone(), &router, ), status::Ok, None, ); let editor_id = Uuid::parse_str("00000000-0000-0000-AAAA-000000000001").unwrap(); let editgroup_id = get_or_create_editgroup(editor_id, &conn).unwrap(); check_http_response( request::post( &format!( "http://localhost:9411/v0/editgroup/{}/accept", uuid2fcid(&editgroup_id) ), headers.clone(), "", &router, ), status::Ok, None, ); } #[test] fn test_accept_editgroup() { let (headers, router, conn) = setup_http(); let editor_id = Uuid::parse_str("00000000-0000-0000-AAAA-000000000001").unwrap(); let editgroup_id = get_or_create_editgroup(editor_id, &conn).unwrap(); let c: i64 = container_ident::table .filter(container_ident::is_live.eq(false)) .count() .get_result(&conn) .unwrap(); assert_eq!(c, 0); let c: i64 = changelog::table .filter(changelog::editgroup_id.eq(editgroup_id)) .count() .get_result(&conn) .unwrap(); assert_eq!(c, 0); check_http_response( request::post( "http://localhost:9411/v0/container", headers.clone(), &format!( "{{\"name\": \"test journal 1\", \"editgroup_id\": \"{}\"}}", uuid2fcid(&editgroup_id) ), &router, ), status::Created, None, ); check_http_response( request::post( "http://localhost:9411/v0/container", headers.clone(), &format!( "{{\"name\": \"test journal 2\", \"editgroup_id\": \"{}\"}}", uuid2fcid(&editgroup_id) ), &router, ), status::Created, None, ); let c: i64 = container_ident::table .filter(container_ident::is_live.eq(false)) .count() .get_result(&conn) .unwrap(); assert_eq!(c, 2); check_http_response( request::get( &format!( "http://localhost:9411/v0/editgroup/{}", uuid2fcid(&editgroup_id) ), headers.clone(), &router, ), status::Ok, None, ); check_http_response( request::post( &format!( "http://localhost:9411/v0/editgroup/{}/accept", uuid2fcid(&editgroup_id) ), headers.clone(), "", &router, ), status::Ok, None, ); let c: i64 = container_ident::table .filter(container_ident::is_live.eq(false)) .count() .get_result(&conn) .unwrap(); assert_eq!(c, 0); let c: i64 = changelog::table .filter(changelog::editgroup_id.eq(editgroup_id)) .count() .get_result(&conn) .unwrap(); assert_eq!(c, 1); } #[test] fn test_changelog() { let (headers, router, _conn) = setup_http(); check_http_response( request::get( "http://localhost:9411/v0/changelog", headers.clone(), &router, ), status::Ok, Some("editgroup_id"), ); check_http_response( request::get( "http://localhost:9411/v0/changelog/1", headers.clone(), &router, ), status::Ok, Some("files"), ); } #[test] fn test_400() { let (headers, router, _conn) = setup_http(); check_http_response( request::post( "http://localhost:9411/v0/release", headers, r#"{"title": "secret paper", "release_type": "article-journal", "doi": "10.1234/abcde.781231231239", "volume": "439", "issue": "IV", "pages": "1-399", "work_id": "aaaaaaaaaaaaavkvaaaaaaaaae", "container_id": "aaaaaaaaaaaaaeiraaaaaae", "refs": [{ "index": 3, "raw": "just a string" },{ "raw": "just a string" }], "contribs": [{ "index": 1, "raw_name": "textual description of contributor (aka, name)", "creator_id": "aaaaaaaaaaaaaircaaaaaaaaae", "contrib_type": "author" },{ "raw_name": "shorter" }], "extra": { "source": "speculation" } }"#, &router, ), status::BadRequest, None, ); } #[test] fn test_edit_gets() { let (headers, router, _conn) = setup_http(); check_http_response( request::get( "http://localhost:9411/v0/editor/aaaaaaaaaaaabkvkaaaaaaaaae", headers.clone(), &router, ), status::Ok, Some("admin"), ); check_http_response( request::get( "http://localhost:9411/v0/editor/aaaaaaaaaaaabkvkaaaaaaaaae/changelog", headers.clone(), &router, ), status::Ok, None, ); check_http_response( request::get( "http://localhost:9411/v0/editgroup/aaaaaaaaaaaabo53aaaaaaaaae", headers.clone(), &router, ), status::Ok, None, ); } #[test] fn test_bad_external_idents() { let (headers, router, _conn) = setup_http(); // Bad wikidata QID check_http_response( request::post( "http://localhost:9411/v0/release", headers.clone(), r#"{"title": "secret paper", "wikidata_qid": "P12345" }"#, &router, ), status::BadRequest, Some("Wikidata QID"), ); check_http_response( request::post( "http://localhost:9411/v0/container", headers.clone(), r#"{"name": "my journal", "wikidata_qid": "P12345" }"#, &router, ), status::BadRequest, Some("Wikidata QID"), ); check_http_response( request::post( "http://localhost:9411/v0/creator", headers.clone(), r#"{"display_name": "some body", "wikidata_qid": "P12345" }"#, &router, ), status::BadRequest, Some("Wikidata QID"), ); // Bad PMCID check_http_response( request::post( "http://localhost:9411/v0/release", headers.clone(), r#"{"title": "secret paper", "pmcid": "12345" }"#, &router, ), status::BadRequest, Some("PMCID"), ); // Bad PMID check_http_response( request::post( "http://localhost:9411/v0/release", headers.clone(), r#"{"title": "secret paper", "pmid": "not-a-number" }"#, &router, ), status::BadRequest, Some("PMID"), ); // Bad DOI check_http_response( request::post( "http://localhost:9411/v0/release", headers.clone(), r#"{"title": "secret paper", "doi": "asdf" }"#, &router, ), status::BadRequest, Some("DOI"), ); // Good identifiers check_http_response( request::post( "http://localhost:9411/v0/release", headers.clone(), r#"{"title": "secret paper", "doi": "10.1234/abcde.781231231239", "pmid": "54321", "pmcid": "PMC12345", "wikidata_qid": "Q12345" }"#, &router, ), status::Created, None, ); } #[test] fn test_abstracts() { let (headers, router, conn) = setup_http(); check_http_response( request::post( "http://localhost:9411/v0/release", headers.clone(), r#"{"title": "some paper", "doi": "10.1234/iiiiiii", "abstracts": [ {"lang": "zh", "mimetype": "text/plain", "content": "some rando abstract 24iu3i25u2" }, {"lang": "en", "mimetype": "application/xml+jats", "content": "some other abstract 99139405" } ] }"#, &router, ), status::Created, None, ); // Same abstracts; checking that re-inserting works check_http_response( request::post( "http://localhost:9411/v0/release", headers.clone(), r#"{"title": "some paper again", "abstracts": [ {"lang": "zh", "mimetype": "text/plain", "content": "some rando abstract 24iu3i25u2" }, {"lang": "en", "mimetype": "application/xml+jats", "content": "some other abstract 99139405" } ] }"#, &router, ), status::Created, None, ); let editor_id = Uuid::parse_str("00000000-0000-0000-AAAA-000000000001").unwrap(); let editgroup_id = get_or_create_editgroup(editor_id, &conn).unwrap(); check_http_response( request::post( &format!( "http://localhost:9411/v0/editgroup/{}/accept", uuid2fcid(&editgroup_id) ), headers.clone(), "", &router, ), status::Ok, None, ); check_http_response( request::get( "http://localhost:9411/v0/release/lookup?doi=10.1234/iiiiiii", headers.clone(), &router, ), status::Ok, // SHA-1 of first abstract string (with no trailing newline) Some("65c171bd8c968e12ede25ad95f02cd4b2ce9db52"), ); check_http_response( request::get( "http://localhost:9411/v0/release/lookup?doi=10.1234/iiiiiii", headers.clone(), &router, ), status::Ok, Some("99139405"), ); check_http_response( request::get( "http://localhost:9411/v0/release/lookup?doi=10.1234/iiiiiii", headers.clone(), &router, ), status::Ok, Some("24iu3i25u2"), ); } #[test] fn test_contribs() { let (headers, router, conn) = setup_http(); check_http_response( request::post( "http://localhost:9411/v0/release", headers.clone(), r#"{"title": "some paper", "doi": "10.1234/iiiiiii", "contribs": [{ "index": 1, "raw_name": "textual description of contributor (aka, name)", "creator_id": "aaaaaaaaaaaaaircaaaaaaaaae", "contrib_type": "author", "extra": {"key": "value 28328424942"} },{ "raw_name": "shorter" }] }"#, &router, ), status::Created, None, ); let editor_id = Uuid::parse_str("00000000-0000-0000-AAAA-000000000001").unwrap(); let editgroup_id = get_or_create_editgroup(editor_id, &conn).unwrap(); check_http_response( request::post( &format!( "http://localhost:9411/v0/editgroup/{}/accept", uuid2fcid(&editgroup_id) ), headers.clone(), "", &router, ), status::Ok, None, ); } #[test] fn test_post_batch_autoaccept() { let (headers, router, _conn) = setup_http(); // "true" check_http_response( request::post( "http://localhost:9411/v0/container/batch?autoaccept=true", headers.clone(), r#"[{"name": "test journal"}, {"name": "another test journal"}]"#, &router, ), status::Created, None, ); // "n" check_http_response( request::post( "http://localhost:9411/v0/container/batch?autoaccept=n", headers.clone(), r#"[{"name": "test journal"}, {"name": "another test journal"}]"#, &router, ), status::Created, None, ); // editgroup check_http_response( request::post( "http://localhost:9411/v0/container/batch?autoaccept=yes&editgroup_id=asdf", headers.clone(), r#"[{"name": "test journal"}, {"name": "another test journal"}]"#, &router, ), status::BadRequest, 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": "article-journal", "release_date": "2000-01-02" }"#, &router, ), status::Created, None, ); // Ok check_http_response( request::post( "http://localhost:9411/v0/release", headers.clone(), r#"{"title": "secret minimal paper", "release_type": "article-journal", "release_year": 2000 }"#, &router, ), status::Created, None, ); // Ok; ISO 8601 check_http_response( request::post( "http://localhost:9411/v0/release", headers.clone(), r#"{"title": "secret minimal paper", "release_type": "article-journal", "release_year": -100 }"#, &router, ), status::Created, None, ); check_http_response( request::post( "http://localhost:9411/v0/release", headers.clone(), r#"{"title": "secret minimal paper", "release_type": "article-journal", "release_year": 0 }"#, &router, ), status::Created, None, ); // Ok check_http_response( request::post( "http://localhost:9411/v0/release", headers.clone(), r#"{"title": "secret minimal paper", "release_type": "article-journal", "release_date": "2000-01-02", "release_year": 2000 }"#, &router, ), status::Created, None, ); // Ok for now, but may be excluded later check_http_response( request::post( "http://localhost:9411/v0/release", headers.clone(), r#"{"title": "secret minimal paper", "release_type": "article-journal", "release_date": "2000-01-02", "release_year": 1999 }"#, &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": "article-journal", "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": "article-journal", "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": "article-journal", "release_date": "2000-88-99" }"#, &router, ), status::BadRequest, None, ); } #[test] fn test_release_types() { 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": "article-journal" }"#, &router, ), status::Created, None, ); // Bad check_http_response( request::post( "http://localhost:9411/v0/release", headers.clone(), r#"{"title": "secret minimal paper", "release_type": "journal-article" }"#, &router, ), status::BadRequest, Some("release_type"), ); }