feat: add .spec.ts generation for models, mappers, repositories and use-cases
Add 4 new Mustache templates for generating unit test specs: - model-entity.spec.mustache: tests instantiation, property setting, mock builder - mapper.spec.mustache: tests per-property DTO→Entity mapping, instanceof, all fields - api.repository.impl.spec.mustache: tests HTTP method, response mapping, error propagation - api.use-cases.impl.spec.mustache: tests repository delegation, observable forwarding Generator changes: - Add uppercaseHttpMethod to TagOperation for spec HTTP assertions - Add testValue to TagOperationParam for auto-generated test arguments - Add resolveTestParamValue utility for primitive/complex type test literals - Add specs counter to GeneratedCount and GenerationReport - Wire 4 new renderTemplate calls in schema and tag loops - Update report generator to count .spec.ts files Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
91
templates/api.use-cases.impl.spec.mustache
Normal file
91
templates/api.use-cases.impl.spec.mustache
Normal file
@@ -0,0 +1,91 @@
|
||||
{{#apiInfo}}
|
||||
{{#apis}}
|
||||
{{#operations}}
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
import { of } from 'rxjs';
|
||||
|
||||
import { {{classname}}UseCasesImpl } from './{{classFilename}}.use-cases.impl';
|
||||
|
||||
import { {{constantName}}_REPOSITORY, {{classname}}Repository } from '@/domain/repositories/{{classFilename}}.repository.contract';
|
||||
{{#returnImports}}
|
||||
import { mock{{classname}}Model } from '@/entities/models/{{classFilename}}.model.mock';
|
||||
{{/returnImports}}
|
||||
|
||||
describe('{{classname}}UseCasesImpl', () => {
|
||||
let useCase: {{classname}}UseCasesImpl;
|
||||
let mockRepository: jasmine.SpyObj<{{classname}}Repository>;
|
||||
|
||||
beforeEach(() => {
|
||||
mockRepository = jasmine.createSpyObj('{{classname}}Repository', [{{#operation}}'{{nickname}}', {{/operation}}]);
|
||||
|
||||
TestBed.configureTestingModule({
|
||||
providers: [
|
||||
{{classname}}UseCasesImpl,
|
||||
{ provide: {{constantName}}_REPOSITORY, useValue: mockRepository }
|
||||
]
|
||||
});
|
||||
|
||||
useCase = TestBed.inject({{classname}}UseCasesImpl);
|
||||
});
|
||||
|
||||
it('should be created', () => {
|
||||
expect(useCase).toBeTruthy();
|
||||
});
|
||||
|
||||
{{#operation}}
|
||||
describe('{{nickname}}', () => {
|
||||
it('should delegate to the repository', () => {
|
||||
{{#isListContainer}}
|
||||
mockRepository.{{nickname}}.and.returnValue(of([mock{{returnBaseType}}Model()]));
|
||||
{{/isListContainer}}
|
||||
{{^isListContainer}}
|
||||
{{#returnBaseType}}
|
||||
mockRepository.{{nickname}}.and.returnValue(of(mock{{returnBaseType}}Model()));
|
||||
{{/returnBaseType}}
|
||||
{{^returnBaseType}}
|
||||
mockRepository.{{nickname}}.and.returnValue(of(undefined));
|
||||
{{/returnBaseType}}
|
||||
{{/isListContainer}}
|
||||
|
||||
useCase.{{nickname}}({{#allParams}}{{{testValue}}}{{^-last}}, {{/-last}}{{/allParams}});
|
||||
|
||||
expect(mockRepository.{{nickname}}).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should return the observable from the repository', (done) => {
|
||||
{{#isListContainer}}
|
||||
const expected = [mock{{returnBaseType}}Model()];
|
||||
mockRepository.{{nickname}}.and.returnValue(of(expected));
|
||||
|
||||
useCase.{{nickname}}({{#allParams}}{{{testValue}}}{{^-last}}, {{/-last}}{{/allParams}}).subscribe((result) => {
|
||||
expect(result).toEqual(expected);
|
||||
done();
|
||||
});
|
||||
{{/isListContainer}}
|
||||
{{^isListContainer}}
|
||||
{{#returnBaseType}}
|
||||
const expected = mock{{returnBaseType}}Model();
|
||||
mockRepository.{{nickname}}.and.returnValue(of(expected));
|
||||
|
||||
useCase.{{nickname}}({{#allParams}}{{{testValue}}}{{^-last}}, {{/-last}}{{/allParams}}).subscribe((result) => {
|
||||
expect(result).toEqual(expected);
|
||||
done();
|
||||
});
|
||||
{{/returnBaseType}}
|
||||
{{^returnBaseType}}
|
||||
mockRepository.{{nickname}}.and.returnValue(of(undefined));
|
||||
|
||||
useCase.{{nickname}}({{#allParams}}{{{testValue}}}{{^-last}}, {{/-last}}{{/allParams}}).subscribe({
|
||||
complete: () => done()
|
||||
});
|
||||
{{/returnBaseType}}
|
||||
{{/isListContainer}}
|
||||
});
|
||||
});
|
||||
|
||||
{{/operation}}
|
||||
});
|
||||
|
||||
{{/operations}}
|
||||
{{/apis}}
|
||||
{{/apiInfo}}
|
||||
Reference in New Issue
Block a user