diff --git a/ui/tests/unit/serializers/database/connection-test.js b/ui/tests/unit/serializers/database/connection-test.js index 520ea402aa8e..90445ea1e016 100644 --- a/ui/tests/unit/serializers/database/connection-test.js +++ b/ui/tests/unit/serializers/database/connection-test.js @@ -142,4 +142,61 @@ module('Unit | Serializer | database/connection', function (hooks) { }; assert.deepEqual(normalized, expectedResult, `Normalizes and flattens database response`); }); + + test('it should normalize values if some params do not exist', function (assert) { + const serializer = this.owner.lookup('serializer:database/connection'); + const normalized = serializer.normalizeSecrets({ + request_id: 'request-id', + lease_id: '', + renewable: false, + lease_duration: 0, + data: { + allowed_roles: ['*'], + connection_details: { backend: 'database' }, // no connection_url param intentionally + plugin_name: 'vault-postgres-db', + }, + wrap_info: null, + warnings: null, + auth: null, + mount_type: 'database', + backend: 'database', + id: 'db-test', + }); + const expectedResult = { + allowed_roles: ['*'], + backend: 'database', + id: 'db-test', + name: 'db-test', + plugin_name: 'vault-postgres-db', + }; + assert.deepEqual(normalized, expectedResult, `Normalizes and flattens database response`); + }); + + test('it should fail gracefully if no connection_details', function (assert) { + const serializer = this.owner.lookup('serializer:database/connection'); + const normalized = serializer.normalizeSecrets({ + request_id: 'request-id', + lease_id: '', + renewable: false, + lease_duration: 0, + data: { + allowed_roles: ['*'], + plugin_name: 'vault-postgres-db', + }, + wrap_info: null, + warnings: null, + auth: null, + mount_type: 'database', + backend: 'database', + id: 'db-test', + }); + const expectedResult = { + allowed_roles: ['*'], + backend: 'database', + id: 'db-test', + name: 'db-test', + plugin_name: 'vault-postgres-db', + }; + assert.deepEqual(normalized, expectedResult, `Normalizes and flattens database response`); + }); });