Skip to content

Commit

Permalink
fix: encoding of array related transforms
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelgozi committed Apr 13, 2020
1 parent e41c5be commit 4022ef4
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 39 deletions.
3 changes: 2 additions & 1 deletion src/Transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export default class Transform {
`The value for the transform "${name}" needs to be a${validator === isNumber ? ' number' : 'n array'}.`
);

this[transformName] = name === 'serverTimestamp' ? 'REQUEST_TIME' : encodeValue(value);
if (validator === Array.isArray) this[transformName] = encodeValue(value).arrayValue;
else this[transformName] = name === 'serverTimestamp' ? 'REQUEST_TIME' : encodeValue(value);
}
}
56 changes: 24 additions & 32 deletions test/Transform.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,19 +105,17 @@ describe('Transform', () => {
const given = JSON.stringify(new Transform('appendToArray', [1, 2, 3]));
const expected = JSON.stringify({
appendMissingElements: {
arrayValue: {
values: [
{
integerValue: '1'
},
{
integerValue: '2'
},
{
integerValue: '3'
}
]
}
values: [
{
integerValue: '1'
},
{
integerValue: '2'
},
{
integerValue: '3'
}
]
}
});

Expand All @@ -128,9 +126,7 @@ describe('Transform', () => {
const given = JSON.stringify(new Transform('appendToArray', []));
const expected = JSON.stringify({
appendMissingElements: {
arrayValue: {
values: []
}
values: []
}
});

Expand Down Expand Up @@ -159,19 +155,17 @@ describe('Transform', () => {
const given = JSON.stringify(new Transform('removeFromArray', [1, 2, 3]));
const expected = JSON.stringify({
removeAllFromArray: {
arrayValue: {
values: [
{
integerValue: '1'
},
{
integerValue: '2'
},
{
integerValue: '3'
}
]
}
values: [
{
integerValue: '1'
},
{
integerValue: '2'
},
{
integerValue: '3'
}
]
}
});

Expand All @@ -182,9 +176,7 @@ describe('Transform', () => {
const given = JSON.stringify(new Transform('removeFromArray', []));
const expected = JSON.stringify({
removeAllFromArray: {
arrayValue: {
values: []
}
values: []
}
});

Expand Down
8 changes: 2 additions & 6 deletions test/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -371,17 +371,13 @@ describe('encode', () => {
{
fieldPath: 't5',
appendMissingElements: {
arrayValue: {
values: [{ stringValue: 'hello' }]
}
values: [{ stringValue: 'hello' }]
}
},
{
fieldPath: 't6',
removeAllFromArray: {
arrayValue: {
values: [{ stringValue: 'good bye' }]
}
values: [{ stringValue: 'good bye' }]
}
}
];
Expand Down

0 comments on commit 4022ef4

Please sign in to comment.