diff --git a/account/src/bankaccount_module/controller.rs b/account/src/bankaccount_module/controller.rs new file mode 100644 index 000000000..76ecfbf6e --- /dev/null +++ b/account/src/bankaccount_module/controller.rs @@ -0,0 +1,58 @@ + + use std::sync::{Arc,Mutex, RwLock}; + use std::collections::HashMap; + use serde::{Serialize,Deserialize}; + use std::fmt; + + + use chrono::{Local, NaiveDate, NaiveDateTime}; + + use crate::bankaccount_module::model::bankaccount::{Account}; + use crate::bankaccount_module::*; + use crate::utils::*; + + + + + #[derive(Serialize, Deserialize, Debug, Clone)] + pub struct BankAccountController{ + bank_accounts: Arc>> + } + + + impl BankAccountController{ + + pub fn new() -> BankAccountController { + BankAccountController { + bank_accounts: Arc::new(RwLock::new(HashMap::new())) + } + } + + // HU 1: Add Bank Account as customer user + pub fn add_bank_account(&mut self,c: Account){ + self.bank_accounts.write().unwrap().insert(c.get_id().to_string(), c); + } + + // HU 2: Delete bank account as customer user + pub fn erase_bank_account(&mut self, bank_accout_id: String){ + self.bank_accounts.write().unwrap().remove(&bank_accout_id); + } + + pub fn get_bank_accounts(&self) -> &Arc>> { + &self.bank_accounts + } + + + /// The to_json method allows to account to produce it own JSON serialization + pub fn to_json(&self)->String { + serde_json::to_string_pretty(&self).unwrap() + } + } + + /// The fmt method allows display all atributes of an BankAccountController + impl fmt::Display for BankAccountController{ + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "({:?})", self.bank_accounts) + } + } + diff --git a/account/src/bankaccount_module/mod.rs b/account/src/bankaccount_module/mod.rs index 3e0e28250..a3f181a26 100644 --- a/account/src/bankaccount_module/mod.rs +++ b/account/src/bankaccount_module/mod.rs @@ -1,3 +1,6 @@ pub mod lib; pub mod message; -pub mod routes_handlers; \ No newline at end of file +pub mod routes_handlers; +pub mod model; +pub mod test_galvanic; +pub mod controller; \ No newline at end of file diff --git a/account/src/bankaccount_module/model.rs b/account/src/bankaccount_module/model.rs new file mode 100755 index 000000000..de5969e99 --- /dev/null +++ b/account/src/bankaccount_module/model.rs @@ -0,0 +1,121 @@ +pub mod bankaccount{ + + + use chrono::{Local, NaiveDate, NaiveDateTime}; + use std::fmt; + use serde::{Serialize,Deserialize}; + use crate::utils::model::{Lib}; + + extern crate regex; + extern crate serde; + extern crate serde_json; + + + /// Bank Account model + #[derive(Serialize, Deserialize, Debug, Clone)] + pub struct Account{ + /// Identification of account, it should be an identification intern of app that it's consistent with database identificator + id: String, + + /// International bank code that identifies (worldwide) tha bank associated to account (better than BIC) + /// Example of Swift: BSCHESMMXXX + swift: String, + + /// International Bank Account Number only for Europe. + /// Example of IBAN: ES32 6688 05 1111222233344 + iban:String, + + /// Timestamp. Represent timestamp which account was added in our application. For statisticals use. + created_at: NaiveDateTime, + + /// Status of account. User can disable an account for not operating (not interesting account) + status: bool, + } + + //@todo + // funcion para comprobar un iban valido + impl Account{ + /// Allocates a Account object and initializes it so that it represent the bankaccount needed. + /// # Usage + /// ``` + /// let my_account = Account::new(id,swift,iban,date,status) + /// ``` + pub fn new(new_id: String, new_swift: String, new_iban: String, new_created_at: NaiveDateTime, new_status: bool) -> Account { + Account { + id: new_id, + swift: new_swift, + iban: new_iban, + created_at: new_created_at, + status: new_status + } + } + + /// Getter (inmutable) for id private attribute. + pub fn get_id(&self) -> &String{ + &self.id + } + + /// Getter (inmutable) for swift private attribute. + /// A bank could be fusioned with other bank and change a swift code + pub fn get_swift(&self) -> &String{ + &self.swift + } + + /// Muttable access for swift private attribute + pub fn set_swift(&mut self, new_swift: String) -> &String{ + if Lib::check_swift(new_swift.clone()) { + self.swift=new_swift; + } + + &self.swift + } + + /// Getter (inmutable) for iban private attribute. + pub fn get_iban(&self) -> &String{ + &self.iban + } + + /// Muttable access for swift private attribute + /// A bank could be fusioned with other bank and change a iban code + pub fn set_iban(&mut self, new_iban: String) -> &String{ + if Lib::check_iban(new_iban.clone()) { + self.iban=new_iban; + } + &self.iban + } + + + /// Getter (inmutable) for created_at private attribute. + pub fn get_date(&self) -> &NaiveDateTime{ + &self.created_at + } + + /// Getter (inmutable) for status private attribute. + pub fn get_status(&self) -> &bool{ + &self.status + } + + /// Enables an account + fn enable(&mut self) { + self.status = true + } + + /// Disables an account + fn disable(&mut self) { + self.status = false + } + + /// The to_json method allows to account to produce it own JSON serialization + pub fn to_json(&self)->String { + serde_json::to_string_pretty(&self).unwrap() + } + + } + + /// The fmt method allows display all atributes of an Account + impl fmt::Display for Account{ + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "({}, {}, {}, {}, {})", self.id, self.swift, self.iban, self.created_at, self.status) + } + } +} \ No newline at end of file diff --git a/account/src/bankaccount_module/routes_handlers.rs b/account/src/bankaccount_module/routes_handlers.rs index 79f7cc7fe..252a9589f 100644 --- a/account/src/bankaccount_module/routes_handlers.rs +++ b/account/src/bankaccount_module/routes_handlers.rs @@ -1,53 +1,74 @@ -use warp::*; -use std::collections::HashMap; -use std::sync::{Arc,Mutex, RwLock}; -// use log::{debug, error, log_enabled, info, Level}; - -use crate::bankaccount_module::message::Msg; - -pub async fn get_accunts_handler(s: String) -> Result{ - let mut mesg = Msg::new(); - mesg.msg = String::from("okk"); - let response = Ok(warp::reply::with_status(warp::reply::json(&mesg), http::StatusCode::OK)); - println!("ok"); - return response; - - // let result = c.get_users(); - // let users = result.read().unwrap(); - - // // If there is at least 1 User - // if users.len() > 0 { - // let response = Ok(warp::reply::with_status(warp::reply::json(result), http::StatusCode::OK)); - // println!("ok"); - // return response; - // }else{ - // let response = Ok(warp::reply::with_status(warp::reply::json(result), http::StatusCode::NOT_FOUND)); - // println!("err"); - // return response; + + + use warp::*; + use std::collections::HashMap; + use std::sync::{Arc,Mutex, RwLock}; + // use log::{debug, error, log_enabled, info, Level}; + + + + use chrono::{Local, NaiveDate, NaiveDateTime}; + use crate::bankaccount_module::controller::{BankAccountController}; + use crate::bankaccount_module::message::Msg; + use crate::bankaccount_module::model::bankaccount::{Account}; + + pub async fn get_accounts_handler(bac: BankAccountController) -> Result{ + let mut mesg = Msg::new(); + mesg.msg = String::from("okk"); + let response = Ok(warp::reply::with_status(warp::reply::json(&mesg), http::StatusCode::OK)); + println!("ok"); + return response; + + // let result = c.get_users(); + // let users = result.read().unwrap(); + + // // If there is at least 1 User + // if users.len() > 0 { + // let response = Ok(warp::reply::with_status(warp::reply::json(result), http::StatusCode::OK)); + // println!("ok"); + // return response; + // }else{ + // let response = Ok(warp::reply::with_status(warp::reply::json(result), http::StatusCode::NOT_FOUND)); + // println!("err"); + // return response; + // } + } + + + + // HU 1: add bank account + pub async fn add_accounts_handler(c: Account, mut bac: BankAccountController) -> Result{ + let mut mesg = Msg::new(); + bac.add_bank_account(c); + + mesg.msg = format!("{}", "Bank account added successfully"); + let response = Ok(warp::reply::with_status(warp::reply::json(&mesg), http::StatusCode::OK)); + return response; + } + + + // pub async fn not_responding(req: HttpRequest) -> Result { + // log::info!("Received request from uri: {}", req.uri()); + // let mut mesg = Msg::new(); + // mesg.msg = String::from("You are not allowed to be here"); + // return Ok(HttpResponse::BadRequest().json(mesg)); // } -} -// pub async fn not_responding(req: HttpRequest) -> Result { -// log::info!("Received request from uri: {}", req.uri()); -// let mut mesg = Msg::new(); -// mesg.msg = String::from("You are not allowed to be here"); -// return Ok(HttpResponse::BadRequest().json(mesg)); -// } + // pub async fn healthcheck(req: HttpRequest) -> Result { + // log::info!("Received request from uri: {}", req.uri()); + // let mut mesg = Msg::new(); + // mesg.msg = String::from("I am alive"); + // return Ok(HttpResponse::Ok().json(mesg)); + // } -// pub async fn healthcheck(req: HttpRequest) -> Result { -// log::info!("Received request from uri: {}", req.uri()); -// let mut mesg = Msg::new(); -// mesg.msg = String::from("I am alive"); -// return Ok(HttpResponse::Ok().json(mesg)); -// } + // pub async fn get_account( req: HttpRequest) -> Result { + // log::info!("Received request from uri: {}", req.uri()); + // let mut mesg = Msg::new(); + // mesg.msg = String::from("Here is your account"); + // return Ok(HttpResponse::Ok().json(mesg)); + // } -// pub async fn get_account( req: HttpRequest) -> Result { -// log::info!("Received request from uri: {}", req.uri()); -// let mut mesg = Msg::new(); -// mesg.msg = String::from("Here is your account"); -// return Ok(HttpResponse::Ok().json(mesg)); -// } diff --git a/account/src/bankaccount_module/test.rs b/account/src/bankaccount_module/test.rs new file mode 100755 index 000000000..95386fe13 --- /dev/null +++ b/account/src/bankaccount_module/test.rs @@ -0,0 +1,106 @@ +#[cfg(test)] +/// Test for Bankaccount +mod test_bankaccount{ + + use chrono::{NaiveDate, NaiveDateTime}; + use crate::bankaccount_module::model::*; + + #[test] + /// Test if ID assignment is correct (inmutable getter - constructor) + fn test_get_id(){ + let id : String = String::from("507f1f77bcf86cd799439011"); + let swift : String = String::from("BSCHESMMXXX"); + let iban : String = String::from("ES32668805111122223334"); + let date : NaiveDateTime = NaiveDate::from_ymd(2020, 7, 8).and_hms(22, 18, 0); + let status : bool = true; + let acc : Account = Account::new(id, swift, iban, date, status); + + assert_eq!(*acc.get_id(), String::from("507f1f77bcf86cd799439011")); + } + + + #[test] + /// Test if swift assignment is correct (inmutable getter - constructor) + fn test_get_swift(){ + let id : String = String::from("507f1f77bcf86cd799439011"); + let swift : String = String::from("BSCHESMMXXX"); + let iban : String = String::from("ES32668805111122223334"); + let date : NaiveDateTime = NaiveDate::from_ymd(2020, 7, 8).and_hms(22, 18, 0); + let status : bool = true; + let acc : Account = Account::new(id, swift, iban, date, status); + + assert_eq!(*acc.get_swift(), String::from("BSCHESMMXXX")); + } + + #[test] + /// Test if iban assignment is correct (inmutable getter - constructor) + fn test_get_iban(){ + let id : String = String::from("507f1f77bcf86cd799439011"); + let swift : String = String::from("BSCHESMMXXX"); + let iban : String = String::from("ES32668805111122223334"); + let date : NaiveDateTime = NaiveDate::from_ymd(2020, 7, 8).and_hms(22, 18, 0); + let status : bool = true; + let acc : Account = Account::new(id, swift, iban, date, status); + + assert_eq!(*acc.get_iban(), String::from("ES32668805111122223334")); + } + + #[test] + /// Test if created_at - date assignment is correct (inmutable getter - constructor) + fn test_get_date(){ + let id : String = String::from("507f1f77bcf86cd799439011"); + let swift : String = String::from("BSCHESMMXXX"); + let iban : String = String::from("ES32668805111122223334"); + let date : NaiveDateTime = NaiveDate::from_ymd(2020, 7, 8).and_hms(22, 18, 0); + let status : bool = true; + let acc : Account = Account::new(id, swift, iban, date, status); + + assert_eq!(*acc.get_date(), NaiveDate::from_ymd(2020, 7, 8).and_hms(22, 18, 0)); + } + + #[test] + /// Test if status assignment is correct (inmutable getter - constructor) + fn test_get_status(){ + let id : String = String::from("507f1f77bcf86cd799439011"); + let swift : String = String::from("BSCHESMMXXX"); + let iban : String = String::from("ES32668805111122223334"); + let date : NaiveDateTime = NaiveDate::from_ymd(2020, 7, 8).and_hms(22, 18, 0); + let status : bool = true; + let acc : Account = Account::new(id, swift, iban, date, status); + + assert_eq!(*acc.get_status(), true); + } + + #[test] + /// Test if swift assignment is correct (inmutable getter - setter) + fn test_set_swift(){ + let id : String = String::from("507f1f77bcf86cd799439011"); + let swift : String = String::from("BSCHESMMXXX"); + let iban : String = String::from("ES32668805111122223334"); + let date : NaiveDateTime = NaiveDate::from_ymd(2020, 7, 8).and_hms(22, 18, 0); + let status : bool = true; + let mut acc : Account = Account::new(id, swift, iban, date, status); + + let new_swift : String = String::from("BBVAESMMXXX"); + acc.set_swift(new_swift); + assert_eq!(*acc.get_swift(), String::from("BBVAESMMXXX")); + assert_ne!(*acc.get_swift(), String::from("BSCHESMMXXX")); + } + + #[test] + /// Test if iban assignment is correct (inmutable getter - setter) + fn test_set_iban(){ + let id : String = String::from("507f1f77bcf86cd799439011"); + let swift : String = String::from("BSCHESMMXXX"); + let iban : String = String::from("ES32668805111122223334"); + let date : NaiveDateTime = NaiveDate::from_ymd(2020, 7, 8).and_hms(22, 18, 0); + let status : bool = true; + let mut acc : Account = Account::new(id, swift, iban, date, status); + + let new_iban : String = String::from("ES49998877666655554440"); + acc.set_iban(new_iban); + assert_eq!(*acc.get_iban(), String::from("ES49998877666655554440")); + assert_ne!(*acc.get_iban(), String::from("ES32668805111122223334")); + } + +} \ No newline at end of file diff --git a/account/src/bankaccount_module/test_galvanic.rs b/account/src/bankaccount_module/test_galvanic.rs new file mode 100755 index 000000000..e21397f4b --- /dev/null +++ b/account/src/bankaccount_module/test_galvanic.rs @@ -0,0 +1,122 @@ + +mod test_bankaccount_galvanic{ + use galvanic_assert::*; + use galvanic_assert::matchers::*; + use chrono::{NaiveDate, NaiveDateTime}; + + + use crate::bankaccount_module::model::*; + + + #[test] + /// Test if constructor is correct + fn test_new_account(){ + let id : String = String::from("507f1f77bcf86cd799439011"); + let swift : String = String::from("BSCHESMMXXX"); + let iban : String = String::from("ES32668805111122223334"); + let date : NaiveDateTime = NaiveDate::from_ymd(2020, 7, 8).and_hms(22, 18, 0); + let status : bool = true; + let acc : Account = Account::new(id, swift, iban, date, status); + + assert_that!(&acc, is_variant!(Account)); + } + + + #[test] + /// Test if ID assignment is correct (inmutable getter - constructor) + fn test_get_id(){ + let id : String = String::from("507f1f77bcf86cd799439011"); + let swift : String = String::from("BSCHESMMXXX"); + let iban : String = String::from("ES32668805111122223334"); + let date : NaiveDateTime = NaiveDate::from_ymd(2020, 7, 8).and_hms(22, 18, 0); + let status : bool = true; + let acc : Account = Account::new(id, swift, iban, date, status); + + assert_that!(acc.get_id(), eq(String::from("507f1f77bcf86cd799439011"))); + } + + + #[test] + /// Test if swift assignment is correct (inmutable getter - constructor) + fn test_get_swift(){ + let id : String = String::from("507f1f77bcf86cd799439011"); + let swift : String = String::from("BSCHESMMXXX"); + let iban : String = String::from("ES32668805111122223334"); + let date : NaiveDateTime = NaiveDate::from_ymd(2020, 7, 8).and_hms(22, 18, 0); + let status : bool = true; + let acc : Account = Account::new(id, swift, iban, date, status); + + assert_that!(&acc.get_swift().clone(), is(eq(String::from("BSCHESMMXXX")))); + } + + #[test] + /// Test if iban assignment is correct (inmutable getter - constructor) + fn test_get_iban(){ + let id : String = String::from("507f1f77bcf86cd799439011"); + let swift : String = String::from("BSCHESMMXXX"); + let iban : String = String::from("ES32668805111122223334"); + let date : NaiveDateTime = NaiveDate::from_ymd(2020, 7, 8).and_hms(22, 18, 0); + let status : bool = true; + let acc : Account = Account::new(id, swift, iban, date, status); + + assert_that!(&acc.get_iban().clone(), is(eq(String::from("ES32668805111122223334")))); + } + + #[test] + /// Test if created_at - date assignment is correct (inmutable getter - constructor) + fn test_get_date(){ + let id : String = String::from("507f1f77bcf86cd799439011"); + let swift : String = String::from("BSCHESMMXXX"); + let iban : String = String::from("ES32668805111122223334"); + let date : NaiveDateTime = NaiveDate::from_ymd(2020, 7, 8).and_hms(22, 18, 0); + let status : bool = true; + let acc : Account = Account::new(id, swift, iban, date, status); + + assert_that!(&acc.get_date().clone(), is(eq(NaiveDate::from_ymd(2020, 7, 8).and_hms(22, 18, 0)))); + } + + #[test] + /// Test if status assignment is correct (inmutable getter - constructor) + fn test_get_status(){ + let id : String = String::from("507f1f77bcf86cd799439011"); + let swift : String = String::from("BSCHESMMXXX"); + let iban : String = String::from("ES32668805111122223334"); + let date : NaiveDateTime = NaiveDate::from_ymd(2020, 7, 8).and_hms(22, 18, 0); + let status : bool = true; + let acc : Account = Account::new(id, swift, iban, date, status); + + assert_that!(&acc.get_status().clone(), is(eq(true))); + } + + #[test] + /// Test if swift assignment is correct (inmutable getter - setter) + fn test_set_swift(){ + let id : String = String::from("507f1f77bcf86cd799439011"); + let swift : String = String::from("BSCHESMMXXX"); + let iban : String = String::from("ES32668805111122223334"); + let date : NaiveDateTime = NaiveDate::from_ymd(2020, 7, 8).and_hms(22, 18, 0); + let status : bool = true; + let mut acc : Account = Account::new(id, swift, iban, date, status); + + let new_swift : String = String::from("BBVAESMMXXX"); + acc.set_swift(new_swift.clone()); + assert_that!(&acc.get_swift(), is(eq(String::from("BBVAESMMXXX")))); + assert_that!(&acc.get_swift(), not(is(eq(String::from("BSCHESMMXXX"))))); + } + + #[test] + /// Test if iban assignment is correct (inmutable getter - setter) + fn test_set_iban(){ + let id : String = String::from("507f1f77bcf86cd799439011"); + let swift : String = String::from("BSCHESMMXXX"); + let iban : String = String::from("ES32668805111122223334"); + let date : NaiveDateTime = NaiveDate::from_ymd(2020, 7, 8).and_hms(22, 18, 0); + let status : bool = true; + let mut acc : Account = Account::new(id, swift, iban, date, status); + + let new_iban : String = String::from("ES49998877666655554440"); + acc.set_iban(new_iban); + assert_that!(&acc.get_iban().clone(), is(eq(String::from("ES49998877666655554440")))); + assert_that!(&acc.get_iban().clone(), not(is(eq(String::from("ES32668805111122223334"))))); + } +} \ No newline at end of file diff --git a/account/src/main.rs b/account/src/main.rs index ac759d4da..6da44e475 100644 --- a/account/src/main.rs +++ b/account/src/main.rs @@ -1,5 +1,6 @@ #![allow(unused_imports,dead_code, unused_variables, unused_comparisons, unused_assignments,unused_mut)] mod bankaccount_module; +mod utils; extern crate dotenv; @@ -20,13 +21,23 @@ use env_logger::Env; use std::io::Write; use std::net::{SocketAddr,IpAddr,Ipv4Addr}; use warp::*; -use warp::Filter; +use crate::bankaccount_module::*; use crate::bankaccount_module::routes_handlers::*; +use crate::bankaccount_module::controller::*; +use crate::bankaccount_module::model::bankaccount::{Account}; + use etcd_client::{Client, Error}; +use warp::{Filter}; + +pub fn post_json() -> impl Filter + Clone { + warp::body::content_length_limit(1024 * 16).and(warp::body::json()) +} + + // cargo build --manifest-path=prueba/Cargo.toml // cargo run -p prueba @@ -107,22 +118,32 @@ async fn main() { ) });*/ - let control : String = "".to_string(); - let cbc_filter = warp::any().map(move | | control.clone());//|| cbc.clone()); + + + let mut control : BankAccountController = BankAccountController::new(); + let cbc_filter = warp::any().map(move | | control.clone()); let socket : SocketAddr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), port.parse::().unwrap()); let get_accounts = warp::get() - .and(warp::path("accounts")) - .and(warp::path::end()) - .and(cbc_filter.clone()) - .and_then(get_accunts_handler); + .and(warp::path("accounts")) + .and(warp::path::end()) + .and(cbc_filter.clone()) + .and_then(get_accounts_handler); + + + let add_accounts = warp::post() + .and(warp::path("accounts")) + .and(warp::path::end()) + .and(post_json()) + .and(cbc_filter.clone()) + .and_then(add_accounts_handler); - let routes = get_accounts;//.or(post_account); + let routes = get_accounts.or(add_accounts); println!("Welcome to bank/accounts API {}", VERSION_ENV); - println!("Server is listening in {}", socket); + println!("[Warp] Server is listening in {}", socket); warp::serve(routes).run(socket).await; diff --git a/account/src/utils/mod.rs b/account/src/utils/mod.rs new file mode 100755 index 000000000..bdcc1d4c3 --- /dev/null +++ b/account/src/utils/mod.rs @@ -0,0 +1,2 @@ +pub mod model; +pub mod test_galvanic; \ No newline at end of file diff --git a/account/src/utils/model.rs b/account/src/utils/model.rs new file mode 100755 index 000000000..c6cf0a70a --- /dev/null +++ b/account/src/utils/model.rs @@ -0,0 +1,34 @@ +extern crate regex; +use regex::Regex; +use std::str; + +/// Regular expression patter to check a valid SWIFT code +static REGEX_SWIFT: &str = r"^[A-Z]{6}[A-Z0-9]{2}([A-Z0-9]{3})?$"; + +/// Regular expression patter to check a valid IBAN code +static REGEX_IBAN: &str = r"([A-Z]{2})\s*\t*(\d\d)\s*\t*(\d\d\d\d)\s*\t*(\d\d\d\d)\s*\t*(\d\d)\s*\t*(\d\d\d\d\d\d\d\d)"; + +pub(crate) struct Lib{ + +} + +impl Lib { + + /// Check if an SWIFT is correct or not returning true or false + /// Valid swift example: BBVAESMMXXX + /// Invalid swift example: BVAEMMX + pub fn check_swift(swift: String) -> bool{ + let reg_ex = Regex::new(REGEX_SWIFT).unwrap(); + reg_ex.is_match(&swift) + } + + /// Check if an IBAN code is correct or not returning true or false + /// Valid iban example: ES49998877666655554440 + /// Invalid iban example: XXX632505000002014145 + pub fn check_iban(iban: String) -> bool{ + let reg_ex = Regex::new(REGEX_IBAN).unwrap(); + reg_ex.is_match(&iban) + } + + +} \ No newline at end of file diff --git a/account/src/utils/test_galvanic.rs b/account/src/utils/test_galvanic.rs new file mode 100755 index 000000000..f9eec8cb5 --- /dev/null +++ b/account/src/utils/test_galvanic.rs @@ -0,0 +1,48 @@ +mod test_galvanic_utils{ + use galvanic_assert::*; + use galvanic_assert::matchers::*; + + use chrono::{NaiveDate, NaiveDateTime}; + use crate::bankaccount_module::model::*; + + use crate::utils::model::{Lib}; + + #[test] + /// Test if a swift code is valid or not + fn test_check_valid_swift(){ + let new_swift : String = String::from("BBVAESMMXXX"); + let bad_swift : String = String::from("BVAEMMX"); + + assert_that!(&Lib::check_swift(new_swift), is(eq(true))); + assert_that!(&Lib::check_swift(bad_swift), is(eq(false))); + } + + #[test] + /// Test if a swift code is valid or not + fn test_check_valid_iban(){ + let new_iban : String = String::from("ES49998877666655554440"); + let german_iban : String = String::from("DE63250500000201414513"); + let bad_iban : String = String::from("XXX632505000002014145"); + + assert_that!(&Lib::check_iban(new_iban.clone()), is(eq(true))); + assert_that!(&Lib::check_iban(german_iban), is(eq(true))); + assert_that!(&Lib::check_iban(bad_iban), is(eq(false))); + + } + + + #[test] + /// Test if a card number is valid or not + fn test_check_valid_card_number(){ + let new_card : String = String::from("5500000000000004"); + let bad_card : String = String::from("1111222200000002"); + + assert_that!(&Lib::check_number(new_card), is(eq(true))); + assert_that!(&Lib::check_number(bad_card), is(eq(false))); + } + +} + + + +