mirror of https://github.com/status-im/consul.git
63 lines
1.9 KiB
JavaScript
63 lines
1.9 KiB
JavaScript
import { module, test } from 'qunit';
|
|
import { setupTest } from 'ember-qunit';
|
|
import { get } from 'consul-ui/tests/helpers/api';
|
|
import { HEADERS_SYMBOL as META } from 'consul-ui/utils/http/consul';
|
|
import { createPolicies } from 'consul-ui/tests/helpers/normalizers';
|
|
|
|
module('Integration | Serializer | role', function(hooks) {
|
|
setupTest(hooks);
|
|
const dc = 'dc-1';
|
|
const id = 'role-name';
|
|
test('respondForQuery returns the correct data for list endpoint', function(assert) {
|
|
const serializer = this.owner.lookup('serializer:role');
|
|
const request = {
|
|
url: `/v1/acl/roles?dc=${dc}`,
|
|
};
|
|
return get(request.url).then(function(payload) {
|
|
const expected = payload.map(item =>
|
|
Object.assign({}, item, {
|
|
Datacenter: dc,
|
|
Policies: createPolicies(item),
|
|
uid: `["${dc}","${item.ID}"]`,
|
|
})
|
|
);
|
|
const actual = serializer.respondForQuery(
|
|
function(cb) {
|
|
const headers = {};
|
|
const body = payload;
|
|
return cb(headers, body);
|
|
},
|
|
{
|
|
dc: dc,
|
|
}
|
|
);
|
|
assert.deepEqual(actual, expected);
|
|
});
|
|
});
|
|
test('respondForQueryRecord returns the correct data for item endpoint', function(assert) {
|
|
const serializer = this.owner.lookup('serializer:role');
|
|
const request = {
|
|
url: `/v1/acl/role/${id}?dc=${dc}`,
|
|
};
|
|
return get(request.url).then(function(payload) {
|
|
const expected = Object.assign({}, payload, {
|
|
Datacenter: dc,
|
|
Policies: createPolicies(payload),
|
|
[META]: {},
|
|
uid: `["${dc}","${id}"]`,
|
|
});
|
|
const actual = serializer.respondForQueryRecord(
|
|
function(cb) {
|
|
const headers = {};
|
|
const body = payload;
|
|
return cb(headers, body);
|
|
},
|
|
{
|
|
dc: dc,
|
|
}
|
|
);
|
|
assert.deepEqual(actual, expected);
|
|
});
|
|
});
|
|
});
|