-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Add basic tests for isEqual function [skip pizza] (#2558)
- Loading branch information
1 parent
d885b24
commit 96dddb3
Showing
2 changed files
with
40 additions
and
1 deletion.
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,36 @@ | ||
import { isEqual } from "./middleware"; | ||
|
||
describe("isEqual() helper function", () => { | ||
it("handles undefined secrets", () => { | ||
const req = { headers: { "api-key": undefined } }; | ||
const result = isEqual(req.headers["api-key"], process.env.UNSET_SECRET!); | ||
expect(result).toBe(false); | ||
}); | ||
|
||
it("handles null values", () => { | ||
const req = { headers: { "api-key": null } }; | ||
// @ts-expect-error "api-key" purposefully set to wrong type | ||
const result = isEqual(req.headers["api-key"], null!); | ||
expect(result).toBe(false); | ||
}); | ||
|
||
it("handles undefined headers", () => { | ||
const req = { headers: { "some-other-header": "test123" } }; | ||
// @ts-expect-error "api-key" purposefully not set | ||
const result = isEqual(req.headers["api-key"]!, process.env.UNSET_SECRET!); | ||
expect(result).toBe(false); | ||
}); | ||
|
||
it("handles empty strings", () => { | ||
const req = { headers: { "api-key": "" } }; | ||
expect(isEqual(req.headers["api-key"], "")).toBe(false); | ||
}); | ||
|
||
it("matches equal values", () => { | ||
expect(isEqual("square", "square")).toBe(true); | ||
}); | ||
|
||
it("does not match different values", () => { | ||
expect(isEqual("circle", "triangle")).toBe(false); | ||
}); | ||
}); |
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