Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions pkg/commands/hscan.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { afterAll, expect, test } from "bun:test";
import { afterAll, describe, expect, test } from "bun:test";
import { keygen, newHttpClient } from "../test-utils";

import { HScanCommand } from "./hscan";
Expand All @@ -7,38 +7,38 @@ const client = newHttpClient();

const { newKey, cleanup } = keygen();
afterAll(cleanup);
test("without options", () => {
describe("without options", () => {
test("returns cursor and members", async () => {
const key = newKey();
await new HSetCommand([key, { field: "value" }]).exec(client);
const res = await new HScanCommand([key, 0]).exec(client);

expect(res.length, 2);
expect(typeof res[0], "number");
expect(res![1].length > 0, true);
expect(res.length).toBe(2);
expect(typeof res[0]).toBe("number");
expect(res![1].length > 0).toBe(true);
});
});

test("with match", () => {
describe("with match", () => {
test("returns cursor and members", async () => {
const key = newKey();
await new HSetCommand([key, { field: "value" }]).exec(client);
const res = await new HScanCommand([key, 0, { match: "field" }]).exec(client);

expect(res.length, 2);
expect(typeof res[0], "number");
expect(res![1].length > 0, true);
expect(res.length).toBe(2);
expect(typeof res[0]).toBe("number");
expect(res![1].length > 0).toBe(true);
});
});

test("with count", () => {
describe("with count", () => {
test("returns cursor and members", async () => {
const key = newKey();
await new HSetCommand([key, { field: "value" }]).exec(client);
const res = await new HScanCommand([key, 0, { count: 1 }]).exec(client);

expect(res.length, 2);
expect(typeof res[0], "number");
expect(res![1].length > 0, true);
expect(res.length).toBe(2);
expect(typeof res[0]).toBe("number");
expect(res![1].length > 0).toBe(true);
});
});
2 changes: 1 addition & 1 deletion pkg/commands/json_arrappend.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ test("Add a new color to a list of product colors", async () => {
colors: ["black", "silver"],
},
]).exec(client);
expect(res1, "OK");
expect(res1).toBe("OK");
const res2 = await new JsonArrAppendCommand([key, "$.colors", '"blue"']).exec(client);
expect(res2).toEqual([3]);
const res3 = await new JsonGetCommand([key]).exec(client);
Expand Down
12 changes: 6 additions & 6 deletions pkg/commands/json_arrindex.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ test("Find the specific place of a color in a list of product colors", async ()
colors: ["black", "silver"],
},
]).exec(client);
expect(res1, "OK");
expect(res1).toBe("OK");
const res2 = await new JsonArrAppendCommand([key, "$.colors", '"blue"']).exec(client);
expect(res2).toEqual([3]);
const res3 = await new JsonGetCommand([key]).exec(client);
Expand All @@ -40,15 +40,15 @@ test("Find the specific place of a color in a list of product colors", async ()
colors: ["black", "silver", "blue"],
});
const res4 = await new JsonGetCommand([key, "$.colors[*]"]).exec(client);
expect(res4, ["black", "silver", "blue"]);
expect(res4).toEqual(["black", "silver", "blue"]);

const res5 = await new JsonArrInsertCommand([key, "$.colors", 2, '"yellow"', '"gold"']).exec(
client,
client
);
expect(res5, [5]);
expect(res5).toEqual([5]);
const res6 = await new JsonGetCommand([key, "$.colors"]).exec(client);
expect(res6, [["black", "silver", "yellow", "gold", "blue"]]);
expect(res6).toEqual([["black", "silver", "yellow", "gold", "blue"]]);

const res7 = await new JsonArrIndexCommand([key, "$..colors", '"silver"']).exec(client);
expect(res7, [1]);
expect(res7).toEqual([1]);
});
10 changes: 5 additions & 5 deletions pkg/commands/json_arrinsert.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ test("Add new colors to a specific place in a list of product colors", async ()
colors: ["black", "silver"],
},
]).exec(client);
expect(res1, "OK");
expect(res1).toBe("OK");
const res2 = await new JsonArrAppendCommand([key, "$.colors", '"blue"']).exec(client);
expect(res2).toEqual([3]);
const res3 = await new JsonGetCommand([key]).exec(client);
Expand All @@ -39,11 +39,11 @@ test("Add new colors to a specific place in a list of product colors", async ()
colors: ["black", "silver", "blue"],
});
const res4 = await new JsonGetCommand([key, "$.colors"]).exec(client);
expect(res4, [["black", "silver", "blue"]]);
expect(res4).toEqual([["black", "silver", "blue"]]);
const res5 = await new JsonArrInsertCommand([key, "$.colors", 2, '"yellow"', '"gold"']).exec(
client,
client
);
expect(res5, [5]);
expect(res5).toEqual([5]);
const res6 = await new JsonGetCommand([key, "$.colors"]).exec(client);
expect(res6, [["black", "silver", "yellow", "gold", "blue"]]);
expect(res6).toEqual([["black", "silver", "yellow", "gold", "blue"]]);
});
2 changes: 1 addition & 1 deletion pkg/commands/json_arrlen.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ test("Get lengths of JSON arrays in a document", async () => {
max_level: [80, 100, 120],
},
]).exec(client);
expect(res1, "OK");
expect(res1).toBe("OK");
const res2 = await new JsonArrLenCommand([key, "$.max_level"]).exec(client);
expect(res2).toEqual([3]);
});
2 changes: 1 addition & 1 deletion pkg/commands/json_arrpop.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ test("Pop a value from an index and insert a new value", async () => {
max_level: [80, 90, 100, 120],
},
]).exec(client);
expect(res1, "OK");
expect(res1).toBe("OK");

const res2 = await new JsonArrPopCommand([key, "$.max_level", 0]).exec(client);
expect(res2).toEqual([80]);
Expand Down
6 changes: 3 additions & 3 deletions pkg/commands/json_arrtrim.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ test("Trim an array to a specific set of values", async () => {
a: [1],
},
]).exec(client);
expect(res1, "OK");
expect(res1).toBe("OK");
const res2 = await new JsonArrAppendCommand([key, "$.a", 2]).exec(client);
expect(res2.sort(), [2]);
expect(res2.sort()).toEqual([2]);
const res3 = await new JsonArrTrimCommand([key, "$.a", 1, 1]).exec(client);
expect(res3).toEqual([1]);
const res4 = await new JsonGetCommand([key, "$.a"]).exec(client);
expect(res4, [[2]]);
expect(res4).toEqual([[2]]);
});
2 changes: 1 addition & 1 deletion pkg/commands/json_clear.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ test("Clear container values and set numeric values to 0", async () => {
"$",
'{"obj":{"a":1, "b":2}, "arr":[1,2,3], "str": "foo", "bool": true, "int": 42, "float": 3.14}',
]).exec(client);
expect(res1, "OK");
expect(res1).toBe("OK");
const res2 = await new JsonClearCommand([key, "$.*"]).exec(client);
expect(res2).toEqual(4);
const res3 = await new JsonGetCommand([key, "$"]).exec(client);
Expand Down
2 changes: 1 addition & 1 deletion pkg/commands/json_del.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ test("Delete a value", async () => {
nested: { a: 2, b: 3 },
},
]).exec(client);
expect(res1, "OK");
expect(res1).toBe("OK");
const res2 = await new JsonDelCommand([key, "$..a"]).exec(client);
expect(res2).toEqual(2);
const res3 = await new JsonGetCommand([key, "$"]).exec(client);
Expand Down
2 changes: 1 addition & 1 deletion pkg/commands/json_forget.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ test("Delete a value", async () => {
nested: { a: 2, b: 3 },
},
]).exec(client);
expect(res1, "OK");
expect(res1).toBe("OK");
const res2 = await new JsonForgetCommand([key, "$..a"]).exec(client);
expect(res2).toEqual(2);
const res3 = await new JsonGetCommand([key, "$"]).exec(client);
Expand Down
2 changes: 1 addition & 1 deletion pkg/commands/json_get.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ test("Return the value at path in JSON serialized form", async () => {
nested: { a: 4, b: null },
},
]).exec(client);
expect(res1, "OK");
expect(res1).toBe("OK");
const res2 = await new JsonGetCommand([key, "$..b"]).exec(client);
expect(res2).toEqual([null, 3]);
const res3 = await new JsonGetCommand([key, "$..a", "$..b"]).exec(client);
Expand Down
2 changes: 1 addition & 1 deletion pkg/commands/json_mget.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ test("Return the values at path from multiple key arguments", async () => {
c: null,
},
]).exec(client);
expect(res1, "OK");
expect(res1).toBe("OK");

const res2 = await new JsonSetCommand([
key2,
Expand Down
6 changes: 3 additions & 3 deletions pkg/commands/json_nummultby.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ test("return the length", async () => {
b: [{ a: 2 }, { a: 5 }, { a: "c" }],
},
]).exec(client);
expect(res1, "OK");
expect(res1).toBe("OK");
const res2 = await new JsonNumMultByCommand([key, "$.a", 2]).exec(client);
expect(res2.sort(), [null]);
expect(res2.sort()).toEqual([null]);
const res3 = await new JsonNumMultByCommand([key, "$..a", 2]).exec(client);
expect(res3.sort(), [10, 4, null, null]);
expect(res3.sort()).toEqual([10, 4, null, null]);
});
2 changes: 1 addition & 1 deletion pkg/commands/json_objlen.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ test("return the length", async () => {
nested: { a: { b: 2, c: 1 } },
},
]).exec(client);
expect(res1, "OK");
expect(res1).toBe("OK");
const res2 = await new JsonObjLenCommand([key, "$..a"]).exec(client);
expect(res2).toEqual([2, null]);
});
4 changes: 2 additions & 2 deletions pkg/commands/json_resp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ test("Return an array of RESP details about a document", async () => {
max_level: [80, 100, 120],
},
]).exec(client);
expect(res1, "OK");
expect(res1).toBe("OK");
const res2 = await new JsonRespCommand([key]).exec(client);
expect(res2.length, 15);
expect(res2.length).toBe(15);
});
4 changes: 2 additions & 2 deletions pkg/commands/json_strappend.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ test("Add 'baz' to existing string", async () => {
nested2: { a: 31 },
},
]).exec(client);
expect(res1, "OK");
expect(res1).toBe("OK");
const res2 = await new JsonStrAppendCommand([key, "$..a", '"baz"']).exec(client);
expect(res2.sort(), [6, 8, null]);
expect(res2.sort()).toEqual([6, 8, null]);
const res3 = await new JsonGetCommand([key]).exec(client);
expect(res3).toEqual({
a: "foobaz",
Expand Down
4 changes: 2 additions & 2 deletions pkg/commands/json_strlen.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ test("return the length", async () => {
nested2: { a: 31 },
},
]).exec(client);
expect(res1, "OK");
expect(res1).toBe("OK");
const res2 = await new JsonStrLenCommand([key, "$..a"]).exec(client);
expect(res2.sort(), [3, 5, null]);
expect(res2.sort()).toEqual([3, 5, null]);
});
6 changes: 3 additions & 3 deletions pkg/commands/json_toggle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ afterAll(cleanup);
test("Toogle a Boolean value stored at path", async () => {
const key = newKey();
const res1 = await new JsonSetCommand([key, "$", { bool: true }]).exec(client);
expect(res1, "OK");
expect(res1).toBe("OK");
const res2 = await new JsonToggleCommand([key, "$.bool"]).exec(client);
expect(res2).toEqual([0]);
const res3 = await new JsonGetCommand([key, "$"]).exec(client);
expect(res3).toEqual([{ bool: false }]);
const res4 = await new JsonToggleCommand([key, "$.bool"]).exec(client);
expect(res4, [1]);
expect(res4).toEqual([1]);
const res5 = await new JsonGetCommand([key, "$"]).exec(client);
expect(res5, [{ bool: true }]);
expect(res5).toEqual([{ bool: true }]);
});
6 changes: 3 additions & 3 deletions pkg/commands/json_type.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ test("return the length", async () => {
foo: "bar",
},
]).exec(client);
expect(res1, "OK");
expect(res1).toBe("OK");
const res2 = await new JsonTypeCommand([key, "$..foo"]).exec(client);
expect(res2.sort(), ["string"]);
expect(res2.sort()).toEqual(["string"]);
const res3 = await new JsonTypeCommand([key, "$..a"]).exec(client);
expect(res3.sort(), ["boolean", "integer"]);
expect(res3.sort()).toEqual(["boolean", "integer"]);
});
2 changes: 1 addition & 1 deletion pkg/commands/linsert.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ test("adds the element", async () => {
expect(res).toEqual(2);

const list = await new LRangeCommand([key, 0, -1]).exec(client);
expect(list, [value2, value1]);
expect(list).toEqual([value2, value1]);
});
8 changes: 4 additions & 4 deletions pkg/commands/lmove.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ test("moves the entry from left to left", async () => {
expect(res).toEqual(value);

const elementInSource = await new LPopCommand([source]).exec(client);
expect(elementInSource, null);
expect(elementInSource).toEqual(null);

const elementInDestination = await new LPopCommand([destination]).exec(client);
expect(elementInDestination, value);
expect(elementInDestination).toBe(value);
});

test("moves the entry from left to right", async () => {
Expand All @@ -39,8 +39,8 @@ test("moves the entry from left to right", async () => {
expect(res).toEqual(values.at(-1));

const elementsInSource = await new LLenCommand([source]).exec(client);
expect(elementsInSource, values.length - 1);
expect(elementsInSource).toEqual(values.length - 1);

const elementInDestination = await new LPopCommand([destination]).exec(client);
expect(elementInDestination, values.at(-1));
expect(elementInDestination).toEqual(values.at(-1));
});
2 changes: 1 addition & 1 deletion pkg/commands/lpos.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ test("with rank", () => {
const key = newKey();
await new RPushCommand([key, "a", "b", "c", 1, 2, 3, "c", "c"]).exec(client);
const cmd = new LPosCommand([key, "c", { rank: 2 }]);
expect(cmd.command, ["lpos", key, "c", "rank", 2]);
expect(cmd.command).toEqual(["lpos", key, "c", "rank", 2]);
const res = await cmd.exec(client);
expect(res).toEqual(6);
});
Expand Down
6 changes: 3 additions & 3 deletions pkg/commands/lrange.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ test("returns the correct range", async () => {
const value3 = randomID();
await new RPushCommand([key, value1, value2, value3]).exec(client);
const res = await new LRangeCommand([key, 1, 2]).exec(client);
expect(res!.length, 2);
expect(res![0], value2);
expect(res![1], value3);
expect(res!.length).toBe(2);
expect(res![0]).toBe(value2);
expect(res![1]).toBe(value3);
});
5 changes: 3 additions & 2 deletions pkg/commands/ping.test.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import { describe, test, expect } from "bun:test";
import { newHttpClient, randomID } from "../test-utils";
import { PingCommand } from "./ping";

const client = newHttpClient();

test("with message", () => {
describe("with message", () => {
test("returns the message", async () => {
const message = randomID();
const res = await new PingCommand([message]).exec(client);
expect(res).toEqual(message);
});
});
test("without message", () => {
describe("without message", () => {
test("returns pong", async () => {
const res = await new PingCommand([]).exec(client);
expect(res).toEqual("PONG");
Expand Down
2 changes: 1 addition & 1 deletion pkg/commands/pttl.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ test("returns the ttl on a key", async () => {
const ttl = 60;
await new SetExCommand([key, ttl, "value"]).exec(client);
const res = await new PTtlCommand([key]).exec(client);
expect(res <= ttl * 1000, true);
expect(res <= ttl * 1000).toBe(true);
});
3 changes: 2 additions & 1 deletion pkg/commands/publish.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { expect, test } from "bun:test";
import { newHttpClient } from "../test-utils";

import { PublishCommand } from "./publish";
Expand All @@ -7,5 +8,5 @@ const client = newHttpClient();
test("returns the number of clients that received the message", async () => {
const res = await new PublishCommand(["channel", "hello"]).exec(client);

expect(typeof res, "number");
expect(typeof res).toBe("number");
});
2 changes: 1 addition & 1 deletion pkg/commands/randomkey.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ test("returns a random key", async () => {
const key = newKey();
await new SetCommand([key, randomID()]).exec(client);
const res = await new RandomKeyCommand().exec(client);
expect(typeof res, "string");
expect(typeof res).toBe("string");
});
Loading