Skip to content

Commit fcefc29

Browse files
test: split out test for error when both style and tone are provided
1 parent ff008a3 commit fcefc29

File tree

2 files changed

+24
-15
lines changed

2 files changed

+24
-15
lines changed

tests/core.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ const internalExampleText: Record<string, string> = {
4747
zh: '质子束',
4848
};
4949

50-
const usingMockServer = process.env.DEEPL_MOCK_SERVER_PORT !== undefined;
50+
export const usingMockServer = process.env.DEEPL_MOCK_SERVER_PORT !== undefined;
5151
const usingMockProxyServer =
5252
usingMockServer && process.env.DEEPL_MOCK_PROXY_SERVER_PORT !== undefined;
5353

@@ -290,4 +290,5 @@ module.exports = {
290290
timeout,
291291
urlToMockRegexp,
292292
proxyConfig,
293+
usingMockServer,
293294
};

tests/rephraseText.test.ts

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by an MIT
33
// license that can be found in the LICENSE file.
44

5-
import { exampleText, makeDeeplClient, testTimeout, withRealServer } from './core';
5+
import { exampleText, makeDeeplClient, testTimeout, usingMockServer, withRealServer } from './core';
66

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

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

2525
it('should throw an error for unsupported tone', async () => {
@@ -50,30 +50,38 @@ describe('rephrase text', () => {
5050
);
5151
});
5252

53-
withRealServer(
53+
// TODO: update mock to return error if style and tone are provided
54+
withRealServer('should throw an error if both style and tone are provided', async () => {
55+
const deeplClient = makeDeeplClient();
56+
const deeplClientPromise = deeplClient.rephraseText(
57+
exampleText.de,
58+
'en',
59+
WritingStyle.BUSINESS,
60+
WritingTone.CONFIDENT,
61+
);
62+
await expect(deeplClientPromise).rejects.toBeInstanceOf(Error);
63+
await expect(deeplClientPromise).rejects.toThrow(/Both writing_style and tone defined/);
64+
});
65+
66+
it(
5467
'should rephrase with style and tone',
5568
async () => {
5669
const deeplClient = makeDeeplClient();
5770
const input = 'How are yo dong guys?';
5871

59-
const outputConfident = "Tell me how you're doing, guys.";
72+
const outputConfident = usingMockServer
73+
? 'proton beam'
74+
: "Tell me how you're doing, guys.";
6075
expect(
6176
(await deeplClient.rephraseText(input, 'en', null, WritingTone.CONFIDENT)).text,
6277
).toBe(outputConfident);
6378

64-
const outputBusiness = 'Greetings, gentlemen. How are you?';
79+
const outputBusiness = usingMockServer
80+
? 'proton beam'
81+
: 'Greetings, gentlemen. How are you?';
6582
expect(
6683
(await deeplClient.rephraseText(input, 'en', WritingStyle.BUSINESS, null)).text,
6784
).toBe(outputBusiness);
68-
69-
const deeplClientPromise = deeplClient.rephraseText(
70-
input,
71-
'en',
72-
WritingStyle.BUSINESS,
73-
WritingTone.CONFIDENT,
74-
);
75-
await expect(deeplClientPromise).rejects.toBeInstanceOf(Error);
76-
await expect(deeplClientPromise).rejects.toThrow(/Both writing_style and tone defined/);
7785
},
7886
testTimeout,
7987
);

0 commit comments

Comments
 (0)