This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
it('should send parsed output to the callback', async () => { | |
queueAgentFeedResponse(fullFeedResponseWithAlt); | |
queueAgentFeedResponse(fullFeedLastResponse); | |
const spy = vi.fn(); | |
await bot.run(handle, 'password', spy); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async streamPosts(handle: string, onUpdate: (results: any) => any) { | |
while (true) { | |
try { | |
const result = await this.#agent.getAuthorFeed({ | |
actor: handle, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
it('should stream posts with done set to false when cursor is truthy', async () => { | |
const spy = vi.fn(); | |
queueAgentFeedResponse(fullFeedResponse); | |
queueAgentFeedResponse(fullFeedResponse); | |
queueAgentFeedResponse(fullFeedLastResponse); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { AltTextBot } from './find-altless-posts.js'; | |
let mockAtpAgent; | |
const resolvedHandle = { | |
did: 'handle-did' | |
}; | |
const resetAtpAgentMock = () => { | |
mockAtpAgent = { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { AltTextBot } from './find-altless-posts.js'; | |
let mockAtpAgent; | |
const resolvedHandle = { | |
did: 'handle-did' | |
}; | |
const resetAtpAgentMock = () => { | |
mockAtpAgent = { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const resetAtpAgentMock = () => { | |
mockAtpAgent = { | |
getPost: vi.fn(), | |
resolveHandle: vi.fn().mockResolvedValue({ | |
data: resolvedHandle | |
}), | |
login: vi.fn() | |
}; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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')); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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); |
NewerOlder