diff --git a/Jenkinsfile b/Jenkinsfile index 8eb589f..6d1d721 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -29,21 +29,10 @@ pipeline { sh 'ls -la' } } - stage('Check for package.json changes') { + stage('Install npm package') { steps { - echo "Check for package.json changes" - script { - // Check if package.json has changed - def hasChanges = sh(script: 'git diff --name-only HEAD~1 | grep "package.json"', returnStatus: true) == 0 - if (hasChanges) { - echo "package.json changed, running npm install" - currentBuild.result = 'SUCCESS' - sh 'npm install' - } else { - echo "package.json not changed, skipping npm install" - currentBuild.result = 'SUCCESS' - } - } + echo "Install npm package" + sh 'npm install' } } stage('Run Tests') { diff --git a/config/index.js b/config/index.js index c0c5e5b..6097383 100644 --- a/config/index.js +++ b/config/index.js @@ -7,7 +7,7 @@ const config = { tr_detail_url: "https://www.amazon.com.tr/dp/", headers: { "User-Agent": - "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.105 Safari/537.36", + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36" }, // Amazon'a istek atarken, iki istek arasındaki zaman farkıdır fetchTimeout: 2000, diff --git a/lib/index.js b/lib/index.js index 4fd7bdf..d7ced32 100644 --- a/lib/index.js +++ b/lib/index.js @@ -12,27 +12,32 @@ class AmazonBookSearch { const fetchBookId = async (isbn) => { const headers = config.headers; + try { const url = encodeURI(this.url + isbn); const response = await axios.get(url, { headers }); if (!response.data) { throw new Error("Kitap bilgisi bulunamadı!"); } + const bookId = modules.extractBookId(response.data); - + return bookId; } catch (error) { - throw new Error("Hata: " + error.message); + throw new Error(error.message); } }; this.getBookDetails = async (isbn, geminiApiKey) => { - const headers = config.headers; try { const bookId = await fetchBookId(isbn); - const url = encodeURI(location == "tr" ? config.tr_detail_url + bookId : config.en_detail_url + bookId); - + const url = encodeURI( + location == "tr" + ? config.tr_detail_url + bookId + : config.en_detail_url + bookId + ); + return new Promise((resolve, reject) => { setTimeout(async () => { try { @@ -54,7 +59,7 @@ class AmazonBookSearch { }, config.fetchTimeout); }); } catch (error) { - throw new Error("Hata: " + error.message); + throw new Error(error.message); } }; } @@ -73,13 +78,13 @@ module.exports = AmazonBookSearch; // } // })(); -// // -// (async () => { -// try { -// const BookSearch = new AmazonBookSearch("en"); -// const bookDetails = await BookSearch.getBookDetails("0593724283"); -// console.log(bookDetails); -// } catch (error) { -// console.log(error.message); -// } -// })(); +// // +(async () => { + try { + const BookSearch = new AmazonBookSearch("en"); + const bookDetails = await BookSearch.getBookDetails("0593724283"); + console.log(bookDetails); + } catch (error) { + console.log(error.message); + } +})(); diff --git a/lib/module.js b/lib/module.js index 7005f96..afbecf8 100644 --- a/lib/module.js +++ b/lib/module.js @@ -9,9 +9,7 @@ const geminiDescriptionEdit = async (description, geminiApiKey, location) => { if (location == "en") { prompt = description + - " based on the text above, provide a detailed book description of similar length. Do not add any comments to the text, remain completely faithful to it. Only provide the book description, without using a title like book description."; - console.log(prompt); - + " based on the text above, provide a detailed book description of similar length. Do not add any comments to the text, remain completely faithful to it. Only provide the book description, without using a title like book description."; } else { prompt = description + diff --git a/test/index.js b/test/index.js index a489f37..2900108 100644 --- a/test/index.js +++ b/test/index.js @@ -36,7 +36,7 @@ describe("📦 Amazon Book Search (Turkish) Integration Test", () => { .catch(done); }); - it('Checks if the book thumb image is not empty 🌄', function (done) { + it("Checks if the book thumb image is not empty 🌄", function (done) { this.timeout(timeoutDuration); bookSearch .getBookDetails(isbn) @@ -84,7 +84,7 @@ describe("📦 Amazon Book Search (Turkish) Integration Test", () => { .catch(done); }); - it('Is the Gemini API test working for the book description 🤖', function (done) { + it("Is the Gemini API test working for the book description 🤖", function (done) { this.timeout(timeoutDuration); bookSearch .getBookDetails(isbn, geminiApiKey) @@ -101,7 +101,11 @@ describe("📦 Amazon Book Search (English) Integration Test", () => { let bookSearch; const isbn = "0593724283"; const timeoutDuration = 30000; - const geminiApiKey = "AIzaSyAY15XJcK1VIxzMRe48dyDEeNPqeqhQt2I"; + + before(function (done) { + this.timeout(timeoutDuration + 25000); + setTimeout(done, 25000); + }); beforeEach(() => { bookSearch = new AmazonBookSearch("en"); @@ -125,13 +129,15 @@ describe("📦 Amazon Book Search (English) Integration Test", () => { .getBookDetails(isbn) .then((bookDetails) => { expect(bookDetails).to.have.property("title"); - expect(bookDetails.title).to.equal("The Desert Spear: Book Two of The Demon Cycle"); + 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) { + it("Checks if the book thumb image is not empty 🌄", function (done) { this.timeout(timeoutDuration); bookSearch .getBookDetails(isbn) @@ -178,17 +184,4 @@ describe("📦 Amazon Book Search (English) Integration Test", () => { }) .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); - }); -}); - +}); \ No newline at end of file