Skip to content

Commit

Permalink
test cases added
Browse files Browse the repository at this point in the history
  • Loading branch information
darsan-in committed May 18, 2024
1 parent b75e860 commit 86d4f9e
Show file tree
Hide file tree
Showing 58 changed files with 4,319 additions and 1,265 deletions.
6 changes: 6 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
presets: [
["@babel/preset-env", { targets: { node: "current" } }],
"@babel/preset-typescript",
],
};
8 changes: 8 additions & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import type { Config } from "jest";

const config: Config = {
verbose: true,
testPathIgnorePatterns: ["dist"],
};

export default config;
43 changes: 19 additions & 24 deletions lib/aggregator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ import { cwd } from "node:process";

import { reservedNames, timeFormat } from "../rjsconfig.json";


import { getCode } from "country-list";
import { stat } from "node:fs/promises";

Expand Down Expand Up @@ -132,7 +131,7 @@ export function article(htmlString: string): articleOptions {
const value =
type === reservedNames.common.author.url ?
$(elem).attr("href")
: $(elem).html();
: $(elem).html();

if (type.startsWith(reservedNames.common.author.name)) {
authorMetaData[id].name = value;
Expand Down Expand Up @@ -170,7 +169,7 @@ export function article(htmlString: string): articleOptions {
const value =
type === reservedNames.common.publisher.url ?
$(elem).attr("href")
: $(elem).html();
: $(elem).html();
if (type === reservedNames.common.publisher.name) {
publisherMetaData[id].name = value;
} else if (type === reservedNames.common.publisher.url) {
Expand Down Expand Up @@ -363,8 +362,8 @@ export function course(
if (!availableModeType.includes(mode)) {
throw new Error(
"given mode in HTML is not supported.\nOnly these are supported by Richie JS\n[ " +
availableModeType.join(", ") +
" ]",
availableModeType.join(", ") +
" ]",
);
}

Expand Down Expand Up @@ -438,7 +437,7 @@ export function movie(
//adding url deeplink
movieMetas[id].url = new URL(
relative(cwd(), htmlPath).replace(".html", "") +
`#${movieBaseID}-${id}`,
`#${movieBaseID}-${id}`,
httpsDomainBase,
).href;

Expand Down Expand Up @@ -1150,9 +1149,7 @@ function commonBusinessEntityThings(
$(elem)
.children()
.each((_index: number, areaElem: Element) => {
let availablearea: string = $(areaElem)
.html()
?.trim() as string;
let availablearea: string = $(areaElem).html()?.trim() as string;

//remove special chars to retain only alphanumeric text
availablearea = availablearea?.replace(/[^a-zA-Z0-9]/g, "");
Expand Down Expand Up @@ -1265,7 +1262,7 @@ export async function eventsPage(
} catch {
console.log(
"Error While Parsing Data String\n DateTime format should follow this " +
timeFormat,
timeFormat,
);
process.exit(1);
}
Expand All @@ -1275,7 +1272,7 @@ export async function eventsPage(
} catch {
console.log(
"Error While Parsing Data String\n DateTime format should follow this " +
timeFormat,
timeFormat,
);
process.exit(1);
}
Expand Down Expand Up @@ -1378,7 +1375,7 @@ export async function eventsPage(
const venue: string = $(elem)
.find(
"." +
reservedNames.businessEntity.location.physicalLocationName,
reservedNames.businessEntity.location.physicalLocationName,
)
.html()
?.trim() as string;
Expand Down Expand Up @@ -1439,7 +1436,7 @@ export async function eventsPage(
reservedNames.common.authorAndPubPrefix.organisation?.toLowerCase()
) ?
"Organization"
: "Person",
: "Person",
name: innerText,
url: $(elem).attr("href") ?? "no url found",
};
Expand Down Expand Up @@ -1479,7 +1476,6 @@ export function FAQ(htmlString: string): FAQMeta[] {
return faqsMetaData;
}


export async function video(
htmlString: string,
): Promise<videoObjectOptions[]> {
Expand Down Expand Up @@ -1588,7 +1584,6 @@ export async function localBusiness(
elem,
$,
) as LocalBusinessOptions;

});

// Use Promise.all to await all asynchronous operations
Expand All @@ -1600,7 +1595,6 @@ export async function localBusiness(
return localBusinessMetaData;
}


export function organisation(
htmlString: string,
htmlPath: string,
Expand Down Expand Up @@ -1695,7 +1689,8 @@ export async function productPage(
const productBaseID = reservedNames.product.baseID;
const productMetas: Record<string, ProductOptions> = {};

const validitySecs: number = reservedNames.product.productPriceValidUntilNext * 24 * 60 * 60;
const validitySecs: number =
reservedNames.product.productPriceValidUntilNext * 24 * 60 * 60;

const validTill: string = new Date(
(await stat(resolve(htmlPath))).mtimeMs + validitySecs,
Expand Down Expand Up @@ -1758,8 +1753,8 @@ export async function productPage(

const gender: Gender =
rawGender === "male" ? "MALE"
: rawGender === "female" ? "FEMALE"
: "UNISEX";
: rawGender === "female" ? "FEMALE"
: "UNISEX";

productMetas[id].suggestedGender = gender;

Expand Down Expand Up @@ -1838,9 +1833,9 @@ export async function productPage(

productMetas[id].offer.itemCondition =
itemCondition === "new" ? "NewCondition"
: itemCondition === "used" ? "UsedCondition"
: itemCondition === "refurb" ? "RefurbishedCondition"
: "Not Mentioned";
: itemCondition === "used" ? "UsedCondition"
: itemCondition === "refurb" ? "RefurbishedCondition"
: "Not Mentioned";
} else if (
type === reservedNames.product.offer.shippingDetails.deliveryCost
) {
Expand Down Expand Up @@ -1877,11 +1872,11 @@ export async function productPage(
returnPolicyCategory:
returnWithin > 0 ?
"MerchantReturnFiniteReturnWindow"
: "MerchantReturnNotPermitted",
: "MerchantReturnNotPermitted",
returnFees:
returnFees === "0" || returnFees === "free" ?
"FreeReturn"
: "ReturnFeesCustomerResponsibility",
: "ReturnFeesCustomerResponsibility",
} as MerchantReturnPolicy;
} else if (
type === reservedNames.product.offer.shippingDetails.processingTime
Expand Down
5 changes: 5 additions & 0 deletions lib/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -579,3 +579,8 @@ export const richieGroupB: richies[] = [

//(C) i-HTMLPath
export const richieGroupC: richies[] = ["breadcrumb", "searchbox"];

export interface testProps {
testfile: string;
destFile: string;
}
32 changes: 0 additions & 32 deletions outputs/Test_index.html

This file was deleted.

Loading

0 comments on commit 86d4f9e

Please sign in to comment.