diff options
author | Austin Schaffer <austin.schaffer@ryansg.com> | 2019-11-13 14:08:42 -0500 |
---|---|---|
committer | Austin Schaffer <austin.schaffer@ryansg.com> | 2019-11-20 09:48:28 -0500 |
commit | 9b5cd4e89f8d8778994a01eca641d4b78296c4d9 (patch) | |
tree | 536a3aeed86a285daed32a818e0d1afee57ecd29 /test | |
parent | 309585cf6e02322dcd3f34cda2e719f480a29c72 (diff) | |
download | liza-9b5cd4e89f8d8778994a01eca641d4b78296c4d9.tar.gz liza-9b5cd4e89f8d8778994a01eca641d4b78296c4d9.tar.bz2 liza-9b5cd4e89f8d8778994a01eca641d4b78296c4d9.zip |
[DEV-5312] Call data-processor and instantiate classes
Diffstat (limited to 'test')
-rw-r--r-- | test/system/DeltaProcessorTest.ts | 16 | ||||
-rw-r--r-- | test/system/DeltaPublisherTest.ts | 321 |
2 files changed, 327 insertions, 10 deletions
diff --git a/test/system/DeltaProcessorTest.ts b/test/system/DeltaProcessorTest.ts index 3e70282..d32197e 100644 --- a/test/system/DeltaProcessorTest.ts +++ b/test/system/DeltaProcessorTest.ts @@ -23,9 +23,11 @@ import { DeltaProcessor as Sut } from '../../src/system/DeltaProcessor'; import { AmqpPublisher } from '../../src/system/AmqpPublisher'; import { DeltaDao } from '../../src/system/db/DeltaDao'; import { MongoDeltaType } from '../../src/system/db/MongoDeltaDao'; +import { EventDispatcher } from '../../src/system/event/EventDispatcher'; import { expect, use as chai_use } from 'chai'; +import { EventEmitter } from 'events'; chai_use( require( 'chai-as-promised' ) ); @@ -166,7 +168,8 @@ describe( 'system.DeltaProcessor', () => { const sut = new Sut( createMockDeltaDao(), - createMockDeltaPublisher() + createMockDeltaPublisher(), + new EventDispatcher( new EventEmitter() ), ); const actual = sut.getTimestampSortedDeltas( given ); @@ -287,7 +290,8 @@ describe( 'system.DeltaProcessor', () => { const sut = new Sut( createMockDeltaDao(), - createMockDeltaPublisher() + createMockDeltaPublisher(), + new EventDispatcher( new EventEmitter() ), ); const actual = sut.getDeltas( given, type ); @@ -301,9 +305,9 @@ describe( 'system.DeltaProcessor', () => function createMockDeltaDao(): DeltaDao { return <DeltaDao>{ - getUnprocessedDocuments() { return this }, - advanceDeltaIndexByType() { return this }, - markDocumentAsProcessed() { return this }, + getUnprocessedDocuments() { return Promise.resolve( [] ); }, + advanceDeltaIndex() { return Promise.resolve( null ); }, + markDocumentAsProcessed() { return Promise.resolve( null ); }, }; } @@ -311,6 +315,6 @@ function createMockDeltaDao(): DeltaDao function createMockDeltaPublisher(): AmqpPublisher { return <AmqpPublisher>{ - publish() {}, + publish() { return Promise.resolve( null ); }, }; } diff --git a/test/system/DeltaPublisherTest.ts b/test/system/DeltaPublisherTest.ts index 9f72cd1..fecef2d 100644 --- a/test/system/DeltaPublisherTest.ts +++ b/test/system/DeltaPublisherTest.ts @@ -19,12 +19,14 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ +import { EventDispatcher } from '../../src/system/event/EventDispatcher'; import { DeltaPublisher as Sut, AmqpConfig } from "../../src/system/DeltaPublisher"; import { expect, use as chai_use } from 'chai'; +import { EventEmitter } from "events"; chai_use( require( 'chai-as-promised' ) ); @@ -34,16 +36,327 @@ describe( 'server.DeltaPublisher', () => { it( 'sends a message', () => { - const conf = createMockConf(); + const conf = createMockConf(); + const dispatcher = new EventDispatcher( new EventEmitter() ); - console.log( new Sut( conf, {} ) ); + console.log( new Sut( conf, dispatcher, ts_ctr ) ); expect( true ).to.be.true - }); - }); + } ); + } ); + + describe( '#sendMessage', () => + { + it( 'sends a message', () => + { + const conf = createMockConf(); + const dispatcher = new EventDispatcher( new EventEmitter() ); + + console.log( new Sut( conf, dispatcher, ts_ctr ) ); + expect( true ).to.be.true + } ); + } ); + + describe( '#avroEncode parses', () => + { + [ + { + label: 'Null value', + valid: true, + delta_data: { foo: null }, + }, + { + label: 'Null array', + valid: true, + delta_data: { foo: { "array": [ null ] } }, + }, + { + label: 'Boolean value', + valid: true, + delta_data: { foo: { "array": [ + { "boolean": true }, + ] } }, + }, + { + label: 'Simple string', + valid: true, + delta_data: { foo: { "array": [ + { "string": 'bar' }, + { "string": 'baz' }, + ] } }, + }, + { + label: 'Simple int', + valid: true, + delta_data: { foo: { "array": [ + { "double": 123 }, + ] } }, + }, + { + label: 'Nested array', + valid: true, + delta_data: { foo: { "array": [ + { "array": [ + { "string": 'bar' }, + ] }, + ] } }, + }, + { + label: 'Array with nulls', + valid: true, + delta_data: { foo: { "array": [ + { "string": 'bar' }, + { "string": 'baz' }, + null, + ] } }, + }, + { + label: 'Nested Array with mixed values', + valid: true, + delta_data: { foo: { "array": [ + { "array": [ + { "string": 'bar' }, + { "double": 123321 }, + null, + ] } + ] } }, + }, + { + label: 'Non-array', + valid: false, + delta_data: { foo: 'bar' }, + }, + { + label: 'Map objects', + valid: true, + delta_data: { "foo": { "array": [ + { "map": { + "bar": { "map": { + "baz": { "double": 1572903485000 }, + } } + } } + ] } }, + } + ].forEach( ( { label, delta_data, valid } ) => + { + it( label, () => + { + let errorCalled = false; + + const dispatcher = <EventDispatcher>{ + dispatch( _event_id, _err ) + { + errorCalled = true; + + console.log( 'server.DeltaPublisher.Error' + _err ); + } + } + + const conf = createMockConf(); + const data = createMockData( delta_data ); + const sut = new Sut( conf, dispatcher, ts_ctr ); + const buffer = sut.avroEncode( data ); + + if ( valid ) + { + expect( typeof(buffer) ).to.equal( 'object' ); + } + else + { + expect( buffer ).to.equal( null ); + } + + expect( valid ).to.equal( !errorCalled ); + } ); + } ); + } ); + + + describe( '#avroFormat formats', () => + { + [ + { + label: 'Null', + delta_data: null, + expected: null, + }, + { + label: 'Null Value', + delta_data: { foo: null }, + expected: { foo: null }, + }, + { + label: 'Boolean Value', + delta_data: { foo: [ true ] }, + expected: { foo: { "array": [ + { "boolean": true }, + ] } }, + }, + { + label: 'Simple string', + delta_data: { foo: [ + 'bar', + 'baz', + ] }, + expected: { foo: { "array": [ + { "string": 'bar' }, + { "string": 'baz' }, + ] } }, + }, + { + label: 'Simple int', + delta_data: { foo: [ + 123 + ] }, + expected: { foo: { "array": [ + { "double": 123 }, + ] } }, + }, + { + label: 'Nested array', + delta_data: { foo: [ + [ + 'bar', + 'baz', + ] + ] }, + expected: { foo: { "array": [ + { "array": [ + { "string": 'bar' }, + { "string": 'baz' }, + ] }, + ] } }, + }, + { + label: 'Double nested array', + delta_data: { foo: [ + [ + [ + 'bar', + 123, + null + ], + ], + ] }, + expected: { foo: { "array": [ + { "array": [ + { "array": [ + { "string": 'bar' }, + { "double": 123 }, + null, + ] }, + ] }, + ] } }, + }, + { + label: 'Array with nulls', + delta_data: { foo: [ + 'bar', + 'baz', + null + ] }, + expected: { foo: { "array": [ + { "string": 'bar' }, + { "string": 'baz' }, + null + ] } }, + }, + { + label: 'Nested Array with mixed values', + delta_data: { foo: [ + [ + 'bar', + 123321, + null, + ] + ] }, + expected: { foo: { "array": [ + { "array": [ + { "string": 'bar' }, + { "double": 123321 }, + null, + ] }, + ] } }, + }, + { + label: 'Nested Array with mixed values', + delta_data: { foo: [ + { + "bar": { + "wer": 'qaz', + "qwe": 1572903485000, + "asd": true, + "zxc": null, + }, + }, + ] }, + expected: { "foo": { "array": [ + { "map": { + "bar": { "map": { + "wer": { "string": 'qaz' }, + "qwe": { "double": 1572903485000 }, + "asd": { "boolean": true }, + "zxc": null, + } }, + } }, + ] } }, + }, + ].forEach( ( { label, delta_data, expected } ) => + { + it( label, () => + { + const dispatcher = <EventDispatcher>{} + const conf = createMockConf(); + const sut = new Sut( conf, dispatcher, ts_ctr ); + const actual = sut.avroFormat( delta_data ); + + expect( actual ).to.deep.equal( expected ); + } ); + } ); + } ); } ); +function ts_ctr(): UnixTimestamp +{ + return <UnixTimestamp>Math.floor( new Date().getTime() / 1000 ); +} function createMockConf(): AmqpConfig { return <AmqpConfig>{}; } + + +function createMockData( delta_data: any ): any +{ + + return { + event: { + id: 'RATE', + ts: 1573856916, + actor: 'SERVER', + step: null, + }, + document: { + id: 123123, + created: 1573856916, + modified: 1573856916, + top_visited_step: '2', + }, + session: { + entity_name: 'Foobar', + entity_id: 123123 , + }, + data: null, + delta: { + Data: { + bucket: delta_data, + }, + }, + program: { + Program: { + id: 'quote_server', + version: 'dadaddwafdwa', + }, + }, + }; +}
\ No newline at end of file |