All files / src/search/builders RideEstimatesSearchBuilder.js

79.17% Statements 19/24
50% Branches 5/10
100% Functions 0/0
79.17% Lines 19/24
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55    1x   1x 1x 1x       1x   1x       1x 1x   1x       1x 1x   1x       1x 1x   1x       1x       1x           1x       1x      
'use es6';
 
import {Map} from 'immutable';
 
import Coordinate from '../../data/Coordinate';
import CoordinateBuilder from '../../data/builders/CoordinateBuilder';
import RideEstimatesSearch from '../RideEstimatesSearch';
 
export default class RideEstimatesSearchBuilder {
  static build(json) {
    let args = Map();
 
    Iif (!('start' in json)) {
      throw new TypeError('start is not in the search');
    }
 
    let startCoordinate = CoordinateBuilder.build(json['start']);
    args = args.set('startCoordinate', startCoordinate);
 
    Iif (!('end' in json)) {
      throw new TypeError('end is not in the search');
    }
 
    let endCoordinate = CoordinateBuilder.build(json['end']);
    args = args.set('endCoordinate', endCoordinate);
 
    Iif (!('rideType' in json)) {
      throw new TypeError('rideType is not in the search');
    }
 
    let rideType = RideEstimatesSearchBuilder.validateRideType(json['rideType']);
    args = args.set('rideType', rideType);
 
    return new RideEstimatesSearch(args);
  }
 
  static validateRideType(rideType) {
    Iif (!Object.prototype.toString.call(rideType) === '[object String]') {
      throw new TypeError('rideType is not a string');
    }
 
    const rideTypes = [
      'lyft',
      'lyft_line',
      'lyft_plus',
    ];
 
    Iif (rideTypes.indexOf(rideType) === -1) {
      throw new RangeError('rideType must be either \'lyft\', \'lyft_line\', or \'lyft_plus\'');
    }
 
    return rideType;
  }
}