import {
  VENDOR_TYPES,
  transformAssetData,
  transformToVendorFormat,
  getFileHandle,
  resolveCarouselVideoUpdateFields,
} from '../vendorDataTransformers';

describe('vendorDataTransformers', () => {
  describe('VENDOR_TYPES', () => {
    it('should export correct vendor type constants', () => {
      expect(VENDOR_TYPES.KARIX).toBe('karixwhatsappbulk');
      expect(VENDOR_TYPES.GUPSHUP).toBe('gupshupwhatsappbulk');
      expect(VENDOR_TYPES.HAPTIC).toBe('hapticwhatsappbulk');
      expect(VENDOR_TYPES.TWILIO).toBe('twiliowhatsapptrans');
    });
  });

  describe('transformAssetData', () => {
    describe('HAPTIC vendor transformation', () => {
      it('should transform HAPTIC asset data correctly', () => {
        const hapticAssetData = {
          metaInfo: {
            secure_file_path: 'https://haptic.com/video.mp4',
            name: 'sample_video.mp4',
            duration: '30',
            hapticFileHandle: 'haptic_handle_123',
            height: '720',
            width: '1280',
          },
          previewUrl: 'https://haptic.com/preview.jpg',
        };

        const result = transformAssetData(hapticAssetData, VENDOR_TYPES.HAPTIC);

        expect(result).toEqual({
          videoSrc: 'https://haptic.com/video.mp4',
          previewUrl: 'https://haptic.com/preview.jpg',
          videoName: 'sample_video.mp4',
          videoDuration: '30',
          fileHandle: 'haptic_handle_123',
          videoHeight: '720',
          videoWidth: '1280',
        });
      });

      it('should handle missing metaInfo in HAPTIC data', () => {
        const hapticAssetData = {
          previewUrl: 'https://haptic.com/preview.jpg',
        };

        const result = transformAssetData(hapticAssetData, VENDOR_TYPES.HAPTIC);

        expect(result).toEqual({
          videoSrc: '',
          previewUrl: 'https://haptic.com/preview.jpg',
          videoName: '',
          videoDuration: '',
          fileHandle: '',
          videoHeight: '',
          videoWidth: '',
        });
      });

      it('should handle empty metaInfo object in HAPTIC data', () => {
        const hapticAssetData = {
          metaInfo: {},
          previewUrl: 'https://haptic.com/preview.jpg',
        };

        const result = transformAssetData(hapticAssetData, VENDOR_TYPES.HAPTIC);

        expect(result).toEqual({
          videoSrc: '',
          previewUrl: 'https://haptic.com/preview.jpg',
          videoName: '',
          videoDuration: '',
          fileHandle: '',
          videoHeight: '',
          videoWidth: '',
        });
      });

      it('should handle partial metaInfo in HAPTIC data', () => {
        const hapticAssetData = {
          metaInfo: {
            secure_file_path: 'https://haptic.com/video.mp4',
            name: 'sample_video.mp4',
            // missing duration, hapticFileHandle, height, width
          },
          previewUrl: 'https://haptic.com/preview.jpg',
        };

        const result = transformAssetData(hapticAssetData, VENDOR_TYPES.HAPTIC);

        expect(result).toEqual({
          videoSrc: 'https://haptic.com/video.mp4',
          previewUrl: 'https://haptic.com/preview.jpg',
          videoName: 'sample_video.mp4',
          videoDuration: '',
          fileHandle: '',
          videoHeight: '',
          videoWidth: '',
        });
      });
    });

    describe('Standard vendor transformation (Karix, Gupshup)', () => {
      it('should transform KARIX asset data correctly', () => {
        const karixAssetData = {
          videoSrc: 'https://karix.com/video.mp4',
          previewUrl: 'https://karix.com/preview.jpg',
          videoName: 'sample_video.mp4',
          videoDuration: '30',
          karixFileHandle: 'karix_handle_123',
          videoHeight: '720',
          videoWidth: '1280',
        };

        const result = transformAssetData(karixAssetData, VENDOR_TYPES.KARIX);

        expect(result).toEqual({
          videoSrc: 'https://karix.com/video.mp4',
          previewUrl: 'https://karix.com/preview.jpg',
          videoName: 'sample_video.mp4',
          videoDuration: '30',
          fileHandle: 'karix_handle_123',
          videoHeight: '720',
          videoWidth: '1280',
        });
      });

      it('should transform GUPSHUP asset data correctly', () => {
        const gupshupAssetData = {
          videoSrc: 'https://gupshup.com/video.mp4',
          previewUrl: 'https://gupshup.com/preview.jpg',
          videoName: 'sample_video.mp4',
          videoDuration: '30',
          karixFileHandle: 'gupshup_handle_123',
          videoHeight: '720',
          videoWidth: '1280',
        };

        const result = transformAssetData(gupshupAssetData, VENDOR_TYPES.GUPSHUP);

        expect(result).toEqual({
          videoSrc: 'https://gupshup.com/video.mp4',
          previewUrl: 'https://gupshup.com/preview.jpg',
          videoName: 'sample_video.mp4',
          videoDuration: '30',
          fileHandle: 'gupshup_handle_123',
          videoHeight: '720',
          videoWidth: '1280',
        });
      });

      it('should handle missing fields in standard vendor data', () => {
        const standardAssetData = {
          videoSrc: 'https://vendor.com/video.mp4',
          // missing other fields
        };

        const result = transformAssetData(standardAssetData, VENDOR_TYPES.KARIX);

        expect(result).toEqual({
          videoSrc: 'https://vendor.com/video.mp4',
          previewUrl: '',
          videoName: '',
          videoDuration: '',
          fileHandle: '',
          videoHeight: '',
          videoWidth: '',
        });
      });

      it('should handle default vendor type (unknown vendor)', () => {
        const standardAssetData = {
          videoSrc: 'https://unknown.com/video.mp4',
          previewUrl: 'https://unknown.com/preview.jpg',
          videoName: 'sample_video.mp4',
          videoDuration: '30',
          karixFileHandle: 'unknown_handle_123',
          videoHeight: '720',
          videoWidth: '1280',
        };

        const result = transformAssetData(standardAssetData, 'unknown_vendor');

        expect(result).toEqual({
          videoSrc: 'https://unknown.com/video.mp4',
          previewUrl: 'https://unknown.com/preview.jpg',
          videoName: 'sample_video.mp4',
          videoDuration: '30',
          fileHandle: 'unknown_handle_123',
          videoHeight: '720',
          videoWidth: '1280',
        });
      });
    });

    describe('Edge cases', () => {
      it('should handle null assetData', () => {
        const result = transformAssetData(null, VENDOR_TYPES.HAPTIC);
        expect(result).toEqual({});
      });

      it('should handle undefined assetData', () => {
        const result = transformAssetData(undefined, VENDOR_TYPES.KARIX);
        expect(result).toEqual({});
      });

      it('should handle empty object assetData', () => {
        const result = transformAssetData({}, VENDOR_TYPES.GUPSHUP);
        expect(result).toEqual({
          videoSrc: '',
          previewUrl: '',
          videoName: '',
          videoDuration: '',
          fileHandle: '',
          videoHeight: '',
          videoWidth: '',
        });
      });
    });
  });

  describe('transformToVendorFormat', () => {
    const standardData = {
      videoSrc: 'https://example.com/video.mp4',
      previewUrl: 'https://example.com/preview.jpg',
      videoName: 'sample_video.mp4',
      videoDuration: '30',
      fileHandle: 'handle_123',
      videoHeight: '720',
      videoWidth: '1280',
    };

    describe('HAPTIC vendor format', () => {
      it('should transform to HAPTIC vendor format correctly', () => {
        const result = transformToVendorFormat(standardData, VENDOR_TYPES.HAPTIC);

        expect(result).toEqual({
          metaInfo: {
            secure_file_path: 'https://example.com/video.mp4',
            name: 'sample_video.mp4',
            duration: '30',
            hapticFileHandle: 'handle_123',
            height: '720',
            width: '1280',
          },
          previewUrl: 'https://example.com/preview.jpg',
        });
      });

      it('should handle missing fields when transforming to HAPTIC format', () => {
        const partialData = {
          videoSrc: 'https://example.com/video.mp4',
          videoName: 'sample_video.mp4',
          // missing other fields
        };

        const result = transformToVendorFormat(partialData, VENDOR_TYPES.HAPTIC);

        expect(result).toEqual({
          metaInfo: {
            secure_file_path: 'https://example.com/video.mp4',
            name: 'sample_video.mp4',
            duration: undefined,
            hapticFileHandle: undefined,
            height: undefined,
            width: undefined,
          },
          previewUrl: undefined,
        });
      });
    });

    describe('Standard vendor format (Karix, Gupshup)', () => {
      it('should transform to KARIX vendor format correctly', () => {
        const result = transformToVendorFormat(standardData, VENDOR_TYPES.KARIX);

        expect(result).toEqual({
          videoSrc: 'https://example.com/video.mp4',
          previewUrl: 'https://example.com/preview.jpg',
          videoName: 'sample_video.mp4',
          videoDuration: '30',
          karixFileHandle: 'handle_123',
          videoHeight: '720',
          videoWidth: '1280',
        });
      });

      it('should transform to GUPSHUP vendor format correctly', () => {
        const result = transformToVendorFormat(standardData, VENDOR_TYPES.GUPSHUP);

        expect(result).toEqual({
          videoSrc: 'https://example.com/video.mp4',
          previewUrl: 'https://example.com/preview.jpg',
          videoName: 'sample_video.mp4',
          videoDuration: '30',
          karixFileHandle: 'handle_123',
          videoHeight: '720',
          videoWidth: '1280',
        });
      });

      it('should transform to default vendor format for unknown vendor', () => {
        const result = transformToVendorFormat(standardData, 'unknown_vendor');

        expect(result).toEqual({
          videoSrc: 'https://example.com/video.mp4',
          previewUrl: 'https://example.com/preview.jpg',
          videoName: 'sample_video.mp4',
          videoDuration: '30',
          karixFileHandle: 'handle_123',
          videoHeight: '720',
          videoWidth: '1280',
        });
      });

      it('should handle empty standard data', () => {
        const result = transformToVendorFormat({}, VENDOR_TYPES.KARIX);

        expect(result).toEqual({
          videoSrc: undefined,
          previewUrl: undefined,
          videoName: undefined,
          videoDuration: undefined,
          karixFileHandle: undefined,
          videoHeight: undefined,
          videoWidth: undefined,
        });
      });
    });
  });

  describe('getFileHandle', () => {
    describe('HAPTIC vendor', () => {
      it('should get file handle from HAPTIC asset data', () => {
        const hapticData = {
          metaInfo: {
            hapticFileHandle: 'haptic_handle_123',
          },
        };

        const result = getFileHandle(hapticData, VENDOR_TYPES.HAPTIC);
        expect(result).toBe('haptic_handle_123');
      });

      it('should return empty string if hapticFileHandle is missing', () => {
        const hapticData = {
          metaInfo: {
            // missing hapticFileHandle
          },
        };

        const result = getFileHandle(hapticData, VENDOR_TYPES.HAPTIC);
        expect(result).toBe('');
      });

      it('should return empty string if metaInfo is missing', () => {
        const hapticData = {
          // missing metaInfo
        };

        const result = getFileHandle(hapticData, VENDOR_TYPES.HAPTIC);
        expect(result).toBe('');
      });
    });

    describe('Standard vendors (Karix, Gupshup)', () => {
      it('should get file handle from KARIX asset data', () => {
        const karixData = {
          karixFileHandle: 'karix_handle_123',
        };

        const result = getFileHandle(karixData, VENDOR_TYPES.KARIX);
        expect(result).toBe('karix_handle_123');
      });

      it('should get file handle from GUPSHUP asset data', () => {
        const gupshupData = {
          karixFileHandle: 'gupshup_handle_123',
        };

        const result = getFileHandle(gupshupData, VENDOR_TYPES.GUPSHUP);
        expect(result).toBe('gupshup_handle_123');
      });

      it('should fallback to metaInfo.karixFileHandle if karixFileHandle is missing', () => {
        const standardData = {
          metaInfo: {
            karixFileHandle: 'meta_karix_handle_123',
          },
        };

        const result = getFileHandle(standardData, VENDOR_TYPES.KARIX);
        expect(result).toBe('meta_karix_handle_123');
      });

      it('should return first available handle when both exist', () => {
        const standardData = {
          karixFileHandle: 'direct_handle_123',
          metaInfo: {
            karixFileHandle: 'meta_handle_123',
          },
        };

        const result = getFileHandle(standardData, VENDOR_TYPES.KARIX);
        expect(result).toBe('direct_handle_123');
      });

      it('should return empty string if no file handle is found', () => {
        const standardData = {
          // no file handles
        };

        const result = getFileHandle(standardData, VENDOR_TYPES.KARIX);
        expect(result).toBe('');
      });

      it('should handle unknown vendor type with default logic', () => {
        const standardData = {
          karixFileHandle: 'unknown_vendor_handle_123',
        };

        const result = getFileHandle(standardData, 'unknown_vendor');
        expect(result).toBe('unknown_vendor_handle_123');
      });
    });

    describe('Edge cases', () => {
      it('should return empty string for null assetData', () => {
        const result = getFileHandle(null, VENDOR_TYPES.HAPTIC);
        expect(result).toBe('');
      });

      it('should return empty string for undefined assetData', () => {
        const result = getFileHandle(undefined, VENDOR_TYPES.KARIX);
        expect(result).toBe('');
      });

      it('should handle empty object assetData', () => {
        const result = getFileHandle({}, VENDOR_TYPES.GUPSHUP);
        expect(result).toBe('');
      });
    });
  });

  describe('Integration tests', () => {
    it('should transform HAPTIC data and then back to vendor format correctly', () => {
      const originalHapticData = {
        metaInfo: {
          secure_file_path: 'https://haptic.com/video.mp4',
          name: 'sample_video.mp4',
          duration: '30',
          hapticFileHandle: 'haptic_handle_123',
          height: '720',
          width: '1280',
        },
        previewUrl: 'https://haptic.com/preview.jpg',
      };

      // Transform to standard format
      const standardData = transformAssetData(originalHapticData, VENDOR_TYPES.HAPTIC);

      // Transform back to HAPTIC format
      const transformedBack = transformToVendorFormat(standardData, VENDOR_TYPES.HAPTIC);

      expect(transformedBack).toEqual(originalHapticData);
    });

    it('should transform standard data and then back to vendor format correctly', () => {
      const originalStandardData = {
        videoSrc: 'https://karix.com/video.mp4',
        previewUrl: 'https://karix.com/preview.jpg',
        videoName: 'sample_video.mp4',
        videoDuration: '30',
        karixFileHandle: 'karix_handle_123',
        videoHeight: '720',
        videoWidth: '1280',
      };

      // Transform to standard format (should be same)
      const standardData = transformAssetData(originalStandardData, VENDOR_TYPES.KARIX);

      // Transform back to KARIX format
      const transformedBack = transformToVendorFormat(standardData, VENDOR_TYPES.KARIX);

      expect(transformedBack).toEqual(originalStandardData);
    });

    it('should extract file handle correctly after transformation', () => {
      const hapticData = {
        metaInfo: {
          secure_file_path: 'https://haptic.com/video.mp4',
          hapticFileHandle: 'haptic_handle_123',
        },
      };

      // Transform to standard format
      const standardData = transformAssetData(hapticData, VENDOR_TYPES.HAPTIC);

      // Transform back to vendor format
      const vendorData = transformToVendorFormat(standardData, VENDOR_TYPES.HAPTIC);

      // Extract file handle
      const fileHandle = getFileHandle(vendorData, VENDOR_TYPES.HAPTIC);

      expect(fileHandle).toBe('haptic_handle_123');
    });
  });

  describe('resolveCarouselVideoUpdateFields', () => {
    describe('HAPTIC vendor', () => {
      it('should resolve HAPTIC vendor fields correctly with metaInfo', () => {
        const data = {
          metaInfo: {
            secure_file_path: 'https://haptic.com/video.mp4',
            hapticFileHandle: 'haptic_handle_123',
            name: 'sample_video.mp4',
          },
          previewUrl: 'https://haptic.com/preview.jpg',
        };
        const fallbackVideoSrc = 'https://fallback.com/video.mp4';
        const fallbackPreviewUrl = 'https://fallback.com/preview.jpg';
        const fallbackFileHandle = 'fallback_handle';

        const result = resolveCarouselVideoUpdateFields({
          host: VENDOR_TYPES.HAPTIC,
          data,
          videoSrc: fallbackVideoSrc,
          previewUrl: fallbackPreviewUrl,
          fileHandle: fallbackFileHandle,
        });

        expect(result.resolvedVideoSrc).toBe('https://haptic.com/video.mp4');
        expect(result.resolvedPreviewUrl).toBe('https://haptic.com/preview.jpg');
        expect(result.resolvedHapticHandle).toBe('haptic_handle_123');
        expect(result.resolvedKarixHandle).toBe('');
        expect(result.standardAsset).toEqual({
          videoSrc: 'https://haptic.com/video.mp4',
          previewUrl: 'https://haptic.com/preview.jpg',
          videoName: 'sample_video.mp4',
          videoDuration: '',
          fileHandle: 'haptic_handle_123',
          videoHeight: '',
          videoWidth: '',
        });
        expect(result.updateFields).toEqual([
          { fieldName: "videoSrc", value: 'https://haptic.com/video.mp4' },
          { fieldName: "videoPreviewImg", value: 'https://haptic.com/preview.jpg' },
          { fieldName: "assetList", value: result.standardAsset },
          { fieldName: "hapticFileHandle", value: 'haptic_handle_123' },
          { fieldName: "karixFileHandle", value: '' },
        ]);
      });

      it('should use fallback values when metaInfo fields are missing for HAPTIC', () => {
        const data = {
          metaInfo: {},
        };
        const fallbackVideoSrc = 'https://fallback.com/video.mp4';
        const fallbackPreviewUrl = 'https://fallback.com/preview.jpg';
        const fallbackFileHandle = 'fallback_handle';

        const result = resolveCarouselVideoUpdateFields({
          host: VENDOR_TYPES.HAPTIC,
          data,
          videoSrc: fallbackVideoSrc,
          previewUrl: fallbackPreviewUrl,
          fileHandle: fallbackFileHandle,
        });

        expect(result.resolvedVideoSrc).toBe(fallbackVideoSrc);
        expect(result.resolvedPreviewUrl).toBe(fallbackPreviewUrl);
        expect(result.resolvedHapticHandle).toBe(fallbackFileHandle);
        expect(result.resolvedKarixHandle).toBe('');
      });

      it('should prefer metaInfo secure_file_path over fallback videoSrc for HAPTIC', () => {
        const data = {
          metaInfo: {
            secure_file_path: 'https://haptic.com/video.mp4',
          },
        };
        const fallbackVideoSrc = 'https://fallback.com/video.mp4';

        const result = resolveCarouselVideoUpdateFields({
          host: VENDOR_TYPES.HAPTIC,
          data,
          videoSrc: fallbackVideoSrc,
        });

        expect(result.resolvedVideoSrc).toBe('https://haptic.com/video.mp4');
      });

      it('should use fallback videoSrc when metaInfo secure_file_path is missing for HAPTIC', () => {
        const data = {
          metaInfo: {},
        };
        const fallbackVideoSrc = 'https://fallback.com/video.mp4';

        const result = resolveCarouselVideoUpdateFields({
          host: VENDOR_TYPES.HAPTIC,
          data,
          videoSrc: fallbackVideoSrc,
        });

        expect(result.resolvedVideoSrc).toBe(fallbackVideoSrc);
      });

      it('should prefer metaInfo hapticFileHandle over fallback fileHandle for HAPTIC', () => {
        const data = {
          metaInfo: {
            hapticFileHandle: 'haptic_handle_123',
          },
        };
        const fallbackFileHandle = 'fallback_handle';

        const result = resolveCarouselVideoUpdateFields({
          host: VENDOR_TYPES.HAPTIC,
          data,
          fileHandle: fallbackFileHandle,
        });

        expect(result.resolvedHapticHandle).toBe('haptic_handle_123');
      });

      it('should transform standardAsset correctly for HAPTIC vendor', () => {
        const data = {
          metaInfo: {
            secure_file_path: 'https://haptic.com/video.mp4',
            name: 'sample_video.mp4',
            duration: '30',
            hapticFileHandle: 'haptic_handle_123',
            height: '720',
            width: '1280',
          },
          previewUrl: 'https://haptic.com/preview.jpg',
        };

        const result = resolveCarouselVideoUpdateFields({
          host: VENDOR_TYPES.HAPTIC,
          data,
        });

        expect(result.standardAsset).toEqual({
          videoSrc: 'https://haptic.com/video.mp4',
          previewUrl: 'https://haptic.com/preview.jpg',
          videoName: 'sample_video.mp4',
          videoDuration: '30',
          fileHandle: 'haptic_handle_123',
          videoHeight: '720',
          videoWidth: '1280',
        });
      });
    });

    describe('KARIX vendor', () => {
      it('should resolve KARIX vendor fields correctly', () => {
        const data = {
          videoSrc: 'https://karix.com/video.mp4',
          previewUrl: 'https://karix.com/preview.jpg',
          karixFileHandle: 'karix_handle_123',
        };
        const fallbackFileHandle = 'fallback_handle';

        const result = resolveCarouselVideoUpdateFields({
          host: VENDOR_TYPES.KARIX,
          data,
          videoSrc: data.videoSrc,
          previewUrl: data.previewUrl,
          fileHandle: fallbackFileHandle,
        });

        expect(result.resolvedVideoSrc).toBe('https://karix.com/video.mp4');
        expect(result.resolvedPreviewUrl).toBe('https://karix.com/preview.jpg');
        expect(result.resolvedHapticHandle).toBe('');
        expect(result.resolvedKarixHandle).toBe(fallbackFileHandle);
        expect(result.standardAsset).toBe(data);
      });

      it('should set resolvedKarixHandle from fileHandle parameter for KARIX', () => {
        const data = {};
        const fileHandle = 'karix_handle_123';

        const result = resolveCarouselVideoUpdateFields({
          host: VENDOR_TYPES.KARIX,
          data,
          fileHandle,
        });

        expect(result.resolvedKarixHandle).toBe('karix_handle_123');
        expect(result.resolvedHapticHandle).toBe('');
      });

      it('should not transform standardAsset for KARIX vendor', () => {
        const data = {
          videoSrc: 'https://karix.com/video.mp4',
          previewUrl: 'https://karix.com/preview.jpg',
          customField: 'custom_value',
        };

        const result = resolveCarouselVideoUpdateFields({
          host: VENDOR_TYPES.KARIX,
          data,
        });

        expect(result.standardAsset).toBe(data);
        expect(result.standardAsset.customField).toBe('custom_value');
      });
    });

    describe('GUPSHUP vendor', () => {
      it('should resolve GUPSHUP vendor fields correctly', () => {
        const data = {
          videoSrc: 'https://gupshup.com/video.mp4',
          previewUrl: 'https://gupshup.com/preview.jpg',
        };
        const fileHandle = 'gupshup_handle_123';

        const result = resolveCarouselVideoUpdateFields({
          host: VENDOR_TYPES.GUPSHUP,
          data,
          videoSrc: data.videoSrc,
          previewUrl: data.previewUrl,
          fileHandle,
        });

        expect(result.resolvedVideoSrc).toBe('https://gupshup.com/video.mp4');
        expect(result.resolvedPreviewUrl).toBe('https://gupshup.com/preview.jpg');
        expect(result.resolvedHapticHandle).toBe('');
        expect(result.resolvedKarixHandle).toBe('gupshup_handle_123');
        expect(result.standardAsset).toBe(data);
      });

      it('should set resolvedKarixHandle from fileHandle parameter for GUPSHUP', () => {
        const data = {};
        const fileHandle = 'gupshup_handle_123';

        const result = resolveCarouselVideoUpdateFields({
          host: VENDOR_TYPES.GUPSHUP,
          data,
          fileHandle,
        });

        expect(result.resolvedKarixHandle).toBe('gupshup_handle_123');
        expect(result.resolvedHapticHandle).toBe('');
      });
    });

    describe('Unknown/Other vendors', () => {
      it('should handle unknown vendor type with standard behavior', () => {
        const data = {
          videoSrc: 'https://unknown.com/video.mp4',
          previewUrl: 'https://unknown.com/preview.jpg',
        };
        const fileHandle = 'unknown_handle';

        const result = resolveCarouselVideoUpdateFields({
          host: 'unknown_vendor',
          data,
          videoSrc: data.videoSrc,
          previewUrl: data.previewUrl,
          fileHandle,
        });

        expect(result.resolvedVideoSrc).toBe('https://unknown.com/video.mp4');
        expect(result.resolvedPreviewUrl).toBe('https://unknown.com/preview.jpg');
        expect(result.resolvedHapticHandle).toBe('');
        expect(result.resolvedKarixHandle).toBe('');
        expect(result.standardAsset).toBe(data);
      });

      it('should not transform standardAsset for unknown vendor', () => {
        const data = {
          videoSrc: 'https://unknown.com/video.mp4',
          customField: 'custom_value',
        };

        const result = resolveCarouselVideoUpdateFields({
          host: 'unknown_vendor',
          data,
        });

        expect(result.standardAsset).toBe(data);
      });
    });

    describe('Update fields structure', () => {
      it('should return updateFields array with correct structure', () => {
        const data = {
          metaInfo: {
            secure_file_path: 'https://haptic.com/video.mp4',
            hapticFileHandle: 'haptic_handle_123',
          },
          previewUrl: 'https://haptic.com/preview.jpg',
        };

        const result = resolveCarouselVideoUpdateFields({
          host: VENDOR_TYPES.HAPTIC,
          data,
        });

        expect(result.updateFields).toHaveLength(5);
        expect(result.updateFields[0]).toEqual({ fieldName: "videoSrc", value: expect.any(String) });
        expect(result.updateFields[1]).toEqual({ fieldName: "videoPreviewImg", value: expect.any(String) });
        expect(result.updateFields[2]).toEqual({ fieldName: "assetList", value: expect.any(Object) });
        expect(result.updateFields[3]).toEqual({ fieldName: "hapticFileHandle", value: expect.any(String) });
        expect(result.updateFields[4]).toEqual({ fieldName: "karixFileHandle", value: expect.any(String) });
      });

      it('should include correct field names in updateFields', () => {
        const result = resolveCarouselVideoUpdateFields({
          host: VENDOR_TYPES.KARIX,
          data: {},
        });

        const fieldNames = result.updateFields.map((field) => field.fieldName);
        expect(fieldNames).toEqual([
          "videoSrc",
          "videoPreviewImg",
          "assetList",
          "hapticFileHandle",
          "karixFileHandle",
        ]);
      });
    });

    describe('Edge cases', () => {
      it('should handle null data object', () => {
        const result = resolveCarouselVideoUpdateFields({
          host: VENDOR_TYPES.HAPTIC,
          data: null,
          videoSrc: 'https://fallback.com/video.mp4',
        });

        expect(result.resolvedVideoSrc).toBe('https://fallback.com/video.mp4');
        expect(result.resolvedPreviewUrl).toBe('');
        expect(result.resolvedHapticHandle).toBe('');
      });

      it('should handle undefined data object', () => {
        const result = resolveCarouselVideoUpdateFields({
          host: VENDOR_TYPES.HAPTIC,
          data: undefined,
          videoSrc: 'https://fallback.com/video.mp4',
        });

        expect(result.resolvedVideoSrc).toBe('https://fallback.com/video.mp4');
        expect(result.resolvedPreviewUrl).toBe('');
      });

      it('should handle empty data object', () => {
        const result = resolveCarouselVideoUpdateFields({
          host: VENDOR_TYPES.KARIX,
          data: {},
          videoSrc: 'https://fallback.com/video.mp4',
          previewUrl: 'https://fallback.com/preview.jpg',
          fileHandle: 'fallback_handle',
        });

        expect(result.resolvedVideoSrc).toBe('https://fallback.com/video.mp4');
        expect(result.resolvedPreviewUrl).toBe('https://fallback.com/preview.jpg');
        expect(result.resolvedKarixHandle).toBe('fallback_handle');
      });

      it('should handle empty strings for all fallback parameters', () => {
        const result = resolveCarouselVideoUpdateFields({
          host: VENDOR_TYPES.KARIX,
          data: {},
          videoSrc: '',
          previewUrl: '',
          fileHandle: '',
        });

        expect(result.resolvedVideoSrc).toBe('');
        expect(result.resolvedPreviewUrl).toBe('');
        expect(result.resolvedKarixHandle).toBe('');
        expect(result.resolvedHapticHandle).toBe('');
      });

      it('should handle missing data.metaInfo for HAPTIC vendor', () => {
        const data = {
        };

        const result = resolveCarouselVideoUpdateFields({
          host: VENDOR_TYPES.HAPTIC,
          data,
          videoSrc: 'https://fallback.com/video.mp4',
        });

        expect(result.resolvedVideoSrc).toBe('https://fallback.com/video.mp4');
        expect(result.resolvedHapticHandle).toBe('');
      });

      it('should handle empty metaInfo object for HAPTIC vendor', () => {
        const data = {
          metaInfo: {},
        };

        const result = resolveCarouselVideoUpdateFields({
          host: VENDOR_TYPES.HAPTIC,
          data,
          videoSrc: 'https://fallback.com/video.mp4',
          fileHandle: 'fallback_handle',
        });

        expect(result.resolvedVideoSrc).toBe('https://fallback.com/video.mp4');
        expect(result.resolvedHapticHandle).toBe('fallback_handle');
      });
    });

    describe('Default parameter values', () => {
      it('should use default empty string values when parameters are not provided', () => {
        const result = resolveCarouselVideoUpdateFields({
          host: VENDOR_TYPES.KARIX,
          data: {},
        });

        expect(result.resolvedVideoSrc).toBe('');
        expect(result.resolvedPreviewUrl).toBe('');
        expect(result.resolvedKarixHandle).toBe('');
        expect(result.resolvedHapticHandle).toBe('');
      });

      it('should work with minimal parameters (only host and data)', () => {
        const data = {
          videoSrc: 'https://test.com/video.mp4',
        };

        const result = resolveCarouselVideoUpdateFields({
          host: VENDOR_TYPES.KARIX,
          data,
        });

        expect(result.updateFields).toBeDefined();
        expect(result.updateFields).toHaveLength(5);
      });
    });
  });
});
