2019-12-17 18:47:37 +00:00
|
|
|
import { module, test } from 'qunit';
|
|
|
|
import { setupTest } from 'ember-qunit';
|
|
|
|
|
|
|
|
import { get } from 'consul-ui/tests/helpers/api';
|
2021-09-15 18:50:11 +00:00
|
|
|
import {
|
|
|
|
HEADERS_DATACENTER as DC,
|
|
|
|
HEADERS_PARTITION as PARTITION,
|
|
|
|
} from 'consul-ui/utils/http/consul';
|
|
|
|
// Nspaces don't need any nspace
|
2022-09-15 08:43:17 +00:00
|
|
|
module('Integration | Serializer | nspace', function (hooks) {
|
2019-12-17 18:47:37 +00:00
|
|
|
setupTest(hooks);
|
2021-09-15 18:50:11 +00:00
|
|
|
const dc = 'dc-1';
|
|
|
|
const undefinedPartition = 'default';
|
|
|
|
const partition = 'default';
|
2022-09-15 08:43:17 +00:00
|
|
|
test('respondForQuery returns the correct data for list endpoint', function (assert) {
|
2019-12-17 18:47:37 +00:00
|
|
|
const serializer = this.owner.lookup('serializer:nspace');
|
|
|
|
const request = {
|
2021-09-15 18:50:11 +00:00
|
|
|
url: `/v1/namespaces?dc=${dc}${
|
|
|
|
typeof partition !== 'undefined' ? `&partition=${partition}` : ``
|
|
|
|
}`,
|
2019-12-17 18:47:37 +00:00
|
|
|
};
|
2022-09-15 08:43:17 +00:00
|
|
|
return get(request.url).then(function (payload) {
|
|
|
|
const expected = payload.map((item) =>
|
2021-09-15 18:50:11 +00:00
|
|
|
Object.assign({}, item, {
|
|
|
|
Datacenter: dc,
|
|
|
|
Partition: item.Partition || undefinedPartition,
|
2021-12-01 11:04:02 +00:00
|
|
|
Namespace: '*',
|
|
|
|
uid: `["${item.Partition}","*","${dc}","${item.Name}"]`,
|
2021-09-15 18:50:11 +00:00
|
|
|
})
|
|
|
|
);
|
|
|
|
const actual = serializer.respondForQuery(
|
2022-09-15 08:43:17 +00:00
|
|
|
function (cb) {
|
2021-09-15 18:50:11 +00:00
|
|
|
const headers = {
|
|
|
|
[DC]: dc,
|
|
|
|
};
|
|
|
|
const body = payload;
|
|
|
|
return cb(headers, body);
|
|
|
|
},
|
|
|
|
{
|
|
|
|
dc: dc,
|
|
|
|
}
|
|
|
|
);
|
2019-12-17 18:47:37 +00:00
|
|
|
assert.deepEqual(actual, expected);
|
|
|
|
});
|
|
|
|
});
|
2022-09-15 08:43:17 +00:00
|
|
|
test('respondForQueryRecord returns the correct data for item endpoint', function (assert) {
|
2019-12-17 18:47:37 +00:00
|
|
|
const serializer = this.owner.lookup('serializer:nspace');
|
|
|
|
const id = 'slug';
|
|
|
|
const request = {
|
2021-09-15 18:50:11 +00:00
|
|
|
url: `/v1/namespace/${id}?dc=${dc}${
|
|
|
|
typeof partition !== 'undefined' ? `&partition=${partition}` : ``
|
|
|
|
}`,
|
2019-12-17 18:47:37 +00:00
|
|
|
};
|
2022-09-15 08:43:17 +00:00
|
|
|
return get(request.url).then(function (payload) {
|
2019-12-17 18:47:37 +00:00
|
|
|
// Namespace items don't currently get META attached
|
|
|
|
const expected = payload;
|
|
|
|
const actual = serializer.respondForQueryRecord(
|
2022-09-15 08:43:17 +00:00
|
|
|
function (cb) {
|
2021-09-15 18:50:11 +00:00
|
|
|
const headers = {
|
|
|
|
[DC]: dc,
|
|
|
|
[PARTITION]: partition || undefinedPartition,
|
|
|
|
};
|
2019-12-17 18:47:37 +00:00
|
|
|
const body = payload;
|
|
|
|
return cb(headers, body);
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: id,
|
2021-09-15 18:50:11 +00:00
|
|
|
dc: dc,
|
2019-12-17 18:47:37 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
assert.deepEqual(actual, expected);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|