1
0
Fork 0

DeltaProcessor: Encapsulate getDeltas and remove redundant tests

getDeltas should be encapsulated.  It looks like it was public for the sake
of the tests, and its behavior can be inferred by looking at the result of
processing.
master
Mike Gerwitz 2019-12-09 15:45:01 -05:00 committed by Austin Schaffer
parent d0a3ba573f
commit 819701eca3
2 changed files with 38 additions and 126 deletions

View File

@ -155,8 +155,8 @@ export class DeltaProcessor
*/
private _getTimestampSortedDeltas( doc: DeltaDocument ): Delta<any>[]
{
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<any>[]
private _getDeltas( doc: DeltaDocument, type: DeltaType ): Delta<any>[]
{
const deltas_obj = doc.rdelta || <ReverseDelta<any>>{};
const deltas: Delta<any>[] = deltas_obj[ type ] || [];

View File

@ -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 = [];