Skip to content

Commit

Permalink
Release: v0.8.1-beta
Browse files Browse the repository at this point in the history
Fix askTheRabbi(): Answer resolve to correct text
  • Loading branch information
itsrn authored Aug 28, 2023
2 parents 1208573 + 0f10fb7 commit 489f835
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 11 deletions.
19 changes: 17 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hidabroot",
"version": "0.8.0-beta",
"version": "0.8.1-beta",
"description": "An unofficial API for hidabroot",
"main": "./build/index.js",
"types": "./build/index.d.ts",
Expand Down Expand Up @@ -36,6 +36,7 @@
"dependencies": {
"@testdeck/mocha": "^0.3.3",
"cheerio": "^1.0.0-rc.12",
"hidabroot": "^0.8.0-beta",
"nyc": "^15.1.0",
"ts-mockito": "^2.6.1"
}
Expand Down
15 changes: 7 additions & 8 deletions src/askTheRabbi/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,18 @@ export async function askTheRabbi(
const formattedQuestion =
question.text().replace(/\s+/g, " ").replace(/<br>/g, "\n") || "";
// gets the whole div with id "article_inner" and save only the answer div in the answer variable
const answer = $("[id=article_inner]").contents().eq(1);
const answer = $("[id=article_inner]").contents().eq(3);
// format the answer div text content
const formattedAnswer =
answer.text().replace(/\s+/g, " ").replace(/<br>/g, "\n") || "";
// saves the json response
const jsonResponse = {
const formattedAnswer = answer
.text()
.replace(/<br>/g, "\n")
.replace(/\s+/g, " ")
.trim();
return {
title: header,
question: formattedQuestion,
answer: formattedAnswer,
};

// returns the json response
return jsonResponse;
}
})
.catch((error) => {
Expand Down
1 change: 1 addition & 0 deletions test/allTests.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ describe("askTheRabbi function", () => {
it("should return a json with 2 string keys - question and answer", async () => {
const questionID = 325090;
const response = await askTheRabbi(questionID);
console.log(response);
expect(response).to.be.an("object");
});

Expand Down

0 comments on commit 489f835

Please sign in to comment.