1
0
Fork 0

Accommodate ancient qtype data on init and clean

* src/program/ProgramInit.js (_isKnownType): Account for ancient qtype
    representation (as a string).
* src/server/quote/ProgramQuoteCleaner.js (_isKnownType): Likewise.
* test/program/ProgramInitTest.js: New test case for this situation.
* test/server/quote/ProgramQuoteCleanerTest.js: Modify existing test case
    for this situation.
master
Mike Gerwitz 2018-11-19 11:10:16 -05:00
parent b96479409c
commit f9f7cebce7
4 changed files with 46 additions and 11 deletions

View File

@ -115,16 +115,22 @@ module.exports = Class( 'ProgramInit',
/**
* Determine whether question type QTYPE is known
*
* This assumes that the type is known unless QTYPE.type is "undefined".
* This assumes that the type is known unless QTYPE.type is
* "undefined". Ancient versions (pre-"liza") represented QTYPE as a
* string rather than an object.
*
* @param {Object} qtype type data for question
* @param {Object|string} qtype type data for question
*
* @return {boolean} whether type is known
*/
'private _isKnownType'( qtype )
{
return qtype
&& ( typeof qtype.type === 'string' )
&& ( qtype.type !== 'undefined' );
// this was a string in ancient versions (pre-"liza")
const type = ( typeof qtype === 'object' )
? qtype.type
: qtype;
return ( typeof type === 'string' )
&& ( type !== 'undefined' );
},
} );

View File

@ -195,17 +195,23 @@ module.exports = Class( 'ProgramQuoteCleaner',
/**
* Determine whether question type QTYPE is known
*
* This assumes that the type is known unless QTYPE.type is "undefined".
* This assumes that the type is known unless QTYPE.type is
* "undefined". Ancient versions (pre-"liza") represented QTYPE as a
* string rather than an object.
*
* @param {Object} qtype type data for question
* @param {Object|string} qtype type data for question
*
* @return {boolean} whether type is known
*/
'private _isKnownType'( qtype )
{
return qtype
&& ( typeof qtype.type === 'string' )
&& ( qtype.type !== 'undefined' );
// this was a string in ancient versions (pre-"liza")
const type = ( typeof qtype === 'object' )
? qtype.type
: qtype;
return ( typeof type === 'string' )
&& ( type !== 'undefined' );
},
} );

View File

@ -50,6 +50,27 @@ describe( 'ProgramInit', () =>
b: [ "two" ],
},
},
// for ancient versions of liza-proguic (before it was even called
// "liza")
{
label: "initializes defaults for ancient data representations",
defaults: { a: "one", b: "two" },
meta: {
groups: {},
qtypes: {
a: "noyes",
b: "noyes",
},
},
groupExclusiveFields: {
Something: [ "a", "b" ]
},
doc_data: {},
expected: {
a: [ "one" ],
b: [ "two" ],
},
},
{
label: "does nothing with no data or defaults",
defaults: {},

View File

@ -55,7 +55,9 @@ describe( 'ProgramQuoteCleaner', () =>
"field21": { type: "text" },
"field22": { type: "text" },
"field31": { type: "text" },
"field32": { type: "text" },
// ancient pre-"liza" data representation
"field32": "text",
},
existing: {