import { getLineItemsFlattened } from '@/helpers/line-items-helper';

describe('getLineItemsFlattened', () => {
    describe('getLineItemsFlattened', () => {
        it('Returns empty array when null is passed', () => {
            // Arrange
            const lineItems = null;
            // Act
            const result = getLineItemsFlattened(lineItems);

            // Assert
            expect(result).not.toBeNull();
            expect(result).toStrictEqual([]);
        });

        it('Returns empty array when empty array is passed', () => {
            // Arrange
            const lineItems = [];
            // Act
            const result = getLineItemsFlattened(lineItems);

            // Assert
            expect(result).not.toBeNull();
            expect(result).toStrictEqual([]);
        });

        it('Returns line items as flat array without child parts', () => {
            // Arrange
            const lineItems = [{ partType: 'a' }, { partType: 'b' }, { partType: 'c' }];
            // Act
            const result = getLineItemsFlattened(lineItems);

            // Assert
            expect(result).not.toBeNull();
            expect(result).toStrictEqual(lineItems);
        });

        it('Returns line items as flat array with child parts', () => {
            // Arrange
            const a = { partType: 'a' };
            const c = { partType: 'c' };
            const d = { partType: 'd' };
            const b = { partType: 'b', childParts: [c, d] };
            const e = { partType: 'e', childParts: null };

            const lineItems = [a, b, e];
            // Act
            const result = getLineItemsFlattened(lineItems);

            // Assert
            expect(result).not.toBeNull();
            expect(result).toStrictEqual([a, b, c, d, e]);
        });
    });
});
