Skip to content

Commit 2dbdb37

Browse files
authored
Included linting for test files (#120)
* v2.7.7 * 2.8.7 * adding deals * adding deals api * update readme * adde get deals support * updated readme * 2.8.9 * update package json * fix linting on test * fix lint
1 parent ceb4a70 commit 2dbdb37

File tree

10 files changed

+1444
-1189
lines changed

10 files changed

+1444
-1189
lines changed

src/credentials.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ const getAccessToken = function () {
1313
if (!this.options.clientID) throw new Error('Missing Client ID');
1414
if (!this.options.clientSecret) throw new Error('Missing Client Secret or Cert Id');
1515
if (!this.options.body) throw new Error('Missing Body, required Grant type');
16-
let scopesParam = this.options.body.scope
17-
? Array.isArray(this.options.body.scope)
18-
? this.options.body.scope.join('%20')
19-
: this.options.body.scope
16+
const scopesParam = this.options.body.scopes
17+
? Array.isArray(this.options.body.scopes)
18+
? this.options.body.scopes.join('%20')
19+
: this.options.body.scopes
2020
: DEFAULT_API_SCOPE;
2121
this.options.data = qs.stringify({
2222
grant_type: 'client_credentials',
@@ -44,10 +44,10 @@ const getUserAuthorizationUrl = function (state = null) {
4444
if (!this.options.clientSecret) throw new Error('Missing Client Secret or Cert Id');
4545
if (!this.options.body) throw new Error('Missing Body, required Grant type');
4646
if (!this.options.redirectUri) throw new Error('redirect_uri is required for redirection after sign in\nkindly check here https://developer.ebay.com/api-docs/static/oauth-redirect-uri.html');
47-
let scopesParam = this.options.body.scopes
48-
? Array.isArray(this.options.body.scopes)
49-
? this.options.body.scopes.join('%20')
50-
: this.options.body.scopes
47+
const scopesParam = this.options.body.scope
48+
? Array.isArray(this.options.body.scope)
49+
? this.options.body.scope.join('%20')
50+
: this.options.body.scope
5151
: DEFAULT_API_SCOPE;
5252
let queryParam = `client_id=${this.options.clientID}`;
5353
queryParam += `&redirect_uri=${this.options.redirectUri}`;
@@ -77,7 +77,7 @@ const getUserTokenByCode = function (code) {
7777
const self = this;
7878
const encodedStr = base64Encode(`${this.options.clientID}:${this.options.clientSecret}`);
7979
const auth = `Basic ${encodedStr}`;
80-
return makeRequest(this.options, '/identity/v1/oauth2/token', 'POST', auth).then(result => {
80+
return makeRequest(this.options, '/identity/v1/oauth2/token', 'POST', auth).then((result) => {
8181
const resultJSON = JSON.parse(result);
8282
if (!resultJSON.error) self.setUserAccessToken(resultJSON);
8383
return resultJSON;
@@ -88,7 +88,7 @@ const getUserTokenByCode = function (code) {
8888
* Use a refresh token to update a User access token (Updating the expired access token)
8989
*
9090
* @param refreshToken refresh token, defaults to pre-assigned refresh token
91-
* @param scopes array of scopes for the access token
91+
* @param scope array of scopes for the access token
9292
* @return userAccessToken object (without refresh_token)
9393
*/
9494
const getUserTokenByRefresh = function (refreshToken = null) {
@@ -99,10 +99,10 @@ const getUserTokenByRefresh = function (refreshToken = null) {
9999
throw new Error('Refresh token is required, to generate refresh token use getUserTokenByCode method'); // eslint-disable-line max-len
100100
}
101101
refreshToken = refreshToken ? refreshToken : this.options.refreshToken;
102-
let scopesParam = this.options.body.scopes
103-
? Array.isArray(this.options.body.scopes)
104-
? this.options.body.scopes.join('%20')
105-
: this.options.body.scopes
102+
const scopesParam = this.options.body.scope
103+
? Array.isArray(this.options.body.scope)
104+
? this.options.body.scope.join('%20')
105+
: this.options.body.scope
106106
: DEFAULT_API_SCOPE;
107107
this.options.data = qs.stringify({
108108
refresh_token: refreshToken,
@@ -113,7 +113,7 @@ const getUserTokenByRefresh = function (refreshToken = null) {
113113
const self = this;
114114
const encodedStr = base64Encode(`${this.options.clientID}:${this.options.clientSecret}`);
115115
const auth = `Basic ${encodedStr}`;
116-
return makeRequest(this.options, '/identity/v1/oauth2/token', 'POST', auth).then(result => {
116+
return makeRequest(this.options, '/identity/v1/oauth2/token', 'POST', auth).then((result) => {
117117
const resultJSON = JSON.parse(result);
118118
if (!resultJSON.error) self.setUserAccessToken(resultJSON);
119119
return resultJSON;

src/finding.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,10 @@ const getVersion = function () {
8989
const findItemsByProduct = function (options) {
9090
if (!options) throw new Error('INVALID_REQUEST_PARMS --> Please enter the Valid input.');
9191
if (!options.productId) throw new Error('INVALID_REQUEST_PARMS --> Product ID is required.');
92-
let type = options.type ? options.type : 'ReferenceID';
92+
const type = options.type ? options.type : 'ReferenceID';
9393
this.options.operationName = 'findItemsByProduct';
9494
this.options.additionalParam = utils.constructAdditionalParams(options);
95-
let url = `${urlObject.buildSearchUrl(this.options)}&productId.@type=${type}`;
95+
const url = `${urlObject.buildSearchUrl(this.options)}&productId.@type=${type}`;
9696
return getRequest(url).then((data) => {
9797
return JSON.parse(data).findItemsByProductResponse;
9898
}, console.error // eslint-disable-line no-console

src/request.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ const qs = require('querystring');
55
const getRequest = (url) => {
66
if (url.includes('http://')) httpRequest = require('http');
77
return new Promise(((resolve, reject) => {
8-
httpRequest.get(url, res => {
8+
httpRequest.get(url, (res) => {
99
res.setEncoding('utf8');
1010
let body = '';
11-
res.on('data', data => {
11+
res.on('data', (data) => {
1212
body += data;
1313
});
1414
res.on('end', () => {
@@ -45,10 +45,10 @@ const makeRequest = function postRequest(self, endpoint, methodName, token) {
4545
}
4646
};
4747
return new Promise(((resolve, reject) => {
48-
const req = httpRequest.request(options, res => {
48+
const req = httpRequest.request(options, (res) => {
4949
res.setEncoding('utf8');
5050
let body = '';
51-
res.on('data', data => {
51+
res.on('data', (data) => {
5252
body += data;
5353
//console.log(body);
5454
});

test/buildURL.test.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
let expect = require('chai').expect;
2-
let should = require('chai').should();
3-
let eBay = require('../src/index');
4-
let buildURL = require('../src/buildURL');
1+
'use strict';
2+
const expect = require('chai').expect;
3+
const should = require('chai').should();
4+
const eBay = require('../src/index');
5+
const buildURL = require('../src/buildURL');
56

67
describe('test building url methods', () => {
78

89

910
it('test search url', () => {
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';
11-
let options = {
11+
const 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';
12+
const options = {
1213
name: 'iphone',
1314
operationName: 'findItemsByKeywords',
1415
param: 'keywords',
@@ -21,8 +22,8 @@ describe('test building url methods', () => {
2122
});
2223

2324
it('test Shopping url without selector', () => {
24-
let expectedSearchUrl = 'https://open.api.ebay.com/Shopping?appid=testID&callname=demoShoppingName&version=967&siteid=0&responseencoding=JSON';
25-
let options = {
25+
const expectedSearchUrl = 'https://open.api.ebay.com/Shopping?appid=testID&callname=demoShoppingName&version=967&siteid=0&responseencoding=JSON';
26+
const options = {
2627
name: 'iphone',
2728
param: 'keywords',
2829
clientID: 'testID',
@@ -32,8 +33,8 @@ describe('test building url methods', () => {
3233
});
3334

3435
it('test Shopping url including selector', () => {
35-
let expectedSearchUrl = 'https://open.api.ebay.com/Shopping?appid=testID&callname=demoShoppingName&version=967&siteid=0&responseencoding=JSON&IncludeSelector=true';
36-
let options = {
36+
const expectedSearchUrl = 'https://open.api.ebay.com/Shopping?appid=testID&callname=demoShoppingName&version=967&siteid=0&responseencoding=JSON&IncludeSelector=true';
37+
const options = {
3738
name: 'iphone',
3839
param: 'keywords',
3940
clientID: 'testID',

test/common.test.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ describe('test common util methods', () => {
1919

2020
describe('test constructAdditionalParams', () => {
2121
it('test constructAdditionalParams with required params', () => {
22-
let expectedParam = 'keywords=iphone&categoryId=111&sortOrder=PricePlusShippingLowest';
22+
const expectedParam = 'keywords=iphone&categoryId=111&sortOrder=PricePlusShippingLowest';
2323
const options = {
2424
keywords: 'iphone',
2525
categoryId: '111',
@@ -31,8 +31,8 @@ describe('test common util methods', () => {
3131
});
3232

3333
it('test constructAdditionalParams with affiliate params', () => {
34-
let expectedParamWithAffiliate = 'keywords=iphone&categoryId=111&sortOrder=PricePlusShippingLowest&affiliate.trackingId=1234567899&affiliate.networkId=123';
35-
let expectedParam = 'keywords=iphone&categoryId=111&sortOrder=PricePlusShippingLowest';
34+
const expectedParamWithAffiliate = 'keywords=iphone&categoryId=111&sortOrder=PricePlusShippingLowest&affiliate.trackingId=1234567899&affiliate.networkId=123';
35+
const expectedParam = 'keywords=iphone&categoryId=111&sortOrder=PricePlusShippingLowest';
3636
const options = {
3737
keywords: 'iphone',
3838
categoryId: '111',
@@ -55,8 +55,8 @@ describe('test common util methods', () => {
5555
});
5656

5757
it('test constructAdditionalParams with additional params', () => {
58-
let expectedParam = 'keywords=iphone%206s&categoryId=111&sortOrder=PricePlusShippingLowest&itemFilter(0).name=Condition&itemFilter(0).value=3000&itemFilter(1).name=SoldItemsOnly&itemFilter(1).value=true&storeName=addidas%20store';
59-
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';
58+
const expectedParam = 'keywords=iphone%206s&categoryId=111&sortOrder=PricePlusShippingLowest&itemFilter(0).name=Condition&itemFilter(0).value=3000&itemFilter(1).name=SoldItemsOnly&itemFilter(1).value=true&storeName=addidas%20store';
59+
const 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';
6060
const options = {
6161
keywords: 'iphone 6s',
6262
categoryId: '111',

test/findItemsByKeyword.test.js

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

55
describe('Test find items by keyword method', () => {
66

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

2424
it('test input parameter in findItemsByKeyword method', () => {
25-
let ebay = new Ebay({
25+
const ebay = new Ebay({
2626
clientID: 'ClientId'
2727
});
2828
expect(() => { ebay.findItemsByKeywords(); }).to.throw('Keyword is missing, Keyword is required');

test/finding.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ describe('test ebay finding Api', () => {
88

99
describe('test findingApi methods with required params', () => {
1010
it('test findItemsByCategory with required params', () => {
11-
let ebay = new Ebay({
11+
const ebay = new Ebay({
1212
clientID: 'ClientId'
1313
});
1414
expect(() => { ebay.findItemsByCategory(); }).to.throw('Category ID is null or invalid');
1515
});
1616

1717
it('test findCompletedItemswith required params', () => {
18-
let ebay = new Ebay({
18+
const ebay = new Ebay({
1919
clientID: 'ClientId'
2020
});
2121
expect(() => { ebay.findCompletedItems(''); }).to.throw('Keyword or category ID are required.');
@@ -24,7 +24,7 @@ describe('test ebay finding Api', () => {
2424

2525
describe('test all get apis', () => {
2626
it('test findItemsAdvanced', () => {
27-
let ebay = new Ebay({
27+
const ebay = new Ebay({
2828
clientID: 'ABCD'
2929
});
3030
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')

test/index.test.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
let expect = require('chai').expect;
2-
let should = require('chai').should();
3-
let Ebay = require('../src/index');
1+
const expect = require('chai').expect;
2+
const should = require('chai').should();
3+
const 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', () => {
@@ -10,7 +10,7 @@ describe('check all the options provided is valid or not - Ebay Constructor ', (
1010
});
1111

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

@@ -21,7 +21,7 @@ describe('check all the options provided is valid or not - Ebay Constructor ', (
2121
});
2222

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

test/shopping.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const Ebay = require('../src/index');
77
describe('test shopping api', () => {
88
describe('test all error scenarios', () => {
99
it('test input params', () => {
10-
let ebay = new Ebay({
10+
const ebay = new Ebay({
1111
clientID: 'ClientId'
1212
});
1313
expect(() => { ebay.getSingleItem(); }).to.throw('invalid_request_error -> Item ID is null or invalid');

0 commit comments

Comments
 (0)