Skip to content

Commit 8dde5b4

Browse files
devin-ai-integration[bot]rmarescuautofix-ci[bot]
authored
chore: add unit tests for createHash utility (#418)
# Add unit tests for create-hash utility This PR adds unit tests for the create-hash.ts utility file without modifying the original functionality. Link to Devin run: https://app.devin.ai/sessions/afbceacc93aa454d8be8ac4ce5d8c311 Requested by: Razvan Marescu --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Razvan Marescu <razvan@marescu.net> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent a881b06 commit 8dde5b4

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import { describe, expect, it } from "vitest";
2+
import { createHash } from "./create-hash";
3+
4+
describe("createHash", () => {
5+
it("should create a SHA-256 hash from a string", () => {
6+
const data = "test string";
7+
const hash = createHash(data);
8+
9+
expect(hash).toHaveLength(64);
10+
expect(hash).toBe(createHash(data));
11+
});
12+
13+
it("should create a SHA-256 hash from an object", () => {
14+
const data = { key: "value", nested: { prop: true } };
15+
const hash = createHash(data);
16+
17+
expect(hash).toHaveLength(64);
18+
expect(hash).toBe(createHash(data));
19+
});
20+
21+
it("should create a SHA-256 hash from an array", () => {
22+
const data = [1, 2, "three", { four: 4 }];
23+
const hash = createHash(data);
24+
25+
expect(hash).toHaveLength(64);
26+
expect(hash).toBe(createHash(data));
27+
});
28+
29+
it("should create a SHA-256 hash from a number", () => {
30+
const data = 12345;
31+
const hash = createHash(data);
32+
33+
expect(hash).toHaveLength(64);
34+
expect(hash).toBe(createHash(data));
35+
});
36+
37+
it("should create a SHA-256 hash from null", () => {
38+
const data = null;
39+
const hash = createHash(data);
40+
41+
expect(hash).toHaveLength(64);
42+
expect(hash).toBe(createHash(data));
43+
});
44+
45+
it("should truncate the hash to the specified length", () => {
46+
const data = "test string";
47+
const length = 10;
48+
const hash = createHash(data, { length });
49+
50+
expect(hash).toHaveLength(length);
51+
expect(createHash(data).startsWith(hash)).toBe(true);
52+
});
53+
54+
it("should handle length of 0", () => {
55+
const data = "test string";
56+
const hash = createHash(data, { length: 0 });
57+
58+
expect(hash).toHaveLength(64);
59+
expect(hash).toBe(createHash(data));
60+
});
61+
62+
it("should handle length greater than hash length", () => {
63+
const data = "test string";
64+
const hash = createHash(data, { length: 100 });
65+
66+
expect(hash).toHaveLength(64);
67+
expect(hash).toBe(createHash(data));
68+
});
69+
});

0 commit comments

Comments
 (0)