Skip to content

Commit 8e771b5

Browse files
committed
handle mongodb error
1 parent 99275b4 commit 8e771b5

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

billing.js

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
const { setupBilling, OrmType } = require("fdk-billing-javascript");
22
const mongoose = require('mongoose');
33

4-
// Connect to MongoDB (using local MongoDB or MongoDB Atlas)
5-
const MONGODB_URI = process.env.MONGODB_URI || 'mongodb://localhost:27017/fynd-extension-billing';
4+
// Only connect to MongoDB if we're not in test environment
5+
if (process.env.NODE_ENV !== 'test') {
6+
const MONGODB_URI = process.env.MONGODB_URI || 'mongodb://localhost:27017/fynd-extension-billing';
7+
8+
mongoose.connect(MONGODB_URI)
9+
.then(() => {
10+
console.log('Connected to MongoDB for billing');
11+
})
12+
.catch((error) => {
13+
console.error('MongoDB connection error:', error);
14+
});
15+
}
616

7-
// Connect to MongoDB (removed deprecated options)
8-
mongoose.connect(MONGODB_URI)
9-
.then(() => {
10-
console.log('Connected to MongoDB for billing');
11-
})
12-
.catch((error) => {
13-
console.error('MongoDB connection error:', error);
14-
});
15-
16-
// Initialize billing instance
17+
// Initialize billing instance with fallback for tests
1718
const fdkBillingInstance = setupBilling({
18-
extension_id: process.env.EXTENSION_API_KEY,
19+
extension_id: process.env.EXTENSION_API_KEY || "test-extension-key",
1920
db_connection: mongoose.connection,
2021
collection_name: {
2122
plan: "plans",

0 commit comments

Comments
 (0)