Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

arboria

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

arboria - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

42

lib/arboria.js

@@ -27,6 +27,7 @@ var fs = require('fs');

Fixture.prototype._setCollectionName = function(){
this._config.collectionName = path.basename(this._config.fixture);
if(this._config.collectionName === undefined) {
this._config.collectionName = path.basename(this._config.fixture);
}
}
Fixture.prototype.getFixtureData = function(){

@@ -37,20 +38,27 @@ return this._fileToObject(this._config.fixture);

Fixture.prototype._fileToObject = function(file, callback) {
var filePath = path.resolve(process.cwd(), this._config.fixtureDir, file);
var data = require(filePath);
return data;
if (_.isString(this._config.fixture)){
var filePath = path.resolve(process.cwd(), this._config.fixtureDir, file);
var data = require(filePath);
return data;
} else {
return file;
}
};
Fixture.prototype.load = function(callback){
if(this._config.db.serverConfig.isConnected()) {
var collection = this._config.db.collection(this._config.collectionName);
var fixtureData = this._fileToObject(this._config.fixture);
if(_.isArray(fixtureData)){
var done = _.after(fixtureData.length, callback)
for (var i = 0; i < fixtureData.length; i += 1) {
collection.insert(fixtureData[i], done);
var _this = this;
this.remove(function(){
if(_this._config.db.serverConfig.isConnected()) {
var collection = _this._config.db.collection(_this._config.collectionName);
var fixtureData = _this._fileToObject(_this._config.fixture);
if(_.isArray(fixtureData)){
var done = _.after(fixtureData.length, callback)
for (var i = 0; i < fixtureData.length; i += 1) {
collection.insert(fixtureData[i], done);
}
} else {
collection.insert(fixtureData, callback);
}
} else {
collection.insert(fixtureData, callback);
}
}
})
};

@@ -61,3 +69,5 @@

var collection = this._config.db.collection(this._config.collectionName);
collection.drop(callback);
collection.remove(function(){
collection.drop(callback);
});
}

@@ -64,0 +74,0 @@ }

{
"name": "arboria",
"version": "0.0.1",
"version": "0.0.2",
"description": "A fixture loader for mongo (that doesn't db.open)",

@@ -5,0 +5,0 @@ "main": "lib/arboria.js",

@@ -9,4 +9,6 @@ var Fixture = require('../lib/arboria');

it('can take a file path', function(done){
var fixture = new Fixture({fixture: 'people', db: ''})
it('can take a collectionName, fixture and db and get fixture data', function(done){
var server = new Server('localhost', '27017', { native_parser: true });
var _connection = new MongoClient(server);
var fixture = new Fixture({collectionName: 'people', fixture: [{name: 'Shane', age: 25}], db: _connection.db('test')});
var data = fixture.getFixtureData()

@@ -19,5 +21,5 @@ data.should.eql([{ "name": "Shane", "age": 25 }]);

var server = new Server('localhost', '27017', { native_parser: true });
_connection = new MongoClient(server);
var _connection = new MongoClient(server);
_connection.open(function(err, mongoClient) {
var fixture = new Fixture({fixture: 'people', db: mongoClient.db('test')});
var fixture = new Fixture({collectionName: 'people', fixture: {name: 'Shane', age: 25}, db: _connection.db('test')});
fixture.load(done);

@@ -29,5 +31,5 @@ });

var server = new Server('localhost', '27017', { native_parser: true });
_connection = new MongoClient(server);
var _connection = new MongoClient(server);
_connection.open(function(err, mongoClient) {
var fixture = new Fixture({fixture: 'people', db: mongoClient.db('test')});
var fixture = new Fixture({collectionName: 'people', fixture: {name: 'Shane', age: 25}, db: _connection.db('test')});
fixture.load(function(){

@@ -39,2 +41,13 @@ fixture.remove(done);

it('can take in an object instead of a filename', function(done){
var server = new Server('localhost', '27017', { native_parser: true });
var _connection = new MongoClient(server);
_connection.open(function(err, mongoClient) {
var fixture = new Fixture({collectionName: 'people', fixture: {name: 'Shane'}, db: _connection.db('test')});
fixture.load(function(){
fixture.remove(done);
});
});
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc