diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 9fd45e0..8671c63 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -14,9 +14,13 @@ jobs: runs-on: ubuntu-latest + strategy: + matrix: + feature: [eu_vat, gb_vat, ch_vat, no_vat] + steps: - - uses: actions/checkout@v4 - - name: Build - run: cargo build --verbose - - name: Run tests - run: cargo test --verbose + - uses: actions/checkout@v4 + - name: Build + run: cargo build --verbose --no-default-features --features ${{ matrix.feature }} + - name: Run tests + run: cargo test --verbose --no-default-features --features ${{ matrix.feature }} diff --git a/src/ch_vat/bfs.rs b/src/ch_vat/bfs.rs index fa7634b..213562f 100644 --- a/src/ch_vat/bfs.rs +++ b/src/ch_vat/bfs.rs @@ -4,8 +4,8 @@ use reqwest::header::{HeaderMap, HeaderName, HeaderValue, ACCEPT, CONTENT_TYPE}; use roxmltree; use serde_json::json; use crate::verification::{Verifier, Verification, VerificationStatus, VerificationResponse}; -use crate::tax_id::TaxId; use crate::errors::VerificationError; +use crate::TaxId; // INFO(2024-05-07 mollemoll): // https://www.bfs.admin.ch/bfs/en/home/registers/enterprise-register/enterprise-identification/uid-register/uid-interfaces.html#-125185306 diff --git a/src/ch_vat/mod.rs b/src/ch_vat/mod.rs index 63f1fbc..4cb5937 100644 --- a/src/ch_vat/mod.rs +++ b/src/ch_vat/mod.rs @@ -3,7 +3,7 @@ mod bfs; use std::collections::HashMap; use lazy_static::lazy_static; use regex::Regex; -use crate::tax_id::TaxIdType; +use crate::TaxIdType; use crate::verification::Verifier; lazy_static! { diff --git a/src/gb_vat/hmrc.rs b/src/gb_vat/hmrc.rs index bff6beb..386beb8 100644 --- a/src/gb_vat/hmrc.rs +++ b/src/gb_vat/hmrc.rs @@ -1,6 +1,6 @@ use serde_json::json; use crate::errors::VerificationError; -use crate::tax_id::TaxId; +use crate::TaxId; use crate::verification::{Verification, VerificationResponse, VerificationStatus, Verifier}; // INFO(2024-05-08 mollemoll): diff --git a/src/gb_vat/mod.rs b/src/gb_vat/mod.rs index 122857e..960e2be 100644 --- a/src/gb_vat/mod.rs +++ b/src/gb_vat/mod.rs @@ -3,7 +3,7 @@ mod hmrc; use std::collections::HashMap; use lazy_static::lazy_static; use regex::Regex; -use crate::tax_id::TaxIdType; +use crate::TaxIdType; use crate::verification::Verifier; lazy_static! { @@ -43,7 +43,7 @@ impl TaxIdType for GbVat { #[cfg(test)] mod tests { use crate::gb_vat::GbVat; - use crate::tax_id::TaxIdType; + use crate::TaxIdType; #[test] fn test_gb_vat() { @@ -62,11 +62,11 @@ mod tests { ]; for valid in valid_vat_numbers { - assert!(GbVat::validate_syntax(&GBVat, valid).is_ok()); + assert!(GbVat::validate_syntax(&GbVat, valid).is_ok()); } for invalid in invalid_vat_numbers { - assert!(GbVat::validate_syntax(&GBVat, invalid).is_err()); + assert!(GbVat::validate_syntax(&GbVat, invalid).is_err()); } } diff --git a/src/lib.rs b/src/lib.rs index 377f310..886f507 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -125,14 +125,12 @@ mod tests { #[test] fn test_validate_syntax() { - let mut valid_vat_numbers: Vec<&str>; + let mut valid_vat_numbers: Vec<&str> = Vec::new(); #[cfg(feature = "eu_vat")] { - valid_vat_numbers = vec![ - "SE123456789101", - "EL123456789", - "XI591819014", - ]; + valid_vat_numbers.push("SE123456789101"); + valid_vat_numbers.push("EL123456789"); + valid_vat_numbers.push("XI591819014"); } #[cfg(feature = "gb_vat")] valid_vat_numbers.push("GB591819014"); @@ -160,26 +158,77 @@ mod tests { } #[test] - fn test_validate_syntax_failed_validation() { + fn test_new_unsupported_country() { + let tax_id = TaxId::new("XX123456789"); + assert!(tax_id.is_err()); + assert_eq!(tax_id.unwrap_err(), ValidationError::UnsupportedCountryCode("XX".to_string())); + } + + + #[cfg(feature = "eu_vat")] + #[test] + fn test_validate_eu_syntax_fail() { let validation = TaxId::validate_syntax("SE12"); assert!(validation.is_err()); assert_eq!(validation.unwrap_err(), ValidationError::InvalidSyntax); } + #[cfg(feature = "gb_vat")] #[test] - fn test_new_failed_validation() { - let tax_id = TaxId::new("XX123456789"); - assert!(tax_id.is_err()); - assert_eq!(tax_id.unwrap_err(), ValidationError::UnsupportedCountryCode("XX".to_string())); + fn test_validate_gb_syntax_fail() { + let validation = TaxId::validate_syntax("GB12"); + assert!(validation.is_err()); + assert_eq!(validation.unwrap_err(), ValidationError::InvalidSyntax); } + #[cfg(feature = "ch_vat")] #[test] - fn test_new_unsupported_country_code_err() { + fn test_validate_ch_syntax_fail() { + let validation = TaxId::validate_syntax("CHE12"); + assert!(validation.is_err()); + assert_eq!(validation.unwrap_err(), ValidationError::InvalidSyntax); + } + + #[cfg(feature = "no_vat")] + #[test] + fn test_validate_no_syntax_fail() { + let validation = TaxId::validate_syntax("NO12"); + assert!(validation.is_err()); + assert_eq!(validation.unwrap_err(), ValidationError::InvalidSyntax); + } + + #[cfg(feature = "eu_vat")] + #[test] + fn test_eu_new_unsupported_country_code_err() { let tax_id = TaxId::new("SE12"); assert!(tax_id.is_err()); assert_eq!(tax_id.unwrap_err(), ValidationError::InvalidSyntax); } + #[cfg(feature = "gb_vat")] + #[test] + fn test_new_gb_unsupported_country_code_err() { + let tax_id = TaxId::new("GB12"); + assert!(tax_id.is_err()); + assert_eq!(tax_id.unwrap_err(), ValidationError::InvalidSyntax); + } + + #[cfg(feature = "ch_vat")] + #[test] + fn test_new_ch_unsupported_country_code_err() { + let tax_id = TaxId::new("CHE12"); + assert!(tax_id.is_err()); + assert_eq!(tax_id.unwrap_err(), ValidationError::InvalidSyntax); + } + + #[cfg(feature = "no_vat")] + #[test] + fn test_new_no_unsupported_country_code_err() { + let tax_id = TaxId::new("NO12"); + assert!(tax_id.is_err()); + assert_eq!(tax_id.unwrap_err(), ValidationError::InvalidSyntax); + } + #[cfg(feature = "eu_vat")] #[test] fn test_new_eu_vat() { diff --git a/src/no_vat/brreg.rs b/src/no_vat/brreg.rs index d82d24a..b55ec94 100644 --- a/src/no_vat/brreg.rs +++ b/src/no_vat/brreg.rs @@ -3,10 +3,10 @@ use lazy_static::lazy_static; use reqwest::header::{HeaderMap, HeaderValue, ACCEPT}; use serde_json::{json, Value}; use crate::verification::{Verifier, Verification, VerificationStatus, VerificationResponse}; -use crate::tax_id::TaxId; use crate::errors::VerificationError; use crate::no_vat::NoVat; use crate::no_vat::translator::translate_keys; +use crate::TaxId; // INFO(2024-05-08 mollemoll): // Data from Brønnøysund Register Centre @@ -60,7 +60,7 @@ impl Verifier for BRReg { fn make_request(&self, tax_id: &TaxId) -> Result { let client = reqwest::blocking::Client::new(); let res = client - .get(format!("{}/{}", BASE_URI, NoVat::extract_org_number(&NOVat, tax_id))) + .get(format!("{}/{}", BASE_URI, NoVat::extract_org_number(&NoVat, tax_id))) .headers(HEADERS.clone()) .send() .map_err(VerificationError::HttpError)?; diff --git a/src/no_vat/mod.rs b/src/no_vat/mod.rs index 2d3c774..b713ec7 100644 --- a/src/no_vat/mod.rs +++ b/src/no_vat/mod.rs @@ -4,7 +4,7 @@ mod translator; use std::collections::HashMap; use lazy_static::lazy_static; use regex::Regex; -use crate::tax_id::{TaxId, TaxIdType}; +use crate::{TaxId, TaxIdType}; use crate::verification::Verifier; lazy_static! { diff --git a/src/verification.rs b/src/verification.rs index 9655201..b447940 100644 --- a/src/verification.rs +++ b/src/verification.rs @@ -99,7 +99,16 @@ mod tests { #[test] fn test_verify() { - let tax_id = TaxId::new("SE123456789101").unwrap(); + #[cfg(feature="eu_vat")] + let value = "SE123456789101"; + #[cfg(feature="gb_vat")] + let value = "GB123456789"; + #[cfg(feature="ch_vat")] + let value = "CHE123456789"; + #[cfg(feature = "no_vat")] + let value = "NO123456789"; + + let tax_id = TaxId::new(value).unwrap(); let verifier = TestVerifier; let verification = verifier.verify(&tax_id).unwrap(); assert_eq!(verification.status(), &VerificationStatus::Verified);