Merged PR 1968: #5307 Entscheidungs Dialog

#5307 Entscheidungs Dialog
This commit is contained in:
Nino Righi
2025-10-16 08:56:56 +00:00
committed by Lorenz Hilpert
parent 596ae1da1b
commit b5c8dc4776
80 changed files with 3442 additions and 118 deletions

View File

@@ -36,7 +36,7 @@ describe('CatalougeSearchService', () => {
});
describe('searchByEans', () => {
it('should return items when search is successful', (done) => {
it('should return items when search is successful', async () => {
// Arrange
const mockItems: Item[] = [
{
@@ -57,21 +57,17 @@ describe('CatalougeSearchService', () => {
searchServiceSpy.SearchByEAN.mockReturnValue(of(mockResponse));
// Act
service.searchByEans('123456789', '987654321').subscribe({
next: (result) => {
// Assert
expect(result).toEqual(mockItems);
expect(searchServiceSpy.SearchByEAN).toHaveBeenCalledWith([
'123456789',
'987654321',
]);
done();
},
error: done.fail,
});
const result = await service.searchByEans(['123456789', '987654321']);
// Assert
expect(result).toEqual(mockItems);
expect(searchServiceSpy.SearchByEAN).toHaveBeenCalledWith([
'123456789',
'987654321',
]);
});
it('should throw error when response has error', (done) => {
it('should return empty array when response has error', async () => {
// Arrange
const mockResponse = {
error: true,
@@ -80,18 +76,14 @@ describe('CatalougeSearchService', () => {
searchServiceSpy.SearchByEAN.mockReturnValue(of(mockResponse));
// Act
service.searchByEans('123456789').subscribe({
next: () => done.fail('Should have thrown error'),
error: (error) => {
// Assert
expect(error).toBeInstanceOf(Error);
expect(error.message).toBe('Search failed');
done();
},
});
const result = await service.searchByEans(['123456789']);
// Assert
expect(result).toEqual([]);
expect(searchServiceSpy.SearchByEAN).toHaveBeenCalledWith(['123456789']);
});
it('should handle single EAN', (done) => {
it('should handle single EAN', async () => {
// Arrange
const mockItems: Item[] = [
{
@@ -107,20 +99,14 @@ describe('CatalougeSearchService', () => {
searchServiceSpy.SearchByEAN.mockReturnValue(of(mockResponse));
// Act
service.searchByEans('123456789').subscribe({
next: (result) => {
// Assert
expect(result).toEqual(mockItems);
expect(searchServiceSpy.SearchByEAN).toHaveBeenCalledWith([
'123456789',
]);
done();
},
error: done.fail,
});
const result = await service.searchByEans(['123456789']);
// Assert
expect(result).toEqual(mockItems);
expect(searchServiceSpy.SearchByEAN).toHaveBeenCalledWith(['123456789']);
});
it('should handle empty EAN array', (done) => {
it('should handle empty EAN array', async () => {
// Arrange
const mockResponse = {
error: false,
@@ -129,15 +115,11 @@ describe('CatalougeSearchService', () => {
searchServiceSpy.SearchByEAN.mockReturnValue(of(mockResponse));
// Act
service.searchByEans().subscribe({
next: (result) => {
// Assert
expect(result).toEqual([]);
expect(searchServiceSpy.SearchByEAN).toHaveBeenCalledWith([]);
done();
},
error: done.fail,
});
const result = await service.searchByEans([]);
// Assert
expect(result).toEqual([]);
expect(searchServiceSpy.SearchByEAN).toHaveBeenCalledWith([]);
});
});

View File

@@ -4,7 +4,7 @@ import {
ResponseArgsOfUISettingsDTO,
SearchService,
} from '@generated/swagger/cat-search-api';
import { firstValueFrom, map, Observable } from 'rxjs';
import { firstValueFrom, map } from 'rxjs';
import {
catchResponseArgsErrorPipe,
ResponseArgsError,
@@ -26,8 +26,13 @@ export class CatalougeSearchService {
#searchService = inject(SearchService);
#logger = logger(() => ({ service: 'CatalougeSearchService' }));
searchByEans(...ean: string[]): Observable<Item[]> {
return this.#searchService.SearchByEAN(ean).pipe(
async searchByEans(
ean: string[],
abortSignal?: AbortSignal,
): Promise<Item[]> {
this.#logger.info('Searching items by EANs', () => ({ count: ean.length }));
let req$ = this.#searchService.SearchByEAN(ean).pipe(
map((res) => {
if (res.error) {
throw new Error(res.message);
@@ -36,6 +41,27 @@ export class CatalougeSearchService {
return res.result as Item[];
}),
);
if (abortSignal) {
req$ = req$.pipe(takeUntilAborted(abortSignal));
}
try {
const items = await firstValueFrom(req$);
this.#logger.debug('Successfully fetched items by EANs', () => ({
count: items.length,
}));
return items;
} catch (error) {
this.#logger.error(
'Error fetching items by EANs',
error as Error,
() => ({
eanCount: ean.length,
}),
);
return [];
}
}
async searchByTerm(