Skip to content

Commit

Permalink
feat: add blacklist for delivery countries (#203)
Browse files Browse the repository at this point in the history
INT-325
  • Loading branch information
joerivanveen authored Jan 18, 2024
1 parent 66696ee commit 5386e5c
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 5 deletions.
7 changes: 6 additions & 1 deletion src/data/carriers/abstractCarrierConfiguration.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ export class AbstractCarrierConfiguration {
* @returns {boolean}
*/
allowsDeliveryIn(country) {
return this.getCountriesForDelivery().includes(country.toUpperCase()) || this.hasFakeDelivery();
return this.getCountriesForDelivery().includes(country.toUpperCase())
|| (this.hasFakeDelivery() && !this.getCountriesBlacklist().includes(country.toUpperCase()));
}

/**
Expand Down Expand Up @@ -82,6 +83,10 @@ export class AbstractCarrierConfiguration {
return [];
}

getCountriesBlacklist() {
return [];
}

/**
* The countries this carrier can find pickup locations in.
*
Expand Down
10 changes: 6 additions & 4 deletions src/data/carriers/upsCarrierConfiguration.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ import {
BULGARIA,
CROATIA,
CZECH_REPUBLIC,
DENMARK,
ESTONIA,
FINLAND,
FRANCE,
GERMANY,
GREECE,
HUNGARY,
Expand All @@ -16,17 +14,17 @@ import {
LATVIA,
LITHUANIA,
LUXEMBOURG,
NETHERLANDS,
POLAND,
PORTUGAL,
ROMANIA,
SLOVAKIA,
SLOVENIA,
SPAIN,
SWEDEN,
} from '@myparcel/js-sdk/dist/constant/countries-iso2';
import { CITY, POSTAL_CODE, STREET } from '../keys/addressKeys';
import { MYPARCEL, SENDMYPARCEL } from '@/data/keys/platformKeys';
import { AbstractCarrierConfiguration } from '@/data/carriers/abstractCarrierConfiguration';
import { MYPARCEL } from '@/data/keys/platformKeys';
import { UPS } from '../keys/carrierKeys';

export class UpsCarrierConfiguration extends AbstractCarrierConfiguration {
Expand Down Expand Up @@ -67,6 +65,10 @@ export class UpsCarrierConfiguration extends AbstractCarrierConfiguration {
return true;
}

getCountriesBlacklist() {
return [NETHERLANDS];
}

getCountriesForPickup() {
return [
GERMANY,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

exports[`CarrierConfigurationFactory should create a configuration for bpost 1`] = `
Object {
"countriesBlacklist": Array [],
"countriesForDelivery": Array [
"BE",
"NL",
Expand Down Expand Up @@ -45,13 +46,19 @@ Object {
],
],
},
"getDefaultRequestParameters": Array [
"city",
"postalCode",
],
"hasFakeDelivery": false,
"name": "bpost",
"platformFeatures": Array [],
}
`;

exports[`CarrierConfigurationFactory should create a configuration for dhl 1`] = `
Object {
"countriesBlacklist": Array [],
"countriesForDelivery": Array [
"AT",
"BG",
Expand Down Expand Up @@ -101,6 +108,11 @@ Object {
],
],
},
"getDefaultRequestParameters": Array [
"city",
"postalCode",
],
"hasFakeDelivery": false,
"name": "dhl",
"platformFeatures": Array [
Array [
Expand All @@ -120,6 +132,7 @@ Object {

exports[`CarrierConfigurationFactory should create a configuration for dhleuroplus 1`] = `
Object {
"countriesBlacklist": Array [],
"countriesForDelivery": Array [
"BE",
"BG",
Expand Down Expand Up @@ -157,6 +170,12 @@ Object {
],
],
},
"getDefaultRequestParameters": Array [
"city",
"postalCode",
"street",
],
"hasFakeDelivery": false,
"name": "dhleuroplus",
"platformFeatures": Array [
Array [
Expand All @@ -169,6 +188,7 @@ Object {

exports[`CarrierConfigurationFactory should create a configuration for dhlforyou 1`] = `
Object {
"countriesBlacklist": Array [],
"countriesForDelivery": Array [
"NL",
"BE",
Expand Down Expand Up @@ -213,6 +233,11 @@ Object {
],
],
},
"getDefaultRequestParameters": Array [
"city",
"postalCode",
],
"hasFakeDelivery": false,
"name": "dhlforyou",
"platformFeatures": Array [
Array [
Expand Down Expand Up @@ -254,6 +279,7 @@ Object {

exports[`CarrierConfigurationFactory should create a configuration for dhlparcelconnect 1`] = `
Object {
"countriesBlacklist": Array [],
"countriesForDelivery": Array [
"BG",
"DE",
Expand Down Expand Up @@ -314,6 +340,12 @@ Object {
],
],
},
"getDefaultRequestParameters": Array [
"city",
"postalCode",
"street",
],
"hasFakeDelivery": false,
"name": "dhlparcelconnect",
"platformFeatures": Array [
Array [
Expand All @@ -330,6 +362,7 @@ Object {

exports[`CarrierConfigurationFactory should create a configuration for dpd 1`] = `
Object {
"countriesBlacklist": Array [],
"countriesForDelivery": Array [
"AT",
"BE",
Expand Down Expand Up @@ -404,6 +437,12 @@ Object {
],
],
},
"getDefaultRequestParameters": Array [
"postalCode",
"street",
"city",
],
"hasFakeDelivery": false,
"name": "dpd",
"platformFeatures": Array [
Array [
Expand All @@ -416,6 +455,7 @@ Object {

exports[`CarrierConfigurationFactory should create a configuration for postnl 1`] = `
Object {
"countriesBlacklist": Array [],
"countriesForDelivery": Array [
"NL",
"BE",
Expand Down Expand Up @@ -510,6 +550,12 @@ Object {
],
],
},
"getDefaultRequestParameters": Array [
"postalCode",
"street",
"city",
],
"hasFakeDelivery": true,
"name": "postnl",
"platformFeatures": Array [
Array [
Expand Down Expand Up @@ -567,6 +613,9 @@ Object {

exports[`CarrierConfigurationFactory should create a configuration for ups 1`] = `
Object {
"countriesBlacklist": Array [
"NL",
],
"countriesForDelivery": Array [
"BG",
"DE",
Expand Down Expand Up @@ -600,6 +649,12 @@ Object {
],
],
},
"getDefaultRequestParameters": Array [
"postalCode",
"street",
"city",
],
"hasFakeDelivery": true,
"name": "ups",
"platformFeatures": Array [
Array [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ describe('CarrierConfigurationFactory', () => {
features: config.getFeatures(),
platformFeatures: config.getPlatformFeatures(),
countriesForDelivery: config.getCountriesForDelivery(),
countriesBlacklist: config.getCountriesBlacklist(),
countriesForPickup: config.getCountriesForPickup(),
hasFakeDelivery: config.hasFakeDelivery(),
getDefaultRequestParameters: config.getDefaultRequestParameters(),
}).toMatchSnapshot();
});

Expand Down

0 comments on commit 5386e5c

Please sign in to comment.