open-consul/ui-v2/tests/unit/utils/create-fingerprinter-test.js
John Cowen 31f36ce096 ui: Namespace Support (#6639)
Adds namespace support to the UI:

1. Namespace CRUD/management
2. Show Namespace in relevant areas (intentions, upstreams)
3. Main navigation bar improvements
4. Logic/integration to interact with a new `internal/acl/authorize` endpoint
2019-12-18 12:26:47 +00:00

41 lines
1.3 KiB
JavaScript

import createFingerprinter from 'consul-ui/utils/create-fingerprinter';
import { module, test } from 'qunit';
module('Unit | Utility | create fingerprinter', function() {
test("fingerprint returns a 'unique' fingerprinted object based on primary, slug and foreign keys", function(assert) {
const obj = {
ID: 'slug',
};
const expected = {
Datacenter: 'dc',
Namespace: 'default',
ID: 'slug',
uid: '["default","dc","slug"]',
};
const fingerprint = createFingerprinter('Datacenter', 'Namespace', 'default');
const actual = fingerprint('uid', 'ID', 'dc')(obj);
assert.deepEqual(actual, expected);
});
test("fingerprint throws an error if it can't find a foreignKey", function(assert) {
const fingerprint = createFingerprinter('Datacenter', 'Namespace', 'default');
[undefined, null].forEach(function(item) {
assert.throws(function() {
fingerprint('uid', 'ID', item);
}, /missing foreignKey/);
});
});
test("fingerprint throws an error if it can't find a slug", function(assert) {
const fingerprint = createFingerprinter('Datacenter', 'Namespace', 'default');
[
{},
{
ID: null,
},
].forEach(function(item) {
assert.throws(function() {
fingerprint('uid', 'ID', 'dc')(item);
}, /missing slug/);
});
});
});