|
| 1 | +import { describe, expect, inject, it } from 'vitest'; |
| 2 | + |
| 3 | +import type { AtpSessionData } from '@atcute/client'; |
| 4 | + |
| 5 | +import { createAgent } from '~/tsky'; |
| 6 | + |
| 7 | +describe('createAgent', () => { |
| 8 | + it('can create agent for Alice', async () => { |
| 9 | + const agent = await createAgent( |
| 10 | + { |
| 11 | + identifier: 'alice.test', |
| 12 | + password: 'password', |
| 13 | + }, |
| 14 | + { service: inject('testPdsUrl') }, |
| 15 | + ); |
| 16 | + expect(agent.session).not.toBe(undefined); |
| 17 | + expect(agent.session?.handle).toBe('alice.test'); |
| 18 | + expect(agent.session?.email).toBe('alice.test@example.com'); |
| 19 | + }); |
| 20 | + |
| 21 | + it('can resume from stored session', async () => { |
| 22 | + let session: AtpSessionData; |
| 23 | + { |
| 24 | + const agent = await createAgent( |
| 25 | + { |
| 26 | + identifier: 'alice.test', |
| 27 | + password: 'password', |
| 28 | + }, |
| 29 | + { service: inject('testPdsUrl') }, |
| 30 | + ); |
| 31 | + expect(agent.session).toBeDefined(); |
| 32 | + session = agent.session as AtpSessionData; |
| 33 | + } |
| 34 | + |
| 35 | + { |
| 36 | + const agent = await createAgent( |
| 37 | + { session }, |
| 38 | + { service: inject('testPdsUrl') }, |
| 39 | + ); |
| 40 | + expect(agent.session).not.toBe(undefined); |
| 41 | + expect(agent.session?.handle).toBe('alice.test'); |
| 42 | + expect(agent.session?.email).toBe('alice.test@example.com'); |
| 43 | + } |
| 44 | + }); |
| 45 | +}); |
0 commit comments