Skip to content

Commit 0b562f4

Browse files
Add override option for internal testing
1 parent 40c9c3e commit 0b562f4

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

src/translator.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,9 +252,11 @@ export class Translator {
252252
const singular = appendTextsAndReturnIsSingular(data, texts);
253253
validateAndAppendTextOptions(data, options);
254254

255+
const translatePath = options?.__path ?? '/v2/translate';
256+
255257
const { statusCode, content } = await this.httpClient.sendRequestWithBackoff<string>(
256258
'POST',
257-
'/v2/translate',
259+
translatePath,
258260
{ data },
259261
);
260262
await checkStatusCode(statusCode, content);

src/types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,9 @@ export interface TranslateTextOptions {
157157

158158
/** Extra parameters to be added to a text translation request. */
159159
extraRequestParameters?: RequestParameters;
160+
161+
/** (internal only) Override path to send translate request to. */
162+
__path?: string;
160163
}
161164

162165
/**

tests/translateText.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,16 @@ describe('translate text', () => {
6060
expect(result.detectedSourceLang).toBe('en');
6161
});
6262

63+
withMockServer('should translate using overridden path', async () => {
64+
const translator = makeTranslator();
65+
const result = await translator.translateText(exampleText.en, null, 'de', {
66+
__path: '/v2/translate_secondary',
67+
});
68+
expect(result.text).toBe(exampleText.de);
69+
expect(result.detectedSourceLang).toBe('en');
70+
expect(result.billedCharacters).toBe(exampleText.en.length);
71+
});
72+
6373
it('should reject deprecated target codes', async () => {
6474
const translator = makeTranslator();
6575

0 commit comments

Comments
 (0)