2022-09-01 15:37:37 +00:00
|
|
|
import { module, skip, test } from 'qunit';
|
|
|
|
import { setupTest } from 'ember-qunit';
|
2019-05-01 18:09:29 +00:00
|
|
|
import repo from 'consul-ui/tests/helpers/repo';
|
|
|
|
import { createPolicies } from 'consul-ui/tests/helpers/normalizers';
|
|
|
|
|
2022-09-15 08:43:17 +00:00
|
|
|
module(`Integration | Service | role`, function (hooks) {
|
2022-09-01 15:37:37 +00:00
|
|
|
setupTest(hooks);
|
|
|
|
const now = new Date().getTime();
|
|
|
|
const dc = 'dc-1';
|
|
|
|
const id = 'role-name';
|
|
|
|
const undefinedNspace = 'default';
|
|
|
|
const undefinedPartition = 'default';
|
|
|
|
const partition = 'default';
|
2022-09-15 08:43:17 +00:00
|
|
|
[undefinedNspace, 'team-1', undefined].forEach((nspace) => {
|
|
|
|
test(`findByDatacenter returns the correct data for list endpoint when nspace is ${nspace}`, function (assert) {
|
2022-09-01 15:37:37 +00:00
|
|
|
const subject = this.owner.lookup('service:repository/role');
|
|
|
|
|
2022-09-15 08:43:17 +00:00
|
|
|
subject.store.serializerFor('role').timestamp = function () {
|
2022-09-01 15:37:37 +00:00
|
|
|
return now;
|
|
|
|
};
|
|
|
|
return repo(
|
|
|
|
'Role',
|
|
|
|
'findAllByDatacenter',
|
|
|
|
subject,
|
|
|
|
function retrieveStub(stub) {
|
|
|
|
return stub(
|
|
|
|
`/v1/acl/roles?dc=${dc}${typeof nspace !== 'undefined' ? `&ns=${nspace}` : ``}${
|
|
|
|
typeof partition !== 'undefined' ? `&partition=${partition}` : ``
|
|
|
|
}`,
|
|
|
|
{
|
|
|
|
CONSUL_ROLE_COUNT: '100',
|
|
|
|
}
|
|
|
|
);
|
|
|
|
},
|
|
|
|
function performTest(service) {
|
|
|
|
return service.findAllByDatacenter({
|
|
|
|
dc: dc,
|
|
|
|
nspace: nspace || undefinedNspace,
|
|
|
|
partition: partition || undefinedPartition,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
function performAssertion(actual, expected) {
|
2022-09-15 08:43:17 +00:00
|
|
|
assert.propContains(
|
2022-09-01 15:37:37 +00:00
|
|
|
actual,
|
2022-09-15 08:43:17 +00:00
|
|
|
expected(function (payload) {
|
|
|
|
return payload.map((item) =>
|
2022-09-01 15:37:37 +00:00
|
|
|
Object.assign({}, item, {
|
|
|
|
SyncTime: now,
|
|
|
|
Datacenter: dc,
|
|
|
|
Namespace: item.Namespace || undefinedNspace,
|
|
|
|
Partition: item.Partition || undefinedPartition,
|
2022-09-15 08:43:17 +00:00
|
|
|
uid: `["${item.Partition || undefinedPartition}","${
|
|
|
|
item.Namespace || undefinedNspace
|
|
|
|
}","${dc}","${item.ID}"]`,
|
2022-09-01 15:37:37 +00:00
|
|
|
Policies: createPolicies(item),
|
|
|
|
})
|
|
|
|
);
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
// FIXME: For some reason this tries to initialize the metrics service?
|
2022-09-15 08:43:17 +00:00
|
|
|
skip(`findBySlug returns the correct data for item endpoint when the nspace is ${nspace}`, function (assert) {
|
2022-09-01 15:37:37 +00:00
|
|
|
const subject = this.owner.lookup('service:repository/role');
|
|
|
|
|
|
|
|
return repo(
|
|
|
|
'Role',
|
|
|
|
'findBySlug',
|
|
|
|
subject,
|
|
|
|
function retrieveStub(stub) {
|
|
|
|
return stub(
|
|
|
|
`/v1/acl/role/${id}?dc=${dc}${typeof nspace !== 'undefined' ? `&ns=${nspace}` : ``}${
|
|
|
|
typeof partition !== 'undefined' ? `&partition=${partition}` : ``
|
|
|
|
}`
|
|
|
|
);
|
|
|
|
},
|
|
|
|
function performTest(service) {
|
|
|
|
return service.findBySlug({
|
|
|
|
id,
|
|
|
|
dc,
|
|
|
|
ns: nspace || undefinedNspace,
|
|
|
|
partition: partition || undefinedPartition,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
function performAssertion(actual, expected) {
|
2022-09-15 08:43:17 +00:00
|
|
|
assert.propContains(
|
2022-09-01 15:37:37 +00:00
|
|
|
actual,
|
2022-09-15 08:43:17 +00:00
|
|
|
expected(function (payload) {
|
2022-09-01 15:37:37 +00:00
|
|
|
const item = payload;
|
|
|
|
return Object.assign({}, item, {
|
2019-12-17 18:47:37 +00:00
|
|
|
Datacenter: dc,
|
|
|
|
Namespace: item.Namespace || undefinedNspace,
|
2021-09-15 18:50:11 +00:00
|
|
|
Partition: item.Partition || undefinedPartition,
|
2022-09-15 08:43:17 +00:00
|
|
|
uid: `["${partition || undefinedPartition}","${
|
|
|
|
item.Namespace || undefinedNspace
|
|
|
|
}","${dc}","${item.ID}"]`,
|
2019-12-17 18:47:37 +00:00
|
|
|
Policies: createPolicies(item),
|
2022-09-01 15:37:37 +00:00
|
|
|
});
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
2019-12-17 18:47:37 +00:00
|
|
|
});
|
2019-05-01 18:09:29 +00:00
|
|
|
});
|