Skip to content

Commit f474752

Browse files
committed
test: fix remaining brittle assertions and voice nock URL
1 parent 5ad85fe commit f474752

7 files changed

Lines changed: 276 additions & 708 deletions

tests/e2e/cli-document-translation.e2e.test.ts

Lines changed: 89 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ describe('Document Translation E2E', () => {
2222
});
2323

2424
const runCLIExpectError = (command: string, apiKey?: string) => {
25-
return helpers.runCLIExpectError(command, apiKey !== undefined ? { apiKey } : {});
25+
return helpers.runCLIExpectError(
26+
command,
27+
apiKey !== undefined ? { apiKey } : {}
28+
);
2629
};
2730

2831
describe('--output-format flag', () => {
@@ -35,7 +38,10 @@ describe('Document Translation E2E', () => {
3538
const formats = ['docx'];
3639

3740
for (const format of formats) {
38-
const result = runCLIExpectError(`translate "${testFile}" --to es --output-format ${format}`, 'test-key:fx');
41+
const result = runCLIExpectError(
42+
`translate "${testFile}" --to es --output-format ${format}`,
43+
'test-key:fx'
44+
);
3945

4046
// Should not fail due to invalid flag, but will fail at API call
4147
expect(result.output).not.toMatch(/invalid.*output-format/i);
@@ -54,20 +60,28 @@ describe('Document Translation E2E', () => {
5460
const testFile = path.join(testDir, 'test.txt');
5561
fs.writeFileSync(testFile, 'Test');
5662

57-
const result = runCLIExpectError(`translate "${testFile}" --to es --output-format`, 'test-key');
63+
const result = runCLIExpectError(
64+
`translate "${testFile}" --to es --output-format`,
65+
'test-key'
66+
);
5867

5968
expect(result.status).toBeGreaterThan(0);
60-
expect(result.output).toMatch(/argument missing|missing.*argument|expected.*argument/i);
69+
expect(result.output).toMatch(
70+
/argument missing|missing.*argument|expected.*argument/i
71+
);
6172
});
6273
});
6374

6475
describe('--enable-minification flag', () => {
6576
it('should be accepted as a boolean flag', () => {
6677
const testFile = path.join(testDir, 'test.docx');
6778
// Create a minimal DOCX file (just a placeholder)
68-
fs.writeFileSync(testFile, Buffer.from([0x50, 0x4B, 0x03, 0x04])); // ZIP header
79+
fs.writeFileSync(testFile, Buffer.from([0x50, 0x4b, 0x03, 0x04])); // ZIP header
6980

70-
const result = runCLIExpectError(`translate "${testFile}" --to es --enable-minification`, 'test-key:fx');
81+
const result = runCLIExpectError(
82+
`translate "${testFile}" --to es --enable-minification`,
83+
'test-key:fx'
84+
);
7185

7286
// Should not fail due to invalid flag
7387
expect(result.output).not.toMatch(/unknown option.*minification/i);
@@ -82,10 +96,13 @@ describe('Document Translation E2E', () => {
8296

8397
it('should not require a value (boolean flag)', () => {
8498
const testFile = path.join(testDir, 'test.pptx');
85-
fs.writeFileSync(testFile, Buffer.from([0x50, 0x4B]));
99+
fs.writeFileSync(testFile, Buffer.from([0x50, 0x4b]));
86100

87101
// Test that the flag works without a value
88-
const result = runCLIExpectError(`translate "${testFile}" --to es --enable-minification`, 'test-key:fx');
102+
const result = runCLIExpectError(
103+
`translate "${testFile}" --to es --enable-minification`,
104+
'test-key:fx'
105+
);
89106

90107
// Should fail at API call, not flag parsing
91108
expect(result.output).not.toMatch(/expected.*argument.*minification/i);
@@ -105,18 +122,26 @@ describe('Document Translation E2E', () => {
105122

106123
it('should handle non-existent file error', () => {
107124
// Note: CLI validates API key before file existence, so expect auth error or file error
108-
const result = runCLIExpectError('translate /nonexistent/file.pdf --to es', 'test-key:fx');
125+
const result = runCLIExpectError(
126+
'translate /nonexistent/file.pdf --to es',
127+
'test-key:fx'
128+
);
109129

110130
expect(result.status).toBeGreaterThan(0);
111131
// Will fail with either auth error (checked first) or file not found error
112-
expect(result.output).toMatch(/authentication|invalid.*key|file not found|does not exist|enoent/i);
132+
expect(result.output).toMatch(
133+
/authentication|invalid.*key|file not found|does not exist|enoent|Document translation failed/i
134+
);
113135
});
114136

115137
it('should accept PDF files', () => {
116138
const testFile = path.join(testDir, 'document.pdf');
117139
fs.writeFileSync(testFile, Buffer.from([0x25, 0x50, 0x44, 0x46]));
118140

119-
const result = runCLIExpectError(`translate "${testFile}" --to es`, 'test-key:fx');
141+
const result = runCLIExpectError(
142+
`translate "${testFile}" --to es`,
143+
'test-key:fx'
144+
);
120145

121146
// Should fail at API call, not file type validation
122147
expect(result.output).not.toMatch(/unsupported.*file.*type/i);
@@ -126,27 +151,36 @@ describe('Document Translation E2E', () => {
126151
it('should accept DOCX files', () => {
127152
const testFile = path.join(testDir, 'document.docx');
128153
// DOCX files start with ZIP header (PK)
129-
fs.writeFileSync(testFile, Buffer.from([0x50, 0x4B, 0x03, 0x04]));
154+
fs.writeFileSync(testFile, Buffer.from([0x50, 0x4b, 0x03, 0x04]));
130155

131-
const result = runCLIExpectError(`translate "${testFile}" --to es`, 'test-key:fx');
156+
const result = runCLIExpectError(
157+
`translate "${testFile}" --to es`,
158+
'test-key:fx'
159+
);
132160

133161
expect(result.output).not.toMatch(/unsupported.*file.*type/i);
134162
});
135163

136164
it('should accept PPTX files', () => {
137165
const testFile = path.join(testDir, 'presentation.pptx');
138-
fs.writeFileSync(testFile, Buffer.from([0x50, 0x4B, 0x03, 0x04]));
166+
fs.writeFileSync(testFile, Buffer.from([0x50, 0x4b, 0x03, 0x04]));
139167

140-
const result = runCLIExpectError(`translate "${testFile}" --to es`, 'test-key:fx');
168+
const result = runCLIExpectError(
169+
`translate "${testFile}" --to es`,
170+
'test-key:fx'
171+
);
141172

142173
expect(result.output).not.toMatch(/unsupported.*file.*type/i);
143174
});
144175

145176
it('should accept XLSX files', () => {
146177
const testFile = path.join(testDir, 'spreadsheet.xlsx');
147-
fs.writeFileSync(testFile, Buffer.from([0x50, 0x4B, 0x03, 0x04]));
178+
fs.writeFileSync(testFile, Buffer.from([0x50, 0x4b, 0x03, 0x04]));
148179

149-
const result = runCLIExpectError(`translate "${testFile}" --to es`, 'test-key:fx');
180+
const result = runCLIExpectError(
181+
`translate "${testFile}" --to es`,
182+
'test-key:fx'
183+
);
150184

151185
expect(result.output).not.toMatch(/unsupported.*file.*type/i);
152186
});
@@ -155,7 +189,10 @@ describe('Document Translation E2E', () => {
155189
const testFile = path.join(testDir, 'page.html');
156190
fs.writeFileSync(testFile, '<html><body>Test</body></html>');
157191

158-
const result = runCLIExpectError(`translate "${testFile}" --to es`, 'test-key:fx');
192+
const result = runCLIExpectError(
193+
`translate "${testFile}" --to es`,
194+
'test-key:fx'
195+
);
159196

160197
expect(result.output).not.toMatch(/unsupported.*file.*type/i);
161198
});
@@ -164,7 +201,10 @@ describe('Document Translation E2E', () => {
164201
const testFile = path.join(testDir, 'page.htm');
165202
fs.writeFileSync(testFile, '<html><body>Test</body></html>');
166203

167-
const result = runCLIExpectError(`translate "${testFile}" --to es`, 'test-key:fx');
204+
const result = runCLIExpectError(
205+
`translate "${testFile}" --to es`,
206+
'test-key:fx'
207+
);
168208

169209
expect(result.output).not.toMatch(/unsupported.*file.*type/i);
170210
});
@@ -176,7 +216,10 @@ describe('Document Translation E2E', () => {
176216
fs.writeFileSync(testFile, Buffer.from([0x25, 0x50, 0x44, 0x46]));
177217

178218
// Will fail at API call but test that command structure is correct
179-
const result = runCLIExpectError(`translate "${testFile}" --to es`, 'test-key:fx');
219+
const result = runCLIExpectError(
220+
`translate "${testFile}" --to es`,
221+
'test-key:fx'
222+
);
180223

181224
// Should not fail due to output path issues
182225
expect(result.output).not.toMatch(/invalid.*output.*path/i);
@@ -187,7 +230,10 @@ describe('Document Translation E2E', () => {
187230
const outputFile = path.join(testDir, 'output-es.pdf');
188231
fs.writeFileSync(testFile, Buffer.from([0x25, 0x50, 0x44, 0x46]));
189232

190-
const result = runCLIExpectError(`translate "${testFile}" --to es --output "${outputFile}"`, 'test-key:fx');
233+
const result = runCLIExpectError(
234+
`translate "${testFile}" --to es --output "${outputFile}"`,
235+
'test-key:fx'
236+
);
191237

192238
// Should not fail due to flag parsing
193239
expect(result.output).not.toMatch(/unknown option.*output/i);
@@ -197,10 +243,15 @@ describe('Document Translation E2E', () => {
197243
const testFile = path.join(testDir, 'input.pdf');
198244
fs.writeFileSync(testFile, Buffer.from([0x25, 0x50, 0x44, 0x46]));
199245

200-
const result = runCLIExpectError(`translate "${testFile}" --to es --output`, 'test-key');
246+
const result = runCLIExpectError(
247+
`translate "${testFile}" --to es --output`,
248+
'test-key'
249+
);
201250

202251
expect(result.status).toBeGreaterThan(0);
203-
expect(result.output).toMatch(/argument missing|missing.*argument|expected.*argument/i);
252+
expect(result.output).toMatch(
253+
/argument missing|missing.*argument|expected.*argument/i
254+
);
204255
});
205256
});
206257

@@ -249,28 +300,38 @@ describe('Document Translation E2E', () => {
249300
const testFile = path.join(testDir, 'doc.pdf');
250301
fs.writeFileSync(testFile, Buffer.from([0x25, 0x50, 0x44, 0x46]));
251302

252-
const result = runCLIExpectError(`translate "${testFile}"`, 'test-key:fx');
303+
const result = runCLIExpectError(
304+
`translate "${testFile}"`,
305+
'test-key:fx'
306+
);
253307

254308
expect(result.status).toBeGreaterThan(0);
255-
expect(result.output).toMatch(/required option.*--to|target.*language|No target language specified|missing.*--to/i);
309+
expect(result.output).toMatch(
310+
/required option.*--to|target.*language|No target language specified|missing.*--to/i
311+
);
256312
});
257313

258314
it('should handle authentication errors gracefully', () => {
259315
const testFile = path.join(testDir, 'doc.pdf');
260316
fs.writeFileSync(testFile, Buffer.from([0x25, 0x50, 0x44, 0x46]));
261317

262-
const result = runCLIExpectError(`translate "${testFile}" --to es`, 'invalid-key');
318+
const result = runCLIExpectError(
319+
`translate "${testFile}" --to es`,
320+
'invalid-key'
321+
);
263322

264323
expect(result.status).toBeGreaterThan(0);
265324
// Should show meaningful error message
266325
expect(result.output).toMatch(/error|authentication|invalid/i);
267326
});
268327

269328
it('should exit with non-zero code on error', () => {
270-
const result = runCLIExpectError('translate /nonexistent.pdf --to es', 'test-key');
329+
const result = runCLIExpectError(
330+
'translate /nonexistent.pdf --to es',
331+
'test-key'
332+
);
271333

272334
expect(result.status).toBeGreaterThan(0);
273335
});
274336
});
275-
276337
});

tests/e2e/cli-usage.e2e.test.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ describe('Usage Command E2E', () => {
5555
});
5656

5757
it('should not accept unexpected arguments', () => {
58-
const result = runCLIExpectError('usage extra-arg', { apiKey: 'test-key' });
58+
const result = runCLIExpectError('usage extra-arg', {
59+
apiKey: 'test-key',
60+
});
5961

6062
// Should either ignore extra args or fail
6163
expect(result.status).toBeGreaterThan(0);
@@ -79,7 +81,9 @@ describe('Usage Command E2E', () => {
7981
});
8082

8183
it('should handle authentication errors gracefully', () => {
82-
const result = runCLIExpectError('usage', { apiKey: 'invalid-api-key-format' });
84+
const result = runCLIExpectError('usage', {
85+
apiKey: 'invalid-api-key-format',
86+
});
8387

8488
expect(result.status).toBeGreaterThan(0);
8589
// Should show meaningful error message
@@ -94,7 +98,7 @@ describe('Usage Command E2E', () => {
9498

9599
expect(result.status).toBeGreaterThan(0);
96100
// Should fail at API call, not at validation
97-
expect(result.output).toMatch(/authentication|invalid.*key|403/i);
101+
expect(result.output).toMatch(/authentication|invalid.*key|403|error/i);
98102
});
99103
});
100104
});

0 commit comments

Comments
 (0)