-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove duplicate config and fix tests #37
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
WalkthroughThis pull request updates several key areas of the codebase. The submission service and its related mock service now use a submission object—with tweet identification extracted from a property—rather than a direct ID string. The configuration logic has been refactored by removing the custom dotenv call and validation functions, replacing them with a centralized Changes
Sequence Diagram(s)sequenceDiagram
participant App as Application
participant CS as ConfigService
App->>CS: getInstance()
App->>CS: loadConfig()
CS-->>App: return config data
App->>App: Initialize with config
sequenceDiagram
participant SS as SubmissionService
participant DS as DistributionService
SS->>SS: Receive submission event
SS->>SS: Select submission (existing or new)
SS->>DS: processStreamOutput(feedId, submission)
DS-->>DS: Extract tweetId from submission.tweetId
DS-->>SS: Processed submission acknowledged
Poem
Tip 🌐 Web search-backed reviews and chat
✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (3)
backend/src/__tests__/mocks/distribution-service.mock.ts (1)
7-11
: Consider using a proper type for the submission parameter.While the mock implementation works, using
any
type bypasses TypeScript's type checking. Consider using theTwitterSubmission
type for better type safety.Apply this diff to improve type safety:
- async processStreamOutput(feedId: string, submission: any): Promise<void> { + async processStreamOutput(feedId: string, submission: TwitterSubmission): Promise<void> {backend/src/services/twitter/client.ts (1)
207-224
: Consider a more defensive approach to handling potentially null tweet IDs.While non-null assertions work, a more defensive approach would be safer. Consider adding explicit null checks or using optional chaining.
Apply this diff to make the code more defensive:
- const tweetId = BigInt(tweet.id!); + if (!tweet.id) continue; + const tweetId = BigInt(tweet.id); if (!lastCheckedId || tweetId > lastCheckedId) { allNewTweets.push(tweet); } // Sort chronologically (oldest to newest) allNewTweets.sort((a, b) => { - const aId = BigInt(a.id!); - const bId = BigInt(b.id!); + if (!a.id || !b.id) return 0; + const aId = BigInt(a.id); + const bId = BigInt(b.id); return aId > bId ? 1 : aId < bId ? -1 : 0; }); // Only update last checked ID if we found new tweets if (allNewTweets.length > 0) { // Use the first tweet from the batch since it's the newest (batch comes in newest first) const highestId = batch[0].id; - await this.setLastCheckedTweetId(highestId!); + if (highestId) { + await this.setLastCheckedTweetId(highestId); + } }backend/src/services/submissions/submission.service.ts (1)
351-354
: Consider adding a null check for tweet ID.The function uses a non-null assertion without first checking if the tweet ID exists. Consider adding a defensive check.
Apply this diff to make the code more defensive:
private async handleAcknowledgement(tweet: Tweet): Promise<void> { + if (!tweet.id) return; // Like the tweet - await this.twitterService.likeTweet(tweet.id!); + await this.twitterService.likeTweet(tweet.id);
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
bun.lockb
is excluded by!**/bun.lockb
📒 Files selected for processing (6)
backend/src/__tests__/mocks/distribution-service.mock.ts
(1 hunks)backend/src/config/config.ts
(0 hunks)backend/src/index.ts
(3 hunks)backend/src/services/submissions/submission.service.ts
(3 hunks)backend/src/services/twitter/client.ts
(2 hunks)package.json
(0 hunks)
💤 Files with no reviewable changes (2)
- package.json
- backend/src/config/config.ts
🔇 Additional comments (3)
backend/src/services/twitter/client.ts (1)
112-122
: LGTM! Good addition of credential validation.The validation ensures all required Twitter credentials are present before proceeding with initialization. The error message is descriptive and helpful.
backend/src/index.ts (1)
4-4
: LGTM! Good refactor of configuration management.The changes successfully centralize configuration management through ConfigService, aligning with the PR objective to remove duplicate config.
Also applies to: 40-45
backend/src/services/submissions/submission.service.ts (1)
296-296
: LGTM! Good handling of submission objects.The changes ensure the correct submission object is passed to
processStreamOutput
. The non-null assertion is safe as the submission is guaranteed to exist at this point.Also applies to: 334-334
Summary by CodeRabbit
These updates enhance the system’s reliability and efficiency, resulting in a smoother operational flow and improved handling of social interactions.