Skip to content

Commit

Permalink
Added freeze
Browse files Browse the repository at this point in the history
  • Loading branch information
ncthbrt committed Jan 17, 2018
1 parent 00e78ec commit f03604d
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/actor.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const systemMap = require('./system-map');
const { ActorReference, TemporaryReference, Nobody } = require('./references');
const Queue = require('denque');
const assert = require('assert');
const freeze = require('deep-freeze-node');
const freeze = require('./freeze');
const { Subject } = require('rxjs');
const { stop } = require('./functions');
const { defaultSupervisionPolicy, SupervisionActions } = require('./supervision');
Expand Down
2 changes: 1 addition & 1 deletion lib/paths.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const freeze = require('deep-freeze-node');
const freeze = require('./freeze');

class ActorPath {
constructor (parts) {
Expand Down
2 changes: 1 addition & 1 deletion lib/persistence/persistence-engine.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const freeze = require('deep-freeze-node');
const freeze = require('../freeze');
const assert = require('assert');

class AbstractPersistenceEngine {
Expand Down
2 changes: 1 addition & 1 deletion lib/persistence/persistent-actor.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require('rxjs');
const { PersistedEvent, PersistedSnapshot } = require('./persistence-engine');
const { Actor } = require('../actor');
const freeze = require('deep-freeze-node');
const freeze = require('../freeze');
const { applyOrThrowIfStopped } = require('../system-map');

class PersistentActor extends Actor {
Expand Down
2 changes: 1 addition & 1 deletion lib/references.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const freeze = require('deep-freeze-node');
const freeze = require('./freeze');

class Nobody {
constructor () {
Expand Down
69 changes: 69 additions & 0 deletions test/freeze.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/* eslint-env mocha */
/* eslint-disable no-unused-expressions */
var freeze = require('../lib/freeze');
require('chai').should();

describe('freeze', function () {
let person = {};
let expectedPerson = {};

beforeEach(function () {
person = {
name: 'John',
surname: 'Johnson',
age: 26,
address: {
street: '1st Street',
city: 'Los Angeles',
country: 'USA'
},
vehicles: ['BMW', 'Ferrari', 'Lamborghini']
};

expectedPerson = {
name: 'John',
surname: 'Johnson',
age: 26,
address: {
street: '1st Street',
city: 'Los Angeles',
country: 'USA'
},
vehicles: ['BMW', 'Ferrari', 'Lamborghini']
};
});

it('should not override any object properties', function () {
person = freeze(person);
person.name = 'Jack';
person.surname = 'Jackson';
person.age = 18;
person.address = {
street: 'Third Street',
city: 'San Francisco',
country: 'USA'
};
person.vehicles = ['Toyota'];
person.name = 'Jack';
person.surname = 'Jackson';
person.age = 18;
person.address.street = 'Third Street';
person.address.city = 'San Francisco';
person.address.country = 'USA';
person.vehicles[0] = 'Toyota';

delete person.vehicles[1];
delete person.vehicles[2];

person.should.deep.equal(expectedPerson, 'any object properties should not be overridden');
});

it('should not add new properties to an object', function () {
person = freeze(person);

person.occupation = 'Lawyer';
person.nickname = 'JJ';

person.should.deep.equal(expectedPerson);
});
});

0 comments on commit f03604d

Please sign in to comment.