ui: Coordinates don't require a nspace, so don't expect one in the repo (#7378)

* ui: Coordinates don't require a nspace, so don't expect one in the repo

* Add a test to prove the correct number of arguments are being passed
This commit is contained in:
John Cowen 2020-03-04 18:12:47 +00:00 committed by GitHub
parent 468e82dcf9
commit 6074a1b4c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 2 deletions

View File

@ -10,8 +10,19 @@ export default RepositoryService.extend({
getModelName: function() {
return modelName;
},
findAllByNode: function(node, dc, nspace, configuration) {
return this.findAllByDatacenter(dc, nspace, configuration).then(function(coordinates) {
// Coordinates don't need nspaces so we have a custom method here
// that doesn't accept nspaces
findAllByDatacenter: function(dc, configuration = {}) {
const query = {
dc: dc,
};
if (typeof configuration.cursor !== 'undefined') {
query.index = configuration.cursor;
}
return this.store.query(this.getModelName(), query);
},
findAllByNode: function(node, dc, configuration) {
return this.findAllByDatacenter(dc, configuration).then(function(coordinates) {
let results = {};
if (get(coordinates, 'length') > 1) {
results = tomography(node, coordinates.map(item => get(item, 'data')));

View File

@ -44,3 +44,18 @@ test('findAllByDatacenter returns the correct data for list endpoint', function(
}
);
});
test('findAllByNode calls findAllByDatacenter with the correct arguments', function(assert) {
assert.expect(3);
const datacenter = 'dc-1';
const conf = {
cursor: 1,
};
const service = this.subject();
service.findAllByDatacenter = function(dc, configuration) {
assert.equal(arguments.length, 2, 'Expected to be called with the correct number of arguments');
assert.equal(dc, datacenter);
assert.deepEqual(configuration, conf);
return Promise.resolve([]);
};
return service.findAllByNode('node-name', datacenter, conf);
});