Skip to content

Commit c36e6b3

Browse files
authored
Added test cases all shopping api's (#85)
* v2.7.7 * added test for shopping api
1 parent c98f5fd commit c36e6b3

File tree

8 files changed

+171
-44
lines changed

8 files changed

+171
-44
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"main": "./src/index.js",
66
"homepage": "https://github.com/pajaydev/ebay-node-api",
77
"scripts": {
8-
"lint": "eslint src/*.js",
8+
"lint": "eslint src/*.js test/*.js",
99
"test": "mocha && npm run lint",
1010
"docs": "docsify init ./docs",
1111
"serve-docs": "docsify serve docs",

src/shopping.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,38 +6,42 @@ const makeString = require('make-string');
66

77
const getAllCategories = function (categoryID) {
88
const requestURL = `${urlObject.buildShoppingUrl(this.options, 'GetCategoryInfo')}&${stringifyUrl({ 'CategoryID': categoryID || -1 })}`;
9+
console.log(requestURL);
910
return getRequest(requestURL).then((data) => {
1011
return JSON.parse(data);
1112
}, console.error // eslint-disable-line no-console
1213
);
1314
};
1415

1516
const getUserDetails = function (input) {
16-
if (!input || typeof input !== 'object') throw new Error('Invalid input');
17+
if (!input || typeof input !== 'object') throw new Error('invalid_request_error -> Invalid input');
1718
if (!input.userId) throw new Error('invalid_request_error -> userId is null or invalid');
1819
const requestUrl = `${urlObject.buildShoppingUrl(this.options, 'GetUserProfile')}&${stringifyUrl(input)}`;
20+
console.log(requestUrl);
1921
return getRequest(requestUrl).then((data) => {
2022
return JSON.parse(data);
2123
}, console.error // eslint-disable-line no-console
2224
);
2325
};
2426

2527
const getItemStatus = function (itemIds) {
26-
if (!itemIds) throw new Error('invalid_request_error -> itemIds is null or invalid');
28+
if (!itemIds) throw new Error('invalid_request_error -> Item ID is null or invalid');
2729
const paramsObj = {
2830
'ItemID': makeString(itemIds, { braces: 'false', quotes: 'no' })
2931
};
3032
const requestUrl = `${urlObject.buildShoppingUrl(this.options, 'GetItemStatus')}&${stringifyUrl(paramsObj)}`;
33+
console.log(requestUrl);
3134
return getRequest(requestUrl).then((data) => {
3235
return JSON.parse(data);
3336
}, console.error // eslint-disable-line no-console
3437
);
3538
};
3639

3740
const getShippingCosts = function (input) {
38-
if (!input || typeof input !== 'object') throw new Error('Invalid input');
41+
if (!input || typeof input !== 'object') throw new Error('invalid_request_error -> Invalid input');
3942
if (!input.itemId) throw new Error('invalid_request_error -> Item id is null or invalid');
4043
const url = `${urlObject.buildShoppingUrl(this.options, 'GetShippingCosts')}&${stringifyUrl(input)} `;
44+
console.log(url);
4145
return getRequest(url).then((data) => {
4246
return JSON.parse(data);
4347
}, console.error // eslint-disable-line no-console
@@ -52,6 +56,7 @@ const getShippingCosts = function (input) {
5256
const getMultipleItems = function (options) {
5357
if (!options || !options.itemId) throw new Error('invalid_request_error -> Item ID is null or invalid');
5458
const requestUrl = `${urlObject.buildShoppingUrl(this.options, 'GetMultipleItems')}&${stringifyUrl({ 'itemId': makeString(options.itemId, { braces: 'false', quotes: 'no' }) })}`;
59+
console.log(requestUrl);
5560
return getRequest(requestUrl).then((data) => {
5661
return JSON.parse(data);
5762
}, console.error // eslint-disable-line no-console

test/buildURL.test.js

Lines changed: 6 additions & 6 deletions
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 = 'https://svcs.ebay.com/services/search/FindingService/v1?SECURITY-APPNAME=testID&OPERATION-NAME=findItemsByKeywords&SERVICE-VERSION=1.0.0&RESPONSE-DATA-FORMAT=JSON&keywords=iphone&outputSelector(0)=SellerInfo&outputSelector(1)=PictureURLLarge&paginationInput.entriesPerPage=6&GLOBAL-ID=EBAY-US';
10+
let expectedSearchUrl = 'https://svcs.ebay.com/services/search/FindingService/v1?SECURITY-APPNAME=testID&OPERATION-NAME=findItemsByKeywords&SERVICE-VERSION=1.0.0&RESPONSE-DATA-FORMAT=JSON&keywords=iphone&outputSelector(0)=SellerInfo&outputSelector(1)=PictureURLLarge&paginationInput.entriesPerPage=6&GLOBAL-ID=EBAY-US';
1111
let options = {
1212
name: 'iphone',
1313
operationName: 'findItemsByKeywords',
@@ -17,29 +17,29 @@ describe('test building url methods', () => {
1717
globalID: 'EBAY-US',
1818
baseSvcUrl: 'svcs.ebay.com'
1919
};
20-
expect(buildURL.buildSearchUrl(options, 'findItemsByKeywords')).to.be.equal(expected_search_url);
20+
expect(buildURL.buildSearchUrl(options, 'findItemsByKeywords')).to.be.equal(expectedSearchUrl);
2121
});
2222

2323
it('test Shopping url without selector', () => {
24-
let expected_search_url = 'https://open.api.ebay.com/Shopping?appid=testID&callname=demoShoppingName&version=967&siteid=0&responseencoding=JSON';
24+
let expectedSearchUrl = 'https://open.api.ebay.com/Shopping?appid=testID&callname=demoShoppingName&version=967&siteid=0&responseencoding=JSON';
2525
let options = {
2626
name: 'iphone',
2727
param: 'keywords',
2828
clientID: 'testID',
2929
baseUrl: 'open.api.ebay.com'
3030
};
31-
expect(buildURL.buildShoppingUrl(options, 'demoShoppingName')).to.be.equal(expected_search_url);
31+
expect(buildURL.buildShoppingUrl(options, 'demoShoppingName')).to.be.equal(expectedSearchUrl);
3232
});
3333

3434
it('test Shopping url including selector', () => {
35-
let expected_search_url = 'https://open.api.ebay.com/Shopping?appid=testID&callname=demoShoppingName&version=967&siteid=0&responseencoding=JSON&IncludeSelector=true';
35+
let expectedSearchUrl = 'https://open.api.ebay.com/Shopping?appid=testID&callname=demoShoppingName&version=967&siteid=0&responseencoding=JSON&IncludeSelector=true';
3636
let options = {
3737
name: 'iphone',
3838
param: 'keywords',
3939
clientID: 'testID',
4040
includeSelector: true,
4141
baseUrl: 'open.api.ebay.com'
4242
};
43-
expect(buildURL.buildShoppingUrl(options, 'demoShoppingName')).to.be.equal(expected_search_url);
43+
expect(buildURL.buildShoppingUrl(options, 'demoShoppingName')).to.be.equal(expectedSearchUrl);
4444
});
4545
});

test/common.test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ const { parseObj } = require('../src/common-utils/index');
55

66
describe('test common util methods', () => {
77
it('test parse object to query params', () => {
8-
const expected_param = '&keywords=iphone&categoryId=111&sortOrder=PricePlusShippingLowest';
8+
const expectedParam = '&keywords=iphone&categoryId=111&sortOrder=PricePlusShippingLowest';
99
const options = {
1010
keywords: 'iphone',
1111
categoryId: '111',
1212
sortOrder: 'PricePlusShippingLowest'
1313
};
1414
const emptyOptions = {};
15-
expect(parseObj(options)).to.be.equal(expected_param);
15+
expect(parseObj(options)).to.be.equal(expectedParam);
1616
expect(parseObj(emptyOptions)).to.be.equal('');
17-
expect(parseObj(options, 'userName=ebay')).to.be.equal(`userName=ebay${expected_param}`);
17+
expect(parseObj(options, 'userName=ebay')).to.be.equal(`userName=ebay${expectedParam}`);
1818
});
19-
});
19+
});

test/findItemsByKeyword.test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const nock = require('nock');
2-
const eBay = require('../src/index');
2+
const Ebay = require('../src/index');
33
let expect = require('chai').expect;
44

55
describe('Test find items by keyword method', () => {
@@ -22,9 +22,9 @@ describe('Test find items by keyword method', () => {
2222
});
2323

2424
it('test input parameter in findItemsByKeyword method', () => {
25-
let ebay = new eBay({
25+
let ebay = new Ebay({
2626
clientID: 'ClientId'
27-
})
28-
expect(() => { ebay.findItemsByKeywords() }).to.throw('Keyword is missing, Keyword is required');
27+
});
28+
expect(() => { ebay.findItemsByKeywords(); }).to.throw('Keyword is missing, Keyword is required');
2929
});
3030
});
Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
1+
'use strict';
12
const expect = require('chai').expect;
23
const should = require('chai').should();
34
const nock = require('nock');
4-
const eBay = require('../src/index');
5+
const Ebay = require('../src/index');
56
const { constructAdditionalParams } = require('../src/findingApi');
67
const nockFindingApi = nock('https://svcs.ebay.com/');
78

89
describe('test ebay finding Api', () => {
910

1011
describe('test findingApi methods with required params', () => {
1112
it('test findItemsByCategory with required params', () => {
12-
let ebay = new eBay({
13+
let ebay = new Ebay({
1314
clientID: 'ClientId'
1415
});
1516
expect(() => { ebay.findItemsByCategory(); }).to.throw('Category ID is null or invalid');
1617
});
1718

1819
it('test findCompletedItemswith required params', () => {
19-
let ebay = new eBay({
20+
let ebay = new Ebay({
2021
clientID: 'ClientId'
2122
});
2223
expect(() => { ebay.findCompletedItems(''); }).to.throw('Keyword or category ID are required.');
@@ -25,20 +26,20 @@ describe('test ebay finding Api', () => {
2526

2627
describe('test constructAdditionalParams', () => {
2728
it('test constructAdditionalParams with required params', () => {
28-
let expected_param = 'keywords=iphone&categoryId=111&sortOrder=PricePlusShippingLowest';
29+
let expectedParam = 'keywords=iphone&categoryId=111&sortOrder=PricePlusShippingLowest';
2930
const options = {
3031
keywords: 'iphone',
3132
categoryId: '111',
3233
sortOrder: 'PricePlusShippingLowest'
3334
};
3435
const emptyOptions = {};
35-
expect(constructAdditionalParams(options)).to.be.equal(expected_param);
36+
expect(constructAdditionalParams(options)).to.be.equal(expectedParam);
3637
expect(constructAdditionalParams(emptyOptions)).to.be.equal('');
3738
});
3839

3940
it('test constructAdditionalParams with affiliate params', () => {
40-
let expected_param_with_affiliate = 'keywords=iphone&categoryId=111&sortOrder=PricePlusShippingLowest&affiliate.trackingId=1234567899&affiliate.networkId=123';
41-
let expected_param = 'keywords=iphone&categoryId=111&sortOrder=PricePlusShippingLowest';
41+
let expectedParamWithAffiliate = 'keywords=iphone&categoryId=111&sortOrder=PricePlusShippingLowest&affiliate.trackingId=1234567899&affiliate.networkId=123';
42+
let expectedParam = 'keywords=iphone&categoryId=111&sortOrder=PricePlusShippingLowest';
4243
const options = {
4344
keywords: 'iphone',
4445
categoryId: '111',
@@ -55,14 +56,14 @@ describe('test ebay finding Api', () => {
5556
sortOrder: 'PricePlusShippingLowest'
5657
};
5758
const emptyOptions = {};
58-
expect(constructAdditionalParams(options)).to.be.equal(expected_param_with_affiliate);
59-
expect(constructAdditionalParams(optionsWithNoAffiliate)).to.be.equal(expected_param);
59+
expect(constructAdditionalParams(options)).to.be.equal(expectedParamWithAffiliate);
60+
expect(constructAdditionalParams(optionsWithNoAffiliate)).to.be.equal(expectedParam);
6061
expect(constructAdditionalParams(emptyOptions)).to.be.equal('');
6162
});
6263

6364
it('test constructAdditionalParams with additional params', () => {
64-
let expected_param = 'keywords=iphone&categoryId=111&sortOrder=PricePlusShippingLowest&itemFilter(0).name=Condition&itemFilter(0).value=3000&itemFilter(1).name=SoldItemsOnly&itemFilter(1).value=true';
65-
let expected_pag_param = 'keywords=iphone&categoryId=111&sortOrder=PricePlusShippingLowest&itemFilter(0).name=Condition&itemFilter(0).value=3000&itemFilter(1).name=SoldItemsOnly&itemFilter(1).value=true&paginationInput.entriesPerPage=2';
65+
let expectedParam = 'keywords=iphone&categoryId=111&sortOrder=PricePlusShippingLowest&itemFilter(0).name=Condition&itemFilter(0).value=3000&itemFilter(1).name=SoldItemsOnly&itemFilter(1).value=true';
66+
let expectedPaginationParam = 'keywords=iphone&categoryId=111&sortOrder=PricePlusShippingLowest&itemFilter(0).name=Condition&itemFilter(0).value=3000&itemFilter(1).name=SoldItemsOnly&itemFilter(1).value=true&paginationInput.entriesPerPage=2';
6667
const options = {
6768
keywords: 'iphone',
6869
categoryId: '111',
@@ -78,18 +79,18 @@ describe('test ebay finding Api', () => {
7879
SoldItemsOnly: true,
7980
entriesPerPage: 2
8081
};
81-
expect(constructAdditionalParams(options)).to.be.equal(expected_param);
82-
expect(constructAdditionalParams(optionsWithPagination)).to.be.equal(expected_pag_param);
82+
expect(constructAdditionalParams(options)).to.be.equal(expectedParam);
83+
expect(constructAdditionalParams(optionsWithPagination)).to.be.equal(expectedPaginationParam);
8384
});
8485
});
8586

8687
describe('test all get apis', () => {
87-
it("test findItemsAdvanced", () => {
88-
let ebay = new eBay({
88+
it('test findItemsAdvanced', () => {
89+
let ebay = new Ebay({
8990
clientID: 'ABCD'
9091
});
9192
nockFindingApi.get('/services/search/FindingService/v1?SECURITY-APPNAME=ABCD&OPERATION-NAME=findItemsAdvanced&SERVICE-VERSION=1.0.0&RESPONSE-DATA-FORMAT=JSON&paginationInput.entriesPerPage=2&keywords=ipad&itemFilter(0).name=ExpeditedShippingType&itemFilter(0).value=OneDayShipping&outputSelector(0)=SellerInfo&outputSelector(1)=PictureURLLarge&GLOBAL-ID=EBAY-US')
92-
.reply(200, { "findItemsAdvancedResponse": [{ "ack": ["Success"] }] });
93+
.reply(200, { 'findItemsAdvancedResponse': [{ 'ack': ['Success'] }] });
9394
return ebay.findItemsAdvanced({
9495
entriesPerPage: 2,
9596
keywords: 'ipad',
@@ -101,4 +102,4 @@ describe('test ebay finding Api', () => {
101102
});
102103
});
103104
});
104-
});
105+
});

test/index.test.js

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,54 @@
11
let expect = require('chai').expect;
22
let should = require('chai').should();
3-
let eBay = require('../src/index');
3+
let Ebay = require('../src/index');
44

55
describe('check all the options provided is valid or not - Ebay Constructor ', () => {
66
it('check input is provided or not', () => {
77
expect(() => {
8-
new eBay();
8+
new Ebay();
99
}).to.throw('Options is missing, please provide the input');
1010
});
1111

1212
it('should have client ID', () => {
13-
let ebayApi = new eBay({ clientID: '12345' });
13+
let ebayApi = new Ebay({ clientID: '12345' });
1414
ebayApi.options.should.have.property('clientID');
1515
});
1616

1717
it('should not have client ID', () => {
1818
expect(() => {
19-
new eBay({});
19+
new Ebay({});
2020
}).to.throw('Client ID is Missing\ncheck documentation to get Client ID http://developer.ebay.com/DevZone/account/');
2121
});
2222

2323
it('check instance of Ebay', () => {
24-
let ebayApi = new eBay({ clientID: '12345' });
25-
expect(ebayApi).to.be.a.instanceOf(eBay);
24+
let ebayApi = new Ebay({ clientID: '12345' });
25+
expect(ebayApi).to.be.a.instanceOf(Ebay);
2626
});
2727

28-
});
29-
30-
28+
it('test default params', () => {
29+
const ebay = new Ebay({
30+
clientID: 'ClientId'
31+
});
32+
const expected = {
33+
clientID: 'ClientId',
34+
env: 'PROD',
35+
baseUrl: 'api.ebay.com',
36+
baseSvcUrl: 'svcs.ebay.com',
37+
globalID: 'EBAY-US',
38+
siteId: '0'
39+
};
40+
expect(ebay.options).to.deep.equal(expected);
41+
});
3142

43+
it('test site id, env and country code', () => {
44+
const ebay = new Ebay({
45+
clientID: 'ClientId',
46+
siteId: 3,
47+
env: 'SANDBOX',
48+
countryCode: 'EBAY_UK'
49+
});
50+
expect(ebay.options.siteId).to.equals(3);
51+
expect(ebay.options.env).to.equals('SANDBOX');
52+
expect(ebay.options.globalID).to.equals('EBAY_UK');
53+
});
54+
});

0 commit comments

Comments
 (0)