mgnlq_testmodel_replay
v0.1.9
Published
sample mongoose mock data replay
Downloads
41
Maintainers
Readme
mgnlq_testmodel_replay
The mongo testmodel replay files and an hard coded instantiation hook assuming:
Property | Value (hard coded!)
Mongo DB Connection string | 'mongodb://localhost/testdb' --------------|----------------------- data Folder | mgrecrep/
Note: in default mode no mongo connection is established and REPLAY mode is on. (see mongoose_record_replay)
usage
plain hook:
const Model = require('mgnlq_model');
require('mgnlq_testmodel_replay').getTestModel().then( theModel =>
{
// your code using theModel
Model.releaseModel(theModel);
}
);
just use file storage.
var mongooseMock = require('mongoose_record_replay').instrumentMongoose(require('mongoose'),
'node_modules/mgnlq_testmodel_replay/mgrecrep/',
mode);
var aPromise = undefined;
function getModel() {
if(mode === 'REPLAY') {
// in replay mode during testing, using a singleton is sufficient
aPromise = aPromise || Model.loadModelsOpeningConnection(mongooseMock,'mongodb://localhost/testdb' );
return aPromise;
}
// open a real connection, which has to be closed
return Model.loadModelsOpeningConnection(mongooseMock, 'mongodb://localhost/testdb');
}
environment Switching to Record mode ...
environment variable MGNLQ_TESTMODEL_REPLAY control the mode.
- REPLAY (default)
- RECORD
- OFF (access db)
Beware: the underlying model uses a caching mechanism, thus it attempts to write to folders.
Similar, in RECORD mode, mgrecrep/queries.json and mgrecrep/data may be extened with new files.
Tasks to maintain the model
Rebuilding the model from scratch (raw files)
goto mgnlq_model run env_reset.cmd npm run load_data
Updating the queries
changliest
starting wiht 0.1.1 files are located in the current dir /test/data/mongoose_record_replay/testmodel/ ..