client: Truncate diff posted to server after first null
Before this change, since `undefined' is encoded as `null' when serialized,
there was no way for the server to disambiguate between unmodified values
and a truncation point. For example:
[ undefined, undefined, null, null, null ]
The above array represents two unmodified and three removed indexes. But
this is serialzed into JSON as:
[ null, null, null, null, null ]
It isn't possible for the server to determine what the truncation point is
from that diff. The solution is to therefore truncate the array _before_
sending it to the server, providing a trailing null to indicate that a
truncation has occurred:
[ null, null, null ]
The above means that the first two indexes are unmodified, and that index 2
and later should all be truncated.
* doc/client.texi (Saving to Server): New section.
* src/client/transport/XhttpQuoteTransport.js (_truncateDiff): New method to
perform truncation.
(getBucketDataJson): Use it.
* test/client/transport/XhttpQuoteTransportTest.js: New file with respective
test case.
2018-03-07 13:20:21 -05:00
|
|
|
/**
|
|
|
|
* Test case for XhttpQuoteTransport
|
|
|
|
*
|
2019-08-30 09:41:33 -04:00
|
|
|
* Copyright (C) 2010-2019 R-T Specialty, LLC.
|
client: Truncate diff posted to server after first null
Before this change, since `undefined' is encoded as `null' when serialized,
there was no way for the server to disambiguate between unmodified values
and a truncation point. For example:
[ undefined, undefined, null, null, null ]
The above array represents two unmodified and three removed indexes. But
this is serialzed into JSON as:
[ null, null, null, null, null ]
It isn't possible for the server to determine what the truncation point is
from that diff. The solution is to therefore truncate the array _before_
sending it to the server, providing a trailing null to indicate that a
truncation has occurred:
[ null, null, null ]
The above means that the first two indexes are unmodified, and that index 2
and later should all be truncated.
* doc/client.texi (Saving to Server): New section.
* src/client/transport/XhttpQuoteTransport.js (_truncateDiff): New method to
perform truncation.
(getBucketDataJson): Use it.
* test/client/transport/XhttpQuoteTransportTest.js: New file with respective
test case.
2018-03-07 13:20:21 -05:00
|
|
|
*
|
|
|
|
* This file is part of the Liza Data Collection Framework
|
|
|
|
*
|
|
|
|
* Liza is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const expect = require( 'chai' ).expect;
|
|
|
|
const Class = require( 'easejs' ).Class;
|
|
|
|
|
|
|
|
const { XhttpQuoteTransport: Sut } = require( '../../../' ).client.transport;
|
|
|
|
|
|
|
|
|
|
|
|
describe( "XhttpQuoteTransport", () =>
|
|
|
|
{
|
|
|
|
it( "truncates index removals", done =>
|
|
|
|
{
|
|
|
|
// before truncating
|
|
|
|
const bucket = { getFilledDiff: () => ( {
|
|
|
|
none: [ 'no', 'truncate' ],
|
|
|
|
empty: [],
|
|
|
|
one_null: [ null ],
|
|
|
|
all_null: [ null, null, null ],
|
|
|
|
tail_null: [ 'a', 'b', null ],
|
|
|
|
tail_null_many: [ 'a', 'b', null, null, null ],
|
|
|
|
undefined_null: [ undefined, 'b', undefined, null, null ],
|
|
|
|
|
|
|
|
// this shouldn't ever happen, but let's make sure the behavior
|
|
|
|
// is sane anyway
|
|
|
|
bs: [ null, 'should', 'not', 'ever', 'happen' ],
|
|
|
|
} ) };
|
|
|
|
|
|
|
|
// after truncating
|
|
|
|
const expected_data = {
|
|
|
|
none: [ 'no', 'truncate' ],
|
|
|
|
empty: [],
|
|
|
|
one_null: [ null ],
|
|
|
|
all_null: [ null ],
|
|
|
|
tail_null: [ 'a', 'b', null ],
|
|
|
|
tail_null_many: [ 'a', 'b', null ],
|
|
|
|
undefined_null: [ null, 'b', null, null ],
|
|
|
|
bs: [ null ],
|
|
|
|
};
|
|
|
|
|
|
|
|
const stub_quote = { visitData: c => c( bucket ) };
|
|
|
|
|
|
|
|
const mock_proxy = {
|
|
|
|
post( _, data )
|
|
|
|
{
|
|
|
|
expect( JSON.parse( data.data ) )
|
|
|
|
.to.deep.equal( expected_data );
|
|
|
|
|
|
|
|
done();
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
Sut( '', mock_proxy ).send( stub_quote );
|
|
|
|
} );
|
|
|
|
} );
|