Skip to content
This repository has been archived by the owner on Jun 7, 2019. It is now read-only.

Commit

Permalink
🔥 Remove unhelpful api utils
Browse files Browse the repository at this point in the history
Closes #311
  • Loading branch information
willclarktech committed Oct 30, 2017
1 parent 67d2c92 commit 541659a
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 95 deletions.
5 changes: 3 additions & 2 deletions src/api/privateApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,10 @@ export function createRequestObject(method, requestType, providedOptions) {
const options = providedOptions || {};
const url =
method === GET
? `${getFullURL.call(
? `${getFullURL.call(this)}/api/${requestType}?${utils.toQueryString.call(
this,
)}/api/${requestType}${utils.serialiseHTTPData.call(this, options)}`
options,
)}`
: `${getFullURL.call(this)}/api/${requestType}`;

return {
Expand Down
39 changes: 0 additions & 39 deletions src/api/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,32 +80,6 @@ export const checkOptions = options => {
return options;
};

/**
* @method trimObj
* @param obj
*
* @return trimmed object
*/
export const trimObj = obj => {
const isArray = Array.isArray(obj);
if (!isArray && typeof obj !== 'object') {
return Number.isInteger(obj) ? obj.toString() : obj;
}

const trim = value =>
typeof value === 'string' ? value.trim() : trimObj(value);

return isArray
? obj.map(trim)
: Object.entries(obj).reduce((accumulator, [key, value]) => {
const trimmedKey = trim(key);
const trimmedValue = trim(value);
return Object.assign({}, accumulator, {
[trimmedKey]: trimmedValue,
});
}, {});
};

/**
* @method toQueryString
* @param obj
Expand All @@ -123,16 +97,3 @@ export const toQueryString = obj => {

return parts.join('&');
};

/**
* @method serialiseHTTPData
* @param data
*
* @return serialisedData string
*/

export const serialiseHTTPData = data => {
const trimmed = trimObj(data);
const queryString = toQueryString(trimmed);
return `?${queryString}`;
};
54 changes: 0 additions & 54 deletions test/api/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,40 +33,6 @@ describe('api utils module', () => {
.resolves(Object.assign({}, sendRequestResult));
});

describe('#trimObj', () => {
const { trimObj } = utils;

it('should not trim strings', () => {
const str = ' string ';
const trimmedString = trimObj(str);
trimmedString.should.be.equal(str);
});

it('should convert integers to strings', () => {
const trimmedInteger = trimObj(123);
trimmedInteger.should.be.eql('123');
});

it('should convert nested integers to strings', () => {
const trimmedObject = trimObj({ myObj: 2 });
trimmedObject.should.be.eql({ myObj: '2' });
});

it('should remove whitespace from keys and values', () => {
const trimmedObject = trimObj({ ' my_Obj ': ' my val ' });
trimmedObject.should.be.eql({ my_Obj: 'my val' }); // eslint-disable-line camelcase
});

it('should trim each member of an array', () => {
const trimmedArray = trimObj([
' string ',
{ ' key ': ' value ' },
[' array item '],
]);
trimmedArray.should.be.eql(['string', { key: 'value' }, ['array item']]);
});
});

describe('#toQueryString', () => {
const { toQueryString } = utils;

Expand Down Expand Up @@ -126,26 +92,6 @@ describe('api utils module', () => {
});
});

describe('#serialiseHTTPData', () => {
const { serialiseHTTPData } = utils;
const queryStringData = 'key%2F1=value%20%252&key3=4';

let data;
let serialisedData;

beforeEach(() => {
data = {
' key/1 ': ' value %2',
key3: 4,
};
serialisedData = serialiseHTTPData(data);
});

it('should trim, escape, and prepend a question mark to the query string', () => {
serialisedData.should.equal(`?${queryStringData}`);
});
});

describe('#wrapSendRequest', () => {
const { wrapSendRequest } = utils;
const value = '123';
Expand Down

0 comments on commit 541659a

Please sign in to comment.