mirror of
https://dev.azure.com/hugendubel/ISA/_git/ISA-Frontend
synced 2025-12-28 22:42:11 +01:00
Merged PR 1885: Remi Add Flow - ohne offener Remi
Related work items: #5135
This commit is contained in:
committed by
Nino Righi
parent
b015e97e1f
commit
442670bdd0
@@ -0,0 +1,143 @@
|
||||
import { BatchResponseArgs } from './batch-response-args';
|
||||
import { ReturnValue } from './return-value';
|
||||
|
||||
describe('BatchResponseArgs', () => {
|
||||
describe('interface structure', () => {
|
||||
it('should support all properties', () => {
|
||||
// Arrange
|
||||
const testData: BatchResponseArgs<string> = {
|
||||
alreadyProcessed: [
|
||||
{ error: false, result: 'processed1' },
|
||||
{ error: false, result: 'processed2' },
|
||||
],
|
||||
ambiguous: ['ambiguous1', 'ambiguous2'],
|
||||
completed: true,
|
||||
duplicates: [
|
||||
{ key: 'key1', value: 1 },
|
||||
{ key: 'key2', value: 2 },
|
||||
],
|
||||
error: false,
|
||||
failed: [
|
||||
{ error: true, message: 'Failed', result: 'failed1' },
|
||||
],
|
||||
invalidProperties: { field1: 'Invalid value' },
|
||||
message: 'Success',
|
||||
requestId: 12345,
|
||||
successful: [
|
||||
{ key: 'key1', value: 'value1' },
|
||||
{ key: 'key2', value: 'value2' },
|
||||
],
|
||||
total: 10,
|
||||
unknown: [
|
||||
{ error: false, result: 'unknown1' },
|
||||
],
|
||||
};
|
||||
|
||||
// Assert
|
||||
expect(testData.alreadyProcessed).toHaveLength(2);
|
||||
expect(testData.ambiguous).toHaveLength(2);
|
||||
expect(testData.completed).toBe(true);
|
||||
expect(testData.duplicates).toHaveLength(2);
|
||||
expect(testData.error).toBe(false);
|
||||
expect(testData.failed).toHaveLength(1);
|
||||
expect(testData.invalidProperties).toEqual({ field1: 'Invalid value' });
|
||||
expect(testData.message).toBe('Success');
|
||||
expect(testData.requestId).toBe(12345);
|
||||
expect(testData.successful).toHaveLength(2);
|
||||
expect(testData.total).toBe(10);
|
||||
expect(testData.unknown).toHaveLength(1);
|
||||
});
|
||||
|
||||
it('should support required properties only', () => {
|
||||
// Arrange
|
||||
const testData: BatchResponseArgs<number> = {
|
||||
completed: false,
|
||||
error: true,
|
||||
total: 0,
|
||||
};
|
||||
|
||||
// Assert
|
||||
expect(testData.completed).toBe(false);
|
||||
expect(testData.error).toBe(true);
|
||||
expect(testData.total).toBe(0);
|
||||
expect(testData.alreadyProcessed).toBeUndefined();
|
||||
expect(testData.ambiguous).toBeUndefined();
|
||||
expect(testData.duplicates).toBeUndefined();
|
||||
expect(testData.failed).toBeUndefined();
|
||||
expect(testData.invalidProperties).toBeUndefined();
|
||||
expect(testData.message).toBeUndefined();
|
||||
expect(testData.requestId).toBeUndefined();
|
||||
expect(testData.successful).toBeUndefined();
|
||||
expect(testData.unknown).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should support generic type parameter', () => {
|
||||
// Arrange
|
||||
interface TestObject {
|
||||
id: number;
|
||||
name: string;
|
||||
}
|
||||
|
||||
const testData: BatchResponseArgs<TestObject> = {
|
||||
completed: true,
|
||||
error: false,
|
||||
total: 1,
|
||||
successful: [
|
||||
{ key: { id: 1, name: 'test' }, value: { id: 1, name: 'test' } },
|
||||
],
|
||||
};
|
||||
|
||||
// Assert
|
||||
expect(testData.successful?.[0].key.id).toBe(1);
|
||||
expect(testData.successful?.[0].key.name).toBe('test');
|
||||
expect(testData.successful?.[0].value.id).toBe(1);
|
||||
expect(testData.successful?.[0].value.name).toBe('test');
|
||||
});
|
||||
|
||||
it('should support ReturnValue arrays', () => {
|
||||
// Arrange
|
||||
const returnValue: ReturnValue<string> = {
|
||||
error: false,
|
||||
result: 'test result',
|
||||
message: 'Success',
|
||||
};
|
||||
|
||||
const testData: BatchResponseArgs<string> = {
|
||||
completed: true,
|
||||
error: false,
|
||||
total: 1,
|
||||
alreadyProcessed: [returnValue],
|
||||
failed: [returnValue],
|
||||
unknown: [returnValue],
|
||||
};
|
||||
|
||||
// Assert
|
||||
expect(testData.alreadyProcessed?.[0]).toEqual(returnValue);
|
||||
expect(testData.failed?.[0]).toEqual(returnValue);
|
||||
expect(testData.unknown?.[0]).toEqual(returnValue);
|
||||
});
|
||||
|
||||
it('should support empty arrays', () => {
|
||||
// Arrange
|
||||
const testData: BatchResponseArgs<string> = {
|
||||
completed: true,
|
||||
error: false,
|
||||
total: 0,
|
||||
alreadyProcessed: [],
|
||||
ambiguous: [],
|
||||
duplicates: [],
|
||||
failed: [],
|
||||
successful: [],
|
||||
unknown: [],
|
||||
};
|
||||
|
||||
// Assert
|
||||
expect(testData.alreadyProcessed).toHaveLength(0);
|
||||
expect(testData.ambiguous).toHaveLength(0);
|
||||
expect(testData.duplicates).toHaveLength(0);
|
||||
expect(testData.failed).toHaveLength(0);
|
||||
expect(testData.successful).toHaveLength(0);
|
||||
expect(testData.unknown).toHaveLength(0);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,16 @@
|
||||
import { ReturnValue } from './return-value';
|
||||
|
||||
export interface BatchResponseArgs<T> {
|
||||
alreadyProcessed?: Array<ReturnValue<T>>;
|
||||
ambiguous?: Array<T>;
|
||||
completed: boolean;
|
||||
duplicates?: Array<{ key: T; value: number }>;
|
||||
error: boolean;
|
||||
failed?: Array<ReturnValue<T>>;
|
||||
invalidProperties?: { [key: string]: string };
|
||||
message?: string;
|
||||
requestId?: number;
|
||||
successful?: Array<{ key: T; value: T }>;
|
||||
total: number;
|
||||
unknown?: Array<ReturnValue<T>>;
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
export * from './async-result';
|
||||
export * from './callback-result';
|
||||
export * from './entity-cotnainer';
|
||||
export * from './list-response-args';
|
||||
export * from './response-args';
|
||||
export * from './async-result';
|
||||
export * from './batch-response-args';
|
||||
export * from './callback-result';
|
||||
export * from './entity-cotnainer';
|
||||
export * from './list-response-args';
|
||||
export * from './response-args';
|
||||
export * from './return-value';
|
||||
|
||||
128
libs/common/data-access/src/lib/models/return-value.spec.ts
Normal file
128
libs/common/data-access/src/lib/models/return-value.spec.ts
Normal file
@@ -0,0 +1,128 @@
|
||||
import { ReturnValue } from './return-value';
|
||||
|
||||
describe('ReturnValue', () => {
|
||||
describe('interface structure', () => {
|
||||
it('should support all properties', () => {
|
||||
// Arrange
|
||||
const testData: ReturnValue<string> = {
|
||||
error: false,
|
||||
invalidProperties: { field1: 'Invalid value', field2: 'Another error' },
|
||||
message: 'Operation successful',
|
||||
result: 'test result',
|
||||
};
|
||||
|
||||
// Assert
|
||||
expect(testData.error).toBe(false);
|
||||
expect(testData.invalidProperties).toEqual({
|
||||
field1: 'Invalid value',
|
||||
field2: 'Another error'
|
||||
});
|
||||
expect(testData.message).toBe('Operation successful');
|
||||
expect(testData.result).toBe('test result');
|
||||
});
|
||||
|
||||
it('should support required properties only', () => {
|
||||
// Arrange
|
||||
const testData: ReturnValue<number> = {
|
||||
error: true,
|
||||
result: 42,
|
||||
};
|
||||
|
||||
// Assert
|
||||
expect(testData.error).toBe(true);
|
||||
expect(testData.result).toBe(42);
|
||||
expect(testData.invalidProperties).toBeUndefined();
|
||||
expect(testData.message).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should support generic type parameter', () => {
|
||||
// Arrange
|
||||
interface TestObject {
|
||||
id: number;
|
||||
name: string;
|
||||
}
|
||||
|
||||
const testObject: TestObject = { id: 1, name: 'test' };
|
||||
const testData: ReturnValue<TestObject> = {
|
||||
error: false,
|
||||
result: testObject,
|
||||
};
|
||||
|
||||
// Assert
|
||||
expect(testData.result.id).toBe(1);
|
||||
expect(testData.result.name).toBe('test');
|
||||
});
|
||||
|
||||
it('should support arrays as generic type', () => {
|
||||
// Arrange
|
||||
const testData: ReturnValue<string[]> = {
|
||||
error: false,
|
||||
result: ['item1', 'item2', 'item3'],
|
||||
message: 'Array operation successful',
|
||||
};
|
||||
|
||||
// Assert
|
||||
expect(testData.result).toHaveLength(3);
|
||||
expect(testData.result[0]).toBe('item1');
|
||||
expect(testData.result[1]).toBe('item2');
|
||||
expect(testData.result[2]).toBe('item3');
|
||||
});
|
||||
|
||||
it('should support null result', () => {
|
||||
// Arrange
|
||||
const testData: ReturnValue<string | null> = {
|
||||
error: false,
|
||||
result: null,
|
||||
};
|
||||
|
||||
// Assert
|
||||
expect(testData.result).toBeNull();
|
||||
});
|
||||
|
||||
it('should support error state with message', () => {
|
||||
// Arrange
|
||||
const testData: ReturnValue<string> = {
|
||||
error: true,
|
||||
message: 'Operation failed',
|
||||
result: '',
|
||||
};
|
||||
|
||||
// Assert
|
||||
expect(testData.error).toBe(true);
|
||||
expect(testData.message).toBe('Operation failed');
|
||||
expect(testData.result).toBe('');
|
||||
});
|
||||
|
||||
it('should support complex invalidProperties', () => {
|
||||
// Arrange
|
||||
const testData: ReturnValue<any> = {
|
||||
error: true,
|
||||
invalidProperties: {
|
||||
'user.email': 'Invalid email format',
|
||||
'user.age': 'Age must be a positive number',
|
||||
'nested.field.value': 'Required field missing',
|
||||
},
|
||||
result: null,
|
||||
};
|
||||
|
||||
// Assert
|
||||
expect(testData.invalidProperties).toEqual({
|
||||
'user.email': 'Invalid email format',
|
||||
'user.age': 'Age must be a positive number',
|
||||
'nested.field.value': 'Required field missing',
|
||||
});
|
||||
});
|
||||
|
||||
it('should support empty invalidProperties', () => {
|
||||
// Arrange
|
||||
const testData: ReturnValue<string> = {
|
||||
error: false,
|
||||
invalidProperties: {},
|
||||
result: 'success',
|
||||
};
|
||||
|
||||
// Assert
|
||||
expect(testData.invalidProperties).toEqual({});
|
||||
});
|
||||
});
|
||||
});
|
||||
6
libs/common/data-access/src/lib/models/return-value.ts
Normal file
6
libs/common/data-access/src/lib/models/return-value.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
export interface ReturnValue<T> {
|
||||
error: boolean;
|
||||
invalidProperties?: { [key: string]: string };
|
||||
message?: string;
|
||||
result: T;
|
||||
}
|
||||
Reference in New Issue
Block a user