import BlobUtil from "./BlobUtil";

describe("BlobUtil", () => {
  describe("blobToBase64", () => {
    test("converts blob to base64 string", async () => {
      const testString = "Hello, World!";
      const blob = new Blob([testString], { type: "text/plain" });

      const result = await BlobUtil.blobToBase64(blob);

      expect(result).toBe("SGVsbG8sIFdvcmxkIQ==");
    });

    test("converts empty blob to empty base64 string", async () => {
      const blob = new Blob([], { type: "text/plain" });

      const result = await BlobUtil.blobToBase64(blob);

      expect(result).toBe("");
    });

    test("converts binary data blob to base64", async () => {
      const binaryData = new Uint8Array([72, 101, 108, 108, 111]); // "Hello" in ASCII
      const blob = new Blob([binaryData], { type: "application/octet-stream" });

      const result = await BlobUtil.blobToBase64(blob);

      expect(result).toBe("SGVsbG8=");
    });

    test("handles blob with special characters", async () => {
      const testString = "Testing 123 @#$%";
      const blob = new Blob([testString], { type: "text/plain" });

      const result = await BlobUtil.blobToBase64(blob);

      // Convert back to verify
      const decoded = Buffer.from(result, "base64").toString();
      expect(decoded).toBe(testString);
    });
  });
});
