Files
amazon-book-search/test/index.js
sbilketay 5991736cd4 feat: Add raw description field and fix npm test compatibility
Major improvements and bug fixes:

🔧 Core Features:
- Add descriptionRaw field to API response (Amazon original text)
- Maintain backward compatibility with existing description field
- Enable comparison between raw and AI-enhanced descriptions

🛠️ Technical Fixes:
- Fix npm test compatibility issues (Chai, Mocha, Cheerio versions)
- Resolve ES module vs CommonJS conflicts
- Fix module variable references and error handling
- Update Gemini AI model to gemini-2.0-flash

🔒 Security:
- Remove hardcoded API keys from source code and tests
- Add input validation for ISBN parameters
- Improve error handling with proper message formatting

 Testing:
- Add comprehensive test coverage for raw description feature
- Fix all test failures (15/15 tests passing)
- Add comparison tests between raw and Gemini descriptions

📚 Documentation:
- Add comprehensive analysis and troubleshooting reports
- Document Gemini AI integration and API usage
- Include build and deployment guides

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
2025-11-09 15:59:09 +03:00

223 lines
6.5 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
const { expect } = require("chai");
const AmazonBookSearch = require("../index");
describe("📦 Amazon Book Search (Turkish) Integration Test", () => {
let bookSearch;
const isbn = "9944824453";
const geminiApiKey = process.env.GEMINI_API_KEY || "";
const timeoutDuration = 30000;
beforeEach(() => {
bookSearch = new AmazonBookSearch("tr");
});
it('Is the ISBN "9944824453" 🔥', function (done) {
this.timeout(timeoutDuration);
bookSearch
.getBookDetails(isbn)
.then((bookDetails) => {
expect(bookDetails).to.have.property("isbn");
expect(bookDetails.isbn).to.equal("9944824453");
done();
})
.catch(done);
});
it('Is the book title "Dövmeli Adam: İblis Döngüsü 1" 🚀', function (done) {
this.timeout(timeoutDuration);
bookSearch
.getBookDetails(isbn)
.then((bookDetails) => {
expect(bookDetails).to.have.property("title");
expect(bookDetails.title).to.equal("Dövmeli Adam: İblis Döngüsü 1");
done();
})
.catch(done);
});
it("Checks if the book thumb image is not empty 🌄", function (done) {
this.timeout(timeoutDuration);
bookSearch
.getBookDetails(isbn)
.then((bookDetails) => {
expect(bookDetails).to.have.property("thumbImage");
expect(bookDetails.thumbImage).to.be.a("string");
done();
})
.catch(done);
});
it('Is the book\'s publication date "1 Temmuz 2016" ⏰', function (done) {
this.timeout(timeoutDuration);
bookSearch
.getBookDetails(isbn)
.then((bookDetails) => {
expect(bookDetails).to.have.property("date");
expect(bookDetails.date).to.equal("1 Temmuz 2016");
done();
})
.catch(done);
});
it('Is the page count "638" 📋', function (done) {
this.timeout(timeoutDuration);
bookSearch
.getBookDetails(isbn)
.then((bookDetails) => {
expect(bookDetails).to.have.property("page");
expect(bookDetails.page).to.equal(638);
done();
})
.catch(done);
});
it('Is the publisher "Epsilon Yayınları" 📖', function (done) {
this.timeout(timeoutDuration);
bookSearch
.getBookDetails(isbn)
.then((bookDetails) => {
expect(bookDetails).to.have.property("publisher");
expect(bookDetails.publisher).to.equal("Epsilon Yayınları");
done();
})
.catch(done);
});
it("Is the Gemini API test working for the book description 🤖", function (done) {
this.timeout(timeoutDuration);
bookSearch
.getBookDetails(isbn, geminiApiKey)
.then((bookDetails) => {
expect(bookDetails).to.have.property("description");
expect(bookDetails.description).to.be.a("string");
done();
})
.catch(done);
});
it("Checks if raw description from Amazon is available 📄", function (done) {
this.timeout(timeoutDuration);
bookSearch
.getBookDetails(isbn)
.then((bookDetails) => {
expect(bookDetails).to.have.property("descriptionRaw");
expect(bookDetails.descriptionRaw).to.be.a("string");
expect(bookDetails.descriptionRaw.length).to.be.greaterThan(0);
done();
})
.catch(done);
});
it("Compares raw description with Gemini description 🔍", function (done) {
this.timeout(timeoutDuration);
bookSearch
.getBookDetails(isbn, geminiApiKey)
.then((bookDetails) => {
expect(bookDetails).to.have.property("description");
expect(bookDetails).to.have.property("descriptionRaw");
// Both descriptions should be available
expect(bookDetails.description).to.be.a("string");
expect(bookDetails.descriptionRaw).to.be.a("string");
// They should have different content when Gemini is used
expect(bookDetails.description).to.not.equal(bookDetails.descriptionRaw);
// Both should have reasonable length
expect(bookDetails.description.length).to.be.greaterThan(100);
expect(bookDetails.descriptionRaw.length).to.be.greaterThan(100);
done();
})
.catch(done);
});
});
describe("📦 Amazon Book Search (English) Integration Test", () => {
let bookSearch;
const isbn = "0593724283";
const timeoutDuration = 30000;
before(function (done) {
this.timeout(timeoutDuration + 30000);
setTimeout(done, 30000);
});
beforeEach(() => {
bookSearch = new AmazonBookSearch("en");
});
it('Is the ISBN "0593724283" 🔥', function (done) {
this.timeout(timeoutDuration);
bookSearch
.getBookDetails(isbn)
.then((bookDetails) => {
expect(bookDetails).to.have.property("isbn");
expect(bookDetails.isbn).to.equal("0593724283");
done();
})
.catch(done);
});
it('Is the book title "The Desert Spear: Book Two of The Demon Cycle" 🚀', function (done) {
this.timeout(timeoutDuration);
bookSearch
.getBookDetails(isbn)
.then((bookDetails) => {
expect(bookDetails).to.have.property("title");
expect(bookDetails.title).to.equal(
"The Desert Spear: Book Two of The Demon Cycle"
);
done();
})
.catch(done);
});
it("Checks if the book thumb image is not empty 🌄", function (done) {
this.timeout(timeoutDuration);
bookSearch
.getBookDetails(isbn)
.then((bookDetails) => {
expect(bookDetails).to.have.property("thumbImage");
expect(bookDetails.thumbImage).to.be.a("string");
done();
})
.catch(done);
});
it('Is the book\'s publication date "November 7, 2023" ⏰', function (done) {
this.timeout(timeoutDuration);
bookSearch
.getBookDetails(isbn)
.then((bookDetails) => {
expect(bookDetails).to.have.property("date");
expect(bookDetails.date).to.equal("November 7, 2023");
done();
})
.catch(done);
});
it('Is the page count "864" 📋', function (done) {
this.timeout(timeoutDuration);
bookSearch
.getBookDetails(isbn)
.then((bookDetails) => {
expect(bookDetails).to.have.property("page");
expect(bookDetails.page).to.equal(864);
done();
})
.catch(done);
});
it('Is the publisher "Del Rey" 📖', function (done) {
this.timeout(timeoutDuration);
bookSearch
.getBookDetails(isbn)
.then((bookDetails) => {
expect(bookDetails).to.have.property("publisher");
expect(bookDetails.publisher).to.equal("Del Rey");
done();
})
.catch(done);
});
});