2018-08-29 09:00:15 +00:00
|
|
|
import { moduleFor, test } from 'ember-qunit';
|
|
|
|
import repo from 'consul-ui/tests/helpers/repo';
|
2019-05-15 13:44:57 +00:00
|
|
|
import { get } from '@ember/object';
|
2018-08-29 09:00:15 +00:00
|
|
|
const NAME = 'node';
|
2018-10-26 16:36:15 +00:00
|
|
|
moduleFor(`service:repository/${NAME}`, `Integration | Service | ${NAME}`, {
|
2018-08-29 09:00:15 +00:00
|
|
|
// Specify the other units that are required for this test.
|
2018-10-26 16:36:15 +00:00
|
|
|
integration: true,
|
2018-08-29 09:00:15 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
const dc = 'dc-1';
|
|
|
|
const id = 'token-name';
|
2019-05-15 13:44:57 +00:00
|
|
|
const now = new Date().getTime();
|
2019-12-17 18:47:37 +00:00
|
|
|
const nspace = 'default';
|
2018-08-29 09:00:15 +00:00
|
|
|
test('findByDatacenter returns the correct data for list endpoint', function(assert) {
|
2019-05-15 13:44:57 +00:00
|
|
|
get(this.subject(), 'store').serializerFor(NAME).timestamp = function() {
|
|
|
|
return now;
|
|
|
|
};
|
2018-08-29 09:00:15 +00:00
|
|
|
return repo(
|
|
|
|
'Node',
|
|
|
|
'findAllByDatacenter',
|
|
|
|
this.subject(),
|
|
|
|
function retrieveStub(stub) {
|
|
|
|
return stub(`/v1/internal/ui/nodes?dc=${dc}`, {
|
|
|
|
CONSUL_NODE_COUNT: '100',
|
|
|
|
});
|
|
|
|
},
|
|
|
|
function performTest(service) {
|
|
|
|
return service.findAllByDatacenter(dc);
|
|
|
|
},
|
|
|
|
function performAssertion(actual, expected) {
|
|
|
|
assert.deepEqual(
|
|
|
|
actual,
|
|
|
|
expected(function(payload) {
|
|
|
|
return payload.map(item =>
|
|
|
|
Object.assign({}, item, {
|
2019-05-15 13:44:57 +00:00
|
|
|
SyncTime: now,
|
2018-08-29 09:00:15 +00:00
|
|
|
Datacenter: dc,
|
2019-12-17 18:47:37 +00:00
|
|
|
uid: `["${nspace}","${dc}","${item.ID}"]`,
|
2018-08-29 09:00:15 +00:00
|
|
|
})
|
|
|
|
);
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
test('findBySlug returns the correct data for item endpoint', function(assert) {
|
|
|
|
return repo(
|
|
|
|
'Node',
|
|
|
|
'findBySlug',
|
|
|
|
this.subject(),
|
|
|
|
function(stub) {
|
|
|
|
return stub(`/v1/internal/ui/node/${id}?dc=${dc}`);
|
|
|
|
},
|
|
|
|
function(service) {
|
|
|
|
return service.findBySlug(id, dc);
|
|
|
|
},
|
|
|
|
function(actual, expected) {
|
|
|
|
assert.deepEqual(
|
|
|
|
actual,
|
|
|
|
expected(function(payload) {
|
|
|
|
const item = payload;
|
|
|
|
return Object.assign({}, item, {
|
|
|
|
Datacenter: dc,
|
2019-12-17 18:47:37 +00:00
|
|
|
uid: `["${nspace}","${dc}","${item.ID}"]`,
|
2019-03-22 17:24:40 +00:00
|
|
|
meta: {
|
|
|
|
cursor: undefined,
|
2019-12-17 18:47:37 +00:00
|
|
|
dc: dc,
|
|
|
|
nspace: nspace,
|
2019-03-22 17:24:40 +00:00
|
|
|
},
|
2018-08-29 09:00:15 +00:00
|
|
|
});
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|