Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

admin-config

Package Overview
Dependencies
Maintainers
2
Versions
50
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

admin-config - npm Package Compare versions

Comparing version 0.1.8 to 0.1.9

29

lib/Queries/ReadQueries.js

@@ -37,4 +37,9 @@ import Queries from './Queries'

sortField = sortField || view.getSortFieldName();
sortDir = sortDir || view.sortDir();
if (sortField && sortField.split('.')[0] === view.name()) {
sortField = sortField;
sortDir = sortDir;
} else {
sortField = view.getSortFieldName();
sortDir = view.sortDir();
}

@@ -48,3 +53,3 @@ return this.getRawValues(view.entity, view.name(), view.type, page, view.perPage(), filters, view.filters(), sortField, sortDir, url)

});
};
}

@@ -103,3 +108,3 @@ /**

.getList(params, entity.name(), this._application.getRouteFor(entity, url, viewType));
};
}

@@ -134,3 +139,3 @@ /**

return this.fillFilteredReferencedData(calls, references, rawValues);
};
}

@@ -289,6 +294,14 @@ /**

viewName = referencedList.datagridName(),
currentSortField = referencedList.getSortFieldName(),
currentSortDir = referencedList.sortDir(),
filter = {};
if (sortField && sortField.split('.')[0] === viewName) {
currentSortField = sortField;
currentSortDir = sortDir || 'ASC';
}
filter[referencedList.targetReferenceField()] = entityId;
calls.push(getRawValues(targetEntity, viewName, 'listView', 1, referencedList.perPage(), filter, {}, sortField || referencedList.getSortFieldName(), sortDir || referencedList.sortDir()));
calls.push(getRawValues(targetEntity, viewName, 'listView', 1, referencedList.perPage(), filter, {}, currentSortField, currentSortDir));
}

@@ -313,5 +326,5 @@

});
};
}
}
export default ReadQueries
export default ReadQueries;

@@ -8,2 +8,3 @@ import View from './View';

this._type = 'BatchDeleteView';
this._enabled = true;
}

@@ -10,0 +11,0 @@ }

{
"name": "admin-config",
"version": "0.1.8",
"version": "0.1.9",
"private": false,

@@ -5,0 +5,0 @@ "repository": {

@@ -5,6 +5,6 @@ let assert = require('chai').assert,

import ReadQueries from "../../../lib/Queries/ReadQueries";
import DataStore from "../../../lib/DataStore/DataStore";
import PromisesResolver from "../../mock/PromisesResolver";
import Entity from "../../../lib/Entity/Entity";
import ReferenceField from "../../../lib/Field/ReferenceField";
import ReferencedListField from "../../../lib/Field/ReferencedListField";
import TextField from "../../../lib/Field/TextField";

@@ -22,3 +22,4 @@ import Field from "../../../lib/Field/Field";

humanEntity,
catView;
catView,
humanView;

@@ -40,3 +41,8 @@ beforeEach(() => {

humanEntity = new Entity('human');
catView = catEntity.views["ListView"]
humanView = humanEntity.listView()
.fields([
new Field('name'),
new ReferencedListField('cat_id').targetEntity(catEntity).targetReferenceField('human_id')
]);
catView = catEntity.listView()
.addField(new TextField('name'))

@@ -108,2 +114,24 @@ .addField(new ReferenceField('human_id').targetEntity(humanEntity).targetField(new Field('firstName')));

});
it('should send correct page params to the API call', () => {
let spy = sinon.spy(readQueries, 'getRawValues');
readQueries.getAll(catView, 2);
assert(spy.withArgs(catEntity, catView.name(), catView.type, 2).calledOnce);
});
it('should send correct sort params to the API call', () => {
let spy = sinon.spy(readQueries, 'getRawValues');
catView.sortField('name').sortDir('DESC');
let viewName = catView.name();
readQueries.getAll(catView, 1);
readQueries.getAll(catView, 1, [], 'unknow_ListView.name', 'ASC');
readQueries.getAll(catView, 1, [], viewName + '.id', 'ASC');
assert(spy.withArgs(catEntity, viewName, catView.type, 1, catView.perPage(), undefined, catView.filters(), viewName + '.name', 'DESC').calledOnce);
assert(spy.withArgs(catEntity, viewName, catView.type, 1, catView.perPage(), [], catView.filters(), viewName + '.name', 'DESC').calledOnce);
assert(spy.withArgs(catEntity, viewName, catView.type, 1, catView.perPage(), [], catView.filters(), viewName + '.id', 'ASC').calledOnce);
});
});

@@ -185,2 +213,33 @@

});
describe('getReferencedListData', () => {
it('should return all referenced list data for a View', () => {
restWrapper.getList = sinon.stub().returns(buildPromise({data: rawCats, headers: () => {}}));
PromisesResolver.allEvenFailed = sinon.stub().returns(buildPromise([
{status: 'success', result: { data: rawCats }}
]));
readQueries.getReferencedListData(humanView.getReferencedLists(), null, null, 1)
.then((referencedListEntries) => {
assert.equal(referencedListEntries['cat_id'].length, 2);
assert.equal(referencedListEntries['cat_id'][0].id, 1);
assert.equal(referencedListEntries['cat_id'][1].name, 'Suna');
});
});
it('should send correct sort params to the API call', () => {
let spy = sinon.spy(readQueries, 'getRawValues');
humanView.getReferencedLists()['cat_id'].sortField('name').sortDir('DESC');
let viewName = catView.name();
let perPage = humanView.getReferencedLists()['cat_id'].perPage();
let targetEntity = humanView.getReferencedLists()['cat_id'].targetEntity();
readQueries.getReferencedListData(humanView.getReferencedLists(), null, null, 1);
readQueries.getReferencedListData(humanView.getReferencedLists(), 'unknow_ListView.name', 'ASC', 1);
readQueries.getReferencedListData(humanView.getReferencedLists(), 'cat_ListView.id', 'ASC', 1);
assert(spy.withArgs(catEntity, viewName, 'listView', 1, perPage, { 'human_id': 1 }, {}, viewName + '.name', 'DESC').calledTwice);
assert(spy.withArgs(targetEntity, viewName, 'listView', 1, perPage, { 'human_id': 1 }, {}, viewName + '.id', 'ASC').calledOnce);
});
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc