Skip to content

Commit 83f20da

Browse files
fix: broken search and sort test cases
1 parent e6a2ad3 commit 83f20da

2 files changed

Lines changed: 17 additions & 27 deletions

File tree

src/lib/utilities/search.test.ts

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,19 @@ import { createSearchKey, createSearchKeys, findMatches } from "./search";
55
import type { Store } from "$lib/types/store";
66

77
const createStore = (overrides: Partial<Store> = {}): Store => ({
8-
l: "",
98
n: "",
109
u: "",
11-
c: "",
1210
s30: 0,
13-
sav: 0,
14-
aff: "",
15-
cc: 0,
11+
a30: 0,
12+
p: 0,
13+
c: 0,
1614
...overrides
1715
});
1816

1917
describe("createSearchKey", () => {
20-
it("combines name, url, and country into lowercase key", () => {
21-
const store = createStore({ n: "Amazon", u: "amazon.com", c: "US" });
22-
expect(createSearchKey(store)).toBe("amazon amazon.com us");
18+
it("combines name and url into lowercase key", () => {
19+
const store = createStore({ n: "Amazon", u: "amazon.com" });
20+
expect(createSearchKey(store)).toBe("amazon amazon.com");
2321
});
2422

2523
it("handles missing fields gracefully", () => {
@@ -59,11 +57,11 @@ describe("createSearchKeys", () => {
5957

6058
describe("findMatches", () => {
6159
const stores = [
62-
createStore({ n: "Amazon", u: "amazon.com", c: "US" }),
63-
createStore({ n: "Amazon UK", u: "amazon.co.uk", c: "UK" }),
64-
createStore({ n: "Walmart", u: "walmart.com", c: "US" }),
65-
createStore({ n: "Best Buy", u: "bestbuy.com", c: "US" }),
66-
createStore({ n: "Target", u: "target.com", c: "US" })
60+
createStore({ n: "Amazon", u: "amazon.com" }),
61+
createStore({ n: "Amazon UK", u: "amazon.co.uk" }),
62+
createStore({ n: "Walmart", u: "walmart.com" }),
63+
createStore({ n: "Best Buy", u: "bestbuy.com" }),
64+
createStore({ n: "Target", u: "target.com" })
6765
];
6866
const keys = createSearchKeys(stores);
6967
const allIndices = [0, 1, 2, 3, 4];
@@ -93,14 +91,8 @@ describe("findMatches", () => {
9391
expect(stores[results[0]].n).toBe("Best Buy");
9492
});
9593

96-
it("matches by country", () => {
97-
const results = findMatches(allIndices, keys, "uk", 100);
98-
expect(results).toHaveLength(1);
99-
expect(stores[results[0]].n).toBe("Amazon UK");
100-
});
101-
10294
it("respects maxResults limit", () => {
103-
const results = findMatches(allIndices, keys, "us", 2);
95+
const results = findMatches(allIndices, keys, "m", 2);
10496
expect(results).toHaveLength(2);
10597
});
10698

src/lib/utilities/sort.test.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,12 @@ import {
88
import type { Store } from "$lib/types/store";
99

1010
const createStore = (overrides: Partial<Store> = {}): Store => ({
11-
l: "",
1211
n: "",
1312
u: "",
14-
c: "",
1513
s30: 0,
16-
sav: 0,
17-
aff: "",
18-
cc: 0,
14+
a30: 0,
15+
p: 0,
16+
c: 0,
1917
...overrides
2018
});
2119

@@ -24,8 +22,8 @@ describe("getValue", () => {
2422
n: "Amazon",
2523
u: "amazon.com",
2624
s30: 1000,
27-
sav: 500,
28-
cc: 25
25+
a30: 500,
26+
c: 25
2927
});
3028

3129
it("returns name for 'info' key", () => {

0 commit comments

Comments
 (0)