Skip to content

Commit

Permalink
Add failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hansott committed Dec 18, 2024
1 parent 4997531 commit 17d8b32
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions library/helpers/attackPath.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import * as t from "tap";
import { getPathsToPayload as get } from "./attackPath";

t.test("it throws error if max matches is less than 1", async (t) => {
t.throws(() => get("payload", {}, 0));
t.throws(() => get("payload", {}, -1));
});

t.test("it gets paths to payload", async (t) => {
const testObj1 = {
a: {
Expand Down Expand Up @@ -91,3 +96,15 @@ t.test("respects max depth and array length", async (t) => {
t.test("first item in array", async (t) => {
t.same(get("id = 1", ["id = 1"]), [".[0]"]);
});

t.test("it checks max matches when iterating over object props", async (t) => {
const testObj = {
a: ["test"],
b: ["test"],
c: ["test"],
};

t.same(get("test", testObj, 1), [".a.[0]"]);
t.same(get("test", testObj, 2), [".a.[0]", ".b.[0]"]);
t.same(get("test", testObj, 3), [".a.[0]", ".b.[0]", ".c.[0]"]);
});

0 comments on commit 17d8b32

Please sign in to comment.