import { AuthService } from "./auth.service";
import { HttpClientModule } from "@angular/common/http";
import { UserService } from "../user/user.service";
import { HttpClientTestingModule, HttpTestingController } from "@angular/common/http/testing";
import { TestBed } from "@angular/core/testing";
import { User } from "../user/user";
describe("O service AuthService", () => {
let service: AuthService;
let httpMock: HttpTestingController;
let userService: UserService;
//test smoke - fumaza
beforeEach(() => {
TestBed.configureTestingModule({
//imports: [HttpClientModule],
imports: [HttpClientTestingModule],
providers: [AuthService]
});
service = TestBed.get(AuthService);
httpMock = TestBed.get(HttpTestingController);
userService = TestBed.get(UserService);
});
it("Deve ser instanciado", () => {
/*
const http=new HttpClient();
const userService=new UserService();
const service = new AuthService();
*/
expect(service).toBeTruthy();
});
it("Deve autenticar o usuario", () => {
const fakeBody = {
id: 1,
name: "Ad",
email: "adolmit@gmail.com"
}
spyOn(userService, "setToken").and.returnValue(null);
service.authenticate("adolfo", "1234").subscribe(response => {
expect(response.body).toEqual(fakeBody);
expect(response.headers.get('x-acess-token')).toBe('tokenTest');
});
const httpRequest = httpMock.expectOne((req) => {
return req.method === "POST"
});
httpRequest.flush(fakeBody, {
headers: { 'x-acess-toke': 'tokenTest' }
});
});
});