diff --git a/src/system/DeltaProcessor.ts b/src/system/DeltaProcessor.ts index fbb85ac..d68615f 100644 --- a/src/system/DeltaProcessor.ts +++ b/src/system/DeltaProcessor.ts @@ -155,8 +155,8 @@ export class DeltaProcessor */ private _getTimestampSortedDeltas( doc: DeltaDocument ): Delta[] { - const data_deltas = this.getDeltas( doc, this.DELTA_RATEDATA ); - const ratedata_deltas = this.getDeltas( doc, this.DELTA_DATA ); + const data_deltas = this._getDeltas( doc, this.DELTA_RATEDATA ); + const ratedata_deltas = this._getDeltas( doc, this.DELTA_DATA ); const deltas = data_deltas.concat( ratedata_deltas ); deltas.sort( this._sortByTimestamp ); @@ -173,7 +173,7 @@ export class DeltaProcessor * * @return a trimmed list of deltas */ - getDeltas( doc: DeltaDocument, type: DeltaType ): Delta[] + private _getDeltas( doc: DeltaDocument, type: DeltaType ): Delta[] { const deltas_obj = doc.rdelta || >{}; const deltas: Delta[] = deltas_obj[ type ] || []; diff --git a/test/system/DeltaProcessorTest.ts b/test/system/DeltaProcessorTest.ts index 07e288c..0b7c35d 100644 --- a/test/system/DeltaProcessorTest.ts +++ b/test/system/DeltaProcessorTest.ts @@ -22,7 +22,7 @@ import { DeltaProcessor as Sut } from '../../src/system/DeltaProcessor'; import { AmqpPublisher } from '../../src/system/AmqpPublisher'; import { DeltaDao } from '../../src/system/db/DeltaDao'; -import { DeltaType, DeltaDocument } from "../../src/bucket/delta"; +import { DeltaDocument } from "../../src/bucket/delta"; import { DocumentId } from '../../src/document/Document'; import { EventEmitter } from 'events'; @@ -32,128 +32,6 @@ chai_use( require( 'chai-as-promised' ) ); describe( 'system.DeltaProcessor', () => { - describe( '#getDeltas', () => - { - ( <{ - label: string, - type: DeltaType, - given: any, - expected: any - }[]>[ - { - label: 'return empty array if no deltas are present', - type: 'data', - given: { - rdelta: {}, - }, - expected: [], - }, - { - label: 'return full list if no lastPublished index is found', - type: 'data', - given: { - rdelta: { - data: [ - { - data: { foo: [ 'first_bar' ] }, - timestamp: 123, - }, - { - data: { foo: [ 'second_bar' ] }, - timestamp: 234, - }, - ], - }, - }, - expected: [ - { - data: { foo: [ 'first_bar' ] }, - timestamp: 123, - type: 'data', - }, - { - data: { foo: [ 'second_bar' ] }, - timestamp: 234, - type: 'data', - }, - ], - }, - { - label: 'marks deltas with their type', - type: 'data', - given: { - rdelta: { - data: [ - { - data: { foo: [ 'first_bar' ] }, - timestamp: 123, - }, - { - data: { foo: [ 'second_bar' ] }, - timestamp: 234, - }, - ], - }, - totalPublishDelta: { - data: 0, - }, - }, - expected: [ - { - data: { foo: [ 'first_bar' ] }, - timestamp: 123, - type: 'data', - }, - { - data: { foo: [ 'second_bar' ] }, - timestamp: 234, - type: 'data', - }, - ], - }, - { - label: 'trims delta array based on index', - type: 'data', - given: { - rdelta: { - data: [ - { - data: { foo: [ 'first_bar' ] }, - timestamp: 123, - }, - { - data: { foo: [ 'second_bar' ] }, - timestamp: 234, - }, - ], - }, - totalPublishDelta: { - data: 1, - }, - }, - expected: [ - { - data: { foo: [ 'second_bar' ] }, - timestamp: 234, - type: 'data', - }, - ], - }, - ] ).forEach( ( { type, given, expected, label } ) => it( label, () => - { - const sut = new Sut( - createMockDeltaDao(), - createMockDeltaPublisher(), - new EventEmitter(), - ); - - const actual = sut.getDeltas( given, type ); - - expect( actual ).to.deep.equal( expected ); - } ) ); - } ); - - describe( '#process', () => { ( <{ @@ -320,6 +198,40 @@ describe( 'system.DeltaProcessor', () => }, ], }, + { + label: 'trims delta array based on index', + given: [ + { + id: 111, + lastUpdate: 123123123, + data: { foo: [ 'bar' ] }, + ratedata: {}, + rdelta: { + data: [ + { + data: { foo: [ 'first_bar' ] }, + timestamp: 123, + }, + { + data: { foo: [ 'second_bar' ] }, + timestamp: 234, + }, + ], + }, + totalPublishDelta: { + data: 1, + }, + }, + ], + expected: [ + { + doc_id: 111, + delta: { foo: [ 'second_bar' ] }, + bucket: { foo: [ 'second_bar' ] }, + ratedata: {} + }, + ], + }, ] ).forEach( ( { label, given, expected } ) => it( label, () => { let published: any = [];