update 5 files
This commit is contained in:
17
Jenkinsfile
vendored
17
Jenkinsfile
vendored
@@ -29,21 +29,10 @@ pipeline {
|
|||||||
sh 'ls -la'
|
sh 'ls -la'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
stage('Check for package.json changes') {
|
stage('Install npm package') {
|
||||||
steps {
|
steps {
|
||||||
echo "Check for package.json changes"
|
echo "Install npm package"
|
||||||
script {
|
sh 'npm install'
|
||||||
// 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'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
stage('Run Tests') {
|
stage('Run Tests') {
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ const config = {
|
|||||||
tr_detail_url: "https://www.amazon.com.tr/dp/",
|
tr_detail_url: "https://www.amazon.com.tr/dp/",
|
||||||
headers: {
|
headers: {
|
||||||
"User-Agent":
|
"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
|
// Amazon'a istek atarken, iki istek arasındaki zaman farkıdır
|
||||||
fetchTimeout: 2000,
|
fetchTimeout: 2000,
|
||||||
|
|||||||
37
lib/index.js
37
lib/index.js
@@ -12,27 +12,32 @@ class AmazonBookSearch {
|
|||||||
|
|
||||||
const fetchBookId = async (isbn) => {
|
const fetchBookId = async (isbn) => {
|
||||||
const headers = config.headers;
|
const headers = config.headers;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const url = encodeURI(this.url + isbn);
|
const url = encodeURI(this.url + isbn);
|
||||||
const response = await axios.get(url, { headers });
|
const response = await axios.get(url, { headers });
|
||||||
if (!response.data) {
|
if (!response.data) {
|
||||||
throw new Error("Kitap bilgisi bulunamadı!");
|
throw new Error("Kitap bilgisi bulunamadı!");
|
||||||
}
|
}
|
||||||
|
|
||||||
const bookId = modules.extractBookId(response.data);
|
const bookId = modules.extractBookId(response.data);
|
||||||
|
|
||||||
return bookId;
|
return bookId;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new Error("Hata: " + error.message);
|
throw new Error(error.message);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
this.getBookDetails = async (isbn, geminiApiKey) => {
|
this.getBookDetails = async (isbn, geminiApiKey) => {
|
||||||
|
|
||||||
const headers = config.headers;
|
const headers = config.headers;
|
||||||
try {
|
try {
|
||||||
const bookId = await fetchBookId(isbn);
|
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) => {
|
return new Promise((resolve, reject) => {
|
||||||
setTimeout(async () => {
|
setTimeout(async () => {
|
||||||
try {
|
try {
|
||||||
@@ -54,7 +59,7 @@ class AmazonBookSearch {
|
|||||||
}, config.fetchTimeout);
|
}, config.fetchTimeout);
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new Error("Hata: " + error.message);
|
throw new Error(error.message);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -73,13 +78,13 @@ module.exports = AmazonBookSearch;
|
|||||||
// }
|
// }
|
||||||
// })();
|
// })();
|
||||||
|
|
||||||
// //
|
// //
|
||||||
// (async () => {
|
(async () => {
|
||||||
// try {
|
try {
|
||||||
// const BookSearch = new AmazonBookSearch("en");
|
const BookSearch = new AmazonBookSearch("en");
|
||||||
// const bookDetails = await BookSearch.getBookDetails("0593724283");
|
const bookDetails = await BookSearch.getBookDetails("0593724283");
|
||||||
// console.log(bookDetails);
|
console.log(bookDetails);
|
||||||
// } catch (error) {
|
} catch (error) {
|
||||||
// console.log(error.message);
|
console.log(error.message);
|
||||||
// }
|
}
|
||||||
// })();
|
})();
|
||||||
|
|||||||
@@ -9,9 +9,7 @@ const geminiDescriptionEdit = async (description, geminiApiKey, location) => {
|
|||||||
if (location == "en") {
|
if (location == "en") {
|
||||||
prompt =
|
prompt =
|
||||||
description +
|
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.";
|
" 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);
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
prompt =
|
prompt =
|
||||||
description +
|
description +
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ describe("📦 Amazon Book Search (Turkish) Integration Test", () => {
|
|||||||
.catch(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);
|
this.timeout(timeoutDuration);
|
||||||
bookSearch
|
bookSearch
|
||||||
.getBookDetails(isbn)
|
.getBookDetails(isbn)
|
||||||
@@ -84,7 +84,7 @@ describe("📦 Amazon Book Search (Turkish) Integration Test", () => {
|
|||||||
.catch(done);
|
.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);
|
this.timeout(timeoutDuration);
|
||||||
bookSearch
|
bookSearch
|
||||||
.getBookDetails(isbn, geminiApiKey)
|
.getBookDetails(isbn, geminiApiKey)
|
||||||
@@ -101,7 +101,11 @@ describe("📦 Amazon Book Search (English) Integration Test", () => {
|
|||||||
let bookSearch;
|
let bookSearch;
|
||||||
const isbn = "0593724283";
|
const isbn = "0593724283";
|
||||||
const timeoutDuration = 30000;
|
const timeoutDuration = 30000;
|
||||||
const geminiApiKey = "AIzaSyAY15XJcK1VIxzMRe48dyDEeNPqeqhQt2I";
|
|
||||||
|
before(function (done) {
|
||||||
|
this.timeout(timeoutDuration + 25000);
|
||||||
|
setTimeout(done, 25000);
|
||||||
|
});
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
bookSearch = new AmazonBookSearch("en");
|
bookSearch = new AmazonBookSearch("en");
|
||||||
@@ -125,13 +129,15 @@ describe("📦 Amazon Book Search (English) Integration Test", () => {
|
|||||||
.getBookDetails(isbn)
|
.getBookDetails(isbn)
|
||||||
.then((bookDetails) => {
|
.then((bookDetails) => {
|
||||||
expect(bookDetails).to.have.property("title");
|
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();
|
done();
|
||||||
})
|
})
|
||||||
.catch(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);
|
this.timeout(timeoutDuration);
|
||||||
bookSearch
|
bookSearch
|
||||||
.getBookDetails(isbn)
|
.getBookDetails(isbn)
|
||||||
@@ -178,17 +184,4 @@ describe("📦 Amazon Book Search (English) Integration Test", () => {
|
|||||||
})
|
})
|
||||||
.catch(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);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user