Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: workflow testing all features #36

Merged
merged 7 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
2 changes: 1 addition & 1 deletion src/ch_vat/bfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/ch_vat/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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! {
Expand Down
2 changes: 1 addition & 1 deletion src/gb_vat/hmrc.rs
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
8 changes: 4 additions & 4 deletions src/gb_vat/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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! {
Expand Down Expand Up @@ -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() {
Expand All @@ -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());
}

}
Expand Down
73 changes: 61 additions & 12 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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() {
Expand Down
4 changes: 2 additions & 2 deletions src/no_vat/brreg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -60,7 +60,7 @@ impl Verifier for BRReg {
fn make_request(&self, tax_id: &TaxId) -> Result<VerificationResponse, VerificationError> {
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)?;
Expand Down
2 changes: 1 addition & 1 deletion src/no_vat/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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! {
Expand Down
11 changes: 10 additions & 1 deletion src/verification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down