Skip to content

Instantly share code, notes, and snippets.

it('should send parsed output to the callback', async () => {
queueAgentFeedResponse(fullFeedResponseWithAlt);
queueAgentFeedResponse(fullFeedLastResponse);
const spy = vi.fn();
await bot.run(handle, 'password', spy);
describe('run()', () => {
it('should fire the callback on every streaming event', async () => {
queueAgentFeedResponse(fullFeedResponse);
queueAgentFeedResponse(fullFeedLastResponse);
const spy = vi.fn();
await bot.run(handle, 'password', spy);
expect(spy).toHaveBeenCalledTimes(2);
async streamPosts(handle: string, onUpdate: (results: any) => any) {
while (true) {
try {
const result = await this.#agent.getAuthorFeed({
actor: handle,
it('should stream posts with done set to false when cursor is truthy', async () => {
const spy = vi.fn();
queueAgentFeedResponse(fullFeedResponse);
queueAgentFeedResponse(fullFeedResponse);
queueAgentFeedResponse(fullFeedLastResponse);
describe('checkSinglePost()', () => {
it('should return the error message if fetch post failed', async () => {
resetAtpAgentMock();
const postUri = 'postUri';
const bot = new AltTextBot();
const error = { message: 'error' };
mockAtpAgent.getPost.mockRejectedValue(error);
const result = await bot.checkSinglePost(postUri);
import { AltTextBot } from './find-altless-posts.js';
let mockAtpAgent;
const resolvedHandle = {
did: 'handle-did'
};
const resetAtpAgentMock = () => {
mockAtpAgent = {
import { AltTextBot } from './find-altless-posts.js';
let mockAtpAgent;
const resolvedHandle = {
did: 'handle-did'
};
const resetAtpAgentMock = () => {
mockAtpAgent = {
const resetAtpAgentMock = () => {
mockAtpAgent = {
getPost: vi.fn(),
resolveHandle: vi.fn().mockResolvedValue({
data: resolvedHandle
}),
login: vi.fn()
};
}
<!DOCTYPE html>
<html lang="en">
<head>
<script type="module" defer>
import { AltTextBot } from './agent/find-altless-posts.ts';
async function start() {
const bot = new AltTextBot();
console.log(await bot.checkSinglePost('https://bsky.app/profile/yonatankra.com/post/3lczalvz7uk2l'));
}
#returnPostWithAltlessImages(post: { uri: string; cid: string; value: Record; }) {
const images = post.value?.embed?.images || [];
const imagesWithoutAlt = images.filter(img => !img.alt);
return { post, imagesWithoutAlt };
}
async checkSinglePost(postUri: string) {
try {
const post = await this.#agent.getPost(await parsePostUri(postUri, this.#agent));
return this.#returnPostWithAltlessImages(post);