Skip to content

Commit

Permalink
fix: /sources in deltaCache full build (#585)
Browse files Browse the repository at this point in the history
If the request is under /sources we need to build the full
based on all deltas so that the full /sources structure gets
built.

Fixes #584.
  • Loading branch information
tkurki committed Aug 9, 2018
1 parent 0f2dcfa commit efa17a2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
14 changes: 13 additions & 1 deletion lib/deltacache.js
Expand Up @@ -84,7 +84,12 @@ DeltaCache.prototype.buildFull = function (user, path) {
JSON.parse(JSON.stringify(this.defaults))
)

const leaf = getLeafObject(this.cache, path, false, false)
const leaf = getLeafObject(
this.cache,
pathToProcessForFull(path),
false,
false
)
if (leaf) {
const deltas = findDeltas(leaf).map(toDelta)
const secFilter = this.app.securityStrategy.shouldFilterDeltas()
Expand All @@ -96,6 +101,13 @@ DeltaCache.prototype.buildFull = function (user, path) {
return signalk.retrieve()
}

function pathToProcessForFull (pathArray) {
if (pathArray.length > 0 && pathArray[0] === 'sources') {
return []
}
return pathArray
}

DeltaCache.prototype.getCachedDeltas = function (user, contextFilter, key) {
var contexts = []
_.keys(this.cache).forEach(type => {
Expand Down
10 changes: 10 additions & 0 deletions test/deltacache.js
Expand Up @@ -123,4 +123,14 @@ describe('deltacache', () => {
})
})
})

it('returns /sources correctly', function () {
return serverP.then(server => {
return deltaP.then(() => {
var fullTree = server.app.deltaCache.buildFull(null, ['sources'])
fullTree.should.be.validSignalK
fullTree.sources.should.deep.equal({ deltaFromHttp: {} })
})
})
})
})

0 comments on commit efa17a2

Please sign in to comment.