Skip to content

Commit

Permalink
Included linting for test files (#120)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
pajaydev authored Aug 14, 2020
1 parent ceb4a70 commit 2dbdb37
Show file tree
Hide file tree
Showing 10 changed files with 1,444 additions and 1,189 deletions.
30 changes: 15 additions & 15 deletions src/credentials.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ const getAccessToken = function () {
if (!this.options.clientID) throw new Error('Missing Client ID');
if (!this.options.clientSecret) throw new Error('Missing Client Secret or Cert Id');
if (!this.options.body) throw new Error('Missing Body, required Grant type');
let scopesParam = this.options.body.scope
? Array.isArray(this.options.body.scope)
? this.options.body.scope.join('%20')
: this.options.body.scope
const scopesParam = this.options.body.scopes
? Array.isArray(this.options.body.scopes)
? this.options.body.scopes.join('%20')
: this.options.body.scopes
: DEFAULT_API_SCOPE;
this.options.data = qs.stringify({
grant_type: 'client_credentials',
Expand Down Expand Up @@ -44,10 +44,10 @@ const getUserAuthorizationUrl = function (state = null) {
if (!this.options.clientSecret) throw new Error('Missing Client Secret or Cert Id');
if (!this.options.body) throw new Error('Missing Body, required Grant type');
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');
let scopesParam = this.options.body.scopes
? Array.isArray(this.options.body.scopes)
? this.options.body.scopes.join('%20')
: this.options.body.scopes
const scopesParam = this.options.body.scope
? Array.isArray(this.options.body.scope)
? this.options.body.scope.join('%20')
: this.options.body.scope
: DEFAULT_API_SCOPE;
let queryParam = `client_id=${this.options.clientID}`;
queryParam += `&redirect_uri=${this.options.redirectUri}`;
Expand Down Expand Up @@ -77,7 +77,7 @@ const getUserTokenByCode = function (code) {
const self = this;
const encodedStr = base64Encode(`${this.options.clientID}:${this.options.clientSecret}`);
const auth = `Basic ${encodedStr}`;
return makeRequest(this.options, '/identity/v1/oauth2/token', 'POST', auth).then(result => {
return makeRequest(this.options, '/identity/v1/oauth2/token', 'POST', auth).then((result) => {
const resultJSON = JSON.parse(result);
if (!resultJSON.error) self.setUserAccessToken(resultJSON);
return resultJSON;
Expand All @@ -88,7 +88,7 @@ const getUserTokenByCode = function (code) {
* Use a refresh token to update a User access token (Updating the expired access token)
*
* @param refreshToken refresh token, defaults to pre-assigned refresh token
* @param scopes array of scopes for the access token
* @param scope array of scopes for the access token
* @return userAccessToken object (without refresh_token)
*/
const getUserTokenByRefresh = function (refreshToken = null) {
Expand All @@ -99,10 +99,10 @@ const getUserTokenByRefresh = function (refreshToken = null) {
throw new Error('Refresh token is required, to generate refresh token use getUserTokenByCode method'); // eslint-disable-line max-len
}
refreshToken = refreshToken ? refreshToken : this.options.refreshToken;
let scopesParam = this.options.body.scopes
? Array.isArray(this.options.body.scopes)
? this.options.body.scopes.join('%20')
: this.options.body.scopes
const scopesParam = this.options.body.scope
? Array.isArray(this.options.body.scope)
? this.options.body.scope.join('%20')
: this.options.body.scope
: DEFAULT_API_SCOPE;
this.options.data = qs.stringify({
refresh_token: refreshToken,
Expand All @@ -113,7 +113,7 @@ const getUserTokenByRefresh = function (refreshToken = null) {
const self = this;
const encodedStr = base64Encode(`${this.options.clientID}:${this.options.clientSecret}`);
const auth = `Basic ${encodedStr}`;
return makeRequest(this.options, '/identity/v1/oauth2/token', 'POST', auth).then(result => {
return makeRequest(this.options, '/identity/v1/oauth2/token', 'POST', auth).then((result) => {
const resultJSON = JSON.parse(result);
if (!resultJSON.error) self.setUserAccessToken(resultJSON);
return resultJSON;
Expand Down
4 changes: 2 additions & 2 deletions src/finding.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ const getVersion = function () {
const findItemsByProduct = function (options) {
if (!options) throw new Error('INVALID_REQUEST_PARMS --> Please enter the Valid input.');
if (!options.productId) throw new Error('INVALID_REQUEST_PARMS --> Product ID is required.');
let type = options.type ? options.type : 'ReferenceID';
const type = options.type ? options.type : 'ReferenceID';
this.options.operationName = 'findItemsByProduct';
this.options.additionalParam = utils.constructAdditionalParams(options);
let url = `${urlObject.buildSearchUrl(this.options)}&productId.@type=${type}`;
const url = `${urlObject.buildSearchUrl(this.options)}&productId.@type=${type}`;
return getRequest(url).then((data) => {
return JSON.parse(data).findItemsByProductResponse;
}, console.error // eslint-disable-line no-console
Expand Down
8 changes: 4 additions & 4 deletions src/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ const qs = require('querystring');
const getRequest = (url) => {
if (url.includes('http://')) httpRequest = require('http');
return new Promise(((resolve, reject) => {
httpRequest.get(url, res => {
httpRequest.get(url, (res) => {
res.setEncoding('utf8');
let body = '';
res.on('data', data => {
res.on('data', (data) => {
body += data;
});
res.on('end', () => {
Expand Down Expand Up @@ -45,10 +45,10 @@ const makeRequest = function postRequest(self, endpoint, methodName, token) {
}
};
return new Promise(((resolve, reject) => {
const req = httpRequest.request(options, res => {
const req = httpRequest.request(options, (res) => {
res.setEncoding('utf8');
let body = '';
res.on('data', data => {
res.on('data', (data) => {
body += data;
//console.log(body);
});
Expand Down
21 changes: 11 additions & 10 deletions test/buildURL.test.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
let expect = require('chai').expect;
let should = require('chai').should();
let eBay = require('../src/index');
let buildURL = require('../src/buildURL');
'use strict';
const expect = require('chai').expect;
const should = require('chai').should();
const eBay = require('../src/index');
const buildURL = require('../src/buildURL');

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


it('test search url', () => {
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';
let options = {
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';
const options = {
name: 'iphone',
operationName: 'findItemsByKeywords',
param: 'keywords',
Expand All @@ -21,8 +22,8 @@ describe('test building url methods', () => {
});

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

it('test Shopping url including selector', () => {
let expectedSearchUrl = 'https://open.api.ebay.com/Shopping?appid=testID&callname=demoShoppingName&version=967&siteid=0&responseencoding=JSON&IncludeSelector=true';
let options = {
const expectedSearchUrl = 'https://open.api.ebay.com/Shopping?appid=testID&callname=demoShoppingName&version=967&siteid=0&responseencoding=JSON&IncludeSelector=true';
const options = {
name: 'iphone',
param: 'keywords',
clientID: 'testID',
Expand Down
10 changes: 5 additions & 5 deletions test/common.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('test common util methods', () => {

describe('test constructAdditionalParams', () => {
it('test constructAdditionalParams with required params', () => {
let expectedParam = 'keywords=iphone&categoryId=111&sortOrder=PricePlusShippingLowest';
const expectedParam = 'keywords=iphone&categoryId=111&sortOrder=PricePlusShippingLowest';
const options = {
keywords: 'iphone',
categoryId: '111',
Expand All @@ -31,8 +31,8 @@ describe('test common util methods', () => {
});

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

it('test constructAdditionalParams with additional params', () => {
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';
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';
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';
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';
const options = {
keywords: 'iphone 6s',
categoryId: '111',
Expand Down
4 changes: 2 additions & 2 deletions test/findItemsByKeyword.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const nock = require('nock');
const Ebay = require('../src/index');
let expect = require('chai').expect;
const expect = require('chai').expect;

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

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

it('test input parameter in findItemsByKeyword method', () => {
let ebay = new Ebay({
const ebay = new Ebay({
clientID: 'ClientId'
});
expect(() => { ebay.findItemsByKeywords(); }).to.throw('Keyword is missing, Keyword is required');
Expand Down
6 changes: 3 additions & 3 deletions test/finding.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ describe('test ebay finding Api', () => {

describe('test findingApi methods with required params', () => {
it('test findItemsByCategory with required params', () => {
let ebay = new Ebay({
const ebay = new Ebay({
clientID: 'ClientId'
});
expect(() => { ebay.findItemsByCategory(); }).to.throw('Category ID is null or invalid');
});

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

describe('test all get apis', () => {
it('test findItemsAdvanced', () => {
let ebay = new Ebay({
const ebay = new Ebay({
clientID: 'ABCD'
});
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')
Expand Down
10 changes: 5 additions & 5 deletions test/index.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
let expect = require('chai').expect;
let should = require('chai').should();
let Ebay = require('../src/index');
const expect = require('chai').expect;
const should = require('chai').should();
const Ebay = require('../src/index');

describe('check all the options provided is valid or not - Ebay Constructor ', () => {
it('check input is provided or not', () => {
Expand All @@ -10,7 +10,7 @@ describe('check all the options provided is valid or not - Ebay Constructor ', (
});

it('should have client ID', () => {
let ebayApi = new Ebay({ clientID: '12345' });
const ebayApi = new Ebay({ clientID: '12345' });
ebayApi.options.should.have.property('clientID');
});

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

it('check instance of Ebay', () => {
let ebayApi = new Ebay({ clientID: '12345' });
const ebayApi = new Ebay({ clientID: '12345' });
expect(ebayApi).to.be.a.instanceOf(Ebay);
});

Expand Down
2 changes: 1 addition & 1 deletion test/shopping.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const Ebay = require('../src/index');
describe('test shopping api', () => {
describe('test all error scenarios', () => {
it('test input params', () => {
let ebay = new Ebay({
const ebay = new Ebay({
clientID: 'ClientId'
});
expect(() => { ebay.getSingleItem(); }).to.throw('invalid_request_error -> Item ID is null or invalid');
Expand Down
Loading

0 comments on commit 2dbdb37

Please sign in to comment.