Mike Gerwitz

Activist for User Freedom

aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorMike Gerwitz <mike.gerwitz@rtspecialty.com>2018-11-12 14:53:58 -0500
committerMike Gerwitz <mike.gerwitz@rtspecialty.com>2018-11-14 11:52:52 -0500
commitecdfea5cdba883bcc76f20c906bc59c93cde9a7e (patch)
treeb4163b2c8d16fe476919cc072254d2acef8cdf3e /test
parent52285d0a6c559f8f8b086f7d41a4a0a58226dee8 (diff)
downloadliza-ecdfea5cdba883bcc76f20c906bc59c93cde9a7e.tar.gz
liza-ecdfea5cdba883bcc76f20c906bc59c93cde9a7e.tar.bz2
liza-ecdfea5cdba883bcc76f20c906bc59c93cde9a7e.zip
ProgramInit: Do not initialize bucket values for undefined question types
These denote fields that are generated but do not actually have any data associated with them. For example, select options with predicates have a field generated so that they contribute to the group field count (so that the group will automatically show/hide appropriately), but those should never have values associated with them in the bucket. This was manifesting as a nasty bug: The bucket contained a key for generated options. When the quote is loaded, the client "empties" the bucket. In doing so, it set the option value to the empty string, which had the effect of rendering the dropdown useless---every value was the empty string! * src/program/ProgramInit.js (_isKnownType): New method. (init): Use it and ignore fields with unknown types. * src/server/Server.js: Add note that we shouldn't have this logic duplicated between ProgramInit and ProgramQuoteCleaner. * src/server/quote/ProgramQuoteCleaner.js (_fixGroup): Ignore fields with unknown types. (_isKnownType): New method. * test/program/ProgramInitTest.js: Update existing tests. Add new. * test/server/quote/ProgramQuoteCleanerTest.js: Test this case.
Diffstat (limited to 'test')
-rw-r--r--test/program/ProgramInitTest.js60
-rw-r--r--test/server/quote/ProgramQuoteCleanerTest.js12
2 files changed, 60 insertions, 12 deletions
diff --git a/test/program/ProgramInitTest.js b/test/program/ProgramInitTest.js
index 8d3ee90..02cea98 100644
--- a/test/program/ProgramInitTest.js
+++ b/test/program/ProgramInitTest.js
@@ -35,7 +35,11 @@ describe( 'ProgramInit', () =>
label: "initializes defaults",
defaults: { a: "one", b: "two" },
meta: {
- groups: {}
+ groups: {},
+ qtypes: {
+ a: { type: "noyes" },
+ b: { type: "noyes" },
+ },
},
groupExclusiveFields: {
Something: [ "a", "b" ]
@@ -73,7 +77,11 @@ describe( 'ProgramInit', () =>
bar: "test"
},
meta: {
- groups: {}
+ groups: {},
+ qtypes: {
+ foo: { type: "noyes" },
+ bar: { type: "noyes" },
+ },
},
groupExclusiveFields: {
Something: [ "foo" ],
@@ -89,7 +97,10 @@ describe( 'ProgramInit', () =>
label: "keeps existing data with no defaults",
defaults: {},
meta: {
- groups: {}
+ groups: {},
+ qtypes: {
+ bar: { type: "text" },
+ },
},
groupExclusiveFields: {
SomethingElse: [ "bar" ]
@@ -103,7 +114,10 @@ describe( 'ProgramInit', () =>
label: "does not overwrite existing data with defaults",
defaults: { foo: "init" },
meta: {
- groups: {}
+ groups: {},
+ qtypes: {
+ foo: { type: "text" },
+ },
},
groupExclusiveFields: {
Something: [ "foo" ]
@@ -121,7 +135,10 @@ describe( 'ProgramInit', () =>
Something: {
min: 3
}
- }
+ },
+ qtypes: {
+ foo: { type: "text" },
+ },
},
groupExclusiveFields: {
Something: [ "foo" ]
@@ -139,7 +156,10 @@ describe( 'ProgramInit', () =>
Something: {
min: 5
}
- }
+ },
+ qtypes: {
+ foo: { type: "text" },
+ },
},
groupExclusiveFields: {
Something: [ "foo" ]
@@ -157,7 +177,10 @@ describe( 'ProgramInit', () =>
Something: {
min: 5
}
- }
+ },
+ qtypes: {
+ foo: { type: "text" },
+ },
},
groupExclusiveFields: {
Something: [ "foo" ]
@@ -169,6 +192,21 @@ describe( 'ProgramInit', () =>
foo: [ "1", "2", "3", "4", "init" ],
},
},
+ {
+ label: "ignores undefined types",
+ defaults: { foo: "default" },
+ meta: {
+ groups: {},
+ qtypes: {
+ foo: { type: "undefined" },
+ },
+ },
+ groupExclusiveFields: {
+ Something: [ "foo" ]
+ },
+ doc_data: {},
+ expected: {},
+ },
].forEach( ({ label, doc_data, id, defaults, meta, groupExclusiveFields, expected }) =>
{
it( label, () =>
@@ -176,10 +214,10 @@ describe( 'ProgramInit', () =>
const sut = Sut( null );
const program = {
- id: "foo",
- defaults: defaults,
- meta: meta,
- groupExclusiveFields : groupExclusiveFields
+ id: "foo",
+ defaults: defaults,
+ meta: meta,
+ groupExclusiveFields: groupExclusiveFields
};
return expect( sut.init( program, doc_data ) )
diff --git a/test/server/quote/ProgramQuoteCleanerTest.js b/test/server/quote/ProgramQuoteCleanerTest.js
index cb09a4c..957f7ae 100644
--- a/test/server/quote/ProgramQuoteCleanerTest.js
+++ b/test/server/quote/ProgramQuoteCleanerTest.js
@@ -42,13 +42,22 @@ describe( 'ProgramQuoteCleaner', () =>
exclusive: {
one: [ "field11", "field12" ],
two: [ "field21", "field22" ],
- three: [ "field31", "field32" ],
+ three: [ "field31", "field32", "unknown_ignore_me" ],
},
defaults: {
field12: "12default",
},
+ qtypes: {
+ "field11": { type: "text" },
+ "field12": { type: "text" },
+ "field21": { type: "text" },
+ "field22": { type: "text" },
+ "field31": { type: "text" },
+ "field32": { type: "text" },
+ },
+
existing: {
"field11": [ "1", "", "3" ], // leader one, two
"field12": [ "a", "b" ],
@@ -74,6 +83,7 @@ describe( 'ProgramQuoteCleaner', () =>
program.defaults = test.defaults;
program.groupIndexField = test.group_index;
program.groupExclusiveFields = test.exclusive;
+ program.meta.qtypes = test.qtypes;
const updates = {};