From 634720bbd2a967a4b2a60c215a63070eabd4db06 Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Fri, 20 Jul 2018 20:00:39 -0700 Subject: editor_id and editgroup_id as idents; revisions as raw UUID --- rust/src/api_helpers.rs | 13 ++++--- rust/src/api_server.rs | 88 +++++++++++++++++++++---------------------- rust/src/api_wrappers.rs | 8 ++-- rust/src/database_models.rs | 50 ++++++++++++------------ rust/src/database_schema.rs | 56 +++++++++++++-------------- rust/tests/test_api_server.rs | 23 +++++++---- rust/tests/test_fcid.rs | 6 ++- 7 files changed, 129 insertions(+), 115 deletions(-) (limited to 'rust') diff --git a/rust/src/api_helpers.rs b/rust/src/api_helpers.rs index 1ee08c76..14d3dd5e 100644 --- a/rust/src/api_helpers.rs +++ b/rust/src/api_helpers.rs @@ -6,7 +6,7 @@ use diesel::prelude::*; use errors::*; use uuid::Uuid; -pub fn get_or_create_editgroup(editor_id: i64, conn: &PgConnection) -> Result { +pub fn get_or_create_editgroup(editor_id: Uuid, conn: &PgConnection) -> Result { // check for current active let ed_row: EditorRow = editor::table.find(editor_id).first(conn)?; if let Some(current) = ed_row.active_editgroup_id { @@ -25,7 +25,7 @@ pub fn get_or_create_editgroup(editor_id: i64, conn: &PgConnection) -> Result Result { +pub fn accept_editgroup(editgroup_id: Uuid, conn: &PgConnection) -> Result { conn.build_transaction().run(|| { // check that we haven't accepted already (in changelog) // NB: could leave this to a UNIQUE constraint @@ -34,7 +34,10 @@ pub fn accept_editgroup(editgroup_id: i64, conn: &PgConnection) -> Result 0 { - bail!("editgroup {} has already been accepted", editgroup_id); + bail!( + "editgroup {} has already been accepted", + editgroup_id.to_string() + ); } // for each entity type... @@ -69,7 +72,7 @@ pub fn accept_editgroup(editgroup_id: i64, conn: &PgConnection) -> Result(editgroup_id) + )).bind::(editgroup_id) .execute(conn)?; } @@ -79,7 +82,7 @@ pub fn accept_editgroup(editgroup_id: i64, conn: &PgConnection) -> Result = None; + let no_active: Option = None; diesel::update(editor::table) .filter(editor::active_editgroup_id.eq(editgroup_id)) .set(editor::active_editgroup_id.eq(no_active)) diff --git a/rust/src/api_server.rs b/rust/src/api_server.rs index b7b19a85..fa64bf7b 100644 --- a/rust/src/api_server.rs +++ b/rust/src/api_server.rs @@ -13,7 +13,7 @@ use diesel::{self, insert_into}; use errors::*; use fatcat_api::models; use fatcat_api::models::*; -use uuid; +use uuid::Uuid; type DbConn = diesel::r2d2::PooledConnection>; @@ -99,7 +99,7 @@ fn container_row2entity( coden: rev.coden, state: state, ident: ident_id, - revision: Some(rev.id), + revision: Some(uuid2fcid(&rev.id)), redirect: redirect_id, extra: rev.extra_json, editgroup_id: None, @@ -122,7 +122,7 @@ fn creator_row2entity(ident: Option, rev: CreatorRevRow) -> Res orcid: rev.orcid, state: state, ident: ident_id, - revision: Some(rev.id), + revision: Some(uuid2fcid(&rev.id)), redirect: redirect_id, editgroup_id: None, extra: rev.extra_json, @@ -160,7 +160,7 @@ fn file_row2entity( releases: Some(releases), state: state, ident: ident_id, - revision: Some(rev.id), + revision: Some(uuid2fcid(&rev.id)), redirect: redirect_id, editgroup_id: None, extra: rev.extra_json, @@ -232,7 +232,7 @@ fn release_row2entity( contribs: Some(contribs), state: state, ident: ident_id, - revision: Some(rev.id), + revision: Some(uuid2fcid(&rev.id)), redirect: redirect_id, editgroup_id: None, extra: rev.extra_json, @@ -252,7 +252,7 @@ fn work_row2entity(ident: Option, rev: WorkRevRow) -> Result c, None => conn.unwrap(), }; - let editor_id = 1; // TODO: auth - let editgroup_id = match entity.editgroup_id { + let editor_id = Uuid::parse_str("00000000-0000-0000-AAAA-000000000001")?; // TODO: auth + let editgroup_id: Uuid = match entity.editgroup_id { None => get_or_create_editgroup(editor_id, &conn)?, - Some(param) => param as i64, + Some(param) => fcid2uuid(¶m)?, }; let edit: ContainerEditRow = diesel::sql_query( @@ -461,7 +461,7 @@ impl Server { .bind::, _>(entity.abbrev) .bind::, _>(entity.coden) .bind::, _>(entity.extra) - .bind::(editgroup_id) + .bind::(editgroup_id) .get_result(conn)?; edit.to_model() @@ -481,10 +481,10 @@ impl Server { Some(ref c) => c, None => conn.unwrap(), }; - let editor_id = 1; // TODO: auth + let editor_id = Uuid::parse_str("00000000-0000-0000-AAAA-000000000001")?; // TODO: auth let editgroup_id = match entity.editgroup_id { None => get_or_create_editgroup(editor_id, &conn).expect("current editgroup"), - Some(param) => param as i64, + Some(param) => fcid2uuid(¶m)?, }; let edit: CreatorEditRow = diesel::sql_query( @@ -502,7 +502,7 @@ impl Server { .bind::, _>(entity.surname) .bind::, _>(entity.orcid) .bind::, _>(entity.extra) - .bind::(editgroup_id) + .bind::(editgroup_id) .get_result(conn)?; edit.to_model() @@ -522,10 +522,10 @@ impl Server { Some(ref c) => c, None => conn.unwrap(), }; - let editor_id = 1; // TODO: auth + let editor_id = Uuid::parse_str("00000000-0000-0000-AAAA-000000000001")?; // TODO: auth let editgroup_id = match entity.editgroup_id { None => get_or_create_editgroup(editor_id, &conn).expect("current editgroup"), - Some(param) => param as i64, + Some(param) => fcid2uuid(¶m)?, }; let edit: FileEditRow = @@ -546,7 +546,7 @@ impl Server { .bind::, _>(entity.url) .bind::, _>(entity.mimetype) .bind::, _>(entity.extra) - .bind::(editgroup_id) + .bind::(editgroup_id) .get_result(conn)?; let _releases: Option> = match entity.releases { @@ -589,10 +589,10 @@ impl Server { Some(ref c) => c, None => conn.unwrap(), }; - let editor_id = 1; // TODO: auth + let editor_id = Uuid::parse_str("00000000-0000-0000-AAAA-000000000001")?; // TODO: auth let editgroup_id = match entity.editgroup_id { None => get_or_create_editgroup(editor_id, &conn).expect("current editgroup"), - Some(param) => param as i64, + Some(param) => fcid2uuid(¶m)?, }; let work_id = match entity.work_id { @@ -605,7 +605,7 @@ impl Server { revision: None, redirect: None, state: None, - editgroup_id: Some(editgroup_id), + editgroup_id: Some(uuid2fcid(&editgroup_id)), extra: None, }; let new_entity = self.create_work_handler(work_model, Some(&conn))?; @@ -613,7 +613,7 @@ impl Server { } }; - let container_id: Option = match entity.container_id { + let container_id: Option = match entity.container_id { Some(id) => Some(fcid2uuid(&id)?), None => None, }; @@ -643,7 +643,7 @@ impl Server { .bind::, _>(entity.publisher) .bind::, _>(entity.language) .bind::, _>(entity.extra) - .bind::(editgroup_id) + .bind::(editgroup_id) .get_result(conn)?; let _refs: Option> = match entity.refs { @@ -722,10 +722,10 @@ impl Server { None => conn.unwrap(), }; - let editor_id = 1; // TODO: auth + let editor_id = Uuid::parse_str("00000000-0000-0000-AAAA-000000000001")?; // TODO: auth let editgroup_id = match entity.editgroup_id { None => get_or_create_editgroup(editor_id, &conn).expect("current editgroup"), - Some(param) => param as i64, + Some(param) => fcid2uuid(¶m)?, }; let edit: WorkEditRow = @@ -741,15 +741,15 @@ impl Server { RETURNING *", ).bind::, _>(entity.work_type) .bind::, _>(entity.extra) - .bind::(editgroup_id) + .bind::(editgroup_id) .get_result(conn)?; edit.to_model() } - pub fn accept_editgroup_handler(&self, id: i64) -> Result<()> { + pub fn accept_editgroup_handler(&self, id: String) -> Result<()> { let conn = self.db_pool.get().expect("db_pool error"); - accept_editgroup(id as i64, &conn)?; + accept_editgroup(fcid2uuid(&id)?, &conn)?; Ok(()) } @@ -758,7 +758,7 @@ impl Server { let row: EditgroupRow = insert_into(editgroup::table) .values(( - editgroup::editor_id.eq(entity.editor_id as i64), + editgroup::editor_id.eq(fcid2uuid(&entity.editor_id)?), editgroup::description.eq(entity.description), editgroup::extra_json.eq(entity.extra), )) @@ -766,18 +766,19 @@ impl Server { .expect("error creating edit group"); Ok(Editgroup { - id: Some(row.id), - editor_id: row.editor_id, + id: Some(uuid2fcid(&row.id)), + editor_id: uuid2fcid(&row.editor_id), description: row.description, edits: None, extra: row.extra_json, }) } - pub fn get_editgroup_handler(&self, id: i64) -> Result { + pub fn get_editgroup_handler(&self, id: String) -> Result { let conn = self.db_pool.get().expect("db_pool error"); - let row: EditgroupRow = editgroup::table.find(id as i64).first(&conn)?; + let id = fcid2uuid(&id)?; + let row: EditgroupRow = editgroup::table.find(id).first(&conn)?; let edits = EditgroupEdits { containers: Some( @@ -823,8 +824,8 @@ impl Server { }; let eg = Editgroup { - id: Some(row.id), - editor_id: row.editor_id, + id: Some(uuid2fcid(&row.id)), + editor_id: uuid2fcid(&row.editor_id), description: row.description, edits: Some(edits), extra: row.extra_json, @@ -832,26 +833,25 @@ impl Server { Ok(eg) } - pub fn get_editor_handler(&self, username: String) -> Result { + pub fn get_editor_handler(&self, id: String) -> Result { let conn = self.db_pool.get().expect("db_pool error"); - let row: EditorRow = editor::table - .filter(editor::username.eq(&username)) - .first(&conn)?; + let id = fcid2uuid(&id)?; + let row: EditorRow = editor::table.find(id).first(&conn)?; let ed = Editor { + id: Some(uuid2fcid(&row.id)), username: row.username, }; Ok(ed) } - pub fn editor_changelog_get_handler(&self, username: String) -> Result> { + pub fn editor_changelog_get_handler(&self, id: String) -> Result> { let conn = self.db_pool.get().expect("db_pool error"); + let id = fcid2uuid(&id)?; // TODO: single query - let editor: EditorRow = editor::table - .filter(editor::username.eq(username)) - .first(&conn)?; + let editor: EditorRow = editor::table.find(id).first(&conn)?; let changes: Vec<(ChangelogRow, EditgroupRow)> = changelog::table .inner_join(editgroup::table) .filter(editgroup::editor_id.eq(editor.id)) @@ -862,7 +862,7 @@ impl Server { .map(|(cl_row, eg_row)| ChangelogEntry { index: cl_row.id, editgroup: Some(eg_row.to_model_partial()), - editgroup_id: cl_row.editgroup_id, + editgroup_id: uuid2fcid(&cl_row.editgroup_id), timestamp: chrono::DateTime::from_utc(cl_row.timestamp, chrono::Utc), }) .collect(); @@ -884,7 +884,7 @@ impl Server { .map(|(cl_row, eg_row)| ChangelogEntry { index: cl_row.id, editgroup: Some(eg_row.to_model_partial()), - editgroup_id: cl_row.editgroup_id, + editgroup_id: uuid2fcid(&cl_row.editgroup_id), timestamp: chrono::DateTime::from_utc(cl_row.timestamp, chrono::Utc), }) .collect(); @@ -895,7 +895,7 @@ impl Server { let conn = self.db_pool.get().expect("db_pool error"); let cl_row: ChangelogRow = changelog::table.find(id).first(&conn)?; - let editgroup = self.get_editgroup_handler(cl_row.editgroup_id)?; + let editgroup = self.get_editgroup_handler(uuid2fcid(&cl_row.editgroup_id))?; let mut entry = cl_row.to_model(); entry.editgroup = Some(editgroup); diff --git a/rust/src/api_wrappers.rs b/rust/src/api_wrappers.rs index bc1e61ef..4d5c6ddf 100644 --- a/rust/src/api_wrappers.rs +++ b/rust/src/api_wrappers.rs @@ -268,10 +268,10 @@ impl Api for Server { fn accept_editgroup( &self, - id: i64, + id: String, _context: &Context, ) -> Box + Send> { - let ret = match self.accept_editgroup_handler(id) { + let ret = match self.accept_editgroup_handler(id.clone()) { Ok(()) => AcceptEditgroupResponse::MergedSuccessfully(Success { message: "horray!".to_string(), }), @@ -289,10 +289,10 @@ impl Api for Server { fn get_editgroup( &self, - id: i64, + id: String, _context: &Context, ) -> Box + Send> { - let ret = match self.get_editgroup_handler(id) { + let ret = match self.get_editgroup_handler(id.clone()) { Ok(entity) => GetEditgroupResponse::FoundEntity(entity), Err(Error(ErrorKind::Diesel(::diesel::result::Error::NotFound), _)) => diff --git a/rust/src/database_models.rs b/rust/src/database_models.rs index 15dffad0..79ff45fe 100644 --- a/rust/src/database_models.rs +++ b/rust/src/database_models.rs @@ -11,8 +11,8 @@ use uuid::Uuid; pub enum EntityState { WorkInProgress, - Active(i64), - Redirect(Uuid, i64), + Active(Uuid), + Redirect(Uuid, Uuid), Deleted, } @@ -42,9 +42,9 @@ macro_rules! entity_structs { #[table_name = $edit_table] pub struct $edit_struct { pub id: i64, - pub editgroup_id: i64, + pub editgroup_id: Uuid, pub ident_id: Uuid, - pub rev_id: Option, + pub rev_id: Option, pub redirect_id: Option, pub extra_json: Option, } @@ -53,8 +53,8 @@ macro_rules! entity_structs { /// Go from a row (SQL model) to an API model fn to_model(self) -> Result { Ok(EntityEdit { - editgroup_id: self.editgroup_id, - revision: self.rev_id, + editgroup_id: uuid2fcid(&self.editgroup_id), + revision: self.rev_id.map(|v| uuid2fcid(&v)), redirect_ident: self.redirect_id.map(|v| uuid2fcid(&v)), ident: uuid2fcid(&self.ident_id), edit_id: self.id, @@ -68,7 +68,7 @@ macro_rules! entity_structs { pub struct $ident_struct { pub id: Uuid, pub is_live: bool, - pub rev_id: Option, + pub rev_id: Option, pub redirect_id: Option, } @@ -91,7 +91,7 @@ macro_rules! entity_structs { #[derive(Debug, Queryable, Identifiable, Associations, AsChangeset)] #[table_name = "container_rev"] pub struct ContainerRevRow { - pub id: i64, + pub id: Uuid, pub extra_json: Option, pub name: String, pub publisher: Option, @@ -110,7 +110,7 @@ entity_structs!( #[derive(Debug, Queryable, Identifiable, Associations, AsChangeset)] #[table_name = "creator_rev"] pub struct CreatorRevRow { - pub id: i64, + pub id: Uuid, pub extra_json: Option, pub display_name: String, pub given_name: Option, @@ -128,7 +128,7 @@ entity_structs!( #[derive(Debug, Queryable, Identifiable, Associations, AsChangeset)] #[table_name = "file_rev"] pub struct FileRevRow { - pub id: i64, + pub id: Uuid, pub extra_json: Option, pub size: Option, pub sha1: Option, @@ -143,7 +143,7 @@ entity_structs!("file_edit", FileEditRow, "file_ident", FileIdentRow); #[derive(Debug, Queryable, Identifiable, Associations, AsChangeset)] #[table_name = "release_rev"] pub struct ReleaseRevRow { - pub id: i64, + pub id: Uuid, pub extra_json: Option, pub work_ident_id: Uuid, pub container_ident_id: Option, @@ -170,7 +170,7 @@ entity_structs!( #[derive(Debug, Queryable, Identifiable, Associations, AsChangeset)] #[table_name = "work_rev"] pub struct WorkRevRow { - pub id: i64, + pub id: Uuid, pub extra_json: Option, pub work_type: Option, pub primary_release_id: Option, @@ -182,7 +182,7 @@ entity_structs!("work_edit", WorkEditRow, "work_ident", WorkIdentRow); #[table_name = "release_contrib"] pub struct ReleaseContribRow { pub id: i64, - pub release_rev: i64, + pub release_rev: Uuid, pub creator_ident_id: Option, pub role: Option, pub index: Option, @@ -192,7 +192,7 @@ pub struct ReleaseContribRow { #[derive(Debug, Insertable)] #[table_name = "release_contrib"] pub struct ReleaseContribNewRow { - pub release_rev: i64, + pub release_rev: Uuid, pub creator_ident_id: Option, pub role: Option, pub index: Option, @@ -203,7 +203,7 @@ pub struct ReleaseContribNewRow { #[table_name = "release_ref"] pub struct ReleaseRefRow { pub id: i64, - pub release_rev: i64, + pub release_rev: Uuid, pub target_release_ident_id: Option, pub index: Option, pub key: Option, @@ -217,7 +217,7 @@ pub struct ReleaseRefRow { #[derive(Debug, Insertable, AsChangeset)] #[table_name = "release_ref"] pub struct ReleaseRefNewRow { - pub release_rev: i64, + pub release_rev: Uuid, pub target_release_ident_id: Option, pub index: Option, pub key: Option, @@ -231,16 +231,16 @@ pub struct ReleaseRefNewRow { #[derive(Debug, Queryable, Insertable, Associations, AsChangeset)] #[table_name = "file_release"] pub struct FileReleaseRow { - pub file_rev: i64, + pub file_rev: Uuid, pub target_release_ident_id: Uuid, } #[derive(Debug, Queryable, Identifiable, Associations, AsChangeset)] #[table_name = "editgroup"] pub struct EditgroupRow { - pub id: i64, + pub id: Uuid, pub extra_json: Option, - pub editor_id: i64, + pub editor_id: Uuid, pub description: Option, } @@ -249,8 +249,8 @@ impl EditgroupRow { /// eg, entity history queries (where we already have the entity edit we want) pub fn to_model_partial(self) -> Editgroup { Editgroup { - id: Some(self.id), - editor_id: self.editor_id, + id: Some(uuid2fcid(&self.id)), + editor_id: uuid2fcid(&self.editor_id), description: self.description, extra: self.extra_json, edits: None, @@ -261,17 +261,17 @@ impl EditgroupRow { #[derive(Debug, Queryable, Identifiable, Associations, AsChangeset)] #[table_name = "editor"] pub struct EditorRow { - pub id: i64, + pub id: Uuid, pub username: String, pub is_admin: bool, - pub active_editgroup_id: Option, + pub active_editgroup_id: Option, } #[derive(Debug, Queryable, Identifiable, Associations, AsChangeset)] #[table_name = "changelog"] pub struct ChangelogRow { pub id: i64, - pub editgroup_id: i64, + pub editgroup_id: Uuid, pub timestamp: chrono::NaiveDateTime, } @@ -279,7 +279,7 @@ impl ChangelogRow { pub fn to_model(self) -> ChangelogEntry { ChangelogEntry { index: self.id, - editgroup_id: self.editgroup_id, + editgroup_id: uuid2fcid(&self.editgroup_id), editgroup: None, timestamp: chrono::DateTime::from_utc(self.timestamp, chrono::Utc), } diff --git a/rust/src/database_schema.rs b/rust/src/database_schema.rs index 34ca16c4..d99fdd3f 100644 --- a/rust/src/database_schema.rs +++ b/rust/src/database_schema.rs @@ -1,7 +1,7 @@ table! { changelog (id) { id -> Int8, - editgroup_id -> Int8, + editgroup_id -> Uuid, timestamp -> Timestamp, } } @@ -9,9 +9,9 @@ table! { table! { container_edit (id) { id -> Int8, - editgroup_id -> Int8, + editgroup_id -> Uuid, ident_id -> Uuid, - rev_id -> Nullable, + rev_id -> Nullable, redirect_id -> Nullable, extra_json -> Nullable, } @@ -21,14 +21,14 @@ table! { container_ident (id) { id -> Uuid, is_live -> Bool, - rev_id -> Nullable, + rev_id -> Nullable, redirect_id -> Nullable, } } table! { container_rev (id) { - id -> Int8, + id -> Uuid, extra_json -> Nullable, name -> Text, publisher -> Nullable, @@ -41,9 +41,9 @@ table! { table! { creator_edit (id) { id -> Int8, - editgroup_id -> Int8, + editgroup_id -> Uuid, ident_id -> Uuid, - rev_id -> Nullable, + rev_id -> Nullable, redirect_id -> Nullable, extra_json -> Nullable, } @@ -53,14 +53,14 @@ table! { creator_ident (id) { id -> Uuid, is_live -> Bool, - rev_id -> Nullable, + rev_id -> Nullable, redirect_id -> Nullable, } } table! { creator_rev (id) { - id -> Int8, + id -> Uuid, extra_json -> Nullable, display_name -> Text, given_name -> Nullable, @@ -71,28 +71,28 @@ table! { table! { editgroup (id) { - id -> Int8, + id -> Uuid, extra_json -> Nullable, - editor_id -> Int8, + editor_id -> Uuid, description -> Nullable, } } table! { editor (id) { - id -> Int8, + id -> Uuid, username -> Text, is_admin -> Bool, - active_editgroup_id -> Nullable, + active_editgroup_id -> Nullable, } } table! { file_edit (id) { id -> Int8, - editgroup_id -> Int8, + editgroup_id -> Uuid, ident_id -> Uuid, - rev_id -> Nullable, + rev_id -> Nullable, redirect_id -> Nullable, extra_json -> Nullable, } @@ -102,21 +102,21 @@ table! { file_ident (id) { id -> Uuid, is_live -> Bool, - rev_id -> Nullable, + rev_id -> Nullable, redirect_id -> Nullable, } } table! { file_release (file_rev, target_release_ident_id) { - file_rev -> Int8, + file_rev -> Uuid, target_release_ident_id -> Uuid, } } table! { file_rev (id) { - id -> Int8, + id -> Uuid, extra_json -> Nullable, size -> Nullable, sha1 -> Nullable, @@ -130,7 +130,7 @@ table! { table! { release_contrib (id) { id -> Int8, - release_rev -> Int8, + release_rev -> Uuid, creator_ident_id -> Nullable, role -> Nullable, index -> Nullable, @@ -141,9 +141,9 @@ table! { table! { release_edit (id) { id -> Int8, - editgroup_id -> Int8, + editgroup_id -> Uuid, ident_id -> Uuid, - rev_id -> Nullable, + rev_id -> Nullable, redirect_id -> Nullable, extra_json -> Nullable, } @@ -153,7 +153,7 @@ table! { release_ident (id) { id -> Uuid, is_live -> Bool, - rev_id -> Nullable, + rev_id -> Nullable, redirect_id -> Nullable, } } @@ -161,7 +161,7 @@ table! { table! { release_ref (id) { id -> Int8, - release_rev -> Int8, + release_rev -> Uuid, target_release_ident_id -> Nullable, index -> Nullable, key -> Nullable, @@ -175,7 +175,7 @@ table! { table! { release_rev (id) { - id -> Int8, + id -> Uuid, extra_json -> Nullable, work_ident_id -> Uuid, container_ident_id -> Nullable, @@ -196,9 +196,9 @@ table! { table! { work_edit (id) { id -> Int8, - editgroup_id -> Int8, + editgroup_id -> Uuid, ident_id -> Uuid, - rev_id -> Nullable, + rev_id -> Nullable, redirect_id -> Nullable, extra_json -> Nullable, } @@ -208,14 +208,14 @@ table! { work_ident (id) { id -> Uuid, is_live -> Bool, - rev_id -> Nullable, + rev_id -> Nullable, redirect_id -> Nullable, } } table! { work_rev (id) { - id -> Int8, + id -> Uuid, extra_json -> Nullable, work_type -> Nullable, primary_release_id -> Nullable, diff --git a/rust/tests/test_api_server.rs b/rust/tests/test_api_server.rs index e7ac9585..056c6a0e 100644 --- a/rust/tests/test_api_server.rs +++ b/rust/tests/test_api_server.rs @@ -3,6 +3,7 @@ extern crate fatcat; extern crate fatcat_api; extern crate iron; extern crate iron_test; +extern crate uuid; use diesel::prelude::*; use fatcat::api_helpers::*; @@ -11,6 +12,7 @@ use iron::headers::ContentType; use iron::mime::Mime; use iron::{status, Headers}; use iron_test::{request, response}; +use uuid::Uuid; fn setup() -> ( Headers, @@ -416,7 +418,8 @@ fn test_post_work() { fn test_accept_editgroup() { let (headers, router, conn) = setup(); - let editgroup_id = get_or_create_editgroup(1, &conn).unwrap(); + 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)) @@ -436,8 +439,8 @@ fn test_accept_editgroup() { "http://localhost:9411/v0/container", headers.clone(), &format!( - "{{\"name\": \"test journal 1\", \"editgroup_id\": {}}}", - editgroup_id + "{{\"name\": \"test journal 1\", \"editgroup_id\": \"{}\"}}", + uuid2fcid(&editgroup_id) ), &router, ), @@ -449,8 +452,8 @@ fn test_accept_editgroup() { "http://localhost:9411/v0/container", headers.clone(), &format!( - "{{\"name\": \"test journal 2\", \"editgroup_id\": {}}}", - editgroup_id + "{{\"name\": \"test journal 2\", \"editgroup_id\": \"{}\"}}", + uuid2fcid(&editgroup_id) ), &router, ), @@ -467,7 +470,10 @@ fn test_accept_editgroup() { check_response( request::get( - &format!("http://localhost:9411/v0/editgroup/{}", editgroup_id), + &format!( + "http://localhost:9411/v0/editgroup/{}", + uuid2fcid(&editgroup_id) + ), headers.clone(), &router, ), @@ -477,7 +483,10 @@ fn test_accept_editgroup() { check_response( request::post( - &format!("http://localhost:9411/v0/editgroup/{}/accept", editgroup_id), + &format!( + "http://localhost:9411/v0/editgroup/{}/accept", + uuid2fcid(&editgroup_id) + ), headers.clone(), "", &router, diff --git a/rust/tests/test_fcid.rs b/rust/tests/test_fcid.rs index befca435..4feaef5d 100644 --- a/rust/tests/test_fcid.rs +++ b/rust/tests/test_fcid.rs @@ -14,8 +14,10 @@ fn test_fcid_conversions() { assert_eq!(test_uuid, fcid2uuid(&test_fcid.to_uppercase()).unwrap()); assert_eq!(test_uuid, fcid2uuid(&uuid2fcid(&test_uuid)).unwrap()); - assert_eq!(Uuid::parse_str("10842108-4210-8421-0842-108421084210").unwrap(), - fcid2uuid("ccccccccccccccccccccccccca").unwrap()); + assert_eq!( + Uuid::parse_str("10842108-4210-8421-0842-108421084210").unwrap(), + fcid2uuid("ccccccccccccccccccccccccca").unwrap() + ); assert_eq!(false, fcid2uuid("asdf").is_ok()); assert_eq!(false, fcid2uuid("q3nouwy3nnbsvo3h5klx").is_ok()); -- cgit v1.2.3