Skip to content

Commit

Permalink
Merge pull request #6 from arshadkazmi42/parser-test
Browse files Browse the repository at this point in the history
Parser test
  • Loading branch information
arshadkazmi42 committed Aug 11, 2019
2 parents 42a15a6 + 1a7baeb commit ccd6ba7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ parser.json = (data) => {
};

parser.blob = (data) => {
return Buffer.from(data, 'utf8');
let rawData = data;
if (typeof data === 'string') {
rawData = JSON.parse(rawData);
}
return Buffer.from(rawData, 'utf8');
};


Expand Down
13 changes: 13 additions & 0 deletions tests/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ const {
InsertFields,
JoinFields,
PrivateFields,
Parser,
QueryValues,
SelectFields,
UpdateValues,
ValuesPointer
} = require('../index');

const BLOB_DATA = '{"type":"Buffer","data":[118,49,48,215,237,167,249,243,19,0,154,172,45,177,18,115,66,18,133,179,117,163,148,13,106,231,219,121,53,252,127,128,5,50,52,161,101,76,166,202,30,253,119,76,22,61,251,177,167,134,247,60,43,193,42,129,125,11,161,21,164,70,169,83,153,213,84,90,234,33,155,190,35,132,106,194,85,196,50,107,105,9,69,44,21,81,101,39,7,192,226,244,206,44,135,11,108,137,190,249,20,133,81,242,184,81,105,249,46,153,103,235,63,53,237,104,61,19,101,36,15,185,191,124,48,176,112,220,218,180,41,144,163,227,127,157,93,124,228,63,246,58,111,171,57,64,245]}';
const FIELDS = ['name', 'class', 'status'];
const MODEL = require('../data/model.json');
const DATA = {
Expand Down Expand Up @@ -187,3 +189,14 @@ describe('test all update values', () => {
expect(values).to.deep.equal(UPDATE_VALUES);
});
});

describe('test parser', () => {
it('should return parsed buffer value', () => {
const blob = Parser.get('blob', BLOB_DATA);
expect(blob).to.deep.equal(Buffer.from(JSON.parse(BLOB_DATA), 'utf8'));
});
it('should return parsed json value', () => {
const blob = Parser.get('json', BLOB_DATA);
expect(blob).to.deep.equal(JSON.parse(BLOB_DATA), 'utf8');
});
});

0 comments on commit ccd6ba7

Please sign in to comment.