-
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.
fix(hgetall): handle unsafe integer in deserialization (#664)
* fix(hgetall): handle unsafe integer in deserialization * test: add test for randomUnsafeIntegerString() * fix(test-utils): Fix randomUnsafeIntegerString implementation * Format changes with fmt --------- Co-authored-by: ogzhanolguncu <[email protected]>
- Loading branch information
1 parent
6460921
commit bf6288e
Showing
5 changed files
with
96 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,8 +1,13 @@ | ||
import { keygen, newHttpClient, randomID } from "../test-utils.ts"; | ||
import { assertEquals } from "https://deno.land/[email protected]/testing/asserts.ts"; | ||
import { afterAll } from "https://deno.land/[email protected]/testing/bdd.ts"; | ||
import { HSetCommand } from "./hset.ts"; | ||
import { | ||
keygen, | ||
newHttpClient, | ||
randomID, | ||
randomUnsafeIntegerString, | ||
} from "../test-utils.ts"; | ||
import { HGetAllCommand } from "./hgetall.ts"; | ||
import { HSetCommand } from "./hset.ts"; | ||
|
||
const client = newHttpClient(); | ||
|
||
|
@@ -29,3 +34,21 @@ Deno.test("when hash does not exist", async (t) => { | |
assertEquals(res, null); | ||
}); | ||
}); | ||
Deno.test("properly return bigint precisely", async () => { | ||
const key = newKey(); | ||
const field3 = randomID(); | ||
const field2 = randomID(); | ||
const field1 = randomID(); | ||
const value1 = false; | ||
const value2 = randomID(); | ||
const value3 = randomUnsafeIntegerString(); | ||
await new HSetCommand([ | ||
key, | ||
{ [field1]: value1, [field2]: value2, [field3]: value3 }, | ||
]).exec(client); | ||
|
||
const res = await new HGetAllCommand([key]).exec(client); | ||
|
||
const obj = { [field1]: value1, [field2]: value2, [field3]: value3 }; | ||
assertEquals(res, obj); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { | ||
assertEquals, | ||
assertFalse, | ||
} from "https://deno.land/[email protected]/testing/asserts.ts"; | ||
import { randomUnsafeIntegerString } from "./test-utils.ts"; | ||
|
||
Deno.test("randomUnsafeIntegerString() should return a string", () => { | ||
const result = randomUnsafeIntegerString(); | ||
assertEquals(typeof result, "string"); | ||
}); | ||
Deno.test("randomUnsafeIntegerString() should return different values", () => { | ||
const result1 = randomUnsafeIntegerString(); | ||
const result2 = randomUnsafeIntegerString(); | ||
assertEquals(result1 !== result2, true); | ||
}); | ||
Deno.test( | ||
"randomUnsafeIntegerString() should return a string with unsafe integer", | ||
() => { | ||
const result = randomUnsafeIntegerString(); | ||
assertFalse(Number.isSafeInteger(Number(result))); | ||
}, | ||
); |
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