Meu teste apresenta o seguinte erro: TypeError: relatorioService.buscarRelatorioEnfornamento is not a function
import {
HttpClientTestingModule,
HttpTestingController,
} from '@angular/common/http/testing';
import { RelatoriosService } from './relatorios.service';
import { TestBed } from '@angular/core/testing';
import { buildRelatorioEnfornamento, buildRelatorioDesenfornamento } from './utils';
const mockDataEnfornamento = {
api: 'http://localhost:5000/api/cq3/escala/relatorios/enfornamento',
data: buildRelatorioEnfornamento(),
};
const mockDataDesenfornamento = {
api: 'http://localhost:5000/api/cq3/escala/relatorios/desenfornamento',
data: buildRelatorioDesenfornamento(),
};
describe(`${RelatoriosService.name}`, () => {
let relatorioService: RelatoriosService;
let httpController: HttpTestingController;
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [HttpClientTestingModule],
providers: [
RelatoriosService,
// {
// provide: PegarCoqueriaURLService,
// useValue: {
// coqeuria(): string { return 'cq3'; }
// },
// },
// {
// provide: RelatoriosService,
// useValue: {
// baseUrl: 'http://localhost:5000/api',
// },
// },
{
provide: RelatoriosService,
useValue: {
url(): string {
return 'http://localhost:5000/api/cq3/escala/relatorios';
},
},
},
],
}).compileComponents();
relatorioService = TestBed.inject(RelatoriosService);
httpController = TestBed.inject(HttpTestingController);
});
afterEach(() => {
httpController.verify();
});
it('deve retornar uma lista de enfornamentos', (done) => {
relatorioService.buscarRelatorioEnfornamento(new Date, new Date).subscribe(response => {
expect(response[0].idForno).toBe(1);
done();
});
httpController.expectOne(mockDataEnfornamento.api).flush(mockDataEnfornamento.data);
});
// it('deve retornar uma lista de desenfornamentos', (done) => {
// relatorioService.buscarRelatorioEnfornamento(new Date, new Date).subscribe(console.log);
// httpController.expectOne(mockDataDesenfornamento.api).flush(mockDataDesenfornamento.data);
// });
});
o serviço que estou tentando testar é:
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { SettingEnvironmentService } from 'src/app/common/service/setting-environment.service';
import { RelatorioEnfornamento } from './../models/relatorio-enfornamento.model';
import { RelatorioDesenfornamento } from '../models/relatorio-desenfornamento.model';
import { PegarCoqueriaURLService } from 'src/app/common/service/pegar-coqueria-url.service';
@Injectable({
providedIn: 'root',
})
export class RelatoriosService {
private baseUrl: string;
constructor(
private http: HttpClient,
private pegarCoqueriaUrl: PegarCoqueriaURLService,
private environmentService: SettingEnvironmentService
) {
this.baseUrl = this.environmentService.baseUrl;
}
private get url() {
return `${this.baseUrl}/${this.pegarCoqueriaUrl.coqueria}/escala/relatorios`;
}
buscarRelatorioEnfornamento(dataInicio: Date, dataFinal: Date) {
return this.http
.get<RelatorioEnfornamento[]>(
`${this.url}/enfornamento?dataInicial=${dataInicio.toISOString()}&dataFinal=${dataFinal.toISOString()}`
);
}
buscarRelatorioDesenfornamento(dataInicio: Date, dataFinal: Date) {
return this.http
.get<RelatorioDesenfornamento[]>(
`${this.url}/desenfornamento?dataInicial=${dataInicio.toISOString()}&dataFinal=${dataFinal.toISOString()}`
);
}
}