UNPKG

gphotos-scraper

Version:

A tool to extract public url and metadata from shared album

107 lines 4.34 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 exceptions_1 = require("../exceptions"); const axiosClient_1 = require("./axiosClient"); const getAlbum_1 = require("./getAlbum"); vitest_1.vi.mock("./axiosClient", () => ({ apiClient: { get: vitest_1.vi.fn(), post: vitest_1.vi.fn(), }, })); (0, vitest_1.describe)("getAlbum", () => { (0, vitest_1.beforeEach)(() => { vitest_1.vi.clearAllMocks(); }); (0, vitest_1.it)("should throw AlbumNotFoundException if canonical URL is missing", () => __awaiter(void 0, void 0, void 0, function* () { axiosClient_1.apiClient.get.mockResolvedValue({ data: "<html></html>" }); yield (0, vitest_1.expect)((0, getAlbum_1.getAlbum)("http://example.com")).rejects.toThrow(exceptions_1.AlbumNotFoundException); })); (0, vitest_1.it)("should parse album metadata correctly", () => __awaiter(void 0, void 0, void 0, function* () { var _a; const mockHtml = ` <html> <head> <link rel="canonical" href="https://photos.app.goo.gl/ALBUM_ID" /> </head> <script>var x = "key=ALBUM_KEY";</script> </html> `; axiosClient_1.apiClient.get.mockResolvedValue({ data: mockHtml }); // Constructing the complex RPC response structure expected by getAlbum.ts // parsedResponse indices: // 1: albumItems (array) // 2: nextToken (string) // 3: albumDetails (array) -> [id, title, [dates...], downloadUrl, cover, owner...] // albumDetails indices: // 0: id // 1: title // 2: dates -> [,,,4:createdAt,,,,8:updatedAt] // 3: downloadUrl (not used in destructuring directly, but index 32 is sharedUrl? No, let's check code) // Code: const [albumId, albumTitle, albumDates, downloadUrl, albumCover, albumOwner] = albumDetails; // Index 32: sharedUrl const albumDates = [ null, null, null, null, 1600000000, null, null, null, 1600000000, ]; const albumCover = ["cover_url", 100, 100]; const albumOwner = [ null, "OwnerID", null, "OwnerPhoto", null, null, null, null, null, null, null, ["Owner Fullname", null, null, "Owner Name"], ]; const albumDetails = [ "ALBUM_ID", "Album Title", albumDates, "DownloadUrl", albumCover, albumOwner, ]; // pad to index 32 for sharedUrl for (let i = 6; i < 32; i++) albumDetails.push(null); albumDetails[32] = "SharedUrl"; const parsedResponse = [ null, [], // albumItems "NextToken", albumDetails, ]; const mockRpcResponse = `)]}'` + JSON.stringify([["w", "snAcKc", JSON.stringify(parsedResponse)]]); axiosClient_1.apiClient.post.mockResolvedValue({ data: mockRpcResponse }); const album = yield (0, getAlbum_1.getAlbum)("http://example.com"); (0, vitest_1.expect)(album.id).toBe("ALBUM_ID"); (0, vitest_1.expect)(album.title).toBe("Album Title"); (0, vitest_1.expect)(album.key).toBe("ALBUM_KEY"); (0, vitest_1.expect)((_a = album.owner) === null || _a === void 0 ? void 0 : _a.fullname).toBe("Owner Fullname"); })); }); //# sourceMappingURL=getAlbum.spec.js.map