diff --git a/js/id/format/xml.js b/js/id/format/xml.js index ec036120f..5167dfe1d 100644 --- a/js/id/format/xml.js +++ b/js/id/format/xml.js @@ -4,9 +4,9 @@ iD.format.XML = { return iD.format.XML.mappings[entity.type](entity); } }, - rep: function(entity) { + rep: function(entity, changeset_id) { if (iD.format.XML.reps[entity.type]) { - return iD.format.XML.reps[entity.type](entity); + return iD.format.XML.reps[entity.type](entity, changeset_id); } else { if (typeof console !== 'undefined') console.log(entity.type); } @@ -47,32 +47,24 @@ iD.format.XML = { }); return ordered; } - var rep = { + + function rep(entity) { + return iD.format.XML.rep(entity, changeset_id); + } + + return (new XMLSerializer()).serializeToString(JXON.unbuild({ osmChange: { '@version': 0.3, '@generator': 'iD', // TODO: copy elements first - create: nest(changes.created.map(function(c) { - var x = iD.Entity(c); - x.changeset = changeset_id; - return x; - }).map(iD.format.XML.rep)), - modify: changes.modified.map(function(c) { - var x = iD.Entity(c); - x.changeset = changeset_id; - return x; - }).map(iD.format.XML.rep), - 'delete': changes.deleted.map(function(c) { - var x = iD.Entity(c); - x.changeset = changeset_id; - return x; - }).map(iD.format.XML.rep) + create: nest(changes.created.map(rep)), + modify: changes.modified.map(rep), + 'delete': changes.deleted.map(rep) } - }; - return (new XMLSerializer()).serializeToString(JXON.unbuild(rep)); + })); }, reps: { - node: function(entity) { + node: function(entity, changeset_id) { var r = { node: { '@id': entity.id.replace('n', ''), @@ -84,10 +76,10 @@ iD.format.XML = { }) } }; - if (entity.changeset) r.node['@changeset'] = entity.changeset; + if (changeset_id) r.node['@changeset'] = changeset_id; return r; }, - way: function(entity) { + way: function(entity, changeset_id) { var r = { way: { '@id': entity.id.replace('w', ''), @@ -100,7 +92,7 @@ iD.format.XML = { }) } }; - if (entity.changeset) r.way['@changeset'] = entity.changeset; + if (changeset_id) r.way['@changeset'] = changeset_id; return r; } }, diff --git a/test/spec/format/xml.js b/test/spec/format/xml.js index ac8143128..db0e3226b 100644 --- a/test/spec/format/xml.js +++ b/test/spec/format/xml.js @@ -1,4 +1,7 @@ describe('XML', function() { + var node = iD.Node({ id: 'n-1', type: 'node', loc: [-77, 38] }), + way = iD.Way({ id: 'w-1', type: 'way', nodes: [] }); + describe('#decode', function() { it('decodes xml', function() { expect(iD.format.XML.decode('<">')).to.eql('<">'); @@ -7,12 +10,28 @@ describe('XML', function() { describe('#rep', function() { it('converts a node to jxon', function() { - expect(iD.format.XML.rep({ id: 'n-1', type: 'node', loc: [-77, 38] })) - .to.eql({ node : { '@id': '-1', '@lat': 38, '@lon': -77, '@version': 0, tag: [ ] } }); + expect(iD.format.XML.rep(node)) + .to.eql({ node : { '@id': '-1', '@lat': 38, '@lon': -77, '@version': 0, tag: [ ] } }); }); + it('converts a way to jxon', function() { - expect(iD.format.XML.rep({ id: 'w-1', type: 'way', nodes: [] })) - .to.eql({ way : { '@id' : '-1', nd : [ ], '@version': 0, tag: [ ] } }); + expect(iD.format.XML.rep(way)) + .to.eql({ way : { '@id' : '-1', nd : [ ], '@version': 0, tag: [ ] } }); + }); + + it('includes changeset if provided', function() { + expect(iD.format.XML.rep(node, '1234')) + .to.eql({ node : { '@id': '-1', '@lat': 38, '@lon': -77, '@version': 0, '@changeset': '1234', tag: [ ] } }); + + expect(iD.format.XML.rep(way, '1234')) + .to.eql({ way : { '@id' : '-1', nd : [ ], '@version': 0, '@changeset': '1234', tag: [ ] } }); + }); + }); + + describe('#osmChange', function() { + it('converts change data to XML', function() { + var jxon = iD.format.XML.osmChange('jfire', '1234', {created: [node], modified: [way], deleted: []}); + expect(jxon).to.eql(''); }); });