Skip to content

Commit

Permalink
Refactor getModuleDependencies() in unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
VadimKovalenkoSNF committed Sep 6, 2023
1 parent 76bf2b1 commit 123e825
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
6 changes: 3 additions & 3 deletions test/unit/downloader.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ describe('Downloader class', () => {
test('getArticle of "London" returns one article', async () => {
const articleId = 'London'
const articleUrl = getArticleUrl(downloader, dump, articleId)
const _moduleDependencies = await downloader.getModuleDependencies(articleId)
const articleDetail = {
title: articleId,
thumbnail: {
Expand All @@ -141,6 +140,7 @@ describe('Downloader class', () => {
timestamp: '2023-08-20T14:54:01Z',
coordinates: '51.50722222;-0.1275',
}
const _moduleDependencies = await downloader.getModuleDependencies(articleDetail.title)
const LondonArticle = await downloader.getArticle(
downloader.webp,
_moduleDependencies,
Expand All @@ -157,14 +157,14 @@ describe('Downloader class', () => {

test('Categories with many subCategories are paginated', async () => {
const articleId = 'Category:Container_categories'
const articleUrl = getArticleUrl(downloader, dump, articleId)
const _moduleDependencies = await downloader.getModuleDependencies(articleId)
const articleDetail = {
title: articleId,
ns: 14,
revisionId: 1168361498,
timestamp: '2023-08-02T09:57:11Z',
}
const articleUrl = getArticleUrl(downloader, dump, articleDetail.title)
const PaginatedArticle = await downloader.getArticle(
downloader.webp,
_moduleDependencies,
Expand All @@ -182,11 +182,11 @@ describe('Downloader class', () => {
test('getArticle response status for non-existent article id is 404', async () => {
const articleId = 'NeverExistingArticle'
const articleUrl = getArticleUrl(downloader, dump, articleId)
const _moduleDependencies = await downloader.getModuleDependencies(articleId)
const articleDetail = {
title: articleId,
missing: '',
}
const _moduleDependencies = await downloader.getModuleDependencies(articleDetail.title)
await expect(
downloader.getArticle(
downloader.webp,
Expand Down
12 changes: 6 additions & 6 deletions test/unit/renderers/article.renderer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe('ArticleRenderer', () => {
it('should return visualeditor content if the main page flag is true', async () => {
const { downloader, dump } = await setupScrapeClasses({ format: '' })
const { data, articleId, articleDetail } = prepareFixtures({ visualeditor: { content: 'Lorem ipsum dolor sit amet' } })
const _moduleDependencies = await downloader.getModuleDependencies(articleId)
const _moduleDependencies = await downloader.getModuleDependencies(articleDetail.title)
const result = await visualEditorRenderer.render({
data,
webp: downloader.webp,
Expand All @@ -58,8 +58,8 @@ describe('ArticleRenderer', () => {
it('should inject header to the visual editor content if the main page flag is false', async () => {
const { downloader, dump } = await setupScrapeClasses({ format: '' })
const content = '<body class="mw-body-content">consectetur adipiscing elit</body>'
const { data, articleId } = prepareFixtures({ visualeditor: { content } })
const _moduleDependencies = await downloader.getModuleDependencies(articleId)
const { data, articleId, articleDetail } = prepareFixtures({ visualeditor: { content } })
const _moduleDependencies = await downloader.getModuleDependencies(articleDetail.title)
const result = await visualEditorRenderer.render({
data,
webp: downloader.webp,
Expand All @@ -78,7 +78,7 @@ describe('ArticleRenderer', () => {
const { downloader, dump } = await setupScrapeClasses({ format: '' })
const htmlBody = '<body>sed do eiusmod tempor incididunt</body>'
const { data, articleId, articleDetail } = prepareFixtures({ html: { body: htmlBody }, contentmodel: 'wikitext' })
const _moduleDependencies = await downloader.getModuleDependencies(articleId)
const _moduleDependencies = await downloader.getModuleDependencies(articleDetail.title)
const result = await visualEditorRenderer.render({
data,
webp: downloader.webp,
Expand All @@ -99,7 +99,7 @@ describe('ArticleRenderer', () => {
const { downloader, dump } = await setupScrapeClasses({ format: '' })
const htmlBody = '<body>ut labore et dolore magna aliqua. Ut enim ad minim veniam</body>'
const { data, articleId, articleDetail } = prepareFixtures({ html: { body: htmlBody } })
const _moduleDependencies = await downloader.getModuleDependencies(articleId)
const _moduleDependencies = await downloader.getModuleDependencies(articleDetail.title)
const result = await visualEditorRenderer.render({
data,
webp: downloader.webp,
Expand All @@ -119,7 +119,7 @@ describe('ArticleRenderer', () => {
it('should return empty string if there was an error during article retrievement', async () => {
const { downloader, dump } = await setupScrapeClasses({ format: '' })
const { data, articleId, articleDetail } = prepareFixtures({ error: 'Unexpected internal error' })
const _moduleDependencies = await downloader.getModuleDependencies(articleId)
const _moduleDependencies = await downloader.getModuleDependencies(articleDetail.title)
const result = await visualEditorRenderer.render({
data,
webp: downloader.webp,
Expand Down
6 changes: 3 additions & 3 deletions test/unit/saveArticles.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ describe('saveArticles', () => {
const wikimediaDesktopRenderer = new WikimediaDesktopRenderer()
const articleId = 'non-existent-article'
const articleUrl = getArticleUrl(downloader, dump, articleId)
const _moduleDependencies = await downloader.getModuleDependencies(articleId)
const articleDetail = { title: 'Non-existent-article', missing: '' }
const _moduleDependencies = await downloader.getModuleDependencies(articleDetail.title)

await expect(
downloader.getArticle(
Expand Down Expand Up @@ -85,11 +85,11 @@ describe('saveArticles', () => {
await downloader.setBaseUrls()
const articleId = 'Main_Page'
const articleUrl = getArticleUrl(downloader, dump, articleId)
const _moduleDependencies = await downloader.getModuleDependencies(articleId)
const _articleDetailsRet = await downloader.getArticleDetailsIds([articleId])
const articlesDetail = mwRetToArticleDetail(_articleDetailsRet)
const { articleDetailXId } = RedisStore
const articleDetail = { title: articleId }
const _moduleDependencies = await downloader.getModuleDependencies(articleDetail.title)
articleDetailXId.setMany(articlesDetail)
const result = await downloader.getArticle(
downloader.webp,
Expand Down Expand Up @@ -248,8 +248,8 @@ describe('saveArticles', () => {
visualeditor: { oldid: 0 },
}

const _moduleDependencies = await downloader.getModuleDependencies(articleId)
const articleDetail = { title: articleId, missing: '' }
const _moduleDependencies = await downloader.getModuleDependencies(articleDetail.title)

const visualEditorRenderer = new VisualEditorRenderer()

Expand Down

0 comments on commit 123e825

Please sign in to comment.