From 39760b5956314684866068a719da3b6060639957 Mon Sep 17 00:00:00 2001 From: Adrian Wozniak Date: Sat, 23 May 2020 19:11:53 +0200 Subject: [PATCH] Fix server tests --- jirs-client/static/index.js | 1 - jirs-server/src/db/users.rs | 41 +++++++++++++++++++++++++------------ 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/jirs-client/static/index.js b/jirs-client/static/index.js index 43d80393..c81041f9 100644 --- a/jirs-client/static/index.js +++ b/jirs-client/static/index.js @@ -4,7 +4,6 @@ const wsUrl = () => `${ getProtocol() }//${ getWsHostName() }:${ process.env.JIR import("/jirs.js").then(async module => { window.module = module; - console.log(module) await module.default(); const host_url = `${ location.protocol }//${ process.env.JIRS_SERVER_BIND }:${ process.env.JIRS_SERVER_PORT }`; module.render(host_url, wsUrl()); diff --git a/jirs-server/src/db/users.rs b/jirs-server/src/db/users.rs index f226d380..4b650b95 100644 --- a/jirs-server/src/db/users.rs +++ b/jirs-server/src/db/users.rs @@ -303,9 +303,10 @@ impl Handler for DbExecutor { #[cfg(test)] mod tests { use crate::db::build_pool; - use crate::models::CreateProjectForm; use super::*; + use diesel::connection::TransactionManager; + use jirs_data::{Project, ProjectCategory}; #[test] fn check_collision() { @@ -316,23 +317,31 @@ mod tests { let pool = build_pool(); let conn = &pool.get().unwrap(); + let tm = conn.transaction_manager(); + + tm.begin_transaction(conn).unwrap(); + diesel::delete(user_projects).execute(conn).unwrap(); diesel::delete(users).execute(conn).unwrap(); diesel::delete(projects).execute(conn).unwrap(); - let project_form = CreateProjectForm { - name: "baz".to_string(), - url: "/uz".to_string(), - description: "None".to_string(), - category: Default::default(), + let project: Project = { + use crate::schema::projects::dsl::*; + + diesel::insert_into(projects) + .values(( + name.eq("baz".to_string()), + url.eq("/uz".to_string()), + description.eq("None".to_string()), + category.eq(ProjectCategory::Software), + )) + .get_result::(conn) + .unwrap() }; - let project: Project = diesel::insert_into(projects) - .values(project_form) - .get_result(conn) - .unwrap(); let user: User = { use crate::schema::users::dsl::*; + diesel::insert_into(users) .values(( name.eq("Foo".to_string()), @@ -354,8 +363,14 @@ mod tests { .unwrap(); } - assert_eq!(count_matching_users("Foo", "bar@example.com", conn), 1); - assert_eq!(count_matching_users("Bar", "foo@example.com", conn), 1); - assert_eq!(count_matching_users("Foo", "foo@example.com", conn), 1); + let res1 = count_matching_users("Foo", "bar@example.com", conn); + let res2 = count_matching_users("Bar", "foo@example.com", conn); + let res3 = count_matching_users("Foo", "foo@example.com", conn); + + tm.rollback_transaction(conn).unwrap(); + + assert_eq!(res1, 1); + assert_eq!(res2, 1); + assert_eq!(res3, 1); } }