All files / src/search/builders DriverEtaSearchBuilder.js

50% Statements 11/22
30% Branches 3/10
100% Functions 0/0
50% Lines 11/22
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    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 DriverEtaSearch from '../DriverEtaSearch';
 
export default class DriverEtaSearchBuilder {
  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) {
      let endCoordinate = CoordinateBuilder.build(json['end']);
      args = args.set('endCoordinate', endCoordinate);
    }
 
    Iif ('rideType' in json) {
      let rideType = DriverEtaSearchBuilder.validateRideType(json['rideType']);
      args = args.set('rideType', rideType);
    }
 
    return new DriverEtaSearch(args);
  }
 
  static validateRideType(rideType) {
    if (!Object.prototype.toString.call(rideType) === '[object String]') {
      throw new TypeError('rideType is not a string');
    }
 
    const rideTypes = [
      'lyft',
      'lyft_line',
      'lyft_plus',
    ];
 
    if (rideTypes.indexOf(rideType) === -1) {
      throw new RangeError('rideType must be either \'lyft\', \'lyft_line\', or \'lyft_plus\'');
    }
 
    return rideType;
  }
}