import 'reflect-metadata' ; import { WebsiteScanResultBase , WebsiteScanResultPart } from 'storage-documents' ; import Parallel from 'paralleljs' ; import { WebsiteScanResultAggregator } from './website-scan-result-aggregator' ; let websiteScanResultAggregator ; describe ( WebsiteScanResultAggregator , ( ) => { beforeEach ( ( ) => { websiteScanResultAggregator = new WebsiteScanResultAggregator ( ) ; } ) ; it ( 'merge website base document' , ( ) => { const source = { deepScanId : '*' , _etag : '*' , deepScanLimit : 7 , discoveryPatterns : [ 'new discovery pattern' , 'existing discovery pattern' , null ] , reports : [ { reportId : 'new report' , } , { reportId : 'existing report' , } , null , ] , } as WebsiteScanResultBase ; const target = { deepScanId : 'deepScanId' , _etag : '_etag' , deepScanLimit : 11 , discoveryPatterns : [ 'existing discovery pattern' , 'old discovery pattern' ] , reports : [ { reportId : 'existing report' , } , { reportId : 'old report' , } , ] , } as WebsiteScanResultBase ; const expectedDocument = { deepScanId : 'deepScanId' , _etag : '_etag' , deepScanLimit : 11 , discoveryPatterns : [ 'existing discovery pattern' , 'old discovery pattern' , 'new discovery pattern' ] , reports : [ { reportId : 'existing report' , } , { reportId : 'old report' , } , { reportId : 'new report' , } , ] , } as WebsiteScanResultBase ; const actualDocument = websiteScanResultAggregator . mergeBaseDocument ( source , target ) ; expect ( actualDocument ) . toEqual ( expectedDocument ) ; } ) ; it ( 'merge website part document' , async ( ) => { const source = { knownPages : [ 'source' ] } as WebsiteScanResultPart ; const target = { knownPages : [ 'target' ] } as WebsiteScanResultPart ; const expectedDocument = { knownPages : [ 'expected' ] } as WebsiteScanResultPart ; const parallel = new Parallel ( [ ] ) ; Parallel . prototype . map = ( fn ) : Parallel < any > => { parallel . data = [ [ expectedDocument ] ] ; return parallel ; } ; const actualDocument = await websiteScanResultAggregator . mergePartDocument ( source , target ) ; expect ( actualDocument ) . toEqual ( expectedDocument ) ; } ) ; } ) ;