forked from marcomaroni-github/instagram-to-bluesky
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstagram-to-bluesky.test.ts
More file actions
751 lines (650 loc) · 22.2 KB
/
Copy pathinstagram-to-bluesky.test.ts
File metadata and controls
751 lines (650 loc) · 22.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
import {
main,
formatDuration,
calculateEstimatedTime,
uploadMediaAndEmbed,
} from "../src/instagram-to-bluesky";
import { BlueskyClient } from "./bluesky/bluesky";
import { ImagesEmbedImpl, VideoEmbedImpl } from "./bluesky/index";
import { logger } from "./logger/logger";
import { InstagramMediaProcessor, ImageMediaProcessResultImpl, readJsonFile } from "./media";
import type { InstagramExportedPost } from "./media/InstagramExportedPost";
// Mock all dependencies
jest.mock("fs");
jest.mock("./bluesky/bluesky", () => {
return {
BlueskyClient: jest.fn().mockImplementation(() => ({
login: jest.fn().mockResolvedValue(undefined),
uploadMedia: jest.fn().mockResolvedValue({
ref: "test-blob-ref",
mimeType: "image/jpeg",
size: 1000,
}),
createPost: jest.fn().mockResolvedValue("https://bsky.app/profile/test/post/test"),
})),
};
});
jest.mock("./media", () => {
const actual = jest.requireActual("./media")
const mockProcess = jest.fn().mockResolvedValue([
{
postDate: new Date(),
postText: "Test post",
embeddedMedia: [{
getType: () => "image",
mediaBuffer: Buffer.from("test"),
mimeType: "image/jpeg",
mediaText: "Test media",
}],
mediaCount: 1,
},
]);
const mockMediaProcessor = {
process: jest.fn().mockResolvedValue([
{
mediaText: "Test media",
mimeType: "image/jpeg",
mediaBuffer: Buffer.from("test"),
},
]),
};
return {
InstagramMediaProcessor: jest
.fn()
.mockImplementation((posts: InstagramExportedPost[], folder: string) => ({
mediaProcessorFactory: {
createProcessor: () => mockMediaProcessor,
},
instagramPosts: posts,
archiveFolder: folder,
process: mockProcess,
})),
decodeUTF8: jest.fn((x) => x),
readJsonFile: jest.fn(),
ImageMediaProcessResultImpl: actual.ImageMediaProcessResultImpl,
VideoMediaProcessResultImpl: actual.VideoMediaProcessResultImpl
};
});
jest.mock("../src/logger/logger", () => ({
logger: {
info: jest.fn(),
warn: jest.fn(),
error: jest.fn(),
debug: jest.fn(),
},
}));
jest.mock("dotenv", () => ({
config: jest.fn(),
}));
jest.mock("../src/video", () => ({
prepareVideoUpload: jest.fn().mockReturnValue({
ref: "", // This will be filled by the upload process with the CID
mimeType: "video/mp4",
size: 1000,
dimensions: {
width: 640,
height: 640,
},
}),
createVideoEmbed: jest.fn(),
validateVideo: jest.fn(),
getVideoDimensions: jest.fn(),
processVideoPost: jest.fn(),
}));
describe("Main App", () => {
const originalEnv = process.env;
const mockReadFileSync = (mockValue) => {
return (path) => {
if (path.endsWith('reels.json')) {
return JSON.parse(JSON.stringify({ "ig_reels_media": mockValue }))
}
return JSON.parse(JSON.stringify(mockValue));
}
};
beforeEach(() => {
jest.clearAllMocks();
// Reset env before each test
process.env = {
...originalEnv,
ARCHIVE_FOLDER: "/test/folder",
BLUESKY_USERNAME: "test_user",
BLUESKY_PASSWORD: "test_pass",
SIMULATE: "0",
TEST_MODE: "0",
};
// Setup default mocks
const mockValue = [
{
creation_timestamp: Date.now() / 1000,
title: "Test Post 1",
media: [
{
creation_timestamp: Date.now() / 1000,
title: "Test Media 1",
},
],
},
];
(readJsonFile as jest.Mock).mockImplementation(mockReadFileSync(mockValue));
// Reset BlueskyClient mock
jest.mocked(BlueskyClient).mockClear();
jest.mocked(BlueskyClient).prototype.login = jest.fn();
jest.mocked(BlueskyClient).prototype.createPost = jest
.fn()
.mockResolvedValue("https://bsky.app/test/post");
});
afterAll(() => {
process.env = originalEnv;
});
test("should process posts in simulate mode", async () => {
process.env.SIMULATE = "1";
await main();
expect(jest.mocked(BlueskyClient)).not.toHaveBeenCalled();
expect(logger.warn).toHaveBeenCalledWith(
expect.stringContaining("SIMULATE mode is enabled")
);
});
test("should process posts and create Bluesky posts in normal mode", async () => {
const mockPost = {
creation_timestamp: Date.now() / 1000,
title: "Test Post",
media: [
{
creation_timestamp: Date.now() / 1000,
title: "Test Media",
},
],
};
(readJsonFile as jest.Mock).mockImplementation(mockReadFileSync([mockPost]));
await main();
expect(jest.mocked(BlueskyClient)).toHaveBeenCalled();
expect(InstagramMediaProcessor).toHaveBeenCalledWith(
expect.any(Array),
expect.stringContaining("/test/folder")
);
expect(
jest.mocked(InstagramMediaProcessor).mock.results[0].value.process
).toHaveBeenCalled();
});
test("should handle date filtering with MIN_DATE", async () => {
process.env.MIN_DATE = "2024-01-01";
const oldPost = {
creation_timestamp: new Date("2023-01-01").getTime() / 1000,
title: "Old Post",
media: [
{
creation_timestamp: new Date("2023-01-01").getTime() / 1000,
title: "Old Media",
},
],
};
(readJsonFile as jest.Mock).mockImplementation(mockReadFileSync([oldPost]));
await main();
expect(logger.warn).toHaveBeenCalledWith(
"Skipping post - Before MIN_DATE: [Sun, 01 Jan 2023 00:00:00 GMT]"
);
});
test("should handle date filtering with MAX_DATE", async () => {
process.env.MAX_DATE = "2024-01-01";
const futurePost = {
creation_timestamp: new Date("2025-01-01").getTime() / 1000,
title: "Future Post",
media: [
{
creation_timestamp: new Date("2025-01-01").getTime() / 1000,
title: "Future Media",
},
],
};
(readJsonFile as jest.Mock).mockImplementation(mockReadFileSync([futurePost]));
await main();
expect(logger.warn).toHaveBeenCalledWith(
"Skipping post - After MAX_DATE [Wed, 01 Jan 2025 00:00:00 GMT]"
);
});
describe("Date Filtering", () => {
test("should include posts exactly on MIN_DATE", async () => {
process.env.MIN_DATE = "2024-01-01";
const exactMinDatePost = {
creation_timestamp: new Date("2024-01-01").getTime() / 1000,
title: "Exact Min Date Post",
media: [
{
creation_timestamp: new Date("2024-01-01").getTime() / 1000,
title: "Exact Min Date Media",
},
],
};
(readJsonFile as jest.Mock).mockImplementation(mockReadFileSync([exactMinDatePost]));
await main();
// The post should be processed, not skipped
expect(logger.warn).not.toHaveBeenCalledWith(
expect.stringContaining("Skipping post - Before MIN_DATE")
);
expect(InstagramMediaProcessor).toHaveBeenCalledWith(
expect.arrayContaining([
expect.objectContaining({ title: "Exact Min Date Post" }),
]),
expect.any(String)
);
});
test("should exclude posts exactly on MAX_DATE", async () => {
process.env.MAX_DATE = "2024-01-01";
const exactMaxDatePost = {
creation_timestamp: new Date("2024-01-01").getTime() / 1000,
title: "Exact Max Date Post",
media: [
{
creation_timestamp: new Date("2024-01-01").getTime() / 1000,
title: "Exact Max Date Media",
},
],
};
(readJsonFile as jest.Mock).mockImplementation(mockReadFileSync([exactMaxDatePost]));
await main();
// The post should be processed, not skipped (MAX_DATE is exclusive)
expect(logger.warn).not.toHaveBeenCalledWith(
expect.stringContaining("Skipping post - After MAX_DATE")
);
expect(InstagramMediaProcessor).toHaveBeenCalledWith(
expect.arrayContaining([
expect.objectContaining({ title: "Exact Max Date Post" }),
]),
expect.any(String)
);
});
test("should filter posts with both MIN_DATE and MAX_DATE set", async () => {
process.env.MIN_DATE = "2023-01-01";
process.env.MAX_DATE = "2025-01-01";
const posts = [
{
creation_timestamp: new Date("2022-01-01").getTime() / 1000, // Too old
title: "Too Old Post",
media: [
{
creation_timestamp: new Date("2022-01-01").getTime() / 1000,
title: "Old Media",
},
],
},
{
creation_timestamp: new Date("2023-06-01").getTime() / 1000, // In range
title: "In Range Post 1",
media: [
{
creation_timestamp: new Date("2023-06-01").getTime() / 1000,
title: "In Range Media 1",
},
],
},
{
creation_timestamp: new Date("2024-06-01").getTime() / 1000, // In range
title: "In Range Post 2",
media: [
{
creation_timestamp: new Date("2024-06-01").getTime() / 1000,
title: "In Range Media 2",
},
],
},
{
creation_timestamp: new Date("2026-01-01").getTime() / 1000, // Too new
title: "Too New Post",
media: [
{
creation_timestamp: new Date("2026-01-01").getTime() / 1000,
title: "New Media",
},
],
},
];
(readJsonFile as jest.Mock).mockImplementation(mockReadFileSync(posts));
await main();
// Should skip the too old post
expect(logger.warn).toHaveBeenCalledWith(
"Skipping post - Before MIN_DATE: [Sat, 01 Jan 2022 00:00:00 GMT]"
);
// Should skip the too new post
expect(logger.warn).toHaveBeenCalledWith(
"Skipping post - After MAX_DATE [Thu, 01 Jan 2026 00:00:00 GMT]"
);
// Should process the in-range posts
expect(InstagramMediaProcessor).toHaveBeenCalledWith(
expect.arrayContaining([
expect.objectContaining({ title: "In Range Post 1" }),
expect.objectContaining({ title: "In Range Post 2" }),
]),
expect.any(String)
);
});
test("should use media timestamp when post timestamp is missing", async () => {
process.env.MIN_DATE = "2023-01-01";
process.env.MAX_DATE = "2025-01-01";
const posts = [
{
// No creation_timestamp at post level
title: "Post with only media timestamp",
media: [
{
creation_timestamp: new Date("2024-01-01").getTime() / 1000,
title: "Media with timestamp",
},
],
},
{
// No creation_timestamp at post level
title: "Post with old media timestamp",
media: [
{
creation_timestamp: new Date("2022-01-01").getTime() / 1000,
title: "Too old media",
},
],
},
];
(readJsonFile as jest.Mock).mockImplementation(mockReadFileSync(posts));
await main();
// Should skip the post with old media timestamp
expect(logger.warn).toHaveBeenCalledWith(
"Skipping post - Before MIN_DATE: [Sat, 01 Jan 2022 00:00:00 GMT]"
);
// Should process the post with valid media timestamp
expect(InstagramMediaProcessor).toHaveBeenCalledWith(
expect.arrayContaining([
expect.objectContaining({ title: "Post with only media timestamp" }),
]),
expect.any(String)
);
});
});
test("should handle posts with missing dates", async () => {
const invalidPost = {
title: "Invalid Post",
media: [{ title: "Invalid Media" }],
};
(readJsonFile as jest.Mock).mockImplementation(mockReadFileSync([invalidPost]));
await main();
expect(logger.warn).toHaveBeenCalledWith("Skipping post - No date");
});
test("should handle file reading errors", async () => {
(readJsonFile as jest.Mock).mockImplementation(() => {
throw new Error("File read error");
});
await expect(main()).rejects.toThrow("File read error");
});
test("should handle Bluesky posting errors", async () => {
const mockPost = {
creation_timestamp: Date.now() / 1000,
title: "Test Post",
media: [
{
creation_timestamp: Date.now() / 1000,
title: "Test Media",
},
],
};
(readJsonFile as jest.Mock).mockImplementation(mockReadFileSync([mockPost]));
jest.mocked(BlueskyClient).prototype.createPost = jest
.fn()
.mockRejectedValue(new Error("Post failed"));
await main();
expect(logger.info).toHaveBeenCalledWith(
expect.stringContaining("Import finished")
);
});
test("should calculate correct estimated time in simulate mode", async () => {
process.env.SIMULATE = "1";
const mockPost = {
creation_timestamp: Date.now() / 1000,
title: "Test Post",
media: [
{
creation_timestamp: Date.now() / 1000,
title: "Test Media",
},
],
};
(readJsonFile as jest.Mock).mockImplementation(mockReadFileSync([mockPost]));
await main();
expect(logger.info).toHaveBeenCalledWith(
expect.stringContaining("Estimated time for real import")
);
});
test("should inform user of imported posts and media in normal mode", async () => {
await main();
// Verify the final import log message
expect(logger.info).toHaveBeenCalledWith(
expect.stringMatching(/Import finished at .+, imported 1 posts with 1 media/)
);
});
test("should inform user of imported posts and media in simulate mode", async () => {
process.env.SIMULATE = "1";
await main();
// Verify the final import log message
expect(logger.info).toHaveBeenCalledWith(
expect.stringMatching(/Import finished at .+, imported 1 posts with 1 media/)
);
});
test("should process posts successfully", async () => {
const mockPost = {
creation_timestamp: Date.now() / 1000,
title: "Test Post",
media: [
{
creation_timestamp: Date.now() / 1000,
title: "Test Media",
},
],
};
(readJsonFile as jest.Mock).mockImplementation(mockReadFileSync([mockPost]));
await main();
expect(jest.mocked(BlueskyClient)).toHaveBeenCalled();
expect(InstagramMediaProcessor).toHaveBeenCalledWith(
expect.any(Array),
expect.stringContaining("/test/folder")
);
expect(
jest.mocked(InstagramMediaProcessor).mock.results[0].value.process
).toHaveBeenCalled();
});
test("should process multiple images in a post correctly", async () => {
// Mock the posts.json content with multiple images
const mockPost = {
creation_timestamp: 1658871955,
title:
"A lil flower garden update:\n\nDalia is in full bloom, Dalia Fascination\nAnd my Hibiscus is looking fierce, Starry Starry Night\n\n#daliaflower #hibiscusplant",
media: [
{
uri: "media/posts/202207/296182505_2306736436140223_1131775985609414029_n_17908919372611575.webp",
creation_timestamp: 1658871953,
},
{
uri: "media/posts/202207/295533146_3324225487861619_7021607269857186723_n_17969743933670683.webp",
creation_timestamp: 1658871953,
},
{
uri: "media/posts/202207/295912830_382044777369802_7402982082333793499_n_18022601347396344.webp",
creation_timestamp: 1658871953,
},
{
uri: "media/posts/202207/295652603_422749169622405_7528877124810844569_n_17957390530916779.webp",
creation_timestamp: 1658871953,
},
{
uri: "media/posts/202207/295709430_3269025470003456_6772629498034016772_n_17932740269206594.webp",
creation_timestamp: 1658871953,
},
],
};
(readJsonFile as jest.Mock).mockImplementation(mockReadFileSync([mockPost]));
const embeddedMedia = mockPost.media.map(() => ({
getType: () => "image",
mediaBuffer: Buffer.from("test"),
mimeType: "image/jpeg",
}));
// Mock the media processor to return multiple images
const mockMediaProcessor = {
process: jest.fn().mockResolvedValue([
{
postDate: new Date(mockPost.creation_timestamp * 1000),
postText: mockPost.title,
// Max images will slice the media to 4
embeddedMedia: embeddedMedia.slice(0, 4),
},
]),
};
(InstagramMediaProcessor as jest.Mock).mockImplementation(() => ({
mediaProcessorFactory: {
createProcessor: () => mockMediaProcessor,
},
instagramPosts: [mockPost],
archiveFolder: "/test/folder",
process: mockMediaProcessor.process,
}));
// Mock BlueskyClient for tracking uploads
const mockBlueskyClient = {
login: jest.fn().mockResolvedValue(undefined),
uploadMedia: jest.fn().mockImplementation(() => {
return Promise.resolve({
ref: `test-blob-ref-${mockBlueskyClient.uploadMedia.mock.calls.length}`,
mimeType: "image/jpeg",
size: 1000,
});
}),
createPost: jest.fn().mockImplementation((_, __, embed) => {
// Verify the post contains all images in the embed
expect(embed.images?.length).toBe(4);
return Promise.resolve("https://bsky.app/profile/test/post/test");
}),
};
(BlueskyClient as jest.Mock).mockImplementation(() => mockBlueskyClient);
await main();
// Verify that uploadMedia was called for each image
expect(mockBlueskyClient.uploadMedia).toHaveBeenCalledTimes(4);
// Verify that createPost was called exactly once with all images
expect(mockBlueskyClient.createPost).toHaveBeenCalledTimes(1);
const createPostCall = mockBlueskyClient.createPost.mock.calls[0];
const embedArg = createPostCall[2];
expect(embedArg.images?.length).toBe(4);
// Verify each image in the embed has a unique blob ref
const blobRefs = new Set(embedArg.images?.map((img: any) => img.image.ref));
expect(blobRefs.size).toBe(4);
});
});
describe("Time Formatting Functions", () => {
describe("formatDuration", () => {
test("should format duration with hours and minutes", () => {
const cases = [
{ input: 3600000, expected: "1 hours and 0 minutes" }, // 1 hour
{ input: 5400000, expected: "1 hours and 30 minutes" }, // 1.5 hours
{ input: 900000, expected: "0 hours and 15 minutes" }, // 15 minutes
{ input: 7200000, expected: "2 hours and 0 minutes" }, // 2 hours
{ input: 8100000, expected: "2 hours and 15 minutes" }, // 2.25 hours
];
cases.forEach(({ input, expected }) => {
expect(formatDuration(input)).toBe(expected);
});
});
});
describe("calculateEstimatedTime", () => {
test("should calculate estimated time based on media count", () => {
// API_RATE_LIMIT_DELAY is 3000ms, with 1.1 multiplier
const cases = [
{ mediaCount: 20, expected: "0 hours and 1 minutes" }, // 20 * 3000 * 1.1 = 66000ms
{ mediaCount: 40, expected: "0 hours and 2 minutes" }, // 40 * 3000 * 1.1 = 132000ms
{ mediaCount: 10, expected: "0 hours and 0 minutes" }, // 10 * 3000 * 1.1 = 33000ms
];
cases.forEach(({ mediaCount, expected }) => {
expect(calculateEstimatedTime(mediaCount)).toBe(expected);
});
});
});
});
describe("uploadMediaAndEmbed", () => {
test("should handle multiple images correctly", async () => {
const mockBluesky = {
uploadMedia: jest.fn().mockImplementation((_, __) =>
Promise.resolve({
ref: `test-blob-ref-${mockBluesky.uploadMedia.mock.calls.length}`,
mimeType: "image/jpeg",
size: 1000,
})
),
};
const mockImages = Array(4)
.fill(null)
.map(
(_, index) =>
new ImageMediaProcessResultImpl(
`Test image ${index + 1}`,
"image/jpeg",
Buffer.from("test"),
{ width: 640, height: 640 }
)
);
const result = await uploadMediaAndEmbed(
"Test post text",
mockImages,
mockBluesky as any
);
// Verify correct number of uploads
expect(mockBluesky.uploadMedia).toHaveBeenCalledTimes(4);
expect(result.importedMediaCount).toBe(4);
// Verify the uploaded media structure
expect(result.uploadedMedia).toBeDefined();
const imagesEmbed = result.uploadedMedia as ImagesEmbedImpl;
expect(imagesEmbed.images).toHaveLength(4);
// Verify each image has a unique blob ref
const blobRefs = new Set(imagesEmbed.images.map((img) => img.image.ref));
expect(blobRefs.size).toBe(4);
});
test("should handle video upload correctly", async () => {
const mockBluesky = {
uploadMedia: jest.fn().mockResolvedValue({
ref: "test-video-blob-ref",
mimeType: "video/mp4",
size: 1000,
}),
};
const mockVideo = {
getType: (): "video" => "video",
mediaBuffer: Buffer.from("test-video"),
mimeType: "video/mp4",
mediaText: "Test video",
aspectRatio: { width: 1920, height: 1080 },
};
const result = await uploadMediaAndEmbed(
"Test video post",
[mockVideo],
mockBluesky as any
);
expect(mockBluesky.uploadMedia).toHaveBeenCalledTimes(1);
expect(result.importedMediaCount).toBe(1);
expect(result.uploadedMedia).toBeDefined();
const videoEmbed = result.uploadedMedia as VideoEmbedImpl;
expect(videoEmbed.video.ref).toBe("test-video-blob-ref");
expect(videoEmbed.video.mimeType).toBe("video/mp4");
});
test("should handle upload failures gracefully", async () => {
const mockBluesky = {
uploadMedia: jest.fn().mockRejectedValue(new Error("Upload failed")),
};
const mockImage = new ImageMediaProcessResultImpl(
"Test image that will fail to upload",
"image/jpeg",
Buffer.from("test"),
{ width: 640, height: 640 }
);
const result = await uploadMediaAndEmbed(
"Test failed upload",
[mockImage],
mockBluesky as any
);
expect(mockBluesky.uploadMedia).toHaveBeenCalledTimes(1);
expect(result.importedMediaCount).toBe(0);
expect(result.uploadedMedia).toBeUndefined();
expect(logger.error).toHaveBeenCalledWith(
expect.stringContaining("Upload failed")
);
});
});