add some test for invalid ids

Signed-off-by: Juan Pablo Garcia Ripa <sarabadu@gmail.com>
This commit is contained in:
Juan Pablo Garcia Ripa
2026-01-26 00:04:49 +01:00
parent bb9b471bd3
commit bd7d15dd7e
4 changed files with 44 additions and 49 deletions
@@ -15,6 +15,7 @@
*/
import { createServiceRef } from '../services';
import { ID_PATTERN } from './constants';
import { createBackendModule } from './createBackendModule';
import { createExtensionPoint } from './createExtensionPoint';
import { InternalBackendRegistrations } from './types';
@@ -77,4 +78,20 @@ describe('createBackendModule', () => {
expect(plugin.$$type).toEqual('@backstage/BackendFeature');
});
it('should reject modules with invalid moduleId', async () => {
expect(() =>
createBackendModule({
pluginId: 'test',
moduleId: 'invalid:module&id',
register(reg) {
reg.registerInit({
deps: {},
async init() {},
});
},
}),
).toThrow(
`Invalid moduleId 'invalid:module&id' for plugin 'test', must match the pattern ${ID_PATTERN} (letters, digits, and dashes only, starting with a letter)`,
);
});
});
@@ -15,6 +15,7 @@
*/
import { createServiceRef } from '../services';
import { ID_PATTERN } from './constants';
import { createBackendPlugin } from './createBackendPlugin';
import { createExtensionPoint } from './createExtensionPoint';
import { InternalBackendRegistrations } from './types';
@@ -90,4 +91,19 @@ describe('createBackendPlugin', () => {
expect(plugin.$$type).toEqual('@backstage/BackendFeature');
});
it('should reject plugins with invalid pluginId', async () => {
expect(() =>
createBackendPlugin({
pluginId: 'test:invalid&id',
register(reg) {
reg.registerInit({
deps: {},
async init() {},
});
},
}),
).toThrow(
`Invalid pluginId 'test:invalid&id', must match the pattern ${ID_PATTERN} (letters, digits, and dashes only, starting with a letter)`,
);
});
});