mirror of
https://dev.azure.com/hugendubel/ISA/_git/ISA-Frontend
synced 2025-12-31 09:37:15 +01:00
Added CatImageService to get the image url
This commit is contained in:
41
projects/cat-service/src/lib/cat-image.service.spec.ts
Normal file
41
projects/cat-service/src/lib/cat-image.service.spec.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import { CatImageService } from './cat-image.service';
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
import { CatSearchMockService } from './cat-search-mock.service';
|
||||
import { CatSearchService } from './cat-search.service';
|
||||
import { of } from 'rxjs';
|
||||
|
||||
describe('CatImageService', () => {
|
||||
|
||||
let service: CatImageService;
|
||||
let mockService: CatSearchMockService;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [],
|
||||
providers: [{ provide: CatSearchService, useClass: CatSearchMockService }]
|
||||
});
|
||||
|
||||
service = TestBed.get(CatImageService);
|
||||
mockService = TestBed.get(CatSearchService);
|
||||
|
||||
|
||||
});
|
||||
|
||||
it('should create the service', () => {
|
||||
expect(service).toBeDefined();
|
||||
});
|
||||
|
||||
describe('#getImageUrl', () => {
|
||||
|
||||
it('should return an url', () => {
|
||||
spyOn(mockService, 'settings').and.returnValue(of({
|
||||
result: { imageUrl: 'https://produktbilder.ihugendubel.de/{ean}_150x150.jpg?showDummy=true' }
|
||||
}));
|
||||
service.getImageUrl('testean123').subscribe((url) => {
|
||||
expect(url).toBe('https://produktbilder.ihugendubel.de/testean123_150x150.jpg?showDummy=true');
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
19
projects/cat-service/src/lib/cat-image.service.ts
Normal file
19
projects/cat-service/src/lib/cat-image.service.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { ItemDTO } from './dtos';
|
||||
import { CatSearchService } from './cat-search.service';
|
||||
import { Observable, of } from 'rxjs';
|
||||
import { map, catchError } from 'rxjs/operators';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class CatImageService {
|
||||
|
||||
constructor(private catSearch: CatSearchService) { }
|
||||
|
||||
getImageUrl(ean: string): Observable<string> {
|
||||
return this.catSearch.settings().pipe(
|
||||
map(response => response.result.imageUrl),
|
||||
map(url => url.replace('{ean}', ean)),
|
||||
catchError(() => of(''))
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user