95 lines
3.1 KiB
Plaintext
95 lines
3.1 KiB
Plaintext
{{#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}}/{{classFilename}}.repository.contract';
|
|
{{#returnImports}}
|
|
import { mock{{classname}}Model } from '@/entities/models/{{tagFilename}}/{{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: () => {
|
|
expect(mockRepository.{{nickname}}).toHaveBeenCalledOnceWith({{#allParams}}{{{testValue}}}{{^-last}}, {{/-last}}{{/allParams}});
|
|
done();
|
|
}
|
|
});
|
|
{{/returnBaseType}}
|
|
{{/isListContainer}}
|
|
});
|
|
});
|
|
|
|
{{/operation}}
|
|
});
|
|
|
|
{{/operations}}
|
|
{{/apis}}
|
|
{{/apiInfo}}
|