21915e600e
> In the future, this should all be moved to each individual repository now, which will mean we can finally get rid of this service. This PR moves reconciliation to 'each individual repository'. I stopped short of getting rid of the service, but its so small now we pretty much don't need it. I'd rather wait until I look at the equivalent DataSink service and see if we can get rid of both equivalent services together (this also currently dependant on work soon to be merged) Reconciliation of models (basically doing the extra work to clean up the ember-data store and bring our frontend 'truth' into line with the actual backend truth) when blocking/long-polling on different views/filters of data is slightly more complicated due to figuring out what should be cleaned up and what should be left in the store. This is especially apparent for KVs. I built in a such a way to hopefully make sure it will all make sense for the future. I also checked that this all worked nicely with all our models, even KV which has never supported blocking queries. I left all that work in so that if we want to enable blocking queries/live updates for KV it now just involves deleting a couple of lines of code. There is a tonne of old stuff that we can clean up here now (our 'fake headers' that we pass around) and I've added that to my list of thing for a 'Big Cleanup PR' that will remove lots of code that we no longer require.
91 lines
2.9 KiB
JavaScript
91 lines
2.9 KiB
JavaScript
import { moduleFor, test } from 'ember-qunit';
|
|
import repo from 'consul-ui/tests/helpers/repo';
|
|
import { env } from '../../../../env';
|
|
import { get } from '@ember/object';
|
|
|
|
const NAME = 'kv';
|
|
moduleFor(`service:repository/${NAME}`, `Integration | Service | ${NAME}`, {
|
|
// Specify the other units that are required for this test.
|
|
integration: true,
|
|
});
|
|
const dc = 'dc-1';
|
|
const id = 'key-name';
|
|
const now = new Date().getTime();
|
|
const undefinedNspace = 'default';
|
|
const undefinedPartition = 'default';
|
|
const partition = 'default';
|
|
[undefinedNspace, 'team-1', undefined].forEach(nspace => {
|
|
test(`findAllBySlug returns the correct data for list endpoint when nspace is ${nspace}`, function(assert) {
|
|
get(this.subject(), 'store').serializerFor(NAME).timestamp = function() {
|
|
return now;
|
|
};
|
|
return repo(
|
|
'Kv',
|
|
'findAllBySlug',
|
|
this.subject(),
|
|
function retrieveTest(stub) {
|
|
return stub(
|
|
`/v1/kv/${id}?keys&dc=${dc}${typeof nspace !== 'undefined' ? `&ns=${nspace}` : ``}${
|
|
typeof partition !== 'undefined' ? `&partition=${partition}` : ``
|
|
}`,
|
|
{
|
|
CONSUL_KV_COUNT: '1',
|
|
}
|
|
);
|
|
},
|
|
function performTest(service) {
|
|
return service.findAllBySlug({
|
|
id,
|
|
dc,
|
|
ns: nspace || undefinedNspace,
|
|
partition: partition || undefinedPartition,
|
|
});
|
|
},
|
|
function performAssertion(actual, expected) {
|
|
const expectedNspace = env('CONSUL_NSPACES_ENABLED')
|
|
? nspace || undefinedNspace
|
|
: 'default';
|
|
const expectedPartition = env('CONSUL_PARTITIONS_ENABLED')
|
|
? partition || undefinedPartition
|
|
: 'default';
|
|
actual.forEach(item => {
|
|
assert.equal(item.uid, `["${expectedPartition}","${expectedNspace}","${dc}","${item.Key}"]`);
|
|
assert.equal(item.Datacenter, dc);
|
|
});
|
|
}
|
|
);
|
|
});
|
|
test(`findBySlug returns the correct data for item endpoint when nspace is ${nspace}`, function(assert) {
|
|
return repo(
|
|
'Kv',
|
|
'findBySlug',
|
|
this.subject(),
|
|
function(stub) {
|
|
return stub(
|
|
`/v1/kv/${id}?dc=${dc}${typeof nspace !== 'undefined' ? `&ns=${nspace}` : ``}${
|
|
typeof partition !== 'undefined' ? `&partition=${partition}` : ``
|
|
}`
|
|
);
|
|
},
|
|
function(service) {
|
|
return service.findBySlug({
|
|
id,
|
|
dc,
|
|
ns: nspace || undefinedNspace,
|
|
partition: partition || undefinedPartition,
|
|
});
|
|
},
|
|
function(actual, expected) {
|
|
expected(
|
|
function(payload) {
|
|
const item = payload[0];
|
|
assert.equal(actual.uid, `["${item.Partition || undefinedPartition}","${item.Namespace ||
|
|
undefinedNspace}","${dc}","${item.Key}"]`);
|
|
assert.equal(actual.Datacenter, dc);
|
|
}
|
|
);
|
|
}
|
|
);
|
|
});
|
|
});
|