Fixed issue where migrating attributes lost their base value calculation
This commit is contained in:
@@ -109,12 +109,14 @@ const transformsByPropType = {
|
|||||||
{from: 'type', to: 'type', up: () => 'action'},
|
{from: 'type', to: 'type', up: () => 'action'},
|
||||||
],
|
],
|
||||||
'attribute': [
|
'attribute': [
|
||||||
{from: 'baseValueCalculation', to: 'baseValue.calculation'},
|
// from: baseValue must be first or else it will delete the field we need
|
||||||
{from: 'baseValue', to: 'baseValue.value', up: nanToNull},
|
{from: 'baseValue', to: 'baseValue.value', up: nanToNull},
|
||||||
|
{from: 'baseValueCalculation', to: 'baseValue.calculation', up: calculationUp, down: calculationDown},
|
||||||
{from: 'baseValueErrors', to: 'baseValue.errors', up: trimErrors},
|
{from: 'baseValueErrors', to: 'baseValue.errors', up: trimErrors},
|
||||||
...getComputedPropertyTransforms('spellSlotLevel'),
|
...getComputedPropertyTransforms('spellSlotLevel'),
|
||||||
...getInlineComputationTransforms('description'),
|
...getInlineComputationTransforms('description'),
|
||||||
{from: 'value', to: 'total', up: nanToNull},
|
{from: 'value', to: 'total', up: nanToNull},
|
||||||
|
{from: 'currentValue', to: 'value', up: nanToNull},
|
||||||
{from: 'proficiency', to: 'proficiency', up: stripZero},
|
{from: 'proficiency', to: 'proficiency', up: stripZero},
|
||||||
],
|
],
|
||||||
'buff': [
|
'buff': [
|
||||||
@@ -214,12 +216,12 @@ function getInlineComputationTransforms(key){
|
|||||||
}
|
}
|
||||||
|
|
||||||
function calculationUp(val){
|
function calculationUp(val){
|
||||||
if (!val || !val.replace) return val;
|
if (typeof val !== 'string') return val;
|
||||||
return val.replace('.value', '.total').replace('.currentValue', '.value');
|
return val.replace('.value', '.total').replace('.currentValue', '.value');
|
||||||
}
|
}
|
||||||
|
|
||||||
function calculationDown(val){
|
function calculationDown(val){
|
||||||
if (!val || !val.replace) return val;
|
if (typeof val !== 'string') return val;
|
||||||
return val.replace('.value', '.currentValue').replace('.total', '.value');
|
return val.replace('.value', '.currentValue').replace('.total', '.value');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import CreatureProperties from '/imports/api/creature/creatureProperties/CreatureProperties.js';
|
import CreatureProperties from '/imports/api/creature/creatureProperties/CreatureProperties.js';
|
||||||
import { migrateProperty } from './2.0-beta.33-dbv1.js';
|
import { migrateProperty } from './dbv1.js';
|
||||||
import { assert } from 'chai';
|
import { assert } from 'chai';
|
||||||
|
|
||||||
const exampleAction = {
|
const exampleAction = {
|
||||||
@@ -63,6 +63,53 @@ const exampleAction = {
|
|||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const exampleAttribute = {
|
||||||
|
_id:'idRWyoj5oxCv73feM',
|
||||||
|
name:'Hit Dice',
|
||||||
|
variableName:'clericHitDice',
|
||||||
|
attributeType:'hitDice',
|
||||||
|
type:'attribute',
|
||||||
|
hitDiceSize:'d8',
|
||||||
|
baseValueCalculation:'cleric.level',
|
||||||
|
parent:{'id':'8jSWKxvgQyKbunFtD','collection':'creatureProperties'},
|
||||||
|
ancestors:[
|
||||||
|
{'collection':'creatures','id':'m9sdCvs6iDf7qRaGv'},
|
||||||
|
{'id':'8jSWKxvgQyKbunFtD','collection':'creatureProperties'}
|
||||||
|
],
|
||||||
|
order: 84,
|
||||||
|
value: 20,
|
||||||
|
tags:[],
|
||||||
|
baseValue: 20,
|
||||||
|
damage: 3,
|
||||||
|
currentValue: 17,
|
||||||
|
constitutionMod: 2,
|
||||||
|
dependencies: ['8jSWKxvgQyKbunFtD','qPP5yQXPxS7uhuXo3']
|
||||||
|
};
|
||||||
|
|
||||||
|
const expectedMigratedAttribute = {
|
||||||
|
_id:'idRWyoj5oxCv73feM',
|
||||||
|
name:'Hit Dice',
|
||||||
|
variableName:'clericHitDice',
|
||||||
|
attributeType:'hitDice',
|
||||||
|
type:'attribute',
|
||||||
|
hitDiceSize:'d8',
|
||||||
|
baseValue: {
|
||||||
|
calculation: 'cleric.level',
|
||||||
|
value: 20
|
||||||
|
},
|
||||||
|
parent:{'id':'8jSWKxvgQyKbunFtD','collection':'creatureProperties'},
|
||||||
|
ancestors:[
|
||||||
|
{'collection':'creatures','id':'m9sdCvs6iDf7qRaGv'},
|
||||||
|
{'id':'8jSWKxvgQyKbunFtD','collection':'creatureProperties'}
|
||||||
|
],
|
||||||
|
order: 84,
|
||||||
|
total: 20,
|
||||||
|
tags:[],
|
||||||
|
damage: 3,
|
||||||
|
value: 17,
|
||||||
|
constitutionMod: 2,
|
||||||
|
}
|
||||||
|
|
||||||
describe('migrateProperty', function () {
|
describe('migrateProperty', function () {
|
||||||
it('Migrates actions reversibly', function () {
|
it('Migrates actions reversibly', function () {
|
||||||
const action = {...exampleAction};
|
const action = {...exampleAction};
|
||||||
@@ -78,4 +125,13 @@ describe('migrateProperty', function () {
|
|||||||
assert.deepEqual(action, exampleAction, 'action should not be bashed');
|
assert.deepEqual(action, exampleAction, 'action should not be bashed');
|
||||||
assert.deepEqual(exampleAction, reversedAction, 'operation should be reversible');
|
assert.deepEqual(exampleAction, reversedAction, 'operation should be reversible');
|
||||||
});
|
});
|
||||||
|
it ('Migrates attributes as expected', function(){
|
||||||
|
const attribute = {...exampleAttribute};
|
||||||
|
const newAttribute = migrateProperty({
|
||||||
|
collection: CreatureProperties,
|
||||||
|
prop: attribute
|
||||||
|
});
|
||||||
|
assert.deepEqual(newAttribute, expectedMigratedAttribute,
|
||||||
|
'Attribute should match the expected result');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
@@ -1 +1 @@
|
|||||||
import './2.0-beta.33-dbv1.js';
|
import './v1/dbv1.js';
|
||||||
|
|||||||
@@ -44,6 +44,15 @@ describe('transformFields', function () {
|
|||||||
assert.equal(doc.name, 'DOC NAME', 'name in uppercase');
|
assert.equal(doc.name, 'DOC NAME', 'name in uppercase');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('Creates objects on the fly', function () {
|
||||||
|
let doc = {...originalDoc};
|
||||||
|
const transformList = [
|
||||||
|
{from: 'name', to:'newObj.name'},
|
||||||
|
];
|
||||||
|
doc = transformFields(doc, transformList);
|
||||||
|
assert.deepEqual(doc.newObj, {name: 'doc name'});
|
||||||
|
});
|
||||||
|
|
||||||
it('Handles empty to and from fields', function () {
|
it('Handles empty to and from fields', function () {
|
||||||
let doc = {...originalDoc};
|
let doc = {...originalDoc};
|
||||||
const transformList = [
|
const transformList = [
|
||||||
|
|||||||
Reference in New Issue
Block a user