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

viewmodel

Package Overview
Dependencies
Maintainers
1
Versions
109
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

viewmodel - npm Package Compare versions

Comparing version 0.1.1 to 0.2.0

.npmignore

5

lib/repository.js

@@ -71,2 +71,3 @@ // lib/queue.js v0.1.0

delete obj.destroy;
delete obj.commit;
delete obj.set;

@@ -88,5 +89,9 @@ delete obj.get;

fromObject: function(obj) {
var self = this;
var vm = _.clone(obj);
vm.actionOnCommit = vm.actionOnCommit || 'update';
vm.destroy = destroy;
vm.commit = function(callback) {
self.commit(this, callback);
};
vm.set = set;

@@ -93,0 +98,0 @@ vm.get = get;

2

package.json
{
"author": "adrai",
"name": "viewmodel",
"version": "0.1.1",
"version": "0.2.0",
"private": false,

@@ -6,0 +6,0 @@ "main": "index.js",

@@ -15,2 +15,3 @@ var expect = require('expect.js')

delete obj.destroy;
delete obj.commit;
delete obj.set;

@@ -33,2 +34,3 @@ delete obj.get;

delete obj.destroy;
delete obj.commit;
delete obj.set;

@@ -40,2 +42,3 @@ delete obj.get;

var vm = _.clone(obj);
var self = this;
vm.actionOnCommit = vm.actionOnCommit || 'update';

@@ -45,2 +48,5 @@ vm.destroy = function() {

};
vm.commit = function(callback) {
self.commit(this, callback);
};
vm.set = function(data) {

@@ -47,0 +53,0 @@ if (arguments.length === 2) {

@@ -15,2 +15,3 @@ var expect = require('expect.js')

delete obj.destroy;
delete obj.commit;
delete obj.set;

@@ -22,2 +23,3 @@ delete obj.get;

var vm = _.clone(obj);
var self = this;
vm.actionOnCommit = vm.actionOnCommit || 'update';

@@ -27,2 +29,5 @@ vm.destroy = function() {

};
vm.commit = function(callback) {
self.commit(this, callback);
};
vm.set = function(data) {

@@ -131,3 +136,3 @@ if (arguments.length === 2) {

it('the returned object should have a set and a get and a destroy function', function(done) {
it('the returned object should have a set and a get and a destroy and a commit function', function(done) {

@@ -138,2 +143,3 @@ dummyRepo.get('1234', function(err, obj) {

expect(obj.destroy).to.be.a('function');
expect(obj.commit).to.be.a('function');
done();

@@ -282,3 +288,3 @@ });

it('the containing objects should have a set and a get and a destroy function', function(done) {
it('the containing objects should have a set and a get and a destroy and a commit function', function(done) {

@@ -294,2 +300,4 @@ dummyRepo.get('4567', function(err, vm1) {

expect(results[1].destroy).to.be.a('function');
expect(results[0].commit).to.be.a('function');
expect(results[1].commit).to.be.a('function');
done();

@@ -624,2 +632,159 @@ });

describe('on a single object', function() {
describe('having an actionOnCommit', function() {
beforeEach(function(done) {
dummyRepo.get('4567', function(err, vm) {
vm.foo = 'bar';
dummyRepo.commit(vm, function(err) {
dummyRepo.get('4568', function(err, vm2) {
vm2.foo = 'wat';
dummyRepo.commit(vm2, done);
});
});
});
});
describe('of create', function() {
describe('on an existing record', function() {
it('it should update the existing record', function(done) {
dummyRepo.get('4567', function(err, vm) {
vm.actionOnCommit = 'create';
vm.foo = 'baz';
vm.commit(function(err) {
dummyRepo.get('4567', function(err, vm2) {
vm.actionOnCommit = 'update';
expect(vm2.id).to.eql(vm.id);
expect(vm2.foo).to.eql(vm.foo);
done();
});
});
});
});
});
describe('on a non-existing record', function() {
it('it should insert a new record', function(done) {
dummyRepo.get('4569', function(err, vm) {
vm.foo = 'baz';
vm.commit(function(err) {
dummyRepo.get('4569', function(err, vm2) {
vm.actionOnCommit = 'update';
expect(vm2.id).to.eql(vm.id);
expect(vm2.foo).to.eql(vm.foo);
done();
});
});
});
});
});
});
describe('of update', function() {
describe('on a non-existing record', function() {
it('it should insert a new record', function(done) {
dummyRepo.get('4569', function(err, vm) {
vm.actionOnCommit = 'update';
vm.foo = 'baz';
vm.commit(function(err) {
dummyRepo.get('4569', function(err, vm2) {
expect(vm2.id).to.eql(vm.id);
expect(vm2.foo).to.eql(vm.foo);
done();
});
});
});
});
});
describe('on an existing record', function() {
it('it should update the existing record', function(done) {
dummyRepo.get('4567', function(err, vm) {
vm.foo = 'baz';
vm.commit(function(err) {
dummyRepo.get('4567', function(err, vm2) {
expect(vm2.id).to.eql(vm.id);
expect(vm2.foo).to.eql(vm.foo);
done();
});
});
});
});
});
});
describe('of delete', function() {
describe('on a non-existing record', function() {
it('it should not modify the view model database', function(done) {
dummyRepo.get('4567', function(err, vm) {
vm.id = '4569';
vm.destroy();
vm.commit(function(err) {
dummyRepo.find(function(err, results) {
expect(results).to.be.an('array');
expect(results).to.have.length(2);
done();
});
});
});
});
});
describe('on an existing record', function() {
it('it should delete the existing record', function(done) {
dummyRepo.get('4567', function(err, vm) {
vm.destroy();
vm.commit(function(err) {
dummyRepo.find(function(err, results) {
expect(results).to.be.an('array');
expect(results).to.have.length(1);
done();
});
});
});
});
});
});
});
});
});

@@ -626,0 +791,0 @@

Sorry, the diff of this file is not supported yet

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