Skip to content

Commit

Permalink
Merge pull request #201 from pactumjs/197-use-stored-data-in-datafunc…
Browse files Browse the repository at this point in the history
…handler

fix: use data management in data function handlers
  • Loading branch information
ASaiAnudeep authored Sep 3, 2022
2 parents 9b169c1 + ee37ece commit b96601d
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pactum",
"version": "3.2.0",
"version": "3.2.1",
"description": "REST API Testing Tool for all levels in a Test Pyramid",
"main": "./src/index.js",
"types": "./src/index.d.ts",
Expand Down
3 changes: 2 additions & 1 deletion src/helpers/dataProcessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ const dataProcessor = {
if (refType === 'F') {
const [handlerName, ..._args] = refValue.split(':');
const handlerFun = handler.getDataFuncHandler(handlerName);
values.push(handlerFun({ args: _args.length > 0 ? _args[0].split(',') : _args }));
const handler_data = handlerFun({ args: _args.length > 0 ? _args[0].split(',') : _args });
values.push(this.processDataRefs(handler_data));
}
if (refType === 'S') {
const value = jq(refValue, { data: stash.getDataStore() }).value;
Expand Down
48 changes: 48 additions & 0 deletions test/unit/dataProcessor.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const expect = require('chai').expect;

const dp = require('../../src/helpers/dataProcessor');
const stash = require('../../src/exports/stash');
const handler = require('../../src/exports/handler');
const config = require('../../src/config');

describe('Data Processing - Templates', () => {
Expand Down Expand Up @@ -779,4 +780,51 @@ describe('Data Processing - Invalid Data', () => {
stash.clearDataMaps();
});

});


describe('Data Processing - Functions', () => {

it('should return object data', () => {
handler.addDataFuncHandler('GetFirstName', () => {
return { user: 'jon' }
});
const data = dp.processData('$F{GetFirstName}');
expect(data).deep.equals({ user: 'jon' });
});

it('should return data with plane data map patterns', () => {
handler.addDataFuncHandler('GetFirstName', () => {
return '$M{User.FirstName}'
})
stash.addDataMap({
User: {
FirstName: 'Jon'
}
});
dp.processMaps();
const data = dp.processData('$F{GetFirstName}');
expect(data).deep.equals('Jon');
});

it('should return data with data map patterns inside object', () => {
handler.addDataFuncHandler('GetFirstName', () => {
return { name: '$M{User.FirstName}' }
})
stash.addDataMap({
User: {
FirstName: 'Jon'
}
});
dp.processMaps();
const data = dp.processData('$F{GetFirstName}');
expect(data).deep.equals({ name: 'Jon' });
});

afterEach(() => {
config.data.ref.map.enabled = false;
config.data.ref.map.processed = false;
stash.clearDataMaps();
});

});

0 comments on commit b96601d

Please sign in to comment.