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) {
|
2020-12-07 09:14:30 +00:00
|
|
|
actual.forEach(item => {
|
|
|
|
assert.equal(item.uid, `["${nspace}","${dc}","${item.ID}"]`);
|
|
|
|
assert.equal(item.Datacenter, dc);
|
|
|
|
});
|
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) {
|
2020-12-07 09:14:30 +00:00
|
|
|
assert.equal(actual.uid, `["${nspace}","${dc}","${actual.ID}"]`);
|
|
|
|
assert.equal(actual.Datacenter, dc);
|
2018-08-29 09:00:15 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|