Skip to content

Commit beb2a77

Browse files
Eibon7claude
andcommitted
test(jest): Fix app import pattern - destructure from index.js - Issue #618
### Error Fixed (18 occurrences across 7 files) **Error:** TypeError: app.address is not a function **Root Cause:** - src/index.js exports: `module.exports = { app, server }` - Tests imported: `const app = require('../../src/index')` ❌ - This assigns the entire `{ app, server }` object to variable `app` - When supertest calls `app.address()`, fails because object doesn't have that method **Fix:** - Changed to: `const { app } = require('../../src/index')` ✅ - Destructures `app` from the exported object - Now supertest can call `app.address()` correctly ### Files Modified (7 tests) 1. tests/integration/styleProfileWorkflow.test.js 2. tests/integration/autoApprovalSecurityV2.test.js 3. tests/integration/multiTenantWorkflowComplete.test.js 4. tests/qa/oauth-integration-tests.js 5. tests/qa/token-management-tests.js 6. tests/qa/payload-processing-tests.js 7. tests/qa/webhook-tests.js ### Pattern This is the **same import/export mismatch pattern as logger** (Session #2): - Module exports object with named properties - Tests must destructure to get the specific property - Without destructuring, variable holds the container object, not the property ### Test Results **Before:** - Error: "app.address is not a function" in 18 test cases - autoApprovalSecurityV2.test.js: 0/9 passing **After:** - Error: ✅ RESOLVED - autoApprovalSecurityV2.test.js: Tests run (fail for different reasons - 404s) - **Progress:** Tests now fail on business logic, not Jest/import errors ### Prevention - ✅ Check how module exports before importing - ✅ If exports object, always destructure: `const { item } = require(...)` - ✅ Pattern applies to: app, server, logger, flags, etc. Related: Pattern #10 (logger import), Session #2 (Issue #618) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent f3e46e9 commit beb2a77

File tree

7 files changed

+7
-7
lines changed

7 files changed

+7
-7
lines changed

tests/integration/autoApprovalSecurityV2.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*/
1212

1313
const request = require('supertest');
14-
const app = require('../../src/index');
14+
const { app } = require('../../src/index');
1515
const { supabaseServiceClient } = require('../../src/config/supabase');
1616

1717
// Mock Supabase

tests/integration/multiTenantWorkflowComplete.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*/
1212

1313
const request = require('supertest');
14-
const app = require('../../src/index');
14+
const { app } = require('../../src/index');
1515
const { createClient } = require('@supabase/supabase-js');
1616
const BaseWorker = require('../../src/workers/BaseWorker');
1717
const AnalyzeToxicityWorker = require('../../src/workers/AnalyzeToxicityWorker');

tests/integration/styleProfileWorkflow.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const request = require('supertest');
2-
const app = require('../../src/index');
2+
const { app } = require('../../src/index');
33
const styleProfileService = require('../../src/services/styleProfileService');
44
const queueService = require('../../src/services/queueService');
55
const { supabaseServiceClient } = require('../../src/config/supabase');

tests/qa/oauth-integration-tests.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88

99
const request = require('supertest');
10-
const app = require('../../src/index');
10+
const { app } = require('../../src/index');
1111
const { flags } = require('../../src/config/flags');
1212
const { logger } = require('../../src/utils/logger');
1313

tests/qa/payload-processing-tests.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
const request = require('supertest');
99
const crypto = require('crypto');
10-
const app = require('../../src/index');
10+
const { app } = require('../../src/index');
1111
const { logger } = require('../../src/utils/logger');
1212
const { flags } = require('../../src/config/flags');
1313

tests/qa/token-management-tests.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77

88
const request = require('supertest');
9-
const app = require('../../src/index');
9+
const { app } = require('../../src/index');
1010
const { OAuthProviderFactory } = require('../../src/services/oauthProvider');
1111
const { flags } = require('../../src/config/flags');
1212
const { logger } = require('../../src/utils/logger');

tests/qa/webhook-tests.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
const request = require('supertest');
1212
const crypto = require('crypto');
13-
const app = require('../../src/index');
13+
const { app } = require('../../src/index');
1414
const { logger } = require('../../src/utils/logger');
1515
const { flags } = require('../../src/config/flags');
1616

0 commit comments

Comments
 (0)