-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of github.com:upstash/upstash-redis into DX-414
- Loading branch information
Showing
7 changed files
with
233 additions
and
162 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,83 @@ | ||
import { newHttpClient } from "../test-utils.ts"; | ||
|
||
import { assertEquals } from "https://deno.land/[email protected]/testing/asserts.ts"; | ||
|
||
import { GeoAddCommand } from "./geo_add.ts"; | ||
import { GeoDistCommand } from "./geo_dist.ts"; | ||
|
||
const client = newHttpClient(); | ||
|
||
Deno.test("should return distance successfully in meters", async () => { | ||
await new GeoAddCommand([ | ||
"Sicily", | ||
{ longitude: 13.361389, latitude: 38.115556, member: "Palermo" }, | ||
{ longitude: 15.087269, latitude: 37.502669, member: "Catania" }, | ||
]).exec(client); | ||
|
||
const res = await new GeoDistCommand(["Sicily", "Palermo", "Catania"]).exec( | ||
client, | ||
); | ||
|
||
assertEquals(res, 166274.1516); | ||
}); | ||
|
||
Deno.test("should return distance for object members", async () => { | ||
await new GeoAddCommand([ | ||
"Sicily", | ||
{ longitude: 13.361389, latitude: 38.115556, member: { name: "Palermo" } }, | ||
{ longitude: 15.087269, latitude: 37.502669, member: { name: "Catania" } }, | ||
]).exec(client); | ||
|
||
const res = await new GeoDistCommand(["Sicily", { name: "Palermo" }, { | ||
name: "Catania", | ||
}]).exec( | ||
client, | ||
); | ||
|
||
assertEquals(res, 166274.1516); | ||
}); | ||
|
||
Deno.test("should return distance successfully in kilometers", async () => { | ||
await new GeoAddCommand([ | ||
"Sicily", | ||
{ longitude: 13.361389, latitude: 38.115556, member: "Palermo" }, | ||
{ longitude: 15.087269, latitude: 37.502669, member: "Catania" }, | ||
]).exec(client); | ||
|
||
const res = await new GeoDistCommand(["Sicily", "Palermo", "Catania", "KM"]) | ||
.exec(client); | ||
|
||
assertEquals(res, 166.2742); | ||
}); | ||
|
||
Deno.test("should return distance successfully in miles", async () => { | ||
await new GeoAddCommand([ | ||
"Sicily", | ||
{ longitude: 13.361389, latitude: 38.115556, member: "Palermo" }, | ||
{ longitude: 15.087269, latitude: 37.502669, member: "Catania" }, | ||
]).exec(client); | ||
|
||
const res = await new GeoDistCommand(["Sicily", "Palermo", "Catania", "MI"]) | ||
.exec(client); | ||
|
||
assertEquals(res, 103.3182); | ||
}); | ||
|
||
Deno.test("should return distance successfully in feet", async () => { | ||
await new GeoAddCommand([ | ||
"Sicily", | ||
{ longitude: 13.361389, latitude: 38.115556, member: "Palermo" }, | ||
{ longitude: 15.087269, latitude: 37.502669, member: "Catania" }, | ||
]).exec(client); | ||
|
||
const res = await new GeoDistCommand(["Sicily", "Palermo", "Catania", "FT"]) | ||
.exec(client); | ||
|
||
assertEquals(res?.toString(), "545518.8700"); | ||
}); | ||
|
||
Deno.test("should return null if members doesn't exist", async () => { | ||
const res = await new GeoDistCommand(["Sicily", "FOO", "BAR"]).exec(client); | ||
|
||
assertEquals(res, null); | ||
}); |
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,19 @@ | ||
import { Command, CommandOptions } from "./command.ts"; | ||
|
||
/** | ||
* @see https://redis.io/commands/geodist | ||
*/ | ||
export class GeoDistCommand<TMemberType = string> | ||
extends Command<number | null, number | null> { | ||
constructor( | ||
[key, member1, member2, unit = "M"]: [ | ||
key: string, | ||
member1: TMemberType, | ||
member2: TMemberType, | ||
unit?: "M" | "KM" | "FT" | "MI", | ||
], | ||
opts?: CommandOptions<number | null, number | null>, | ||
) { | ||
super(["GEODIST", key, member1, member2, unit], opts); | ||
} | ||
} |
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
Oops, something went wrong.