gphotos-scraper
Version:
A tool to extract public url and metadata from shared album
44 lines (36 loc) • 1.22 kB
text/typescript
import { beforeEach, describe, expect, it, vi } from "vitest";
import { extractAlbum } from "./extractAlbum";
import * as getAlbumModule from "./getAlbum";
import * as getPhotosModule from "./getPhotos";
vi.mock("./getAlbum");
vi.mock("./getPhotos");
describe("extractAlbum", () => {
beforeEach(() => {
vi.clearAllMocks();
});
it("should orchestrate fetching and return sorted album with URLs", async () => {
const mockAlbum = {
id: "album-id",
title: "Test Album",
items: [
{ id: "1", url: "http://url1.com" },
{ id: "2", url: "http://url2.com" },
],
key: "album-key",
};
const mockPhotos = [
{ id: "1", createdAt: 100 },
{ id: "2", createdAt: 200 },
];
(getAlbumModule.getAlbum as any).mockResolvedValue(mockAlbum);
(getPhotosModule.getPhotos as any).mockResolvedValue(mockPhotos);
const result = await extractAlbum("http://album.url");
expect(result.id).toBe("album-id");
expect(result.photos).toHaveLength(2);
// Should be sorted by createdAt desc
expect(result.photos[0].id).toBe("2");
expect(result.photos[0].url).toBe("http://url2.com");
expect(result.photos[1].id).toBe("1");
expect(result.photos[1].url).toBe("http://url1.com");
});
});