package pricing import ( "testing" "github.com/stretchr/testify/assert" ) func TestPrices(t *testing.T) { testCases := []struct { name string params PricingParams expectedPrices map[string]Price expectedError bool }{ { name: "Chavallon Combailes Volcans, Clermont destination, outward only", params: PricingParams{ Beneficiary: BeneficiaryParams{ Address: GeographyParams{ IntercommunalityCode: PFM63_CC_CHAVAILLON_COMBAILLES_VOLCANS, }, History: 0, Priority: false, }, SharedMobility: SharedMobilityParams{ PassengerDistance: 10, Destination: GeographyParams{CityCode: PFM63_COM_CLERMONT}, OutwardOnly: true, DriverDistance: 10, }, MobilityType: "solidarity_transport", }, expectedPrices: map[string]Price{ "passenger": {Amount: 5, Currency: "EUR/2"}, "driver": {Amount: 2.2, Currency: "EUR/2"}, }, expectedError: false, }, { name: "Chavallon Combailes Volcans, Aubusson destination, outward only", params: PricingParams{ Beneficiary: BeneficiaryParams{ Address: GeographyParams{ IntercommunalityCode: PFM63_CC_CHAVAILLON_COMBAILLES_VOLCANS, }, History: 0, Priority: false, }, SharedMobility: SharedMobilityParams{ PassengerDistance: 10, Destination: GeographyParams{CityCode: PFM63_COM_AUBUSSON}, OutwardOnly: true, DriverDistance: 10, }, MobilityType: "solidarity_transport", }, expectedPrices: map[string]Price{ "passenger": {Amount: 5, Currency: "EUR/2"}, "driver": {Amount: 2.2, Currency: "EUR/2"}, }, expectedError: false, }, { name: "Domes Sancy Artense, Ussel destination, round trip", params: PricingParams{ Beneficiary: BeneficiaryParams{ Address: GeographyParams{ IntercommunalityCode: PFM63_CC_DOMES_SANCY_ARTENSE, }, History: 0, Priority: false, }, SharedMobility: SharedMobilityParams{ PassengerDistance: 10, Destination: GeographyParams{CityCode: PFM63_COM_USSEL}, OutwardOnly: false, DriverDistance: 10, }, MobilityType: "solidarity_transport", }, expectedPrices: map[string]Price{ "passenger": {Amount: 10, Currency: "EUR/2"}, "driver": {Amount: 2.2, Currency: "EUR/2"}, }, expectedError: false, }, { name: "Ambert Livradois Artense, Clermont destination, round trip", params: PricingParams{ Beneficiary: BeneficiaryParams{ Address: GeographyParams{ IntercommunalityCode: PFM63_CC_AMBERT_LIVRADOIS_FOREZ, }, History: 10, Priority: false, }, SharedMobility: SharedMobilityParams{ PassengerDistance: 150, Destination: GeographyParams{CityCode: PFM63_COM_CLERMONT}, OutwardOnly: true, DriverDistance: 200, }, MobilityType: "solidarity_transport", }, expectedPrices: map[string]Price{ "passenger": {Amount: 17, Currency: "EUR/2"}, "driver": {Amount: 44, Currency: "EUR/2"}, }, expectedError: false, }, { name: "Ambert Livradois Forez, free trip", params: PricingParams{ Beneficiary: BeneficiaryParams{ Address: GeographyParams{ IntercommunalityCode: PFM63_CC_AMBERT_LIVRADOIS_FOREZ, }, History: 0, Priority: false, }, SharedMobility: SharedMobilityParams{ PassengerDistance: 10, Destination: GeographyParams{CityCode: "63113"}, OutwardOnly: true, DriverDistance: 10, }, MobilityType: "solidarity_transport", }, expectedPrices: map[string]Price{ "passenger": {Amount: 0, Currency: "EUR/2"}, "driver": {Amount: 2.2, Currency: "EUR/2"}, }, expectedError: false, }, { name: "Priority beneficiary, history <= 5", params: PricingParams{ Beneficiary: BeneficiaryParams{ Address: GeographyParams{ IntercommunalityCode: "unknown", }, History: 3, Priority: true, }, SharedMobility: SharedMobilityParams{ PassengerDistance: 10, Destination: GeographyParams{CityCode: "63113"}, OutwardOnly: true, DriverDistance: 10, }, MobilityType: "solidarity_transport", }, expectedPrices: map[string]Price{ "passenger": {Amount: 0, Currency: "EUR/2"}, "driver": {Amount: 2.2, Currency: "EUR/2"}, }, expectedError: false, }, { name: "Passenger distance < 15", params: PricingParams{ Beneficiary: BeneficiaryParams{ Address: GeographyParams{ IntercommunalityCode: "unknown", }, History: 6, Priority: false, }, SharedMobility: SharedMobilityParams{ PassengerDistance: 10, Destination: GeographyParams{CityCode: "63113"}, OutwardOnly: true, DriverDistance: 10, }, MobilityType: "solidarity_transport", }, expectedPrices: map[string]Price{ "passenger": {Amount: 2, Currency: "EUR/2"}, "driver": {Amount: 2.2, Currency: "EUR/2"}, }, expectedError: false, }, { name: "Passenger distance < 30", params: PricingParams{ Beneficiary: BeneficiaryParams{ Address: GeographyParams{ IntercommunalityCode: "unknown", }, History: 6, Priority: false, }, SharedMobility: SharedMobilityParams{ PassengerDistance: 20, Destination: GeographyParams{CityCode: "63113"}, OutwardOnly: true, DriverDistance: 20, }, MobilityType: "solidarity_transport", }, expectedPrices: map[string]Price{ "passenger": {Amount: 4, Currency: "EUR/2"}, "driver": {Amount: 4.4, Currency: "EUR/2"}, }, expectedError: false, }, { name: "Passenger distance > 140", params: PricingParams{ Beneficiary: BeneficiaryParams{ Address: GeographyParams{ IntercommunalityCode: "unknown", }, History: 6, Priority: false, }, SharedMobility: SharedMobilityParams{ PassengerDistance: 150, Destination: GeographyParams{CityCode: "63113"}, OutwardOnly: true, DriverDistance: 200, }, MobilityType: "solidarity_transport", }, expectedPrices: map[string]Price{ "passenger": {Amount: 17, Currency: "EUR/2"}, "driver": {Amount: 44.0, Currency: "EUR/2"}, }, expectedError: false, }, } for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { pricingService, err := NewPFM63PricingService() assert.NoError(t, err) prices, err := pricingService.Prices(tc.params) if tc.expectedError { assert.Error(t, err) } else { assert.NoError(t, err) assert.Equal(t, tc.expectedPrices, prices) } }) } }