-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #119 from adjust/DSM-3000-url-strategy
[DSM-3000] Rework URL strategy
- Loading branch information
Showing
13 changed files
with
426 additions
and
262 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,39 @@ | ||
import type { BaseUrlsMap, UrlStrategy } from '../url-strategy' | ||
import { BaseUrlsMap } from '../url-strategy' | ||
|
||
const urlStrategyModule = jest.requireActual('../url-strategy') | ||
type Endpoints = keyof typeof testEndpoints | ||
|
||
const testEndpoints = { | ||
default: { app: 'app.default', gdpr: '' }, | ||
india: { app: 'app.india', gdpr: '' }, | ||
china: { app: 'app.china', gdpr: '' } | ||
export const testEndpoints = { | ||
default: 'default', | ||
world: 'world', | ||
} | ||
|
||
const singleEndpoint = { default: { app: 'app', gdpr: 'gdpr' } } | ||
|
||
export const mockEndpoints = { | ||
endpoints: testEndpoints, | ||
singleEndpoint | ||
export const singleEndpoint = { | ||
default: 'default' | ||
} | ||
|
||
export function urlStrategyRetries<T>( | ||
sendRequest: (urls: BaseUrlsMap) => Promise<T>, | ||
endpoints: Partial<Record<UrlStrategy, BaseUrlsMap>> = mockEndpoints.endpoints | ||
) { | ||
return urlStrategyModule.urlStrategyRetries(sendRequest, endpoints) | ||
} | ||
export function getBaseUrlsIterator(endpoints: Partial<Record<Endpoints, string>> = singleEndpoint) { | ||
const _urls = [] as BaseUrlsMap[] | ||
|
||
for (const i in endpoints) { | ||
const urlMap = { | ||
app: 'app.' + i, | ||
gdpr: 'gdpr.' + i | ||
} | ||
_urls.push(urlMap) | ||
} | ||
|
||
let _counter = 0 | ||
|
||
export function getBaseUrlsIterator(endpoints: Partial<Record<UrlStrategy, BaseUrlsMap>> = mockEndpoints.singleEndpoint) { | ||
return urlStrategyModule.getBaseUrlsIterator(endpoints) | ||
return { | ||
next: () => { | ||
if (_counter < _urls.length) { | ||
return { value: _urls[_counter++], done: false } | ||
} else { | ||
return { value: undefined, done: true } | ||
} | ||
}, | ||
reset: () => { | ||
_counter = 0 | ||
} | ||
} | ||
} |
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
Oops, something went wrong.