-
-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add connection timeout to S3 and Axios calls, and streamline/generali…
…ze axios options
- Loading branch information
Showing
10 changed files
with
86 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -289,11 +289,16 @@ describe('Downloader class', () => { | |
MediaWiki.base = 'https://en.wikipedia.org' | ||
MediaWiki.getCategories = true | ||
|
||
s3 = new S3(`${s3UrlObj.protocol}//${s3UrlObj.host}/`, { | ||
bucketName: s3UrlObj.query.bucketName, | ||
keyId: s3UrlObj.query.keyId, | ||
secretAccessKey: s3UrlObj.query.secretAccessKey, | ||
}) | ||
s3 = new S3( | ||
`${s3UrlObj.protocol}//${s3UrlObj.host}/`, | ||
{ | ||
bucketName: s3UrlObj.query.bucketName, | ||
keyId: s3UrlObj.query.keyId, | ||
secretAccessKey: s3UrlObj.query.secretAccessKey, | ||
}, | ||
1000 * 60, | ||
false, | ||
) | ||
downloader = new Downloader({ | ||
uaString: `${config.userAgent} ([email protected])`, | ||
speed: 1, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,13 +22,23 @@ import { fileURLToPath } from 'url' | |
import { jest } from '@jest/globals' | ||
import fs from 'fs' | ||
import rimraf from 'rimraf' | ||
import Downloader from '../../src/Downloader.js' | ||
import MediaWiki from '../../src/MediaWiki.js' | ||
import { config } from '../../src/config.js' | ||
|
||
jest.setTimeout(10000) | ||
|
||
const __filename = fileURLToPath(import.meta.url) | ||
const __dirname = path.dirname(__filename) | ||
|
||
describe('Utils', () => { | ||
let downloader: Downloader | ||
|
||
MediaWiki.base = 'https://en.wikipedia.org' // Mandatory setting for proper downloader initialization | ||
beforeAll(async () => { | ||
downloader = new Downloader({ uaString: `${config.userAgent} ([email protected])`, speed: 1, reqTimeout: 1000 * 60, webp: true, optimisationCacheUrl: '' }) | ||
}) | ||
|
||
test('util -> interpolateTranslationString', async () => { | ||
expect(interpolateTranslationString('Hello world', {})).toEqual('Hello world') | ||
expect(interpolateTranslationString('Hello ${name}', { name: 'John' })).toEqual('Hello John') | ||
|
@@ -283,30 +293,30 @@ describe('Utils', () => { | |
}) | ||
|
||
test('One string as parameter', async () => { | ||
const result: string[] = await extractArticleList('testString') | ||
const result: string[] = await extractArticleList('testString', downloader) | ||
expect(result).toEqual(['testString']) | ||
}) | ||
|
||
test('Comma separated strings as parameter', async () => { | ||
const result: string[] = await extractArticleList(argumentsList.join(',')) | ||
const result: string[] = await extractArticleList(argumentsList.join(','), downloader) | ||
expect(result).toEqual(argumentsList) | ||
}) | ||
|
||
test('Filename string as parameter', async () => { | ||
const result: string[] = await extractArticleList(filePath) | ||
const result: string[] = await extractArticleList(filePath, downloader) | ||
expect(result).toEqual(argumentsList) | ||
}) | ||
|
||
test('Comma separated filenames string as parameter', async () => { | ||
const result: string[] = await extractArticleList(`${filePath},${anotherFilePath}`) | ||
const result: string[] = await extractArticleList(`${filePath},${anotherFilePath}`, downloader) | ||
expect(result.sort()).toEqual(argumentsList.concat(anotherArgumentsList)) | ||
}) | ||
|
||
test('URL as parameter', async () => { | ||
jest.spyOn(axios, 'get').mockResolvedValue({ | ||
data: fs.createReadStream(filePath), | ||
}) | ||
const result: string[] = await extractArticleList('http://test.com/strings') | ||
const result: string[] = await extractArticleList('http://test.com/strings', downloader) | ||
expect(result).toEqual(argumentsList) | ||
}) | ||
|
||
|
@@ -317,18 +327,18 @@ describe('Utils', () => { | |
jest.spyOn(axios, 'get').mockResolvedValueOnce({ | ||
data: fs.createReadStream(anotherFilePath), | ||
}) | ||
const result: string[] = await extractArticleList('http://test.com/strings,http://test.com/another-strings') | ||
const result: string[] = await extractArticleList('http://test.com/strings,http://test.com/another-strings', downloader) | ||
expect(result.sort()).toEqual(argumentsList.concat(anotherArgumentsList)) | ||
}) | ||
|
||
test('The parameter starts from HTTP but it is not the URL', async () => { | ||
const result: string[] = await extractArticleList('http-test') | ||
const result: string[] = await extractArticleList('http-test', downloader) | ||
expect(result).toEqual(['http-test']) | ||
}) | ||
|
||
test('Error if trying to get articleList from wrong URL ', async () => { | ||
jest.spyOn(axios, 'get').mockRejectedValue({}) | ||
await expect(extractArticleList('http://valid-wrong-url.com/')).rejects.toThrow('Failed to read articleList from URL: http://valid-wrong-url.com/') | ||
await expect(extractArticleList('http://valid-wrong-url.com/', downloader)).rejects.toThrow('Failed to read articleList from URL: http://valid-wrong-url.com/') | ||
}) | ||
}) | ||
|
||
|