Mike Gerwitz

Activist for User Freedom

aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorMike Gerwitz <mike.gerwitz@rtspecialty.com>2018-10-21 23:41:58 -0400
committerMike Gerwitz <mike.gerwitz@rtspecialty.com>2018-10-21 23:41:58 -0400
commit2bc1b96a159b12e4a706436fef05b1e8ab657dd5 (patch)
tree6e5295bd5623f1d88a99d45515d2c579c9fe6032 /test
parent27cc3d2c63ab1bf7ceed6d2542da96a32b0a9ca0 (diff)
downloadliza-2bc1b96a159b12e4a706436fef05b1e8ab657dd5.tar.gz
liza-2bc1b96a159b12e4a706436fef05b1e8ab657dd5.tar.bz2
liza-2bc1b96a159b12e4a706436fef05b1e8ab657dd5.zip
ProgramQuoteCleaner: Clean all groups (not just linked)
* src/server/quote/ProgramQuoteCleaner.js (clean): Add docblock. Replace previous linked group cleaning with call to `_fixGroup'. (_fixGroup): New method. Similar logic to previous linked group cleaning, except that fields are never truncated. (_fixLinkedGroups, _getLinkedIndexLength): Remove methods. (_getGroupLength): New method determining group size from leader length, which also accounts for linked groups. * test/server/quote/ProgramQuoteCleanerTest.js: New test case.
Diffstat (limited to 'test')
-rw-r--r--test/server/quote/ProgramQuoteCleanerTest.js73
1 files changed, 70 insertions, 3 deletions
diff --git a/test/server/quote/ProgramQuoteCleanerTest.js b/test/server/quote/ProgramQuoteCleanerTest.js
index 8e50210..cb09a4c 100644
--- a/test/server/quote/ProgramQuoteCleanerTest.js
+++ b/test/server/quote/ProgramQuoteCleanerTest.js
@@ -1,7 +1,7 @@
/**
* Tests ProgramQuoteCleaner
*
- * Copyright (C) 2017 R-T Specialty, LLC.
+ * Copyright (C) 2017, 2018 R-T Specialty, LLC.
*
* This file is part of the Liza Data Collection Framework.
*
@@ -27,6 +27,71 @@ const Sut = require( '../../../' ).server.quote.ProgramQuoteCleaner;
describe( 'ProgramQuoteCleaner', () =>
{
+ describe( "group cleaning", () =>
+ {
+ [
+ {
+ label: "expands indexes of linked and non-linked groups",
+
+ group_index: {
+ one: 'field11', // linked
+ two: 'field11', // linked
+ three: 'field31',
+ },
+
+ exclusive: {
+ one: [ "field11", "field12" ],
+ two: [ "field21", "field22" ],
+ three: [ "field31", "field32" ],
+ },
+
+ defaults: {
+ field12: "12default",
+ },
+
+ existing: {
+ "field11": [ "1", "", "3" ], // leader one, two
+ "field12": [ "a", "b" ],
+ "field21": [ "e" ],
+ "field22": [ "I", "II" ],
+ "field31": [ "i", "ii" ], // leader three
+ "field32": [ "x" ],
+ },
+
+ expected: {
+ "field12": [ , , "12default" ],
+ "field21": [ , "", "" ],
+ "field22": [ , , "" ],
+ "field32": [ , "" ],
+ },
+ },
+ ].forEach( test =>
+ it( test.label, done =>
+ {
+ const quote = createStubQuote( test.existing, {} );
+ const program = createStubProgram( {} );
+
+ program.defaults = test.defaults;
+ program.groupIndexField = test.group_index;
+ program.groupExclusiveFields = test.exclusive;
+
+ const updates = {};
+
+ quote.setData = given =>
+ Object.keys( given ).forEach( k => updates[ k ] = given[ k ] );
+
+ Sut( program ).clean( quote, err =>
+ {
+ expect( err ).to.deep.equal( null );
+ expect( updates ).to.deep.equal( test.expected );
+
+ done();
+ } );
+ } )
+ );
+ } );
+
+
describe( "metadata cleaning", () =>
{
[
@@ -51,7 +116,7 @@ describe( 'ProgramQuoteCleaner', () =>
].forEach( ( { label, existing, fields, expected } ) =>
it( label, done =>
{
- const quote = createStubQuote( existing );
+ const quote = createStubQuote( {}, existing );
const program = createStubProgram( fields );
Sut( program ).clean( quote, err =>
@@ -68,11 +133,12 @@ describe( 'ProgramQuoteCleaner', () =>
} );
-function createStubQuote( metadata )
+function createStubQuote( data, metadata )
{
return {
getProgramId: () => 'foo',
setData: () => {},
+ getDataByName: name => data[ name ],
getMetabucket: () => ( {
getDataByName: name => metadata[ name ],
getData: () => metadata,
@@ -92,5 +158,6 @@ function createStubProgram( meta_fields )
return {
getId: () => 'foo',
meta: { fields: meta_fields },
+ defaults: {},
};
}