2019-11-12 15:07:37 -05:00
|
|
|
/**
|
|
|
|
* Delta Processor test
|
|
|
|
*
|
|
|
|
* Copyright (C) 2010-2019 R-T Specialty, LLC.
|
|
|
|
*
|
|
|
|
* This file is part of the Liza Data Collection Framework.
|
|
|
|
*
|
|
|
|
* liza is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import { DeltaProcessor as Sut } from '../../src/system/DeltaProcessor';
|
2019-11-12 16:41:31 -05:00
|
|
|
import { AmqpPublisher } from '../../src/system/AmqpPublisher';
|
2019-11-12 15:07:37 -05:00
|
|
|
import { DeltaDao } from '../../src/system/db/DeltaDao';
|
2019-12-10 17:24:19 -05:00
|
|
|
import { DeltaDocument } from '../../src/bucket/delta';
|
2019-12-02 10:00:23 -05:00
|
|
|
import { DocumentId } from '../../src/document/Document';
|
2019-11-25 12:42:03 -05:00
|
|
|
import { EventEmitter } from 'events';
|
2019-11-12 15:07:37 -05:00
|
|
|
|
|
|
|
import { expect, use as chai_use } from 'chai';
|
|
|
|
chai_use( require( 'chai-as-promised' ) );
|
|
|
|
|
|
|
|
|
|
|
|
describe( 'system.DeltaProcessor', () =>
|
|
|
|
{
|
2019-11-26 19:31:39 -05:00
|
|
|
describe( '#process', () =>
|
|
|
|
{
|
|
|
|
( <{
|
|
|
|
label: string,
|
|
|
|
given: any[],
|
|
|
|
expected: any
|
|
|
|
}[]>[
|
|
|
|
{
|
2019-12-10 17:24:19 -05:00
|
|
|
label: 'No deltas are processed',
|
2019-12-02 10:00:23 -05:00
|
|
|
given: [
|
2019-11-26 19:31:39 -05:00
|
|
|
{
|
|
|
|
id: 123,
|
|
|
|
lastUpdate: 123123123,
|
2019-12-02 10:00:23 -05:00
|
|
|
data: {},
|
|
|
|
ratedata: {},
|
2019-11-26 19:31:39 -05:00
|
|
|
rdelta: {},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
expected: [],
|
|
|
|
},
|
2019-12-10 12:27:56 -05:00
|
|
|
|
2019-12-10 17:24:19 -05:00
|
|
|
// when quote is initialized: { foo: [ '' ], state: [ 'a' ] }
|
2019-11-26 19:31:39 -05:00
|
|
|
{
|
2019-12-10 17:24:19 -05:00
|
|
|
label: 'Publishes deltas in order',
|
2019-12-10 12:27:56 -05:00
|
|
|
|
2019-11-26 19:31:39 -05:00
|
|
|
given: [
|
|
|
|
{
|
|
|
|
id: 123,
|
|
|
|
lastUpdate: 123123123,
|
2019-12-10 12:27:56 -05:00
|
|
|
|
|
|
|
data: {
|
2019-12-10 17:24:19 -05:00
|
|
|
foo: [ 'third' ],
|
|
|
|
state: [ 'a', 'b', 'c', 'd' ],
|
2019-12-10 12:27:56 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
ratedata: {
|
2019-12-10 17:24:19 -05:00
|
|
|
prem: [ 'rate_second' ],
|
|
|
|
state: [ 'i', 'ii', 'iii' ],
|
2019-12-10 12:27:56 -05:00
|
|
|
},
|
|
|
|
|
2019-11-26 19:31:39 -05:00
|
|
|
rdelta: {
|
|
|
|
data: [
|
|
|
|
{
|
2019-12-10 12:27:56 -05:00
|
|
|
timestamp: 1,
|
|
|
|
data: {
|
2019-12-10 17:24:19 -05:00
|
|
|
foo: [ '' ],
|
2019-12-10 12:27:56 -05:00
|
|
|
state: [ undefined, null ],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
timestamp: 3,
|
|
|
|
data: {
|
2019-12-10 17:24:19 -05:00
|
|
|
foo: [ 'first' ],
|
2019-12-10 12:27:56 -05:00
|
|
|
state: [ undefined, undefined, null ],
|
|
|
|
},
|
2019-11-26 19:31:39 -05:00
|
|
|
},
|
|
|
|
{
|
2019-12-10 12:27:56 -05:00
|
|
|
timestamp: 5,
|
|
|
|
data: {
|
2019-12-10 17:24:19 -05:00
|
|
|
foo: [ 'second' ],
|
2019-12-10 12:27:56 -05:00
|
|
|
state: [ undefined, undefined, undefined, null ],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
|
|
|
|
ratedata: [
|
|
|
|
{
|
|
|
|
timestamp: 2,
|
|
|
|
data: {
|
2019-12-10 17:24:19 -05:00
|
|
|
prem: [ '' ],
|
2019-12-10 12:27:56 -05:00
|
|
|
state: [ undefined, null ],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
timestamp: 4,
|
|
|
|
data: {
|
2019-12-10 17:24:19 -05:00
|
|
|
prem: [ 'rate_first' ],
|
2019-12-10 12:27:56 -05:00
|
|
|
state: [ undefined, undefined, null ],
|
|
|
|
},
|
2019-11-26 19:31:39 -05:00
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
2019-12-10 12:27:56 -05:00
|
|
|
|
2019-11-26 19:31:39 -05:00
|
|
|
expected: [
|
2019-12-10 12:27:56 -05:00
|
|
|
// bucket
|
2019-11-26 19:31:39 -05:00
|
|
|
{
|
2019-12-02 10:00:23 -05:00
|
|
|
doc_id: 123,
|
2019-12-10 12:27:56 -05:00
|
|
|
rdelta: {
|
2019-12-10 17:24:19 -05:00
|
|
|
foo: [ '' ],
|
2019-12-10 12:27:56 -05:00
|
|
|
state: [ undefined, null ],
|
|
|
|
},
|
|
|
|
bucket: {
|
2019-12-10 17:24:19 -05:00
|
|
|
foo: [ 'first' ],
|
|
|
|
state: [ 'a', 'b' ],
|
2019-12-10 12:27:56 -05:00
|
|
|
},
|
2019-12-02 10:00:23 -05:00
|
|
|
ratedata: {},
|
2019-11-26 19:31:39 -05:00
|
|
|
},
|
2019-12-10 12:27:56 -05:00
|
|
|
|
|
|
|
// rate
|
2019-11-26 19:31:39 -05:00
|
|
|
{
|
2019-12-02 10:00:23 -05:00
|
|
|
doc_id: 123,
|
2019-12-10 12:27:56 -05:00
|
|
|
rdelta: {
|
2019-12-10 17:24:19 -05:00
|
|
|
prem: [ '' ],
|
2019-12-10 12:27:56 -05:00
|
|
|
state: [ undefined, null ],
|
|
|
|
},
|
|
|
|
bucket: {
|
2019-12-10 17:24:19 -05:00
|
|
|
foo: [ 'first' ],
|
|
|
|
state: [ 'a', 'b' ],
|
2019-12-10 12:27:56 -05:00
|
|
|
},
|
|
|
|
ratedata: {
|
2019-12-10 17:24:19 -05:00
|
|
|
prem: [ 'rate_first' ],
|
|
|
|
state: [ 'i', 'ii' ],
|
2019-12-10 12:27:56 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
// bucket
|
|
|
|
{
|
|
|
|
doc_id: 123,
|
|
|
|
rdelta: {
|
2019-12-10 17:24:19 -05:00
|
|
|
foo: [ 'first' ],
|
2019-12-10 12:27:56 -05:00
|
|
|
state: [ undefined, undefined, null ],
|
|
|
|
},
|
|
|
|
bucket: {
|
2019-12-10 17:24:19 -05:00
|
|
|
foo: [ 'second' ],
|
|
|
|
state: [ 'a', 'b', 'c' ],
|
2019-12-10 12:27:56 -05:00
|
|
|
},
|
|
|
|
ratedata: {},
|
|
|
|
},
|
|
|
|
|
|
|
|
// rate
|
|
|
|
{
|
|
|
|
doc_id: 123,
|
|
|
|
rdelta: {
|
2019-12-10 17:24:19 -05:00
|
|
|
prem: [ 'rate_first' ],
|
2019-12-10 12:27:56 -05:00
|
|
|
state: [ undefined, undefined, null ],
|
|
|
|
},
|
|
|
|
bucket: {
|
2019-12-10 17:24:19 -05:00
|
|
|
foo: [ 'second' ],
|
|
|
|
state: [ 'a', 'b', 'c' ],
|
2019-12-10 12:27:56 -05:00
|
|
|
},
|
|
|
|
ratedata: {
|
2019-12-10 17:24:19 -05:00
|
|
|
prem: [ 'rate_second' ],
|
|
|
|
state: [ 'i', 'ii', 'iii' ],
|
2019-12-10 12:27:56 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
// bucket
|
|
|
|
{
|
|
|
|
doc_id: 123,
|
|
|
|
rdelta: {
|
2019-12-10 17:24:19 -05:00
|
|
|
foo: [ 'second' ],
|
2019-12-10 12:27:56 -05:00
|
|
|
state: [ undefined, undefined, undefined, null ],
|
|
|
|
},
|
|
|
|
bucket: {
|
2019-12-10 17:24:19 -05:00
|
|
|
foo: [ 'third' ],
|
|
|
|
state: [ 'a', 'b', 'c', 'd' ],
|
2019-12-10 12:27:56 -05:00
|
|
|
},
|
2019-12-02 10:00:23 -05:00
|
|
|
ratedata: {},
|
2019-11-26 19:31:39 -05:00
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
2019-12-10 12:27:56 -05:00
|
|
|
|
2019-11-26 19:31:39 -05:00
|
|
|
{
|
2019-12-10 17:24:19 -05:00
|
|
|
label: 'Publishes deltas in order for multiple documents',
|
2019-12-10 12:27:56 -05:00
|
|
|
|
2019-11-26 19:31:39 -05:00
|
|
|
given: [
|
|
|
|
{
|
|
|
|
id: 123,
|
|
|
|
lastUpdate: 123123123,
|
2019-12-10 12:27:56 -05:00
|
|
|
|
|
|
|
data: {
|
2019-12-10 17:24:19 -05:00
|
|
|
foo: [ 'first' ],
|
|
|
|
state: [ 'a', 'b' ],
|
2019-12-10 12:27:56 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
ratedata: {
|
2019-12-10 17:24:19 -05:00
|
|
|
prem: [ 'rate_first' ],
|
|
|
|
state: [ 'i', 'ii' ],
|
2019-12-10 12:27:56 -05:00
|
|
|
},
|
|
|
|
|
2019-11-26 19:31:39 -05:00
|
|
|
rdelta: {
|
|
|
|
data: [
|
|
|
|
{
|
2019-12-10 12:27:56 -05:00
|
|
|
timestamp: 1,
|
|
|
|
data: {
|
2019-12-10 17:24:19 -05:00
|
|
|
foo: [ '' ],
|
2019-12-10 12:27:56 -05:00
|
|
|
state: [ undefined, null ],
|
|
|
|
},
|
2019-11-26 19:31:39 -05:00
|
|
|
},
|
|
|
|
],
|
2019-12-10 12:27:56 -05:00
|
|
|
|
2019-11-26 19:31:39 -05:00
|
|
|
ratedata: [
|
|
|
|
{
|
2019-12-10 12:27:56 -05:00
|
|
|
timestamp: 4,
|
|
|
|
data: {
|
2019-12-10 17:24:19 -05:00
|
|
|
prem: [ '' ],
|
2019-12-10 12:27:56 -05:00
|
|
|
state: [ undefined, null ],
|
|
|
|
},
|
2019-11-26 19:31:39 -05:00
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
2019-12-10 12:27:56 -05:00
|
|
|
|
|
|
|
// timestamps of this document are sandwiched between
|
|
|
|
// the above to make sure documents are processed
|
|
|
|
// independently (without splicing their deltas together)
|
2019-11-26 19:31:39 -05:00
|
|
|
{
|
|
|
|
id: 234,
|
2019-12-10 12:27:56 -05:00
|
|
|
lastUpdate: 121212123,
|
|
|
|
|
|
|
|
data: {
|
2019-12-10 17:24:19 -05:00
|
|
|
foo2: [ 'first' ],
|
|
|
|
state: [ 'a', 'b' ],
|
2019-12-10 12:27:56 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
ratedata: {
|
2019-12-10 17:24:19 -05:00
|
|
|
prem2: [ 'rate_first' ],
|
|
|
|
state: [ 'i', 'ii' ],
|
2019-12-10 12:27:56 -05:00
|
|
|
},
|
|
|
|
|
2019-11-26 19:31:39 -05:00
|
|
|
rdelta: {
|
|
|
|
data: [
|
|
|
|
{
|
2019-12-10 12:27:56 -05:00
|
|
|
timestamp: 2,
|
|
|
|
data: {
|
2019-12-10 17:24:19 -05:00
|
|
|
foo2: [ '' ],
|
2019-12-10 12:27:56 -05:00
|
|
|
state: [ undefined, null ],
|
|
|
|
},
|
2019-11-26 19:31:39 -05:00
|
|
|
},
|
|
|
|
],
|
2019-12-10 12:27:56 -05:00
|
|
|
|
2019-11-26 19:31:39 -05:00
|
|
|
ratedata: [
|
|
|
|
{
|
2019-12-10 12:27:56 -05:00
|
|
|
timestamp: 3,
|
|
|
|
data: {
|
2019-12-10 17:24:19 -05:00
|
|
|
prem2: [ '' ],
|
2019-12-10 12:27:56 -05:00
|
|
|
state: [ undefined, null ],
|
|
|
|
},
|
2019-11-26 19:31:39 -05:00
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
2019-12-10 12:27:56 -05:00
|
|
|
|
2019-11-26 19:31:39 -05:00
|
|
|
expected: [
|
2019-12-10 12:27:56 -05:00
|
|
|
// bucket
|
2019-11-26 19:31:39 -05:00
|
|
|
{
|
2019-12-02 10:00:23 -05:00
|
|
|
doc_id: 123,
|
2019-12-10 12:27:56 -05:00
|
|
|
rdelta: {
|
2019-12-10 17:24:19 -05:00
|
|
|
foo: [ '' ],
|
2019-12-10 12:27:56 -05:00
|
|
|
state: [ undefined, null ],
|
|
|
|
},
|
|
|
|
bucket: {
|
2019-12-10 17:24:19 -05:00
|
|
|
foo: [ 'first' ],
|
|
|
|
state: [ 'a', 'b' ],
|
2019-12-10 12:27:56 -05:00
|
|
|
},
|
|
|
|
ratedata: {},
|
2019-11-26 19:31:39 -05:00
|
|
|
},
|
2019-12-10 12:27:56 -05:00
|
|
|
|
|
|
|
// rate
|
2019-11-26 19:31:39 -05:00
|
|
|
{
|
2019-12-02 10:00:23 -05:00
|
|
|
doc_id: 123,
|
2019-12-10 12:27:56 -05:00
|
|
|
rdelta: {
|
2019-12-10 17:24:19 -05:00
|
|
|
prem: [ '' ],
|
2019-12-10 12:27:56 -05:00
|
|
|
state: [ undefined, null ],
|
|
|
|
},
|
|
|
|
bucket: {
|
2019-12-10 17:24:19 -05:00
|
|
|
foo: [ 'first' ],
|
|
|
|
state: [ 'a', 'b' ],
|
2019-12-10 12:27:56 -05:00
|
|
|
},
|
|
|
|
ratedata: {
|
2019-12-10 17:24:19 -05:00
|
|
|
prem: [ 'rate_first' ],
|
|
|
|
state: [ 'i', 'ii' ],
|
2019-12-10 12:27:56 -05:00
|
|
|
},
|
2019-11-26 19:31:39 -05:00
|
|
|
},
|
2019-12-10 12:27:56 -05:00
|
|
|
|
|
|
|
// bucket
|
2019-11-26 19:31:39 -05:00
|
|
|
{
|
2019-12-02 10:00:23 -05:00
|
|
|
doc_id: 234,
|
2019-12-10 12:27:56 -05:00
|
|
|
rdelta: {
|
2019-12-10 17:24:19 -05:00
|
|
|
foo2: [ '' ],
|
2019-12-10 12:27:56 -05:00
|
|
|
state: [ undefined, null ],
|
|
|
|
},
|
|
|
|
bucket: {
|
2019-12-10 17:24:19 -05:00
|
|
|
foo2: [ 'first' ],
|
|
|
|
state: [ 'a', 'b' ],
|
2019-12-10 12:27:56 -05:00
|
|
|
},
|
2019-12-02 10:00:23 -05:00
|
|
|
ratedata: {},
|
2019-11-26 19:31:39 -05:00
|
|
|
},
|
2019-12-10 12:27:56 -05:00
|
|
|
|
|
|
|
// rate
|
2019-11-26 19:31:39 -05:00
|
|
|
{
|
2019-12-02 10:00:23 -05:00
|
|
|
doc_id: 234,
|
2019-12-10 12:27:56 -05:00
|
|
|
rdelta: {
|
2019-12-10 17:24:19 -05:00
|
|
|
prem2: [ '' ],
|
2019-12-10 12:27:56 -05:00
|
|
|
state: [ undefined, null ],
|
|
|
|
},
|
|
|
|
bucket: {
|
2019-12-10 17:24:19 -05:00
|
|
|
foo2: [ 'first' ],
|
|
|
|
state: [ 'a', 'b' ],
|
2019-12-10 12:27:56 -05:00
|
|
|
},
|
|
|
|
ratedata: {
|
2019-12-10 17:24:19 -05:00
|
|
|
prem2: [ 'rate_first' ],
|
|
|
|
state: [ 'i', 'ii' ],
|
2019-12-10 12:27:56 -05:00
|
|
|
},
|
2019-11-26 19:31:39 -05:00
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
2019-12-10 12:27:56 -05:00
|
|
|
|
2019-12-09 15:45:01 -05:00
|
|
|
{
|
2019-12-10 17:24:19 -05:00
|
|
|
label: 'trims delta array based on index',
|
2019-12-09 15:45:01 -05:00
|
|
|
given: [
|
|
|
|
{
|
|
|
|
id: 111,
|
|
|
|
lastUpdate: 123123123,
|
2019-12-10 17:24:19 -05:00
|
|
|
data: { foo: [ 'second' ] },
|
2019-12-09 15:45:01 -05:00
|
|
|
ratedata: {},
|
|
|
|
rdelta: {
|
|
|
|
data: [
|
|
|
|
{
|
2019-12-10 17:24:19 -05:00
|
|
|
data: { foo: [ '' ] },
|
2019-12-09 15:45:01 -05:00
|
|
|
timestamp: 123,
|
|
|
|
},
|
|
|
|
{
|
2019-12-10 17:24:19 -05:00
|
|
|
data: { foo: [ 'first' ] },
|
2019-12-09 15:45:01 -05:00
|
|
|
timestamp: 234,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
totalPublishDelta: {
|
|
|
|
data: 1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
expected: [
|
|
|
|
{
|
|
|
|
doc_id: 111,
|
2019-12-10 17:24:19 -05:00
|
|
|
rdelta: { foo: [ 'first' ] },
|
|
|
|
bucket: { foo: [ 'second' ] },
|
2019-12-09 15:45:01 -05:00
|
|
|
ratedata: {}
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
2019-12-02 10:00:23 -05:00
|
|
|
] ).forEach( ( { label, given, expected } ) => it( label, () =>
|
2019-11-26 19:31:39 -05:00
|
|
|
{
|
|
|
|
let published: any = [];
|
|
|
|
const dao = createMockDeltaDao();
|
|
|
|
const publisher = createMockDeltaPublisher();
|
|
|
|
const emitter = new EventEmitter();
|
|
|
|
|
2019-12-02 10:00:23 -05:00
|
|
|
dao.getUnprocessedDocuments = (): Promise<DeltaDocument[]> =>
|
2019-11-26 19:31:39 -05:00
|
|
|
{
|
|
|
|
return Promise.resolve( given );
|
|
|
|
}
|
|
|
|
|
2019-12-02 10:00:23 -05:00
|
|
|
publisher.publish = (
|
2019-12-10 17:24:19 -05:00
|
|
|
meta,
|
2019-12-02 10:00:23 -05:00
|
|
|
delta,
|
|
|
|
bucket,
|
|
|
|
ratedata,
|
|
|
|
): Promise<void> =>
|
2019-11-26 19:31:39 -05:00
|
|
|
{
|
|
|
|
published.push( {
|
2019-12-10 17:24:19 -05:00
|
|
|
doc_id: meta.id,
|
2019-12-10 12:27:56 -05:00
|
|
|
rdelta: delta.data,
|
2019-12-02 10:00:23 -05:00
|
|
|
bucket: bucket,
|
|
|
|
ratedata: ratedata,
|
2019-11-26 19:31:39 -05:00
|
|
|
} );
|
|
|
|
|
|
|
|
return Promise.resolve();
|
|
|
|
}
|
|
|
|
|
|
|
|
return expect( new Sut( dao, publisher, emitter ).process() )
|
|
|
|
.to.eventually.deep.equal( undefined )
|
|
|
|
.then( _ => expect( published ).to.deep.equal( expected ) );
|
|
|
|
} ) );
|
|
|
|
} );
|
2019-12-02 10:00:23 -05:00
|
|
|
|
|
|
|
|
|
|
|
describe( 'Error handling', () =>
|
|
|
|
{
|
|
|
|
it( 'Marks document in error state and continues', () =>
|
|
|
|
{
|
|
|
|
let published: any = [];
|
|
|
|
let error_flag_set = false;
|
|
|
|
const dao = createMockDeltaDao();
|
|
|
|
const publisher = createMockDeltaPublisher();
|
|
|
|
const emitter = new EventEmitter();
|
2019-12-10 17:24:19 -05:00
|
|
|
const entity_num = 'Some Agency';
|
|
|
|
const entity_id = 4321;
|
|
|
|
const lastUpdate = <UnixTimestamp>123123123;
|
|
|
|
const createdData = <UnixTimestamp>234234234;
|
2019-12-02 10:00:23 -05:00
|
|
|
const doc = <DeltaDocument[]>[ {
|
2019-12-10 17:24:19 -05:00
|
|
|
id: <DocumentId>123,
|
|
|
|
agentName: entity_num,
|
|
|
|
agentEntityId: entity_id,
|
|
|
|
startDate: createdData,
|
|
|
|
lastUpdate: lastUpdate,
|
|
|
|
data: { foo: [ 'start_bar' ] },
|
|
|
|
ratedata: {},
|
|
|
|
rdelta: {
|
2019-12-02 10:00:23 -05:00
|
|
|
data: [
|
|
|
|
{
|
|
|
|
data: { foo: [ 'first_bar' ] },
|
|
|
|
timestamp: <UnixTimestamp>123123,
|
|
|
|
type: 'data',
|
|
|
|
}
|
|
|
|
],
|
|
|
|
ratedata: [],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2019-12-10 17:24:19 -05:00
|
|
|
id: <DocumentId>234,
|
|
|
|
agentName: entity_num,
|
|
|
|
agentEntityId: entity_id,
|
|
|
|
startDate: createdData,
|
|
|
|
lastUpdate: <UnixTimestamp>123123123,
|
|
|
|
data: { foo: [ 'start_bar' ] },
|
|
|
|
ratedata: {},
|
|
|
|
rdelta: {
|
2019-12-02 10:00:23 -05:00
|
|
|
data: [
|
|
|
|
{
|
|
|
|
data: { foo: [ 'first_bar' ] },
|
|
|
|
timestamp: <UnixTimestamp>123123,
|
|
|
|
type: 'data',
|
|
|
|
}
|
|
|
|
],
|
|
|
|
ratedata: [],
|
|
|
|
},
|
|
|
|
} ];
|
|
|
|
|
|
|
|
const expected_published = [
|
|
|
|
{
|
2019-12-10 17:24:19 -05:00
|
|
|
meta: {
|
|
|
|
entity_id: 4321,
|
|
|
|
entity_name: 'Some Agency',
|
|
|
|
id: 123,
|
|
|
|
lastUpdate: 123123123,
|
|
|
|
startDate: 234234234,
|
|
|
|
},
|
2019-12-02 10:00:23 -05:00
|
|
|
delta: { foo: [ 'first_bar' ] },
|
2019-12-10 12:27:56 -05:00
|
|
|
bucket: { foo: [ 'start_bar' ] },
|
2019-12-02 10:00:23 -05:00
|
|
|
ratedata: {},
|
|
|
|
},
|
|
|
|
{
|
2019-12-10 17:24:19 -05:00
|
|
|
meta: {
|
|
|
|
entity_id: 4321,
|
|
|
|
entity_name: 'Some Agency',
|
|
|
|
id: 234,
|
|
|
|
lastUpdate: 123123123,
|
|
|
|
startDate: 234234234,
|
|
|
|
},
|
2019-12-02 10:00:23 -05:00
|
|
|
delta: { foo: [ 'first_bar' ] },
|
2019-12-10 12:27:56 -05:00
|
|
|
bucket: { foo: [ 'start_bar' ] },
|
2019-12-02 10:00:23 -05:00
|
|
|
ratedata: {},
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
const expected_error = 'Uh oh';
|
|
|
|
|
|
|
|
dao.getUnprocessedDocuments = (): Promise<DeltaDocument[]> =>
|
|
|
|
Promise.resolve( doc );
|
|
|
|
|
|
|
|
dao.markDocumentAsProcessed = ( _doc_id, _ts ): Promise<void> =>
|
|
|
|
Promise.reject( new Error( expected_error ) );
|
|
|
|
|
|
|
|
dao.setErrorFlag = (): Promise<void> =>
|
|
|
|
{
|
|
|
|
error_flag_set = true;
|
|
|
|
return Promise.resolve();
|
|
|
|
}
|
|
|
|
|
|
|
|
publisher.publish = (
|
2019-12-10 17:24:19 -05:00
|
|
|
meta,
|
2019-12-02 10:00:23 -05:00
|
|
|
delta,
|
|
|
|
bucket,
|
|
|
|
ratedata,
|
|
|
|
): Promise<void> =>
|
|
|
|
{
|
|
|
|
published.push( {
|
2019-12-10 17:24:19 -05:00
|
|
|
meta: meta,
|
2019-12-02 10:00:23 -05:00
|
|
|
delta: delta.data,
|
|
|
|
bucket: bucket,
|
|
|
|
ratedata: ratedata,
|
|
|
|
} );
|
|
|
|
|
|
|
|
return Promise.resolve();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Prevent node from converting an error event into an error
|
|
|
|
emitter.on( 'error', () => {} );
|
|
|
|
|
|
|
|
return expect( new Sut( dao, publisher, emitter ).process() )
|
|
|
|
.to.eventually.deep.equal( undefined )
|
|
|
|
.then( _ =>
|
|
|
|
{
|
|
|
|
expect( error_flag_set ).to.be.true;
|
|
|
|
expect( published ).to.deep.equal( expected_published );
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
|
|
|
|
|
|
|
describe( 'Error handling', () =>
|
|
|
|
{
|
|
|
|
it( 'Failure to set document error state further processing', () =>
|
|
|
|
{
|
|
|
|
let published: any = [];
|
|
|
|
let caught_error = '';
|
|
|
|
const dao = createMockDeltaDao();
|
|
|
|
const publisher = createMockDeltaPublisher();
|
|
|
|
const emitter = new EventEmitter();
|
|
|
|
const doc = <DeltaDocument[]>[ {
|
2019-12-10 17:24:19 -05:00
|
|
|
id: <DocumentId>123,
|
|
|
|
agentName: 'Some Agency',
|
|
|
|
agentEntityId: 4321,
|
|
|
|
startDate: <UnixTimestamp>234234234,
|
|
|
|
lastUpdate: <UnixTimestamp>123123123,
|
|
|
|
data: { foo: [ 'start_bar' ] },
|
|
|
|
ratedata: {},
|
|
|
|
rdelta: {
|
2019-12-02 10:00:23 -05:00
|
|
|
data: [
|
|
|
|
{
|
|
|
|
data: { foo: [ 'first_bar' ] },
|
|
|
|
timestamp: <UnixTimestamp>123123,
|
|
|
|
type: 'data',
|
|
|
|
}
|
|
|
|
],
|
|
|
|
ratedata: [],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2019-12-10 17:24:19 -05:00
|
|
|
id: <DocumentId>234,
|
|
|
|
agentName: 'Some Agency',
|
|
|
|
agentEntityId: 4321,
|
|
|
|
startDate: <UnixTimestamp>234234234,
|
|
|
|
lastUpdate: <UnixTimestamp>123123123,
|
|
|
|
data: { foo: [ 'start_bar' ] },
|
|
|
|
ratedata: {},
|
|
|
|
rdelta: {
|
2019-12-02 10:00:23 -05:00
|
|
|
data: [
|
|
|
|
{
|
|
|
|
data: { foo: [ 'first_bar' ] },
|
|
|
|
timestamp: <UnixTimestamp>123123,
|
|
|
|
type: 'data',
|
|
|
|
}
|
|
|
|
],
|
|
|
|
ratedata: [],
|
|
|
|
},
|
|
|
|
} ];
|
|
|
|
|
|
|
|
// Only one is published
|
|
|
|
const expected_published = [ {
|
2019-12-10 17:24:19 -05:00
|
|
|
meta: {
|
|
|
|
entity_id: 4321,
|
|
|
|
entity_name: 'Some Agency',
|
|
|
|
id: 123,
|
|
|
|
lastUpdate: 123123123,
|
|
|
|
startDate: 234234234,
|
|
|
|
},
|
2019-12-02 10:00:23 -05:00
|
|
|
delta: { foo: [ 'first_bar' ] },
|
2019-12-10 12:27:56 -05:00
|
|
|
bucket: { foo: [ 'start_bar' ] },
|
2019-12-02 10:00:23 -05:00
|
|
|
ratedata: {},
|
|
|
|
} ];
|
|
|
|
|
|
|
|
const expected_error = 'Uh oh';
|
|
|
|
|
|
|
|
dao.getUnprocessedDocuments = (): Promise<DeltaDocument[]> =>
|
|
|
|
Promise.resolve( doc );
|
|
|
|
|
|
|
|
dao.markDocumentAsProcessed = ( _doc_id, _ts ): Promise<void> =>
|
|
|
|
Promise.reject( new Error( 'Couldn\'t mark document' ) );
|
|
|
|
|
|
|
|
dao.setErrorFlag = (): Promise<void> =>
|
|
|
|
Promise.reject( new Error( expected_error ) );
|
|
|
|
|
|
|
|
publisher.publish = (
|
2019-12-10 17:24:19 -05:00
|
|
|
meta,
|
2019-12-02 10:00:23 -05:00
|
|
|
delta,
|
|
|
|
bucket,
|
|
|
|
ratedata,
|
|
|
|
): Promise<void> =>
|
|
|
|
{
|
|
|
|
published.push( {
|
2019-12-10 17:24:19 -05:00
|
|
|
meta,
|
2019-12-02 10:00:23 -05:00
|
|
|
delta: delta.data,
|
|
|
|
bucket: bucket,
|
|
|
|
ratedata: ratedata,
|
|
|
|
} );
|
|
|
|
|
|
|
|
return Promise.resolve();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Prevent node from converting an error event into an error
|
|
|
|
emitter.on( 'error', () => {} );
|
|
|
|
|
|
|
|
return expect(
|
|
|
|
new Sut( dao, publisher, emitter ).process()
|
|
|
|
.catch( e => { caught_error = e.message } )
|
|
|
|
)
|
|
|
|
.to.eventually.deep.equal( undefined )
|
|
|
|
.then( _ =>
|
|
|
|
{
|
|
|
|
expect( caught_error ).to.equal( expected_error );
|
|
|
|
expect( published ).to.deep.equal( expected_published );
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
} );
|
2019-11-12 15:07:37 -05:00
|
|
|
} );
|
|
|
|
|
|
|
|
|
|
|
|
function createMockDeltaDao(): DeltaDao
|
|
|
|
{
|
|
|
|
return <DeltaDao>{
|
2019-11-13 14:08:42 -05:00
|
|
|
getUnprocessedDocuments() { return Promise.resolve( [] ); },
|
2019-11-26 19:31:39 -05:00
|
|
|
advanceDeltaIndex() { return Promise.resolve(); },
|
|
|
|
markDocumentAsProcessed() { return Promise.resolve(); },
|
|
|
|
setErrorFlag() { return Promise.resolve(); },
|
2019-11-21 15:59:17 -05:00
|
|
|
getErrorCount() { return Promise.resolve( 0 ); },
|
2019-11-12 15:07:37 -05:00
|
|
|
};
|
|
|
|
}
|
2019-11-12 16:41:31 -05:00
|
|
|
|
|
|
|
|
|
|
|
function createMockDeltaPublisher(): AmqpPublisher
|
|
|
|
{
|
|
|
|
return <AmqpPublisher>{
|
2019-11-26 19:31:39 -05:00
|
|
|
publish() { return Promise.resolve(); },
|
2019-11-12 16:41:31 -05:00
|
|
|
};
|
|
|
|
}
|