frontend-plugin-api: basic tests for resolveExtensionDefinition

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2023-11-21 17:02:28 +01:00
parent 1227f693f0
commit e8802b3f83
@@ -0,0 +1,48 @@
/*
* Copyright 2023 The Backstage Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { ExtensionDefinition } from './createExtension';
import { resolveExtensionDefinition } from './resolveExtensionDefinition';
describe('resolveExtensionDefinition', () => {
it.each([
[{ namespace: 'ns' }, 'ns'],
[{ namespace: 'ns', name: 'n' }, 'ns/n'],
[{ kind: 'k', namespace: 'ns' }, 'k:ns'],
[{ kind: 'k', namespace: 'ns', name: 'n' }, 'k:ns/n'],
])(`should resolve extension IDs %s`, (definition, expected) => {
const resolved = resolveExtensionDefinition(
definition as ExtensionDefinition<unknown>,
);
expect(resolved.id).toBe(expected);
});
it('should fail to resolve extension ID without namespace', () => {
expect(() =>
resolveExtensionDefinition({
kind: 'k',
name: 'n',
} as ExtensionDefinition<unknown>),
).toThrow(
'Extension must declare an explicit namespace as it could not be resolved from context, name=n kind=k',
);
expect(() =>
resolveExtensionDefinition({} as ExtensionDefinition<unknown>),
).toThrow(
'Extension must declare an explicit namespace as it could not be resolved from context, name=undefined kind=undefined',
);
});
});