Skip to content

Commit 536edaf

Browse files
committed
fix(test): add article creation in latestArticles tests for accurate ID checks
1 parent f04386f commit 536edaf

File tree

1 file changed

+30
-13
lines changed

1 file changed

+30
-13
lines changed

Diff for: src/connectors/__test__/articleService.test.ts

+30-13
Original file line numberDiff line numberDiff line change
@@ -568,21 +568,36 @@ describe('latestArticles', () => {
568568
value: articleChannelThreshold,
569569
})
570570

571+
// create articles
572+
const [article1] = await articleService.createArticle({
573+
title: 'test',
574+
content: '',
575+
authorId: '1',
576+
})
577+
const [article2] = await articleService.createArticle({
578+
title: 'test2',
579+
content: '',
580+
authorId: '1',
581+
})
582+
const [article3] = await articleService.createArticle({
583+
title: 'test3',
584+
content: '',
585+
authorId: '1',
586+
})
587+
571588
// create channels
572589
const channel = await channelService.updateOrCreateChannel({
573590
name: 'test',
574591
description: 'test',
575592
providerId: 'test-latest',
576593
enabled: true,
577594
})
578-
579595
const channel2 = await channelService.updateOrCreateChannel({
580596
name: 'test2',
581597
description: 'test2',
582598
providerId: 'test-latest2',
583599
enabled: true,
584600
})
585-
586601
const channel3 = await channelService.updateOrCreateChannel({
587602
name: 'test3',
588603
description: 'test3',
@@ -594,7 +609,7 @@ describe('latestArticles', () => {
594609
await atomService.create({
595610
table: 'article_channel',
596611
data: {
597-
articleId: '1',
612+
articleId: article1.id,
598613
channelId: channel.id,
599614
score: articleChannelThreshold + 0.1,
600615
enabled: true,
@@ -603,7 +618,7 @@ describe('latestArticles', () => {
603618
await atomService.create({
604619
table: 'article_channel',
605620
data: {
606-
articleId: '1',
621+
articleId: article2.id,
607622
channelId: channel2.id, // disabled channel
608623
score: articleChannelThreshold + 0.1,
609624
enabled: true,
@@ -613,7 +628,7 @@ describe('latestArticles', () => {
613628
await atomService.create({
614629
table: 'article_channel',
615630
data: {
616-
articleId: '2',
631+
articleId: article3.id,
617632
channelId: channel2.id, // disabled channel
618633
score: articleChannelThreshold + 0.1,
619634
enabled: true,
@@ -623,7 +638,7 @@ describe('latestArticles', () => {
623638
await atomService.create({
624639
table: 'article_channel',
625640
data: {
626-
articleId: '3',
641+
articleId: article3.id,
627642
channelId: channel3.id,
628643
score: articleChannelThreshold + 0.1,
629644
enabled: false, // disabled article channel
@@ -639,9 +654,9 @@ describe('latestArticles', () => {
639654
excludeChannelArticles: false,
640655
})
641656
expect(articles.length).toBe(3)
642-
expect(articles.map(({ id }) => id)).toContain('1')
643-
expect(articles.map(({ id }) => id)).toContain('2')
644-
expect(articles.map(({ id }) => id)).toContain('3')
657+
expect(articles.map(({ id }) => id)).toContain(article1.id)
658+
expect(articles.map(({ id }) => id)).toContain(article2.id)
659+
expect(articles.map(({ id }) => id)).toContain(article3.id)
645660
const [articlesExcludedChannel, totalCount2] =
646661
await articleService.latestArticles({
647662
maxTake: 500,
@@ -651,10 +666,12 @@ describe('latestArticles', () => {
651666
excludeSpam: false,
652667
excludeChannelArticles: true,
653668
})
654-
expect(articlesExcludedChannel.length).toBe(1)
655-
expect(articlesExcludedChannel.map(({ id }) => id)).not.toContain('1')
656-
expect(articlesExcludedChannel.map(({ id }) => id)).toContain('2')
657-
expect(articlesExcludedChannel.map(({ id }) => id)).toContain('3')
669+
expect(articlesExcludedChannel.length).toBe(2)
670+
expect(articlesExcludedChannel.map(({ id }) => id)).not.toContain(
671+
article1.id
672+
)
673+
expect(articlesExcludedChannel.map(({ id }) => id)).toContain(article2.id)
674+
expect(articlesExcludedChannel.map(({ id }) => id)).toContain(article3.id)
658675
expect(totalCount1).toBe(totalCount2 + 1)
659676
})
660677
})

0 commit comments

Comments
 (0)