Skip to content

Commit c0ff433

Browse files
shady-2004MarioRaafatAlyaa242
authored
Test/tweets (#212)
* test(tweets): increased service cov * feat(timeline): for-you v2 (under test) * fix(timeline): circular dependency with bg module * fix(timeline): bug * test(explore): explore unit tests * test(tweets): tweets unit test * test(explore-job): explore job unit tests * test(messages): messages unit test * feat(timeline): v2 done with seen property and interests based * fix(test): unit tests * fix(ci): fix package-lock.json --------- Co-authored-by: Mario Raafat <mariorafat10@gmail.com> Co-authored-by: Mario Raafat <136023677+MarioRaafat@users.noreply.github.com> Co-authored-by: Alyaa Ali <eissaalyaa@gmail.com>
1 parent 217a936 commit c0ff433

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+6315
-476
lines changed

.scannerwork/.sonar_lock

Whitespace-only changes.

package-lock.json

Lines changed: 315 additions & 307 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,10 @@
168168
"!**/enums/**",
169169
"!**/migrations/**",
170170
"!**/seeds/**",
171+
"!**/*.module.ts",
172+
"!**/*.config.ts",
173+
"!**/config/**",
174+
"!**/constants/**",
171175
"!main.ts",
172176
"!**/*.spec.ts",
173177
"!**/*-key.ts",
@@ -179,4 +183,4 @@
179183
"^src/(.*)$": "<rootDir>/$1"
180184
}
181185
}
182-
}
186+
}

sonar-project.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ sonar.test.inclusions=**/*.spec.ts
1111
# Exclude files from analysis
1212
sonar.exclusions=**/node_modules/**,**/dist/**,**/coverage/**,**/*.spec.ts,**/migrations/**,**/seeds/**,**/databases/**,**/*.swagger.ts
1313

14+
# Exclude infrastructure code from coverage (DTOs, Entities, Modules, Configs)
15+
sonar.coverage.exclusions=**/*.dto.ts,**/*.entity.ts,**/*.module.ts,**/config/**,**/migrations/**,**/seeds/**,**/databases/**,**/*.config.ts,**/constants/**,**/*.interface.ts,**/*.enum.ts
16+
1417
# TypeScript specific settings
1518
sonar.typescript.lcov.reportPaths=coverage/lcov.info
1619

src/background-jobs/background-jobs.module.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { FollowProcessor } from './notifications/follow/follow.processor';
1818
import { NotificationsModule } from 'src/notifications/notifications.module';
1919
import { NotificationsGateway } from 'src/notifications/notifications.gateway';
2020
import { User, UserFollows } from 'src/user/entities';
21+
import { UserInterests } from 'src/user/entities/user-interests.entity';
2122
import { TweetReply } from 'src/tweets/entities/tweet-reply.entity';
2223
import { TweetQuote } from 'src/tweets/entities/tweet-quote.entity';
2324
import { ReplyJobService } from './notifications/reply/reply.service';
@@ -52,6 +53,14 @@ import { TweetSummary } from 'src/tweets/entities/tweet-summary.entity';
5253
import { HashtagJobService } from './hashtag/hashtag.service';
5354
import { HashtagProcessor } from './hashtag/hashtag.processor';
5455
import { TrendModule } from 'src/trend/trend.module';
56+
import { TimelineModule } from '../timeline/timeline.module';
57+
import {
58+
CleanupOldTweetsJobService,
59+
InitTimelineQueueJobService,
60+
RefillTimelineQueueJobService,
61+
} from './timeline/timeline.service';
62+
import { TimelineProcessor } from './timeline/timeline.processor';
63+
import { TimelineCron } from './timeline/timeline.cron';
5564

5665
@Module({
5766
imports: [
@@ -144,18 +153,30 @@ import { TrendModule } from 'src/trend/trend.module';
144153
},
145154
},
146155
}),
156+
BullModule.registerQueue({
157+
name: QUEUE_NAMES.TIMELINE,
158+
defaultJobOptions: {
159+
attempts: 3,
160+
backoff: {
161+
type: 'exponential',
162+
delay: 2000,
163+
},
164+
},
165+
}),
147166

148167
TypeOrmModule.forFeature([User]),
149168
TypeOrmModule.forFeature([UserFollows]),
150169
TypeOrmModule.forFeature([Tweet]),
151170
TypeOrmModule.forFeature([TweetSummary]),
152171
TypeOrmModule.forFeature([TweetReply, TweetQuote]),
153172
TypeOrmModule.forFeature([Message]),
173+
TypeOrmModule.forFeature([UserInterests, TweetCategory]),
154174
CommunicationModule,
155175
RedisModuleConfig,
156176
NotificationsModule,
157177
ElasticsearchModule,
158178
TrendModule,
179+
forwardRef(() => TimelineModule),
159180
],
160181
controllers: [ExploreController, EmailJobsController],
161182
providers: [
@@ -192,6 +213,11 @@ import { TrendModule } from 'src/trend/trend.module';
192213
AiSummaryProcessor,
193214
HashtagJobService,
194215
HashtagProcessor,
216+
InitTimelineQueueJobService,
217+
RefillTimelineQueueJobService,
218+
CleanupOldTweetsJobService,
219+
TimelineProcessor,
220+
TimelineCron,
195221
],
196222

197223
exports: [
@@ -220,6 +246,9 @@ import { TrendModule } from 'src/trend/trend.module';
220246
EsFollowJobService,
221247
CompressVideoJobService,
222248
AiSummaryJobService,
249+
InitTimelineQueueJobService,
250+
RefillTimelineQueueJobService,
251+
CleanupOldTweetsJobService,
223252
],
224253
})
225254
export class BackgroundJobsModule {}

src/background-jobs/constants/queue.constants.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ export const JOB_NAMES = {
1515
EMAIL: {
1616
SEND_OTP: 'send-otp-email',
1717
},
18-
TIMELINE: {
19-
PREPARE_FEED: 'prepare-user-feed',
20-
},
2118
FEED: {
2219
INDEX_TWEET: 'index-tweet-to-elastic',
2320
},
@@ -47,6 +44,11 @@ export const JOB_NAMES = {
4744
AI_SUMMARY: {
4845
GENERATE_TWEET_SUMMARY: 'generate-tweet-summary',
4946
},
47+
TIMELINE: {
48+
INIT_QUEUE: 'init-timeline-queue',
49+
REFILL_QUEUE: 'refill-timeline-queue',
50+
CLEANUP_OLD_TWEETS: 'cleanup-old-tweets',
51+
},
5052
HASHTAG: {
5153
UPDATE_HASHTAG: 'update-hashtag',
5254
},

src/background-jobs/explore/explore-jobs.cron.spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,5 +62,13 @@ describe('ExploreJobsCron', () => {
6262

6363
expect(mock_explore_jobs_service.triggerScoreRecalculation).toHaveBeenCalled();
6464
});
65+
66+
it('should handle exceptions thrown during scheduling', async () => {
67+
mock_explore_jobs_service.triggerScoreRecalculation.mockRejectedValue(
68+
new Error('Unexpected error')
69+
);
70+
71+
await expect(cron.scheduleExploreScoreUpdate()).resolves.not.toThrow();
72+
});
6573
});
6674
});

src/background-jobs/explore/explore-jobs.cron.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { ExploreJobsService } from './explore-jobs.service';
1212
export class ExploreJobsCron {
1313
private readonly logger = new Logger(ExploreJobsCron.name);
1414

15+
/* istanbul ignore next */
1516
constructor(private readonly explore_jobs_service: ExploreJobsService) {}
1617

1718
// Schedule explore score update job every hour

0 commit comments

Comments
 (0)