feat: replace browser login with imported Reddit sessions
This commit is contained in:
1 parent
2b0545afcf
commit
c483c7b8be
76 files changed
+2048
-2828
No files matched your search
@@ -1,11 +1,13 @@
|
||||
import { describe, it, expect, beforeEach } from 'vitest';
|
||||
import type { Database } from 'better-sqlite3';
|
||||
import { createTestRepositories } from '../tests/testUtils.js';
|
||||
import { createTestDb, createTestRepositories } from '../tests/testUtils.js';
|
||||
import {
|
||||
PostsRepository,
|
||||
MessagesRepository,
|
||||
SuccessfulMessagesRepository,
|
||||
ConversationStateRepository,
|
||||
} from '../src/database/repositories.js';
|
||||
import { buildConversationState } from '../src/services/conversation-state.js';
|
||||
|
||||
describe('PostsRepository', () => {
|
||||
let postsRepo: PostsRepository;
|
||||
@@ -171,6 +173,14 @@ describe('MessagesRepository', () => {
|
||||
db = repos.db;
|
||||
});
|
||||
|
||||
it('returns only sent timestamps within a rolling window', () => {
|
||||
postsRepo.insert({ id: 'window-post', subreddit: 'test', author: 'window-user', title: 'window', imageUrl: null, processedAt: 1 });
|
||||
messagesRepo.insert({ postId: 'window-post', recipient: 'window-user', subject: 's', message: 'm', sentAt: 100 });
|
||||
messagesRepo.insert({ postId: 'window-post', recipient: 'window-user', subject: 's', message: 'm', sentAt: 200 });
|
||||
|
||||
expect(messagesRepo.getSentTimestampsSince(150)).toEqual([200]);
|
||||
});
|
||||
|
||||
it('insertChat stores a chat-originated send and getByChatRoomId returns it', () => {
|
||||
const id = messagesRepo.insertChat({
|
||||
recipient: 'alice',
|
||||
@@ -522,6 +532,24 @@ describe('SuccessfulMessagesRepository', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('ConversationStateRepository', () => {
|
||||
it('persists state by room id and replaces it on later saves', () => {
|
||||
const db = createTestDb();
|
||||
const repo = new ConversationStateRepository(db);
|
||||
const original = buildConversationState([{ sender: 'Me', text: '32M UK, married.', isSelf: true }]);
|
||||
repo.save('!room:reddit.com', original);
|
||||
|
||||
expect(repo.get('!room:reddit.com')).toMatchObject({
|
||||
persona: { age: 32, location: 'UK', relationshipStatus: 'married' },
|
||||
});
|
||||
|
||||
const updated = buildConversationState([{ sender: 'Me', text: '34M UK.', isSelf: true }]);
|
||||
repo.save('!room:reddit.com', updated);
|
||||
expect(repo.get('!room:reddit.com')?.persona.age).toBe(34);
|
||||
expect(repo.get('missing')).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Repository edge cases', () => {
|
||||
it('handles special characters in post titles', () => {
|
||||
const repos = createTestRepositories();
|
||||
|
||||
Reference in new issue
Block a user