/* tslint:disable max-line-length */ import { TestBed, getTestBed } from '@angular/core/testing'; import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing'; import { BarService } from 'app/entities/bar/bar.service'; import { Bar } from 'app/shared/model/bar.model'; import { SERVER_API_URL } from 'app/app.constants'; describe('Service Tests', () => { describe('Bar Service', () => { let injector: TestBed; let service: BarService; let httpMock: HttpTestingController; beforeEach(() => { TestBed.configureTestingModule({ imports: [HttpClientTestingModule], providers: [BarService] }); injector = getTestBed(); service = injector.get(BarService); httpMock = injector.get(HttpTestingController); }); describe('Service methods', () => { it('should call correct URL', () => { service.find(123).subscribe(() => {}); const req = httpMock.expectOne({ method: 'GET' }); const resourceUrl = SERVER_API_URL + 'api/bars'; expect(req.request.url).toEqual(resourceUrl + '/' + 123); }); it('should create a Bar', () => { service.create(new Bar(null)).subscribe(received => { expect(received.body.id).toEqual(null); }); const req = httpMock.expectOne({ method: 'POST' }); req.flush({ id: null }); }); it('should update a Bar', () => { service.update(new Bar(123)).subscribe(received => { expect(received.body.id).toEqual(123); }); const req = httpMock.expectOne({ method: 'PUT' }); req.flush({ id: 123 }); }); it('should return a Bar', () => { service.find(123).subscribe(received => { expect(received.body.id).toEqual(123); }); const req = httpMock.expectOne({ method: 'GET' }); req.flush({ id: 123 }); }); it('should return a list of Bar', () => { service.query(null).subscribe(received => { expect(received.body[0].id).toEqual(123); }); const req = httpMock.expectOne({ method: 'GET' }); req.flush([new Bar(123)]); }); it('should delete a Bar', () => { service.delete(123).subscribe(received => { expect(received.url).toContain('/' + 123); }); const req = httpMock.expectOne({ method: 'DELETE' }); req.flush(null); }); it('should propagate not found response', () => { service.find(123).subscribe(null, (_error: any) => { expect(_error.status).toEqual(404); }); const req = httpMock.expectOne({ method: 'GET' }); req.flush('Invalid request parameters', { status: 404, statusText: 'Bad Request' }); }); }); afterEach(() => { httpMock.verify(); }); }); });