open-consul/ui/packages/consul-ui/tests/integration/services/repository/kv-test.js
John Cowen c98130cc08
ui: Move to Workspaced Structure (#8994)
* ui: Add the most basic workspace root in /ui

* We already have a LICENSE file in the repository root

* Change directory path in build scripts ui-v2 -> ui

* Make yarn install flags configurable from elsewhere

* Minimal workspace root makefile

* Call the new docker specific target

* Update yarn in the docker build image

* Reconfigure the netlify target and move to the higher makefile

* Move ui-v2 -> ui/packages/consul-ui

* Change repo root to refleect new folder structure

* Temporarily don't hoist consul-api-double

* Fixup CI configuration

* Fixup lint errors

* Fixup Netlify target
2020-10-21 15:23:16 +01:00

72 lines
2.2 KiB
JavaScript

import { moduleFor, test } from 'ember-qunit';
import repo from 'consul-ui/tests/helpers/repo';
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 undefinedNspace = 'default';
[undefinedNspace, 'team-1', undefined].forEach(nspace => {
test(`findAllBySlug returns the correct data for list endpoint when nspace is ${nspace}`, function(assert) {
return repo(
'Kv',
'findAllBySlug',
this.subject(),
function retrieveTest(stub) {
return stub(
`/v1/kv/${id}?keys&dc=${dc}${typeof nspace !== 'undefined' ? `&ns=${nspace}` : ``}`,
{
CONSUL_KV_COUNT: '1',
}
);
},
function performTest(service) {
return service.findAllBySlug(id, dc, nspace || undefinedNspace);
},
function performAssertion(actual, expected) {
assert.deepEqual(
actual,
expected(function(payload) {
return payload.map(item => {
return {
Datacenter: dc,
Namespace: nspace || undefinedNspace,
uid: `["${nspace || undefinedNspace}","${dc}","${item}"]`,
Key: item,
};
});
})
);
}
);
});
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}` : ``}`);
},
function(service) {
return service.findBySlug(id, dc, nspace || undefinedNspace);
},
function(actual, expected) {
assert.deepEqual(
actual,
expected(function(payload) {
const item = payload[0];
return Object.assign({}, item, {
Datacenter: dc,
Namespace: item.Namespace || undefinedNspace,
uid: `["${item.Namespace || undefinedNspace}","${dc}","${item.Key}"]`,
});
})
);
}
);
});
});