🐛 Fix Stripe node multiple metadata values (#2395)

This commit is contained in:
Daniel Santamaría 2021-11-04 01:44:25 +01:00 committed by GitHub
parent a3bfdd3805
commit a5805fb80b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 2 deletions

View file

@ -102,10 +102,10 @@ export function adjustMetadata(
) { ) {
if (!fields.metadata || isEmpty(fields.metadata)) return fields; if (!fields.metadata || isEmpty(fields.metadata)) return fields;
let adjustedMetadata = {}; const adjustedMetadata: Record<string, string> = {};
fields.metadata.metadataProperties.forEach(pair => { fields.metadata.metadataProperties.forEach(pair => {
adjustedMetadata = { ...adjustedMetadata, ...pair }; adjustedMetadata[pair.key] = pair.value;
}); });
return { return {

View file

@ -0,0 +1,30 @@
const helpers = require("../../../nodes/Stripe/helpers");
describe('adjustMetadata', () => {
it('it should adjust multiple metadata values', async () => {
const additionalFieldsValues = {
metadata: {
metadataProperties: [
{
key: "keyA",
value: "valueA"
},
{
key: "keyB",
value: "valueB"
},
],
},
}
const adjustedMetadata = helpers.adjustMetadata(additionalFieldsValues)
const expectedAdjustedMetadata = {
metadata: {
keyA: "valueA",
keyB: "valueB"
}
}
expect(adjustedMetadata).toStrictEqual(expectedAdjustedMetadata)
});
});