Skip to content

Commit

Permalink
test: split out test for error when both style and tone are provided
Browse files Browse the repository at this point in the history
  • Loading branch information
jason-gardella-deepl committed Jan 29, 2025
1 parent ff008a3 commit fcefc29
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
3 changes: 2 additions & 1 deletion tests/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const internalExampleText: Record<string, string> = {
zh: '质子束',
};

const usingMockServer = process.env.DEEPL_MOCK_SERVER_PORT !== undefined;
export const usingMockServer = process.env.DEEPL_MOCK_SERVER_PORT !== undefined;
const usingMockProxyServer =
usingMockServer && process.env.DEEPL_MOCK_PROXY_SERVER_PORT !== undefined;

Expand Down Expand Up @@ -290,4 +290,5 @@ module.exports = {
timeout,
urlToMockRegexp,
proxyConfig,
usingMockServer,
};
36 changes: 22 additions & 14 deletions tests/rephraseText.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by an MIT
// license that can be found in the LICENSE file.

import { exampleText, makeDeeplClient, testTimeout, withRealServer } from './core';
import { exampleText, makeDeeplClient, testTimeout, usingMockServer, withRealServer } from './core';

import { WritingStyle, WritingTone } from './../src/deeplClient';

Expand All @@ -19,7 +19,7 @@ describe('rephrase text', () => {
const deeplClient = makeDeeplClient();
const deeplClientPromise = deeplClient.rephraseText(exampleText.de, 'ja');
await expect(deeplClientPromise).rejects.toBeInstanceOf(Error);
await expect(deeplClientPromise).rejects.toThrow(/Value for 'target_lang' not supported/);
await expect(deeplClientPromise).rejects.toThrow(/Value for '?target_lang'? not supported/);
});

it('should throw an error for unsupported tone', async () => {
Expand Down Expand Up @@ -50,30 +50,38 @@ describe('rephrase text', () => {
);
});

withRealServer(
// TODO: update mock to return error if style and tone are provided
withRealServer('should throw an error if both style and tone are provided', async () => {
const deeplClient = makeDeeplClient();
const deeplClientPromise = deeplClient.rephraseText(
exampleText.de,
'en',
WritingStyle.BUSINESS,
WritingTone.CONFIDENT,
);
await expect(deeplClientPromise).rejects.toBeInstanceOf(Error);
await expect(deeplClientPromise).rejects.toThrow(/Both writing_style and tone defined/);
});

it(
'should rephrase with style and tone',
async () => {
const deeplClient = makeDeeplClient();
const input = 'How are yo dong guys?';

const outputConfident = "Tell me how you're doing, guys.";
const outputConfident = usingMockServer
? 'proton beam'
: "Tell me how you're doing, guys.";
expect(
(await deeplClient.rephraseText(input, 'en', null, WritingTone.CONFIDENT)).text,
).toBe(outputConfident);

const outputBusiness = 'Greetings, gentlemen. How are you?';
const outputBusiness = usingMockServer
? 'proton beam'
: 'Greetings, gentlemen. How are you?';
expect(
(await deeplClient.rephraseText(input, 'en', WritingStyle.BUSINESS, null)).text,
).toBe(outputBusiness);

const deeplClientPromise = deeplClient.rephraseText(
input,
'en',
WritingStyle.BUSINESS,
WritingTone.CONFIDENT,
);
await expect(deeplClientPromise).rejects.toBeInstanceOf(Error);
await expect(deeplClientPromise).rejects.toThrow(/Both writing_style and tone defined/);
},
testTimeout,
);
Expand Down

0 comments on commit fcefc29

Please sign in to comment.