-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
87 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,20 @@ | ||
const expect = require('expect'); | ||
const serpapi = require('./../lib/EbaySearch'); | ||
const serpapi = require('./../lib/main'); | ||
|
||
describe('Ebay Search', () => { | ||
it("json", (done) => { | ||
let api_key = process.env.API_KEY | ||
if (api_key != null) { | ||
let search = new serpapi.EbaySearch(api_key) | ||
search.json({ | ||
_nkw: "Coffee" | ||
}, (data) => { | ||
expect(data.search_metadata.status).toEqual("Success") | ||
expect(data.organic_results.length).toBeGreaterThan(5) | ||
done() | ||
}) | ||
} else { | ||
if (api_key == null) { | ||
done() | ||
return | ||
} | ||
}).timeout(10000) | ||
let search = new serpapi.EbaySearch(api_key) | ||
search.json({ | ||
_nkw: "Coffee" | ||
}, (data) => { | ||
expect(data.search_metadata.status).toEqual("Success") | ||
expect(data.organic_results.length).toBeGreaterThan(5) | ||
done() | ||
}) | ||
}).timeout(100000) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,69 @@ | ||
const expect = require('expect') | ||
const util = require('util') | ||
const gsr = require('../lib/GoogleSearch') | ||
// const expect = require('expect') | ||
// const util = require('util') | ||
// const serpapi = require('../lib/main') | ||
|
||
describe('Google Search - Example', function () { | ||
let parameter, api_key | ||
beforeEach(function () { | ||
parameter = { | ||
q: "Coffee", | ||
location: "Austin, Texas" | ||
} | ||
// describe('Google Search - Example', function () { | ||
// let parameter, api_key | ||
// beforeEach(function () { | ||
// parameter = { | ||
// q: "Coffee", | ||
// location: "Austin, Texas" | ||
// } | ||
|
||
// Copy your secret api_key from https://serpapi.com/dashboard | ||
api_key = process.env.API_KEY || "demo" | ||
}) | ||
// // Copy your secret api_key from https://serpapi.com/dashboard | ||
// api_key = process.env.API_KEY || "demo" | ||
// }) | ||
|
||
it("promisified callback function", (done) => { | ||
if (api_key == "demo") { | ||
done() | ||
return | ||
} | ||
// it("promisified callback function", (done) => { | ||
// if (api_key == "demo") { | ||
// done() | ||
// return | ||
// } | ||
|
||
function getJson(parameter, resolve, reject) { | ||
const search = new gsr.GoogleSearch(api_key) | ||
try { | ||
search.json(parameter, resolve) | ||
} catch (e) { | ||
reject(e) | ||
} | ||
} | ||
// function getJson(parameter, resolve, reject) { | ||
// const search = new serpapi.GoogleSearch(api_key) | ||
// try { | ||
// search.json(parameter, resolve) | ||
// } catch (e) { | ||
// reject(e) | ||
// } | ||
// } | ||
|
||
const blockFn = util.promisify(getJson) | ||
blockFn[util.promisify.custom](parameter).then((data) => { | ||
expect(data.organic_results[0].title.length).toBeGreaterThan(5) | ||
done() | ||
}).catch((error) => { | ||
console.error(error) | ||
done() | ||
}) | ||
}).timeout(10000) | ||
// const blockFn = util.promisify(getJson) | ||
// blockFn[util.promisify.custom](parameter).then((data) => { | ||
// expect(data.organic_results[0].title.length).toBeGreaterThan(5) | ||
// done() | ||
// }).catch((error) => { | ||
// // console.error(error) | ||
// reject() | ||
// }) | ||
// }).timeout(100000) | ||
|
||
// it("callback to custom promise", (done) => { | ||
// if (api_key == "demo") { | ||
// done() | ||
// return | ||
// } | ||
|
||
it("callback to custom promise", (done) => { | ||
if (api_key == "demo") { | ||
done() | ||
return | ||
} | ||
// function blockFn(parameter, callback) { } | ||
|
||
function blockFn(parameter, callback) { } | ||
// blockFn[util.promisify.custom] = (parameter) => { | ||
// return new Promise((resolve, reject) => { | ||
// let search = new serpapi.GoogleSearch(api_key) | ||
// try { | ||
// search.json(parameter, resolve) | ||
// } catch (e) { | ||
// reject(e) | ||
// } | ||
// }) | ||
// } | ||
|
||
blockFn[util.promisify.custom] = (parameter) => { | ||
return new Promise((resolve, reject) => { | ||
let search = new gsr.GoogleSearch(api_key) | ||
try { | ||
search.json(parameter, resolve) | ||
} catch (e) { | ||
reject(e) | ||
} | ||
}) | ||
} | ||
|
||
blockFn[util.promisify.custom](parameter).then((data) => { | ||
expect(data.local_results[0].title.length).toBeGreaterThan(5) | ||
done() | ||
}).catch((error) => { | ||
console.error(error) | ||
done() | ||
}) | ||
}).timeout(10000) | ||
}); | ||
// blockFn[util.promisify.custom](parameter).then((data) => { | ||
// expect(data.organic_results.length).toBeGreaterThan(5) | ||
// done() | ||
// }).catch((error) => { | ||
// //console.error(error) | ||
// fail() | ||
// }) | ||
// }).timeout(100000) | ||
// }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters