func parseFormValues(r *http.Request) flightsToSearch { var result flightsToSearch var earliestDepartureDateRawString string var latestDepartureDateRawString string getIntFormValue(r, &result.minimumStay, "minimumStayInput") getIntFormValue(r, &result.maximumStay, "maximumStayInput") getStringFormValue(r, &earliestDepartureDateRawString, "earliestDeparture") getStringFormValue(r, &latestDepartureDateRawString, "latestDeparture") result.earliestDepartureDate = utils.DateFromString(earliestDepartureDateRawString) result.latestDepartureDate = utils.DateFromString(latestDepartureDateRawString) result.startAirports = collectValues(r, "selected-start-airport") result.destAirports = collectValues(r, "selected-dest-airport") return result }
func TestCalculatePossibleQueriesCheckCount(t *testing.T) { actualDate1 := utils.DateFromString("2015-11-25") actualDate2 := utils.DateFromString("2015-11-26") argument := flightsToSearch{ minimumStay: 5, maximumStay: 6, earliestDepartureDate: actualDate1, latestDepartureDate: actualDate2, startAirports: []string{"INN", "VIE"}, destAirports: []string{"PEK", "PVG"}, } queries := calculatePossibleQueries(&argument) if len(queries) != 16 { t.Errorf("there should be exactly eight queries - but there were : %v", len(queries)) } }
func TestCalculatePossibleQueriesCheckDepartureDate(t *testing.T) { actualStartDate1 := utils.DateFromString("2015-11-05") actualStartDate2 := utils.DateFromString("2015-11-06") actualEndDate1 := utils.DateFromString("2015-11-11") actualEndDate2 := utils.DateFromString("2015-11-12") argument := flightsToSearch{ minimumStay: 6, maximumStay: 6, earliestDepartureDate: actualStartDate1, latestDepartureDate: actualStartDate2, startAirports: []string{"INN"}, destAirports: []string{"PEK"}, } expectedQuery1 := FlightQuery{ StartDate: actualStartDate1, BackDate: actualEndDate1, StartAirport: "INN", DestAirport: "PEK", } expectedQuery2 := FlightQuery{ StartDate: actualStartDate2, BackDate: actualEndDate2, StartAirport: "INN", DestAirport: "PEK", } queries := calculatePossibleQueries(&argument) if len(queries) != 2 { t.Errorf("there should be exactly two queries - but there were : %v", len(queries)) } if queries[0] != expectedQuery1 { t.Errorf("returned query1 %v is not as expected %v", queries[0], expectedQuery1) } if queries[1] != expectedQuery2 { t.Errorf("returned query2 %v is not as expected %v", queries[1], expectedQuery2) } }