-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add testing fakes for Distance Matrix
PiperOrigin-RevId: 577270364
- Loading branch information
1 parent
b69d8bd
commit 40efe98
Showing
3 changed files
with
62 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** | ||
* @license | ||
* Copyright 2023 Google LLC | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
export const FAKE_DM_VALUE = 101; | ||
|
||
/** | ||
* Creates a fake Distance Matrix response, based on a map `fakeDistances` that | ||
* specifies the resulting distance for a given _destination_ point. If a | ||
* destination isn't found in the map, 101 is used as the distance. | ||
*/ | ||
export function makeFakeDistanceMatrixResponse( | ||
request: google.maps.DistanceMatrixRequest, | ||
fakeDistances = | ||
new Map<unknown, number>()): google.maps.DistanceMatrixResponse { | ||
const rows: google.maps.DistanceMatrixResponseRow[] = []; | ||
for (const _ of request.origins) { | ||
const row = []; | ||
for (const destination of request.destinations) { | ||
const fakeValue = fakeDistances.get(destination) ?? FAKE_DM_VALUE; | ||
const result = { | ||
status: 'OK' as google.maps.DistanceMatrixElementStatus, | ||
distance: {value: fakeValue, text: `${fakeValue} ${request.unitSystem}`} | ||
} as google.maps.DistanceMatrixResponseElement; | ||
row.push(result); | ||
} | ||
rows.push({elements: row}); | ||
} | ||
return {originAddresses: [], destinationAddresses: [], rows}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters