|
1 |
| -import { CredentialManager } from '@atcute/client'; |
2 |
| -import { describe, expect, it } from 'vitest'; |
3 |
| -import { Tsky } from '~/index'; |
4 |
| - |
5 |
| -const formatSecret = (secret: string | undefined) => { |
6 |
| - if (!secret) { |
7 |
| - throw new Error('Secret is required'); |
8 |
| - } |
9 |
| - |
10 |
| - return secret.replace(/^tsky /g, '').trim(); |
11 |
| -}; |
12 |
| - |
13 |
| -const TEST_CREDENTIALS = { |
14 |
| - alice: { |
15 |
| - handle: 'alice.tsky.dev', |
16 |
| - did: 'did:plc:jguhdmnjclquqf5lsvkyxqy3', |
17 |
| - password: 'alice_and_bob', |
18 |
| - }, |
19 |
| - bob: { |
20 |
| - handle: 'bob.tsky.dev', |
21 |
| - did: 'did:plc:2ig7akkyfq256j42uxvc4g2h', |
22 |
| - password: 'alice_and_bob', |
23 |
| - }, |
24 |
| -}; |
25 |
| - |
26 |
| -async function getAliceTsky() { |
27 |
| - const manager = new CredentialManager({ service: 'https://bsky.social' }); |
28 |
| - await manager.login({ |
29 |
| - identifier: TEST_CREDENTIALS.alice.handle, |
30 |
| - password: TEST_CREDENTIALS.alice.password, |
31 |
| - }); |
32 |
| - |
33 |
| - return new Tsky(manager); |
34 |
| -} |
35 |
| - |
36 |
| -describe('bsky', () => { |
37 |
| - it('.profile()', async () => { |
38 |
| - const tsky = await getAliceTsky(); |
39 |
| - const profile = await tsky.bsky.profile(TEST_CREDENTIALS.alice.did); |
40 |
| - |
41 |
| - expect(profile).toBeDefined(); |
42 |
| - expect(profile).toHaveProperty('handle', TEST_CREDENTIALS.alice.handle); |
43 |
| - }); |
44 |
| - |
45 |
| - describe('feed', () => { |
46 |
| - it('.timeline()', async () => { |
47 |
| - const tsky = await getAliceTsky(); |
48 |
| - |
49 |
| - const paginator = await tsky.bsky.feed.getTimeline({ |
50 |
| - limit: 30, |
51 |
| - }); |
52 |
| - |
53 |
| - expect(paginator).toBeDefined(); |
54 |
| - expect(paginator.values).toBeDefined(); |
55 |
| - expect(paginator.values).toBeInstanceOf(Array); |
56 |
| - expect(paginator.values.length).toBe(1); // we should get the first page from the paginator |
57 |
| - expect(paginator.values[0].feed.length).toBeGreaterThan(0); // alice has some posts ;) |
58 |
| - expect(paginator.values[0].feed[0]).toHaveProperty('post'); |
59 |
| - }); |
60 |
| - |
61 |
| - it('.feed()', async () => { |
62 |
| - const tsky = await getAliceTsky(); |
63 |
| - |
64 |
| - const paginator = await tsky.bsky.feed.getFeed({ |
65 |
| - // "Birds! 🦉" custom feed |
66 |
| - // - https://bsky.app/profile/daryllmarie.bsky.social/feed/aaagllxbcbsje |
67 |
| - feed: 'at://did:plc:ffkgesg3jsv2j7aagkzrtcvt/app.bsky.feed.generator/aaagllxbcbsje', |
68 |
| - limit: 30, |
69 |
| - }); |
70 |
| - |
71 |
| - expect(paginator).toBeDefined(); |
72 |
| - expect(paginator.values).toBeDefined(); |
73 |
| - expect(paginator.values).toBeInstanceOf(Array); |
74 |
| - expect(paginator.values.length).toBe(1); // we should get the first page from the paginator |
75 |
| - expect(paginator.values[0].feed.length).toBeGreaterThan(0); // we found some birds posts ;) |
76 |
| - expect(paginator.values[0].feed[0]).toHaveProperty('post'); |
77 |
| - }); |
78 |
| - }); |
79 |
| -}); |
| 1 | +import { CredentialManager } from '@atcute/client'; |
| 2 | +import { describe, expect, it } from 'vitest'; |
| 3 | +import { Tsky } from '~/index'; |
| 4 | + |
| 5 | +const formatSecret = (secret: string | undefined) => { |
| 6 | + if (!secret) { |
| 7 | + throw new Error('Secret is required'); |
| 8 | + } |
| 9 | + |
| 10 | + return secret.replace(/^tsky /g, '').trim(); |
| 11 | +}; |
| 12 | + |
| 13 | +const TEST_CREDENTIALS = { |
| 14 | + alice: { |
| 15 | + handle: 'alice.tsky.dev', |
| 16 | + did: 'did:plc:jguhdmnjclquqf5lsvkyxqy3', |
| 17 | + password: 'alice_and_bob', |
| 18 | + }, |
| 19 | + bob: { |
| 20 | + handle: 'bob.tsky.dev', |
| 21 | + did: 'did:plc:2ig7akkyfq256j42uxvc4g2h', |
| 22 | + password: 'alice_and_bob', |
| 23 | + }, |
| 24 | +}; |
| 25 | + |
| 26 | +async function getAliceTsky() { |
| 27 | + const manager = new CredentialManager({ service: 'https://bsky.social' }); |
| 28 | + await manager.login({ |
| 29 | + identifier: TEST_CREDENTIALS.alice.handle, |
| 30 | + password: TEST_CREDENTIALS.alice.password, |
| 31 | + }); |
| 32 | + |
| 33 | + return new Tsky(manager); |
| 34 | +} |
| 35 | + |
| 36 | +describe('bsky', () => { |
| 37 | + it('.profile()', async () => { |
| 38 | + const tsky = await getAliceTsky(); |
| 39 | + const profile = await tsky.bsky.profile(TEST_CREDENTIALS.alice.did); |
| 40 | + |
| 41 | + expect(profile).toBeDefined(); |
| 42 | + expect(profile).toHaveProperty('handle', TEST_CREDENTIALS.alice.handle); |
| 43 | + }); |
| 44 | + |
| 45 | + describe('feed', () => { |
| 46 | + it('.timeline()', async () => { |
| 47 | + const tsky = await getAliceTsky(); |
| 48 | + |
| 49 | + const paginator = await tsky.bsky.feed.getTimeline({ |
| 50 | + limit: 30, |
| 51 | + }); |
| 52 | + |
| 53 | + expect(paginator).toBeDefined(); |
| 54 | + expect(paginator.values).toBeDefined(); |
| 55 | + expect(paginator.values).toBeInstanceOf(Array); |
| 56 | + expect(paginator.values.length).toBe(1); // we should get the first page from the paginator |
| 57 | + expect(paginator.values[0].feed.length).toBeGreaterThan(0); // alice has some posts ;) |
| 58 | + expect(paginator.values[0].feed[0]).toHaveProperty('post'); |
| 59 | + }); |
| 60 | + |
| 61 | + it('.feed()', async () => { |
| 62 | + const tsky = await getAliceTsky(); |
| 63 | + |
| 64 | + const paginator = await tsky.bsky.feed.getFeed({ |
| 65 | + // "Birds! 🦉" custom feed |
| 66 | + // - https://bsky.app/profile/daryllmarie.bsky.social/feed/aaagllxbcbsje |
| 67 | + feed: 'at://did:plc:ffkgesg3jsv2j7aagkzrtcvt/app.bsky.feed.generator/aaagllxbcbsje', |
| 68 | + limit: 30, |
| 69 | + }); |
| 70 | + |
| 71 | + expect(paginator).toBeDefined(); |
| 72 | + expect(paginator.values).toBeDefined(); |
| 73 | + expect(paginator.values).toBeInstanceOf(Array); |
| 74 | + expect(paginator.values.length).toBe(1); // we should get the first page from the paginator |
| 75 | + expect(paginator.values[0].feed.length).toBeGreaterThan(0); // we found some birds posts ;) |
| 76 | + expect(paginator.values[0].feed[0]).toHaveProperty('post'); |
| 77 | + }); |
| 78 | + }); |
| 79 | +}); |
0 commit comments