Skip to content

Commit

Permalink
adds test for unknown buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
douglance committed Oct 23, 2024
1 parent 6466a0f commit 884a270
Showing 1 changed file with 31 additions and 3 deletions.
34 changes: 31 additions & 3 deletions packages/scripts/src/addOrbitChain/tests/transforms.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
/* eslint-disable jest/no-mocks-import */

import fs from "fs";
import path from "path";
import sharp from "sharp";
import { afterAll, afterEach, beforeEach, describe, expect, it } from "vitest";
import {
afterAll,
afterEach,
beforeEach,
describe,
expect,
it,
vi,
} from "vitest";
import { IncomingChainData } from "../schemas";
import {
extractRawChainData,
Expand All @@ -20,6 +26,7 @@ import {
mockOrbitChain,
} from "./__mocks__/chainDataMocks";
import { warning } from "@actions/core";
import axios from "axios";

describe("Transforms", () => {
describe("extractRawChainData", () => {
Expand Down Expand Up @@ -302,6 +309,27 @@ describe("Transforms", () => {
const invalidIpfsUrl = "ipfs://InvalidHash123";
await expect(fetchAndProcessImage(invalidIpfsUrl)).rejects.toThrow();
});

it("should handle non-image buffers and convert to webp", async () => {
// Create a mock non-image buffer
const nonImageBuffer = Buffer.from("not an image");

// Mock axios to return our non-image buffer
const mockUrl = "https://example.com/unknown-file";
vi.spyOn(axios, "get").mockResolvedValueOnce({
status: 200,
data: nonImageBuffer,
headers: {
"content-type": "application/octet-stream",
},
});

const { buffer, fileExtension } = await fetchAndProcessImage(mockUrl);

expect(buffer).toBeTruthy();
expect(buffer.length).toBeGreaterThan(0);
expect(fileExtension).toBe(".webp");
});
});
});

Expand Down

0 comments on commit 884a270

Please sign in to comment.