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';
|
2021-09-15 18:50:11 +00:00
|
|
|
const partition = '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) {
|
2021-09-15 18:50:11 +00:00
|
|
|
return stub(
|
|
|
|
`/v1/internal/ui/nodes?dc=${dc}${
|
|
|
|
typeof partition !== 'undefined' ? `&partition=${partition}` : ``
|
|
|
|
}`,
|
|
|
|
{
|
|
|
|
CONSUL_NODE_COUNT: '100',
|
|
|
|
}
|
|
|
|
);
|
2018-08-29 09:00:15 +00:00
|
|
|
},
|
|
|
|
function performTest(service) {
|
2021-09-15 18:50:11 +00:00
|
|
|
return service.findAllByDatacenter({ dc, partition });
|
2018-08-29 09:00:15 +00:00
|
|
|
},
|
|
|
|
function performAssertion(actual, expected) {
|
2020-12-07 09:14:30 +00:00
|
|
|
actual.forEach(item => {
|
2021-09-15 18:50:11 +00:00
|
|
|
assert.equal(item.uid, `["${partition}","${nspace}","${dc}","${item.ID}"]`);
|
2020-12-07 09:14:30 +00:00
|
|
|
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) {
|
2021-09-15 18:50:11 +00:00
|
|
|
return stub(
|
|
|
|
`/v1/internal/ui/node/${id}?dc=${dc}${
|
|
|
|
typeof partition !== 'undefined' ? `&partition=${partition}` : ``
|
|
|
|
}`
|
|
|
|
);
|
2018-08-29 09:00:15 +00:00
|
|
|
},
|
|
|
|
function(service) {
|
2021-09-15 18:50:11 +00:00
|
|
|
return service.findBySlug({ id, dc, partition });
|
2018-08-29 09:00:15 +00:00
|
|
|
},
|
|
|
|
function(actual, expected) {
|
2021-09-15 18:50:11 +00:00
|
|
|
assert.equal(actual.uid, `["${partition}","${nspace}","${dc}","${actual.ID}"]`);
|
2020-12-07 09:14:30 +00:00
|
|
|
assert.equal(actual.Datacenter, dc);
|
2018-08-29 09:00:15 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|