open-consul/ui/packages/consul-ui/tests/unit/serializers/application-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

129 lines
3.7 KiB
JavaScript

import { module } from 'qunit';
import test from 'ember-sinon-qunit/test-support/test';
import { setupTest } from 'ember-qunit';
import {
HEADERS_SYMBOL as META,
HEADERS_DATACENTER as DC,
HEADERS_NAMESPACE as NSPACE,
} from 'consul-ui/utils/http/consul';
module('Unit | Serializer | application', function(hooks) {
setupTest(hooks);
// Replace this with your real tests.
test('it exists', function(assert) {
const store = this.owner.lookup('service:store');
const serializer = store.serializerFor('application');
assert.ok(serializer);
});
test('respondForDeleteRecord returns the expected pojo structure', function(assert) {
const store = this.owner.lookup('service:store');
const serializer = store.serializerFor('application');
serializer.primaryKey = 'primary-key-name';
serializer.slugKey = 'Name';
serializer.fingerprint = function(primary, slug, foreignValue) {
return function(item) {
return {
...item,
...{
Datacenter: foreignValue,
[primary]: item[slug],
},
};
};
};
// adapter.uidForURL = this.stub().returnsArg(0);
const respond = function(cb) {
const headers = {};
const body = true;
return cb(headers, body);
};
const expected = {
'primary-key-name': 'name',
};
const actual = serializer.respondForDeleteRecord(respond, {}, { Name: 'name', dc: 'dc-1' });
assert.deepEqual(actual, expected);
// assert.ok(adapter.uidForURL.calledOnce);
});
test('respondForQueryRecord returns the expected pojo structure', function(assert) {
const store = this.owner.lookup('service:store');
const serializer = store.serializerFor('application');
serializer.primaryKey = 'primary-key-name';
serializer.slugKey = 'Name';
serializer.fingerprint = function(primary, slug, foreignValue) {
return function(item) {
return {
...item,
...{
Datacenter: foreignValue,
[primary]: item[slug],
},
};
};
};
const expected = {
Datacenter: 'dc-1',
Name: 'name',
[META]: {
[DC.toLowerCase()]: 'dc-1',
[NSPACE.toLowerCase()]: 'default',
},
'primary-key-name': 'name',
};
const respond = function(cb) {
const headers = {};
const body = {
Name: 'name',
};
return cb(headers, body);
};
const actual = serializer.respondForQueryRecord(respond, { Name: 'name', dc: 'dc-1' });
assert.deepEqual(actual, expected);
});
test('respondForQuery returns the expected pojo structure', function(assert) {
const store = this.owner.lookup('service:store');
const serializer = store.serializerFor('application');
serializer.primaryKey = 'primary-key-name';
serializer.slugKey = 'Name';
serializer.fingerprint = function(primary, slug, foreignValue) {
return function(item) {
return {
...item,
...{
Datacenter: foreignValue,
[primary]: item[slug],
},
};
};
};
const expected = [
{
Datacenter: 'dc-1',
Name: 'name1',
'primary-key-name': 'name1',
},
{
Datacenter: 'dc-1',
Name: 'name2',
'primary-key-name': 'name2',
},
];
const respond = function(cb) {
const headers = {};
const body = [
{
Name: 'name1',
},
{
Name: 'name2',
},
];
return cb(headers, body);
};
const actual = serializer.respondForQuery(respond, { Name: 'name', dc: 'dc-1' });
assert.deepEqual(actual, expected);
// assert.ok(adapter.uidForURL.calledTwice);
});
});