Skip to content

Commit 62556e3

Browse files
committed
added test for findItemsByKeyword
1 parent a862fbd commit 62556e3

File tree

5 files changed

+46
-2
lines changed

5 files changed

+46
-2
lines changed

src/buildURL.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const buildURL = {
1616
let base_url = "http://svcs.ebay.com/services/search/FindingService/v1?";
1717
base_url += "SECURITY-APPNAME=" + options.clientID;
1818
base_url += "&OPERATION-NAME=" + options.operationName;
19-
base_url += "&SERVICE-VERSION=1.0.0&RESPONSE-DATA-FORMAT=JSON&REST-PAYLOAD";
19+
base_url += "&SERVICE-VERSION=1.0.0&RESPONSE-DATA-FORMAT=JSON";
2020
base_url += options.param ? "&" + options.param + "=" + options.name : '';
2121
base_url += options.limit ? "&paginationInput.entriesPerPage=" + options.limit : '';
2222
base_url += options.globalID ? "&GLOBAL-ID=" + options.globalID : '';

src/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ function Ebay(options) {
1515
Ebay.prototype = {
1616

1717
findItemsByKeywords: function (keyword) {
18+
// console.log("keyword" + keyword);
19+
if (!keyword) throw new Error("Keyword is missing, Keyword is required");
1820
this.options.name = keyword;
1921
this.options.operationName = "findItemsByKeywords";
2022
this.options.param = "keywords";

test/testBuildURL.js renamed to test/buildURL.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ describe("test building url methods", () => {
77

88

99
it("test search url", () => {
10-
let expected_search_url = "http://svcs.ebay.com/services/search/FindingService/v1?SECURITY-APPNAME=testID&OPERATION-NAME=findItemsByKeywords&SERVICE-VERSION=1.0.0&RESPONSE-DATA-FORMAT=JSON&REST-PAYLOAD&keywords=iphone&paginationInput.entriesPerPage=6&GLOBAL-ID=EBAY-US"
10+
let expected_search_url = "http://svcs.ebay.com/services/search/FindingService/v1?SECURITY-APPNAME=testID&OPERATION-NAME=findItemsByKeywords&SERVICE-VERSION=1.0.0&RESPONSE-DATA-FORMAT=JSON&keywords=iphone&paginationInput.entriesPerPage=6&GLOBAL-ID=EBAY-US"
1111
let options = {
1212
name: "iphone",
1313
operationName: "findItemsByKeywords",

test/findItemsByKeyword.test.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
const nock = require('nock');
2+
const eBay = require('../src/index');
3+
let expect = require("chai").expect;
4+
5+
describe("Test find items by keyword method", () => {
6+
7+
beforeEach(() => {
8+
nock('http://svcs.ebay.com')
9+
.get('/services/search/FindingService/v1')
10+
.query({
11+
'SECURITY-APPNAME': 'ClientId',
12+
'OPERATION-NAME': 'findItemsByKeywords',
13+
'SERVICE-VERSION': '1.0.0',
14+
'RESPONSE-DATA-FORMAT': 'JSON',
15+
'keywords': 'iphone',
16+
'GLOBAL-ID': 'EBAY-US'
17+
18+
})
19+
.reply(200, {
20+
"access_token": "abcd"
21+
});
22+
});
23+
24+
it("test input parameter in findItemsByKeyword method", () => {
25+
let ebay = new eBay({
26+
clientID: "ClientId"
27+
})
28+
expect(() => { ebay.findItemsByKeywords() }).to.throw("Keyword is missing, Keyword is required");
29+
});
30+
31+
it("test get items from findItemsByKeyword method", () => {
32+
let ebay = new eBay({
33+
clientID: "ClientId",
34+
})
35+
36+
return ebay.findItemsByKeywords("iphone").then((response) => {
37+
console.log("------" + response);
38+
//done();
39+
})
40+
})
41+
42+
})
File renamed without changes.

0 commit comments

Comments
 (0)