@mbc-cqrs-serverless/cli
Version:
a CLI to get started with MBC CQRS serverless framework
161 lines (160 loc) • 8.03 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const generate_action_1 = __importDefault(require("./generate.action"));
describe('Generate Action', () => {
const mockCommand = {
name: () => 'generate',
opts: () => ({
dryRun: false,
mode: 'async',
schema: true
})
};
const mockOptions = {
dryRun: false,
mode: 'async',
schema: true
};
beforeEach(() => {
jest.clearAllMocks();
});
describe('Overview: Schematic generation functionality', () => {
describe('Purpose: Test basic generate action execution', () => {
it('should execute generate action without errors', async () => {
await expect((0, generate_action_1.default)('service', 'test-service', mockOptions, mockCommand)).resolves.not.toThrow();
});
it('should handle different schematic types', async () => {
const schematicTypes = ['service', 'controller', 'entity', 'dto', 'module'];
for (const type of schematicTypes) {
await expect((0, generate_action_1.default)(type, `test-${type}`, mockOptions, mockCommand)).resolves.not.toThrow();
}
});
it('should handle generate action with custom command options', async () => {
const customCommand = {
...mockCommand,
opts: () => ({
dryRun: true,
mode: 'sync',
schema: false
})
};
await expect((0, generate_action_1.default)('service', 'custom-service', mockOptions, customCommand)).resolves.not.toThrow();
});
});
describe('Purpose: Test dry-run functionality', () => {
it('should execute dry-run without making actual changes', async () => {
const dryRunCommand = {
...mockCommand,
opts: () => ({
dryRun: true,
mode: 'async',
schema: true
})
};
await expect((0, generate_action_1.default)('service', 'test-service', mockOptions, dryRunCommand)).resolves.not.toThrow();
});
it('should handle dry-run with different modes', async () => {
const syncDryRunCommand = {
...mockCommand,
opts: () => ({
dryRun: true,
mode: 'sync',
schema: false
})
};
await expect((0, generate_action_1.default)('controller', 'test-controller', mockOptions, syncDryRunCommand)).resolves.not.toThrow();
});
});
describe('Purpose: Test error handling scenarios', () => {
it('should handle missing schematic name', async () => {
await expect((0, generate_action_1.default)('service', '', mockOptions, mockCommand)).resolves.not.toThrow();
});
it('should handle undefined schematic name', async () => {
await expect((0, generate_action_1.default)('service', undefined, mockOptions, mockCommand)).resolves.not.toThrow();
});
it('should handle invalid schematic type', async () => {
await expect((0, generate_action_1.default)('invalid-type', 'test-name', mockOptions, mockCommand)).resolves.not.toThrow();
});
it('should handle undefined command', async () => {
await expect((0, generate_action_1.default)('service', 'test-service', mockOptions, undefined)).rejects.toThrow();
});
});
describe('Purpose: Test mode and schema options', () => {
it('should handle async mode with schema', async () => {
const asyncCommand = {
...mockCommand,
opts: () => ({
dryRun: false,
mode: 'async',
schema: true
})
};
await expect((0, generate_action_1.default)('service', 'async-service', mockOptions, asyncCommand)).resolves.not.toThrow();
});
it('should handle sync mode without schema', async () => {
const syncCommand = {
...mockCommand,
opts: () => ({
dryRun: false,
mode: 'sync',
schema: false
})
};
await expect((0, generate_action_1.default)('entity', 'sync-entity', mockOptions, syncCommand)).resolves.not.toThrow();
});
it('should handle noSchema option', async () => {
const noSchemaCommand = {
...mockCommand,
opts: () => ({
dryRun: false,
mode: 'async',
noSchema: true
})
};
await expect((0, generate_action_1.default)('dto', 'no-schema-dto', mockOptions, noSchemaCommand)).resolves.not.toThrow();
});
});
describe('Purpose: Test special characters and edge cases', () => {
it('should handle special characters in schematic names', async () => {
await expect((0, generate_action_1.default)('service', 'test-service_with-special.chars', mockOptions, mockCommand)).resolves.not.toThrow();
});
it('should handle very long schematic names', async () => {
const longName = 'very-long-schematic-name-that-exceeds-normal-length-limits';
await expect((0, generate_action_1.default)('service', longName, mockOptions, mockCommand)).resolves.not.toThrow();
});
it('should handle numeric schematic names', async () => {
await expect((0, generate_action_1.default)('service', '123-numeric-service', mockOptions, mockCommand)).resolves.not.toThrow();
});
it('should handle empty command options', async () => {
const emptyCommand = {
...mockCommand,
opts: () => ({})
};
await expect((0, generate_action_1.default)('service', 'test-service', mockOptions, emptyCommand)).resolves.not.toThrow();
});
});
describe('Purpose: Test concurrent generation scenarios', () => {
it('should handle multiple concurrent generation requests', async () => {
const promises = [
(0, generate_action_1.default)('service', 'service1', mockOptions, mockCommand),
(0, generate_action_1.default)('controller', 'controller1', mockOptions, mockCommand),
(0, generate_action_1.default)('entity', 'entity1', mockOptions, mockCommand)
];
await expect(Promise.all(promises)).resolves.not.toThrow();
});
it('should maintain consistency across multiple calls', async () => {
const results = await Promise.all([
(0, generate_action_1.default)('service', 'test-service', mockOptions, mockCommand),
(0, generate_action_1.default)('service', 'test-service', mockOptions, mockCommand),
(0, generate_action_1.default)('service', 'test-service', mockOptions, mockCommand)
]);
results.forEach(result => {
expect(result).toBeUndefined();
});
});
});
});
});