RideRequestView extends LinearLayout { @NonNull @VisibleForTesting static String buildUrlFromRideParameters(@NonNull Context context, @NonNull RideParameters rideParameters, @NonNull SessionConfiguration loginConfiguration) { final String ENDPOINT = "components"; final String ENVIRONMENT_KEY = "env"; final String HTTPS = "https"; final String PATH = "rides/"; final String SANDBOX = "sandbox"; Uri.Builder builder = new Uri.Builder(); builder.scheme(HTTPS) .authority(ENDPOINT + "." + loginConfiguration.getEndpointRegion().getDomain()) .appendEncodedPath(PATH); if (rideParameters.getUserAgent() == null) { rideParameters.setUserAgent(USER_AGENT_RIDE_VIEW); } RideRequestDeeplink deeplink = new RideRequestDeeplink.Builder(context) .setSessionConfiguration(loginConfiguration) .setRideParameters(rideParameters).build(); Uri uri = deeplink.getUri(); builder.encodedQuery(uri.getEncodedQuery()); if (loginConfiguration.getEnvironment() == SessionConfiguration.Environment.SANDBOX) { builder.appendQueryParameter(ENVIRONMENT_KEY, SANDBOX); } return builder.build().toString(); } RideRequestView(Context context);  RideRequestView(Context context, AttributeSet attrs); void cancelLoad(); @Nullable AccessTokenSession getSession(); void load(); void setSession(@Nullable AccessTokenSession accessTokenSession); void setRideParameters(@NonNull RideParameters rideParameters); void setRideRequestViewCallback(@NonNull RideRequestViewCallback rideRequestViewCallback);  }
@Test public void onBuildUrl_inDefaultRegion_shouldHaveUrlWithDefaultDomain() throws IOException { String path = "src/test/resources/riderequestviewuris/default_uri"; String expectedUri = readUriResourceWithUserAgentParam(path, USER_AGENT_RIDE_VIEW); RideParameters rideParameters = new RideParameters.Builder().build(); SessionConfiguration configuration = new SessionConfiguration.Builder() .setClientId("clientId") .build(); String result = RideRequestView.buildUrlFromRideParameters(context, rideParameters, configuration); assertEquals(expectedUri, result); }
@Test public void onBuildUrl_inSandboxMode_shouldHaveUrlWithSandboxParam() throws IOException { RideParameters rideParameters = new RideParameters.Builder().build(); SessionConfiguration configuration = new SessionConfiguration.Builder() .setClientId("clientId") .setEnvironment(SessionConfiguration.Environment.SANDBOX) .build(); String result = RideRequestView.buildUrlFromRideParameters(context, rideParameters, configuration); assertTrue(result.contains("&env=sandbox")); }
@Test public void onBuildUrl_withRideParams_shouldHaveRideParamsQueryParams() throws IOException { String path = "src/test/resources/riderequestviewuris/full_details_uri"; String expectedUri = readUriResourceWithUserAgentParam(path, USER_AGENT_RIDE_VIEW); RideParameters rideParameters = new RideParameters.Builder() .setPickupLocation(PICKUP_LAT, PICKUP_LONG, PICKUP_NICK, PICKUP_ADDR) .setDropoffLocation(DROPOFF_LAT, DROPOFF_LONG, DROPOFF_NICK, DROPOFF_ADDR) .setProductId(PRODUCT_ID) .build(); SessionConfiguration configuration = new SessionConfiguration.Builder() .setClientId("clientId") .build(); String result = RideRequestView.buildUrlFromRideParameters(context, rideParameters, configuration); assertEquals(expectedUri, result); }
@Test public void onBuildUrl_withUserAgentNonNull_shouldNotOverride() throws IOException { String widgetUserAgent = String.format("rides-android-v%s-ride_request_widget", BuildConfig.VERSION_NAME); String path = "src/test/resources/riderequestviewuris/default_uri"; String expectedUri = readUriResourceWithUserAgentParam(path, widgetUserAgent); RideParameters rideParameters = new RideParameters.Builder().build(); rideParameters.setUserAgent(widgetUserAgent); SessionConfiguration configuration = new SessionConfiguration.Builder() .setClientId("clientId") .build(); String result = RideRequestView.buildUrlFromRideParameters(context, rideParameters, configuration); assertEquals(expectedUri, result); }