Fix cross-account candidate delivery
This commit is contained in:
1 parent
df35648920
commit
deaf86c364
2 files changed
+64
No files matched your search
@@ -0,0 +1,38 @@
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import type { RedditPost } from '../src/reddit/api.js';
|
||||
import type { RedditAccountRuntimeResources } from '../src/services/reddit-account-runtime.js';
|
||||
import { materializePreparedPostForAccount } from '../src/services/reddit-account-runtime-builder.js';
|
||||
import type { ProcessedPost } from '../src/services/processor.js';
|
||||
|
||||
describe('materializePreparedPostForAccount', () => {
|
||||
it('creates the sending account post row before message persistence', () => {
|
||||
const post: RedditPost = {
|
||||
id: 'post-1', subreddit: 'test', author: 'alice', author_fullname: 't2_alice',
|
||||
title: 'title', url: 'https://example.com/image.jpg', permalink: '/r/test/post-1',
|
||||
thumbnail: '', is_self: false, created_utc: 123, over_18: true, spoiler: false,
|
||||
};
|
||||
const processed: ProcessedPost = {
|
||||
post, imageAnalysis: 'analysis', detectedGender: 'female', generatedMessage: 'message',
|
||||
strategyId: null, experimentId: null, promptVersion: null, selectionReason: null,
|
||||
modelId: 'model', sourceType: 'image', toneId: 'default', scripted: false,
|
||||
};
|
||||
const insertIfAbsent = vi.fn();
|
||||
const updateAnalysis = vi.fn();
|
||||
const resources = {
|
||||
postsRepo: { insertIfAbsent, updateAnalysis },
|
||||
redditApi: {
|
||||
getPostUrl: () => 'https://reddit.example/post-1',
|
||||
getImageUrl: () => 'https://reddit.example/image.jpg',
|
||||
},
|
||||
} as unknown as Pick<RedditAccountRuntimeResources, 'postsRepo' | 'redditApi'>;
|
||||
|
||||
materializePreparedPostForAccount(resources, processed, 456);
|
||||
|
||||
expect(insertIfAbsent).toHaveBeenCalledWith({
|
||||
id: 'post-1', subreddit: 'test', author: 'alice', title: 'title',
|
||||
postUrl: 'https://reddit.example/post-1', imageUrl: 'https://reddit.example/image.jpg',
|
||||
postCreatedAt: 123_000, processedAt: 456,
|
||||
});
|
||||
expect(updateAnalysis).toHaveBeenCalledWith('post-1', 'analysis', 'message');
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user