Skip to content

Conversation

@dcoric
Copy link
Collaborator

@dcoric dcoric commented Jan 21, 2026

Summary

  • Add MongoDB integration tests for repos, users, and pushes modules
  • Add unit tests for MongoDB helper and modules with comprehensive mocking
  • Add Vitest configuration for integration tests (vitest.config.integration.ts)
  • Add test setup/teardown with proper connection lifecycle management
  • Add Docker Compose configuration for local MongoDB testing
  • Update CI workflow to run integration tests with MongoDB service

Details

Integration Tests

  • test/db/mongo/repo.integration.test.ts - CRUD operations, user permissions, URL lookups
  • test/db/mongo/users.integration.test.ts - User management and authentication
  • test/db/mongo/pushes.integration.test.ts - Push audit log operations

Unit Tests

  • test/db/mongoHelper.test.ts - Connection logic, AWS auth, session store
  • test/db/mongoModules.test.ts - Mocked tests for pushes, repos, users modules

Infrastructure

  • Tests run conditionally: always in CI, locally when RUN_MONGO_TESTS=true
  • Proper cleanup between tests (collection clearing) and after suite (database drop)

Test plan

  • Unit tests pass (npm test)
  • Integration tests pass in CI with MongoDB service
  • Verify local testing with docker run -d -p 27017:27017 mongo:7 && RUN_MONGO_TESTS=true npm run test:integration

@dcoric dcoric requested a review from jescalada January 21, 2026 07:50
@dcoric dcoric self-assigned this Jan 21, 2026
Copy link
Collaborator

@jescalada jescalada left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good so far, will do some more testing after we work out the connection string issues 👍🏼

- name: MongoDB Integration Tests
env:
GIT_PROXY_MONGO_CONNECTION_STRING: mongodb://localhost:27017/git-proxy-test
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might want to import this env as a repository secret.

We can then make a free tier MongoDB which I'm sure will be enough for the occasional E2E test execution.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this meant to run with Docker in the CI? I suppose we could keep the connection string and use a Dockerized Mongo instead - not sure if this will slow down the CI execution though 🤔

},
{
"type": "mongo",
"connectionString": "mongodb://localhost:27017/git-proxy-test",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been thinking about how we can make this work "out-of-the-box".

Since this forces users to set up a local MongoDB instance to run the tests, I feel it's best to make it optional for running tests locally as it adds too much friction for contributors.

Perhaps we could keep the mocked tests from my PR (finos#1356) for code coverage purposes, make the local MongoDB setup optional for integration testing, and then the CI MongoDB integration tests would catch any problematic code if the contributor didn't set up their local Mongo.

What do you think?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, I think it is a good idea to roll with your PR so we get the coverage back, and after that this can be adjusted and push it to a separate PR (without mocked tests)

} from '../../../src/db/mongo/pushes';
import { Action } from '../../../src/proxy/actions';

// Only run in CI where MongoDB is available, or when explicitly enabled locally
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might want to point users to the docs in case something goes wrong because they didn't set MongoDB up properly.

Suggested change
// Only run in CI where MongoDB is available, or when explicitly enabled locally
// Only run in CI where MongoDB is available, or when explicitly enabled locally
// For more details, check the testing documentation:
// https://github.com/finos/git-proxy/blob/main/website/docs/development/testing.mdx

import { Action } from '../../../src/proxy/actions';

// Only run in CI where MongoDB is available, or when explicitly enabled locally
const shouldRunMongoTests = process.env.CI === 'true' || process.env.RUN_MONGO_TESTS === 'true';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering if there should be a single source of truth for shouldRunMongoTests. Right now we have this in each integration test file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants