vault/ui/tests/unit/utils/openapi-to-attrs-test.js
Chelsea Shaw 8d6d26e531
UI: Refactor path-help service (#28444)
* Add helper combineOpenApiAttrs + test

* hydrateModel working with upgradeModelSchema

* new registerNewModelWithAttrs method for generated models

* Add newFields to generated models

* copyright

* Glimmerize path-help service

* update generated-item-list adapter and path-help usage of it

* remove unused methods combineAttributes and combineFields

* move expandOpenApiProps to ts helper file

* fix auth test

* fix bug where adding user to second userpass mount saves to first mount

* Add mutableId

* fix ent test

* remove addressed deprecation

* Address PR comments

* [VAULT-31208] remove deprecation early-static from decorator tests
2024-09-25 18:17:48 +00:00

81 lines
2.4 KiB
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/
import { combineFieldGroups } from 'vault/utils/openapi-to-attrs';
import { module, test } from 'qunit';
module('Unit | Util | combineFieldGroups', function () {
const NEW_FIELDS = ['one', 'two', 'three'];
test('it adds new fields from OpenAPI to fieldGroups except for exclusions', function (assert) {
assert.expect(3);
const modelFieldGroups = [
{ default: ['name', 'awesomePeople'] },
{
Options: ['ttl'],
},
];
const excludedFields = ['two'];
const expectedGroups = [
{ default: ['name', 'awesomePeople', 'one', 'three'] },
{
Options: ['ttl'],
},
];
const newFieldGroups = combineFieldGroups(modelFieldGroups, NEW_FIELDS, excludedFields);
for (const groupName in modelFieldGroups) {
assert.deepEqual(
newFieldGroups[groupName],
expectedGroups[groupName],
'it incorporates all new fields except for those excluded'
);
}
});
test('it adds all new fields from OpenAPI to fieldGroups when excludedFields is empty', function (assert) {
assert.expect(3);
const modelFieldGroups = [
{ default: ['name', 'awesomePeople'] },
{
Options: ['ttl'],
},
];
const excludedFields = [];
const expectedGroups = [
{ default: ['name', 'awesomePeople', 'one', 'two', 'three'] },
{
Options: ['ttl'],
},
];
const nonExcludedFieldGroups = combineFieldGroups(modelFieldGroups, NEW_FIELDS, excludedFields);
for (const groupName in modelFieldGroups) {
assert.deepEqual(
nonExcludedFieldGroups[groupName],
expectedGroups[groupName],
'it incorporates all new fields'
);
}
});
test('it keeps fields the same when there are no brand new fields from OpenAPI', function (assert) {
assert.expect(3);
const modelFieldGroups = [
{ default: ['name', 'awesomePeople', 'two', 'one', 'three'] },
{
Options: ['ttl'],
},
];
const excludedFields = [];
const expectedGroups = [
{ default: ['name', 'awesomePeople', 'two', 'one', 'three'] },
{
Options: ['ttl'],
},
];
const fieldGroups = combineFieldGroups(modelFieldGroups, NEW_FIELDS, excludedFields);
for (const groupName in modelFieldGroups) {
assert.deepEqual(fieldGroups[groupName], expectedGroups[groupName], 'it incorporates all new fields');
}
});
});