-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from BonnierNews/clean-entity-history
Clean entity history
- Loading branch information
Showing
6 changed files
with
290 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,3 +31,5 @@ config/_revision | |
|
||
# Atom CTAGS | ||
.tags | ||
|
||
*.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"name": "Debug current test file", | ||
"type": "node", | ||
"request": "launch", | ||
"program": "${workspaceRoot}/node_modules/mocha/bin/_mocha", | ||
"stopOnEntry": false, | ||
"args": [ | ||
"${file}", | ||
"--no-timeouts" | ||
], | ||
"cwd": "${workspaceRoot}", | ||
"runtimeExecutable": null, | ||
"env": { | ||
"NODE_ENV": "testing" | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,183 @@ | ||
"use strict"; | ||
|
||
/* eslint no-undef: 0, new-cap: 0 */ | ||
|
||
const crud = require("../../lib/query"); | ||
const uuid = require("uuid"); | ||
const helper = require("../../lib/testHelper"); | ||
|
||
Feature("Clean version history for given entity", () => { | ||
after(helper.tearDown); | ||
|
||
const attributes = [ | ||
{ name: "J Doe 1" }, | ||
{ name: "J Doe 2" }, | ||
{ name: "anonymous" }, | ||
undefined | ||
]; | ||
|
||
const entity = { | ||
id: uuid.v4(), | ||
type: "person" | ||
}; | ||
|
||
const correlationIds = ["x", "y", "z"]; | ||
const expectedEntity = Object.assign({}, entity, { | ||
attributes: attributes[2], | ||
meta: { | ||
correlationId: correlationIds[2] | ||
}}); | ||
|
||
Scenario("Remove all previous versions of an entity", () => { | ||
let entityVersions; | ||
|
||
before((done) => { | ||
helper.clearAndInit(done); | ||
}); | ||
|
||
Given("a new entity is saved", (done) => { | ||
entity.attributes = attributes[0]; | ||
entity.meta = { correlationId: correlationIds[0] }; | ||
crud.upsert(entity, done); | ||
}); | ||
|
||
And("a second version is added to the entity", (done) => { | ||
entity.attributes = attributes[1]; | ||
entity.meta = { correlationId: correlationIds[1] }; | ||
crud.upsert(entity, done); | ||
}); | ||
|
||
When("cleaning the entity history", (done) => { | ||
entity.attributes = attributes[2]; | ||
entity.meta = { correlationId: correlationIds[2] }; | ||
crud.cleanEntityHistory(entity, done); | ||
}); | ||
|
||
And("we forcefully get all the versions", (done) => { | ||
crud.listVersions(entity.id, true, (err, dbEntity) => { | ||
if (err) return done(err); | ||
entityVersions = dbEntity; | ||
return done(); | ||
}); | ||
}); | ||
|
||
Then("there should only be one version", () => { | ||
entityVersions.length.should.eql(1); | ||
}); | ||
|
||
And("the entity should have the latest attributes", (done) => { | ||
crud.load(entity.id, (err, anonymousEntity) => { | ||
if (err) return done(err); | ||
anonymousEntity.should.eql(expectedEntity); | ||
return done(); | ||
}); | ||
}); | ||
|
||
And("the version should have the latest attributes", (done) => { | ||
crud.loadVersion(entityVersions[0].versionId, (err, res) => { | ||
if (err) return done(err); | ||
res.entity.should.eql(expectedEntity); | ||
res.correlationId.should.equal(correlationIds[2]); | ||
return done(); | ||
}); | ||
}); | ||
}); | ||
|
||
Scenario("Remove all previous versions of an soft deleted entity", () => { | ||
let entityVersions; | ||
|
||
before((done) => { | ||
helper.clearAndInit(done); | ||
}); | ||
|
||
Given("a new entity is saved", (done) => { | ||
entity.attributes = attributes[0]; | ||
entity.meta = { correlationId: correlationIds[0] }; | ||
crud.upsert(entity, done); | ||
}); | ||
|
||
And("a second version is added to the entity", (done) => { | ||
entity.attributes = attributes[1]; | ||
entity.meta = { correlationId: correlationIds[1] }; | ||
crud.upsert(entity, done); | ||
}); | ||
|
||
And("we remove the entity", (done) => { | ||
crud.remove(entity.id, done); | ||
}); | ||
|
||
When("cleaning the entity history", (done) => { | ||
entity.attributes = attributes[2]; | ||
entity.meta = { correlationId: correlationIds[2] }; | ||
crud.cleanEntityHistory(entity, done); | ||
}); | ||
|
||
And("we forcefully get all the versions", (done) => { | ||
crud.listVersions(entity.id, true, (err, dbEntity) => { | ||
if (err) return done(err); | ||
entityVersions = dbEntity; | ||
return done(); | ||
}); | ||
}); | ||
|
||
Then("there should only be one version", () => { | ||
entityVersions.length.should.eql(1); | ||
}); | ||
|
||
And("the entity should have the latest attributes and only possible to fetch forcefully", (done) => { | ||
crud.load(entity.id, true, (err, anonymousEntity) => { | ||
if (err) return done(err); | ||
anonymousEntity.should.eql(expectedEntity); | ||
return done(); | ||
}); | ||
}); | ||
|
||
And("the version should have the latest attributes and only possible to fetch forcefully", (done) => { | ||
crud.loadVersion(entityVersions[0].versionId, true, (err, res) => { | ||
if (err) return done(err); | ||
res.entity.should.eql(expectedEntity); | ||
res.correlationId.should.equal(correlationIds[2]); | ||
return done(); | ||
}); | ||
}); | ||
}); | ||
|
||
Scenario("Remove should only be possible for entities that exists", () => { | ||
before((done) => { | ||
helper.clearAndInit(done); | ||
}); | ||
|
||
Given("there is no entity is saved", () => {}); | ||
|
||
When("cleaning the entity history of an entity that dose not exists", (done) => { | ||
entity.attributes = attributes[2]; | ||
entity.meta = { correlationId: correlationIds[2] }; | ||
crud.cleanEntityHistory(entity, (err) => { | ||
err.message.should.eql("No such entity"); | ||
return done(); | ||
}); | ||
}); | ||
}); | ||
|
||
Scenario("Entity needs to have required fields", () => { | ||
Then("entity needs id", (done) => { | ||
entity.id = null; | ||
entity.attributes = attributes[2]; | ||
entity.meta = { correlationId: correlationIds[2] }; | ||
crud.cleanEntityHistory(entity, (err) => { | ||
err.message.should.contain("Missing required fields in entity:"); | ||
return done(); | ||
}); | ||
}); | ||
|
||
And("entity needs type", (done) => { | ||
entity.type = null; | ||
entity.attributes = attributes[2]; | ||
entity.meta = { correlationId: correlationIds[2] }; | ||
crud.cleanEntityHistory(entity, (err) => { | ||
err.message.should.contain("Missing required fields in entity:"); | ||
return done(); | ||
}); | ||
}); | ||
}); | ||
}); |