Skip to content

Commit

Permalink
Support walmart.com and walmart.ca
Browse files Browse the repository at this point in the history
  • Loading branch information
xuhdev committed Dec 26, 2024
1 parent b0b3e57 commit 795920e
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 4 deletions.
32 changes: 28 additions & 4 deletions src/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,8 @@ describe("builtin sitedata", () => {
});
}

for (const neweggSiteId of ["Newegg.ca", "Newegg.com"] as const) {
const tld = neweggSiteId.split(".").pop();
for (const tld of ["ca", "com"] as const) {
const neweggSiteId = `Newegg.${tld}` as const;

test(`${neweggSiteId} activating matched`, async () => {
expect(
Expand All @@ -224,8 +224,8 @@ describe("builtin sitedata", () => {
});
}

for (const targetSiteId of ["Target.com"] as const) {
const tld = targetSiteId.split(".").pop();
for (const tld of ["com"] as const) {
const targetSiteId = `Target.${tld}` as const;

test(`${targetSiteId} activating matched`, async () => {
expect(
Expand All @@ -247,4 +247,28 @@ describe("builtin sitedata", () => {
).toBe(`https://www.target.${tld}/s`);
});
}

for (const tld of ["ca", "com"] as const) {
const walmartSiteId = `Walmart.${tld}` as const;

test(`${walmartSiteId} activating matched`, async () => {
expect(
await generateActivatingUrl(
`https://www.walmart.${tld}/search?`,
builtinSiteData,
),
).toBe(
`https://www.walmart.${tld}/search?${siteParams[walmartSiteId].key}=${encodeURIComponent(siteParams[walmartSiteId].value)}`,
);
});

test(`${walmartSiteId} disabling matched`, () => {
expect(
generateDisablingUrl(
`https://www.walmart.${tld}/search?facetedValue=`,
builtinSiteData,
),
).toBe(`https://www.walmart.${tld}/search`);

Check failure on line 271 in src/main.test.ts

View workflow job for this annotation

GitHub Actions / test / Runtime (22.x, ubuntu-24.04)

src/main.test.ts > builtin sitedata > Walmart.ca disabling matched

AssertionError: expected 'https://www.walmart.ca/search?faceted…' to be 'https://www.walmart.ca/search' // Object.is equality Expected: "https://www.walmart.ca/search" Received: "https://www.walmart.ca/search?facetedValue=" ❯ src/main.test.ts:271:9

Check failure on line 271 in src/main.test.ts

View workflow job for this annotation

GitHub Actions / test / Runtime (22.x, ubuntu-24.04)

src/main.test.ts > builtin sitedata > Walmart.com disabling matched

AssertionError: expected 'https://www.walmart.com/search?facete…' to be 'https://www.walmart.com/search' // Object.is equality Expected: "https://www.walmart.com/search" Received: "https://www.walmart.com/search?facetedValue=" ❯ src/main.test.ts:271:9

Check failure on line 271 in src/main.test.ts

View workflow job for this annotation

GitHub Actions / test / Runtime (22.x, macos-15)

src/main.test.ts > builtin sitedata > Walmart.ca disabling matched

AssertionError: expected 'https://www.walmart.ca/search?faceted…' to be 'https://www.walmart.ca/search' // Object.is equality Expected: "https://www.walmart.ca/search" Received: "https://www.walmart.ca/search?facetedValue=" ❯ src/main.test.ts:271:9

Check failure on line 271 in src/main.test.ts

View workflow job for this annotation

GitHub Actions / test / Runtime (22.x, macos-15)

src/main.test.ts > builtin sitedata > Walmart.com disabling matched

AssertionError: expected 'https://www.walmart.com/search?facete…' to be 'https://www.walmart.com/search' // Object.is equality Expected: "https://www.walmart.com/search" Received: "https://www.walmart.com/search?facetedValue=" ❯ src/main.test.ts:271:9
});
}
});
34 changes: 34 additions & 0 deletions src/site_data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ export const siteParams = {
key: "facetedValue",
value: "dq4mn",
},
"Walmart.ca": {
key: "facet",
value: "retailer_type:Walmart",
},
"Walmart.com": {
key: "facet",
value: "retailer_type:Walmart",
},
} as const;

export const builtinSiteData = [
Expand Down Expand Up @@ -223,4 +231,30 @@ export const builtinSiteData = [
siteParams["Target.com"].value,
),
},
{
id: "Walmart.ca",
name: "Walmart.ca",
urlRegex: /https:\/\/www\.walmart\.ca\/search\?.*/,
disablingFunc: (url: string): string | null =>
removeUrlParam(url, siteParams["Walmart.ca"].key),
activatingFunc: (url: string): string | null =>
addUrlParam(
url,
siteParams["Walmart.ca"].key,
siteParams["Walmart.ca"].value,
),
},
{
id: "Walmart.com",
name: "Walmart.com",
urlRegex: /https:\/\/www\.walmart\.com\/search\?.*/,
disablingFunc: (url: string): string | null =>
removeUrlParam(url, siteParams["Walmart.com"].key),
activatingFunc: (url: string): string | null =>
addUrlParam(
url,
siteParams["Walmart.com"].key,
siteParams["Walmart.com"].value,
),
},
] as const satisfies SiteData;

0 comments on commit 795920e

Please sign in to comment.