eventsourced
Advanced tools
Comparing version 1.0.6 to 1.0.7
@@ -22,2 +22,5 @@ const EventEmitter = require('events'); | ||
* instance's data. | ||
* | ||
* @todo trap contructor to fire warning | ||
* @todo fire warning when attempting to set properties directly | ||
*/ | ||
@@ -24,0 +27,0 @@ const traps = { |
@@ -33,23 +33,22 @@ const Entity = require('.'); | ||
// console.log('CREATING INSTACE A'); | ||
const a = new TestEntity(); | ||
const instance = new TestEntity(); | ||
tap.equals(Entity.inspect(a).version, 0, 'Version should be 0.'); | ||
tap.equals(Entity.inspect(instance).version, 0, 'Version should be 0.'); | ||
a.on('renamed', () => { | ||
instance.on('renamed', () => { | ||
tap.pass('Should emit "renamed" event'); | ||
tap.equals(Entity.inspect(a).version, 1, 'Version should be 1.'); | ||
tap.equals(a.name, fixtures.b.name, `Name should be ${fixtures.b.name}.`); | ||
tap.equals(Entity.inspect(instance).version, 1, 'Version should be 1.'); | ||
tap.equals(instance.name, fixtures.b.name, `Name should be ${fixtures.b.name}.`); | ||
}); | ||
a.rename(fixtures.b.name); | ||
instance.rename(fixtures.b.name); | ||
a.save(); | ||
tap.equals(Entity.inspect(a).version, 2, 'Version should be 2.'); | ||
tap.equals(Entity.inspect(a).history.length, 2, 'History should contain 2 entries.'); | ||
instance.save(); | ||
tap.equals(Entity.inspect(instance).version, 2, 'Version should be 2.'); | ||
tap.equals(Entity.inspect(instance).history.length, 2, 'History should contain 2 entries.'); | ||
a.touch(); | ||
tap.equals(Entity.inspect(a).version, 2, 'Version should be 2.'); | ||
tap.equals(Entity.inspect(a).history.length, 2, 'History should contain 2 entries.'); | ||
instance.touch(); | ||
tap.equals(Entity.inspect(instance).version, 2, 'Version should be 2.'); | ||
tap.equals(Entity.inspect(instance).history.length, 2, 'History should contain 2 entries.'); | ||
tap.same(Entity.snapshot(a), { | ||
tap.same(Entity.snapshot(instance), { | ||
name: fixtures.b.name, | ||
@@ -61,90 +60,14 @@ foo: 'bar', | ||
tap.test('Manually registering a command', t => { | ||
Entity.registerCommand(a, 'fix', function cmd() { | ||
Entity.registerCommand(instance, 'fix', function cmd() { | ||
this.fixed = true; | ||
}); | ||
const cmdInRegistry = (Entity.getRegisteredCommandsOf(a).indexOf('fix') > -1); | ||
const cmdInRegistry = (Entity.getRegisteredCommandsOf(instance).indexOf('fix') > -1); | ||
t.ok(cmdInRegistry, 'Successfully registers a command.'); | ||
a.on('fixed', () => { | ||
instance.on('fixed', () => { | ||
t.pass('Command fires expected event.'); | ||
t.equals(Entity.inspect(a).version, 3, 'Command increases version.'); | ||
t.equals(a.fixed, true, 'Command changes state.'); | ||
t.equals(Entity.inspect(instance).version, 3, 'Command increases version.'); | ||
t.equals(instance.fixed, true, 'Command changes state.'); | ||
t.end(); | ||
}); | ||
a.fix(); | ||
instance.fix(); | ||
}); | ||
// tap.test('Registering a command', t => { | ||
// Entity.command(i, 'fix', function cmd() { | ||
// this.fixed = true; | ||
// }); | ||
// i.on('fixed', () => { | ||
// t.equals(Entity.version(i), 4, 'Instance version should be 4'); | ||
// t.equals(Entity.history(i).length, 4, 'Instance history should have four events'); | ||
// t.end(); | ||
// }); | ||
// i.fix(); | ||
// }); | ||
// | ||
// tap.test('Recreating an entity from a snapshot', t => { | ||
// const b = new TestEntity(Entity.snapshot(i)); | ||
// console.log(Entity.inspect(b)); | ||
// t.end(); | ||
// }); | ||
// console.log(Entity.inspect(i)); | ||
// console.log(i.set('new@email.com')); | ||
// console.log(Entity.commands(i)); | ||
// console.log(Entity.version(i)); | ||
// console.log(Entity.history(i)); | ||
// console.log(Entity.data(i)); | ||
// console.log(Entity.inspect(i)); | ||
// const i = new Entity(new TestEntity()); | ||
// | ||
// console.log(i.name); | ||
// console.log(i.post()); | ||
// | ||
// | ||
// const b = new Entity(new TestEntity()); | ||
// | ||
// console.log(b.name); | ||
// console.log(b.post()); | ||
// setTimeout(() => { | ||
// console.log(b.post()); | ||
// }, 500); | ||
// | ||
// Entity.getHistoryOf(b); | ||
// Entity.getVersionOf(b); | ||
// Entity.getStateOf(b); | ||
// tap.type(i, TestEntity, 'Instance type should be TestEntity'); | ||
// tap.equals(i.version, 0, 'Instance version should be 0'); | ||
// tap.type(i.history, Array, 'Instance history should be an Array'); | ||
// tap.equals(i.history.length, 0, 'Instance history should be empty'); | ||
// tap.ok(i.data.equals(Map({})), 'Instance data should be {}'); | ||
// tap.equals(i.commands.length, 4, 'Instance should have 2 commands'); | ||
// tap.equals(i.post(), null, 'Instance.post() should return null'); | ||
// i.on('posted', data => { | ||
// tap.equals(data, i.data, 'Emitted data should be {}'); | ||
// }); | ||
// i.post(); | ||
// tap.equals(i.delete(), null, 'Instance.delete() should return null'); | ||
// i.on('deleted', data => { | ||
// tap.same(data, {}, 'Emitted data should be {}'); | ||
// }); | ||
// i.delete(); | ||
// console.log(i.events); | ||
// console.log(nlp.verb('set').conjugate().past); | ||
// console.log(nlp.verb('change').conjugate().past); | ||
// console.log(nlp.verb('changeEmail').conjugate().past); | ||
// | ||
// console.log(nlp.verb('set').conjugate().infinitive); | ||
// console.log(nlp.verb('changed').conjugate().infinitive); | ||
// console.log(nlp.verb('changeEmailed').conjugate().infinitive); |
{ | ||
"name": "eventsourced", | ||
"version": "1.0.6", | ||
"version": "1.0.7", | ||
"description": "An Event Sourcing library for Node", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -73,14 +73,6 @@ # Event Sourced | ||
## Testing | ||
## Scripts | ||
One-off tests can be run as usual: | ||
```bash | ||
npm test | ||
``` | ||
Or you can use `npm start` to continuously run tests on every change. | ||
```bash | ||
npm start | ||
``` | ||
* `npm test` to run one-off tests. | ||
* `npm start` to continuously run tests on every change. | ||
* `npm run cov` to see test coverage report. |
13291
266
78