91383269b9
This sounds a bit 'backwards' as the end goal here is to add an improved UX to partitions, not namespaces. The reason for doing it this way is that Namespaces already has a type of 'improved UX' CRUD in that it has one to many relationship in the form when saving your namespaces (the end goal for partitions). In moving Namespaces to use the same approach as partitions we: - Ensure the new approach works with one-to-many forms. - Test the new approach without writing a single test (we already have a bunch of tests for namespaces which are now testing the approach used by both namespaces and partitions) Additionally: - Fixes issue with missing default nspace in the nspace selector - In doing when checking to see that things where consistent between the two, I found a few little minor problems with the Admin Partition CRUD so fixed those up here also. - Removed the old style Nspace notifications
75 lines
2.2 KiB
JavaScript
75 lines
2.2 KiB
JavaScript
import { module, test } from 'qunit';
|
|
import { setupTest } from 'ember-qunit';
|
|
|
|
import { get } from 'consul-ui/tests/helpers/api';
|
|
import {
|
|
HEADERS_DATACENTER as DC,
|
|
HEADERS_PARTITION as PARTITION,
|
|
} from 'consul-ui/utils/http/consul';
|
|
// Nspaces don't need any nspace
|
|
module('Integration | Serializer | nspace', function(hooks) {
|
|
setupTest(hooks);
|
|
const dc = 'dc-1';
|
|
const undefinedPartition = 'default';
|
|
const partition = 'default';
|
|
test('respondForQuery returns the correct data for list endpoint', function(assert) {
|
|
const serializer = this.owner.lookup('serializer:nspace');
|
|
const request = {
|
|
url: `/v1/namespaces?dc=${dc}${
|
|
typeof partition !== 'undefined' ? `&partition=${partition}` : ``
|
|
}`,
|
|
};
|
|
return get(request.url).then(function(payload) {
|
|
const expected = payload.map(item =>
|
|
Object.assign({}, item, {
|
|
Datacenter: dc,
|
|
Partition: item.Partition || undefinedPartition,
|
|
Namespace: '*',
|
|
uid: `["${item.Partition}","*","${dc}","${item.Name}"]`,
|
|
})
|
|
);
|
|
const actual = serializer.respondForQuery(
|
|
function(cb) {
|
|
const headers = {
|
|
[DC]: dc,
|
|
};
|
|
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:nspace');
|
|
const id = 'slug';
|
|
const request = {
|
|
url: `/v1/namespace/${id}?dc=${dc}${
|
|
typeof partition !== 'undefined' ? `&partition=${partition}` : ``
|
|
}`,
|
|
};
|
|
return get(request.url).then(function(payload) {
|
|
// Namespace items don't currently get META attached
|
|
const expected = payload;
|
|
const actual = serializer.respondForQueryRecord(
|
|
function(cb) {
|
|
const headers = {
|
|
[DC]: dc,
|
|
[PARTITION]: partition || undefinedPartition,
|
|
};
|
|
const body = payload;
|
|
return cb(headers, body);
|
|
},
|
|
{
|
|
id: id,
|
|
dc: dc,
|
|
}
|
|
);
|
|
assert.deepEqual(actual, expected);
|
|
});
|
|
});
|
|
});
|