Skip to content

Commit fb840ad

Browse files
authored
fix: workflow testing all features (#36)
### Why? Workflow wasn't building/testing all features which meant some errors have slipped in. ### What changed? - Adjusted the workflow to run a matrix of the features. - Fixed the existing errors
1 parent 76f093f commit fb840ad

File tree

9 files changed

+90
-28
lines changed

9 files changed

+90
-28
lines changed

.github/workflows/rust.yml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,13 @@ jobs:
1414

1515
runs-on: ubuntu-latest
1616

17+
strategy:
18+
matrix:
19+
feature: [eu_vat, gb_vat, ch_vat, no_vat]
20+
1721
steps:
18-
- uses: actions/checkout@v4
19-
- name: Build
20-
run: cargo build --verbose
21-
- name: Run tests
22-
run: cargo test --verbose
22+
- uses: actions/checkout@v4
23+
- name: Build
24+
run: cargo build --verbose --no-default-features --features ${{ matrix.feature }}
25+
- name: Run tests
26+
run: cargo test --verbose --no-default-features --features ${{ matrix.feature }}

src/ch_vat/bfs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ use reqwest::header::{HeaderMap, HeaderName, HeaderValue, ACCEPT, CONTENT_TYPE};
44
use roxmltree;
55
use serde_json::json;
66
use crate::verification::{Verifier, Verification, VerificationStatus, VerificationResponse};
7-
use crate::tax_id::TaxId;
87
use crate::errors::VerificationError;
8+
use crate::TaxId;
99

1010
// INFO(2024-05-07 mollemoll):
1111
// https://www.bfs.admin.ch/bfs/en/home/registers/enterprise-register/enterprise-identification/uid-register/uid-interfaces.html#-125185306

src/ch_vat/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ mod bfs;
33
use std::collections::HashMap;
44
use lazy_static::lazy_static;
55
use regex::Regex;
6-
use crate::tax_id::TaxIdType;
6+
use crate::TaxIdType;
77
use crate::verification::Verifier;
88

99
lazy_static! {

src/gb_vat/hmrc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use serde_json::json;
22
use crate::errors::VerificationError;
3-
use crate::tax_id::TaxId;
3+
use crate::TaxId;
44
use crate::verification::{Verification, VerificationResponse, VerificationStatus, Verifier};
55

66
// INFO(2024-05-08 mollemoll):

src/gb_vat/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ mod hmrc;
33
use std::collections::HashMap;
44
use lazy_static::lazy_static;
55
use regex::Regex;
6-
use crate::tax_id::TaxIdType;
6+
use crate::TaxIdType;
77
use crate::verification::Verifier;
88

99
lazy_static! {
@@ -43,7 +43,7 @@ impl TaxIdType for GbVat {
4343
#[cfg(test)]
4444
mod tests {
4545
use crate::gb_vat::GbVat;
46-
use crate::tax_id::TaxIdType;
46+
use crate::TaxIdType;
4747

4848
#[test]
4949
fn test_gb_vat() {
@@ -62,11 +62,11 @@ mod tests {
6262
];
6363

6464
for valid in valid_vat_numbers {
65-
assert!(GbVat::validate_syntax(&GBVat, valid).is_ok());
65+
assert!(GbVat::validate_syntax(&GbVat, valid).is_ok());
6666
}
6767

6868
for invalid in invalid_vat_numbers {
69-
assert!(GbVat::validate_syntax(&GBVat, invalid).is_err());
69+
assert!(GbVat::validate_syntax(&GbVat, invalid).is_err());
7070
}
7171

7272
}

src/lib.rs

Lines changed: 61 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -125,14 +125,12 @@ mod tests {
125125

126126
#[test]
127127
fn test_validate_syntax() {
128-
let mut valid_vat_numbers: Vec<&str>;
128+
let mut valid_vat_numbers: Vec<&str> = Vec::new();
129129
#[cfg(feature = "eu_vat")]
130130
{
131-
valid_vat_numbers = vec![
132-
"SE123456789101",
133-
"EL123456789",
134-
"XI591819014",
135-
];
131+
valid_vat_numbers.push("SE123456789101");
132+
valid_vat_numbers.push("EL123456789");
133+
valid_vat_numbers.push("XI591819014");
136134
}
137135
#[cfg(feature = "gb_vat")]
138136
valid_vat_numbers.push("GB591819014");
@@ -160,26 +158,77 @@ mod tests {
160158
}
161159

162160
#[test]
163-
fn test_validate_syntax_failed_validation() {
161+
fn test_new_unsupported_country() {
162+
let tax_id = TaxId::new("XX123456789");
163+
assert!(tax_id.is_err());
164+
assert_eq!(tax_id.unwrap_err(), ValidationError::UnsupportedCountryCode("XX".to_string()));
165+
}
166+
167+
168+
#[cfg(feature = "eu_vat")]
169+
#[test]
170+
fn test_validate_eu_syntax_fail() {
164171
let validation = TaxId::validate_syntax("SE12");
165172
assert!(validation.is_err());
166173
assert_eq!(validation.unwrap_err(), ValidationError::InvalidSyntax);
167174
}
168175

176+
#[cfg(feature = "gb_vat")]
169177
#[test]
170-
fn test_new_failed_validation() {
171-
let tax_id = TaxId::new("XX123456789");
172-
assert!(tax_id.is_err());
173-
assert_eq!(tax_id.unwrap_err(), ValidationError::UnsupportedCountryCode("XX".to_string()));
178+
fn test_validate_gb_syntax_fail() {
179+
let validation = TaxId::validate_syntax("GB12");
180+
assert!(validation.is_err());
181+
assert_eq!(validation.unwrap_err(), ValidationError::InvalidSyntax);
174182
}
175183

184+
#[cfg(feature = "ch_vat")]
176185
#[test]
177-
fn test_new_unsupported_country_code_err() {
186+
fn test_validate_ch_syntax_fail() {
187+
let validation = TaxId::validate_syntax("CHE12");
188+
assert!(validation.is_err());
189+
assert_eq!(validation.unwrap_err(), ValidationError::InvalidSyntax);
190+
}
191+
192+
#[cfg(feature = "no_vat")]
193+
#[test]
194+
fn test_validate_no_syntax_fail() {
195+
let validation = TaxId::validate_syntax("NO12");
196+
assert!(validation.is_err());
197+
assert_eq!(validation.unwrap_err(), ValidationError::InvalidSyntax);
198+
}
199+
200+
#[cfg(feature = "eu_vat")]
201+
#[test]
202+
fn test_eu_new_unsupported_country_code_err() {
178203
let tax_id = TaxId::new("SE12");
179204
assert!(tax_id.is_err());
180205
assert_eq!(tax_id.unwrap_err(), ValidationError::InvalidSyntax);
181206
}
182207

208+
#[cfg(feature = "gb_vat")]
209+
#[test]
210+
fn test_new_gb_unsupported_country_code_err() {
211+
let tax_id = TaxId::new("GB12");
212+
assert!(tax_id.is_err());
213+
assert_eq!(tax_id.unwrap_err(), ValidationError::InvalidSyntax);
214+
}
215+
216+
#[cfg(feature = "ch_vat")]
217+
#[test]
218+
fn test_new_ch_unsupported_country_code_err() {
219+
let tax_id = TaxId::new("CHE12");
220+
assert!(tax_id.is_err());
221+
assert_eq!(tax_id.unwrap_err(), ValidationError::InvalidSyntax);
222+
}
223+
224+
#[cfg(feature = "no_vat")]
225+
#[test]
226+
fn test_new_no_unsupported_country_code_err() {
227+
let tax_id = TaxId::new("NO12");
228+
assert!(tax_id.is_err());
229+
assert_eq!(tax_id.unwrap_err(), ValidationError::InvalidSyntax);
230+
}
231+
183232
#[cfg(feature = "eu_vat")]
184233
#[test]
185234
fn test_new_eu_vat() {

src/no_vat/brreg.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ use lazy_static::lazy_static;
33
use reqwest::header::{HeaderMap, HeaderValue, ACCEPT};
44
use serde_json::{json, Value};
55
use crate::verification::{Verifier, Verification, VerificationStatus, VerificationResponse};
6-
use crate::tax_id::TaxId;
76
use crate::errors::VerificationError;
87
use crate::no_vat::NoVat;
98
use crate::no_vat::translator::translate_keys;
9+
use crate::TaxId;
1010

1111
// INFO(2024-05-08 mollemoll):
1212
// Data from Brønnøysund Register Centre
@@ -60,7 +60,7 @@ impl Verifier for BRReg {
6060
fn make_request(&self, tax_id: &TaxId) -> Result<VerificationResponse, VerificationError> {
6161
let client = reqwest::blocking::Client::new();
6262
let res = client
63-
.get(format!("{}/{}", BASE_URI, NoVat::extract_org_number(&NOVat, tax_id)))
63+
.get(format!("{}/{}", BASE_URI, NoVat::extract_org_number(&NoVat, tax_id)))
6464
.headers(HEADERS.clone())
6565
.send()
6666
.map_err(VerificationError::HttpError)?;

src/no_vat/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ mod translator;
44
use std::collections::HashMap;
55
use lazy_static::lazy_static;
66
use regex::Regex;
7-
use crate::tax_id::{TaxId, TaxIdType};
7+
use crate::{TaxId, TaxIdType};
88
use crate::verification::Verifier;
99

1010
lazy_static! {

src/verification.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,16 @@ mod tests {
9999

100100
#[test]
101101
fn test_verify() {
102-
let tax_id = TaxId::new("SE123456789101").unwrap();
102+
#[cfg(feature="eu_vat")]
103+
let value = "SE123456789101";
104+
#[cfg(feature="gb_vat")]
105+
let value = "GB123456789";
106+
#[cfg(feature="ch_vat")]
107+
let value = "CHE123456789";
108+
#[cfg(feature = "no_vat")]
109+
let value = "NO123456789";
110+
111+
let tax_id = TaxId::new(value).unwrap();
103112
let verifier = TestVerifier;
104113
let verification = verifier.verify(&tax_id).unwrap();
105114
assert_eq!(verification.status(), &VerificationStatus::Verified);

0 commit comments

Comments
 (0)