Skip to content

Commit f410b8e

Browse files
committed
Thingz
1 parent 5f8b8ba commit f410b8e

File tree

3 files changed

+21
-13
lines changed

3 files changed

+21
-13
lines changed

lib/index.js

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,14 @@ class PostgresPersistenceEngine extends AbstractPersistenceEngine {
2626
}
2727

2828
static mapDbModelToSnapshotDomainModel (dbSnapshot) {
29-
return new PersistedSnapshot(
30-
dbSnapshot.data,
31-
Number.parseInt(dbSnapshot.sequence_nr),
32-
dbSnapshot.persistence_key,
33-
Number.parseInt(dbSnapshot.created_at)
34-
);
29+
if (dbSnapshot) {
30+
return new PersistedSnapshot(
31+
dbSnapshot.data,
32+
Number.parseInt(dbSnapshot.sequence_nr),
33+
dbSnapshot.persistence_key,
34+
Number.parseInt(dbSnapshot.created_at)
35+
);
36+
}
3537
}
3638

3739
events (persistenceKey, offset = 0, limit = null, tags) {
@@ -108,12 +110,12 @@ class PostgresPersistenceEngine extends AbstractPersistenceEngine {
108110
RETURNING ordering;
109111
`;
110112
return this.db.one(
111-
query, [
112-
persistedSnapshot.key,
113-
persistedSnapshot.sequenceNumber,
114-
persistedSnapshot.createdAt,
115-
persistedSnapshot.data
116-
]
113+
query, [
114+
persistedSnapshot.key,
115+
persistedSnapshot.sequenceNumber,
116+
persistedSnapshot.createdAt,
117+
persistedSnapshot.data
118+
]
117119
);
118120
}
119121
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nact-persistence-postgres",
3-
"version": "4.0.0",
3+
"version": "4.0.1",
44
"description": "nact-persistence-postgres ⇒ nact + postresql = your services have never been so persistent",
55
"main": "lib/index.js",
66
"scripts": {

test/postgres-persistence.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const chai = require('chai');
44
const chaiAsPromised = require('chai-as-promised');
55
chai.use(chaiAsPromised);
66
chai.should();
7+
const expect = chai.expect;
78
const { Promise } = require('bluebird');
89
const delay = Promise.delay;
910
const { PostgresPersistenceEngine } = require('../lib');
@@ -117,6 +118,11 @@ describe('PostgresPersistenceEngine', function () {
117118
const result = await engine.latestSnapshot('test3');
118119
result.should.deep.equal(snapshot3);
119120
});
121+
122+
it('should be able to correct handle cases where no snapshot is available', async function () {
123+
const result = await engine.latestSnapshot('test4');
124+
expect(result).to.equal(undefined);
125+
});
120126
});
121127

122128
describe('#events', async function () {

0 commit comments

Comments
 (0)