2018-10-19 15:17:02 +00:00
|
|
|
import { moduleFor, test, skip } from 'ember-qunit';
|
2020-04-22 16:30:26 +00:00
|
|
|
import { get } from '@ember/object';
|
2018-10-19 15:17:02 +00:00
|
|
|
import repo from 'consul-ui/tests/helpers/repo';
|
2019-05-01 18:09:29 +00:00
|
|
|
const NAME = 'policy';
|
2018-10-26 17:40:51 +00:00
|
|
|
moduleFor(`service:repository/${NAME}`, `Integration | Service | ${NAME}`, {
|
2018-10-19 15:17:02 +00:00
|
|
|
// Specify the other units that are required for this test.
|
2018-10-26 17:40:51 +00:00
|
|
|
integration: true,
|
2018-10-19 15:17:02 +00:00
|
|
|
});
|
2019-12-17 18:47:37 +00:00
|
|
|
skip('translate returns the correct data for the translate endpoint');
|
2020-04-22 16:30:26 +00:00
|
|
|
const now = new Date().getTime();
|
2018-10-19 15:17:02 +00:00
|
|
|
const dc = 'dc-1';
|
|
|
|
const id = 'policy-name';
|
2019-12-17 18:47:37 +00:00
|
|
|
const undefinedNspace = 'default';
|
|
|
|
[undefinedNspace, 'team-1', undefined].forEach(nspace => {
|
|
|
|
test(`findByDatacenter returns the correct data for list endpoint when nspace is ${nspace}`, function(assert) {
|
2020-04-22 16:30:26 +00:00
|
|
|
get(this.subject(), 'store').serializerFor(NAME).timestamp = function() {
|
|
|
|
return now;
|
|
|
|
};
|
2019-12-17 18:47:37 +00:00
|
|
|
return repo(
|
|
|
|
'Policy',
|
|
|
|
'findAllByDatacenter',
|
|
|
|
this.subject(),
|
|
|
|
function retrieveStub(stub) {
|
|
|
|
return stub(
|
|
|
|
`/v1/acl/policies?dc=${dc}${typeof nspace !== 'undefined' ? `&ns=${nspace}` : ``}`,
|
|
|
|
{
|
|
|
|
CONSUL_POLICY_COUNT: '100',
|
|
|
|
}
|
|
|
|
);
|
|
|
|
},
|
|
|
|
function performTest(service) {
|
2021-02-23 08:56:42 +00:00
|
|
|
return service.findAllByDatacenter({ dc, ns: nspace || undefinedNspace });
|
2019-12-17 18:47:37 +00:00
|
|
|
},
|
|
|
|
function performAssertion(actual, expected) {
|
|
|
|
assert.deepEqual(
|
|
|
|
actual,
|
|
|
|
expected(function(payload) {
|
|
|
|
return payload.map(item =>
|
|
|
|
Object.assign({}, item, {
|
2020-04-22 16:30:26 +00:00
|
|
|
SyncTime: now,
|
2019-12-17 18:47:37 +00:00
|
|
|
Datacenter: dc,
|
|
|
|
Namespace: item.Namespace || undefinedNspace,
|
|
|
|
uid: `["${item.Namespace || undefinedNspace}","${dc}","${item.ID}"]`,
|
|
|
|
})
|
|
|
|
);
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
test(`findBySlug returns the correct data for item endpoint when the nspace is ${nspace}`, function(assert) {
|
|
|
|
return repo(
|
|
|
|
'Policy',
|
|
|
|
'findBySlug',
|
|
|
|
this.subject(),
|
|
|
|
function retrieveStub(stub) {
|
|
|
|
return stub(
|
|
|
|
`/v1/acl/policy/${id}?dc=${dc}${typeof nspace !== 'undefined' ? `&ns=${nspace}` : ``}`
|
|
|
|
);
|
|
|
|
},
|
|
|
|
function performTest(service) {
|
2021-02-23 08:56:42 +00:00
|
|
|
return service.findBySlug({ id, dc, ns: nspace || undefinedNspace });
|
2019-12-17 18:47:37 +00:00
|
|
|
},
|
|
|
|
function performAssertion(actual, expected) {
|
|
|
|
assert.deepEqual(
|
|
|
|
actual,
|
|
|
|
expected(function(payload) {
|
|
|
|
const item = payload;
|
|
|
|
return Object.assign({}, item, {
|
2018-10-19 15:17:02 +00:00
|
|
|
Datacenter: dc,
|
2019-12-17 18:47:37 +00:00
|
|
|
Namespace: item.Namespace || undefinedNspace,
|
|
|
|
uid: `["${item.Namespace || undefinedNspace}","${dc}","${item.ID}"]`,
|
2020-04-22 16:30:26 +00:00
|
|
|
meta: {
|
2020-05-05 16:29:35 +00:00
|
|
|
cacheControl: undefined,
|
2020-04-22 16:30:26 +00:00
|
|
|
cursor: undefined,
|
|
|
|
dc: dc,
|
|
|
|
nspace: item.Namespace || undefinedNspace,
|
|
|
|
},
|
2019-12-17 18:47:37 +00:00
|
|
|
});
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
2018-10-19 15:17:02 +00:00
|
|
|
});
|