mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-13 20:57:24 +01:00
* add run-rs to dependencies
* wip: add replica set to api unit github action
* wip: add replica set to api unit github action
* wip: fix gh actions mongodb replica set setting
* usa replica set for integration tests
* add correct mongodb version matrix for integration tests
* use different db connection on gh actions
* Revert "use different db connection on gh actions"
This reverts commit aa8db759d3.
* add example transaction
* add mongo script to package.json
* abstract mongodb utils, connect using hostname on windows
* npm scripts: mongo -> mongo:dev
* add setup script for run-rs on windows
* gh actions: run in test environment
* remove test files
* better error handling, use cross-spawn to avoid issues on windows
* fix lint
51 lines
1.9 KiB
JavaScript
51 lines
1.9 KiB
JavaScript
import os from 'os';
|
|
import nconf from 'nconf';
|
|
import requireAgain from 'require-again';
|
|
|
|
const pathToMongoLib = '../../../../website/server/libs/mongodb';
|
|
|
|
describe('mongodb', () => {
|
|
afterEach(() => {
|
|
sandbox.restore();
|
|
});
|
|
|
|
describe('getDevelopmentConnectionUrl', () => {
|
|
it('returns the original connection url if not on windows', () => {
|
|
sandbox.stub(os, 'platform').returns('linux');
|
|
const mongoLibOverride = requireAgain(pathToMongoLib);
|
|
|
|
const originalString = 'mongodb://localhost:3030';
|
|
const string = mongoLibOverride.getDevelopmentConnectionUrl(originalString);
|
|
expect(string).to.equal(originalString);
|
|
});
|
|
|
|
it('replaces localhost with hostname on windows', () => {
|
|
sandbox.stub(os, 'platform').returns('win32');
|
|
sandbox.stub(os, 'hostname').returns('hostname');
|
|
const mongoLibOverride = requireAgain(pathToMongoLib);
|
|
|
|
const originalString = 'mongodb://localhost:3030';
|
|
const string = mongoLibOverride.getDevelopmentConnectionUrl(originalString);
|
|
expect(string).to.equal('mongodb://hostname:3030');
|
|
});
|
|
});
|
|
|
|
describe('getDefaultConnectionOptions', () => {
|
|
it('returns development config when IS_PROD is false', () => {
|
|
sandbox.stub(nconf, 'get').withArgs('IS_PROD').returns(false);
|
|
const mongoLibOverride = requireAgain(pathToMongoLib);
|
|
|
|
const options = mongoLibOverride.getDefaultConnectionOptions();
|
|
expect(options).to.have.all.keys(['useNewUrlParser', 'useUnifiedTopology']);
|
|
});
|
|
|
|
it('returns production config when IS_PROD is true', () => {
|
|
sandbox.stub(nconf, 'get').withArgs('IS_PROD').returns(true);
|
|
const mongoLibOverride = requireAgain(pathToMongoLib);
|
|
|
|
const options = mongoLibOverride.getDefaultConnectionOptions();
|
|
expect(options).to.have.all.keys(['useNewUrlParser', 'useUnifiedTopology', 'keepAlive', 'keepAliveInitialDelay']);
|
|
});
|
|
});
|
|
});
|