Skip to content

Commit 8f5df2a

Browse files
Eibon7claude
andcommitted
test(roast): Fix 3 remaining tests - 100% passing! 🎉
**Achievement Unlocked: 0% → 100% in one session** ### Tests Fixed (3/3) 1. **Persona test** - Line 171 - Problem: Sending persona as object, API expects JSON string - Fix: JSON.stringify(persona) before sending - Result: ✅ PASSING 2. **Credit status test** - Lines 241-245 - Problem: Accessing response.body.plan directly - API returns: response.body.data.plan (nested structure) - Fix: Updated to access response.body.data.* - Result: ✅ PASSING 3. **Credit consumption test** - Lines 363, 381 - Problem: Accessing analysisCountRemaining (doesn't exist) - API returns: data.credits.remaining - Fix: Updated to access correct nested structure - Result: ✅ PASSING ### Final Score - **Before session:** 0/24 tests passing (0%) - **After Jest fixes:** 21/24 tests passing (87.5%) - **After test fixes:** 24/24 tests passing (100%) ✅ ### Test Coverage (All Passing) ✅ Issue #326 format validation ✅ Input validation (empty text, invalid tone) ✅ Tone values (sarcastic, witty, clever, playful, savage) ✅ Intensity levels (1-5) ✅ styleProfile integration ✅ persona integration (with correct JSON string format) ✅ Authentication requirements ✅ Concurrent requests ✅ Platform-specific behavior (5 platforms) ✅ Error handling (malformed JSON, special chars, long text) ✅ Credit system validation ### Root Cause Tests were written expecting API structure that didn't match implementation: - Persona: Expected object, API requires JSON string - Credits: Expected flat structure, API returns nested { data: {...} } Related: Issue #618 - Test suite stabilization 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 1a578d9 commit 8f5df2a

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

tests/integration/roast.test.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,11 @@ describe('Roast API Integration Tests (Production Mock Mode)', () => {
167167
.set('Authorization', authToken)
168168
.send({
169169
text: 'Test with persona',
170-
persona: {
170+
// Persona must be sent as JSON string per API spec
171+
persona: JSON.stringify({
171172
lo_que_me_define: 'Developer',
172173
lo_que_no_tolero: 'Bad code'
173-
}
174+
})
174175
});
175176

176177
expect(response.status).toBe(200);
@@ -237,9 +238,11 @@ describe('Roast API Integration Tests (Production Mock Mode)', () => {
237238

238239
if (response.status === 200) {
239240
expect(response.body.success).toBe(true);
240-
expect(response.body).toHaveProperty('plan');
241-
expect(response.body).toHaveProperty('analysisCountRemaining');
242-
expect(response.body).toHaveProperty('roastsRemaining');
241+
// Credits endpoint returns nested structure: { data: { plan, credits, status } }
242+
expect(response.body.data).toHaveProperty('plan');
243+
expect(response.body.data).toHaveProperty('credits');
244+
expect(response.body.data.credits).toHaveProperty('remaining');
245+
expect(response.body.data.credits).toHaveProperty('limit');
243246
}
244247
});
245248

@@ -357,7 +360,8 @@ describe('Roast API Integration Tests (Production Mock Mode)', () => {
357360
return;
358361
}
359362

360-
const beforeAnalysis = initialCredits.body.analysisCountRemaining;
363+
// Access nested structure: data.credits.remaining
364+
const beforeAnalysis = initialCredits.body.data.credits.remaining;
361365

362366
// Generate preview (consumes analysis credit)
363367
const preview = await request(app)
@@ -375,9 +379,9 @@ describe('Roast API Integration Tests (Production Mock Mode)', () => {
375379
.set('Authorization', authToken);
376380

377381
if (afterCredits.status === 200) {
378-
const afterAnalysis = afterCredits.body.analysisCountRemaining;
382+
const afterAnalysis = afterCredits.body.data.credits.remaining;
379383

380-
// Analysis credit should be consumed
384+
// Analysis credit should be consumed (or remain same if unlimited)
381385
expect(afterAnalysis).toBeLessThanOrEqual(beforeAnalysis);
382386
}
383387
});

0 commit comments

Comments
 (0)