UNPKG

gphotos-scraper

Version:

A tool to extract public url and metadata from shared album

70 lines 3.31 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const vitest_1 = require("vitest"); const axiosClient_1 = require("./axiosClient"); const getPhotos_1 = require("./getPhotos"); vitest_1.vi.mock("./axiosClient", () => ({ apiClient: { post: vitest_1.vi.fn(), }, })); (0, vitest_1.describe)("getPhotos", () => { (0, vitest_1.beforeEach)(() => { vitest_1.vi.clearAllMocks(); }); (0, vitest_1.it)("should return an empty array if parsing fails", () => __awaiter(void 0, void 0, void 0, function* () { axiosClient_1.apiClient.post.mockResolvedValue({ data: "invalid json" }); const photos = yield (0, getPhotos_1.getPhotos)("test-key", ["id1"]); (0, vitest_1.expect)(photos).toEqual([]); })); (0, vitest_1.it)("should parse valid photo data correctly", () => __awaiter(void 0, void 0, void 0, function* () { // RPCID must match "fDcn4b" from getPhotos.ts // The structure inside the stringified JSON must match: // [id, description, filename, createdAt, unknown, size, width, height] const innerJson1 = JSON.stringify([ ["Item1", null, "filename.jpg", 1234567890, null, 1024, 800, 600], ]); const innerJson2 = JSON.stringify([ ["Item2", null, "image.png", 1234567890, null, 2048, 1920, 1080], ]); const mockResponseData = `)]}'` + JSON.stringify([ ["w", "fDcn4b", innerJson1], ["w", "fDcn4b", innerJson2], ]); axiosClient_1.apiClient.post.mockResolvedValue({ data: mockResponseData }); const photos = yield (0, getPhotos_1.getPhotos)("test-key", ["id1", "id2"]); (0, vitest_1.expect)(photos).toHaveLength(2); (0, vitest_1.expect)(photos[0]).toEqual({ id: "Item1", url: "", description: null, filename: "filename.jpg", createdAt: 1234567890, size: 1024, width: 800, height: 600, mimeType: "image/jpeg", }); (0, vitest_1.expect)(photos[1].mimeType).toBe("image/png"); })); (0, vitest_1.it)("should ignore items with incorrect RPCID", () => __awaiter(void 0, void 0, void 0, function* () { const mockResponseData = `)]}' [ ["wrongID", "[]"] ]`; axiosClient_1.apiClient.post.mockResolvedValue({ data: mockResponseData }); const photos = yield (0, getPhotos_1.getPhotos)("test-key", ["id1"]); (0, vitest_1.expect)(photos).toEqual([]); })); }); //# sourceMappingURL=getPhotos.spec.js.map