Push JXON.stringify's down for easier testing

This commit is contained in:
John Firebaugh
2013-01-28 11:24:52 -05:00
parent fcbd792e9d
commit 05e3dd73a8
2 changed files with 21 additions and 13 deletions
+9 -9
View File
@@ -183,8 +183,8 @@ iD.Connection = function() {
}
// Generate Changeset XML. Returns a string.
connection.changesetXML = function(tags) {
return JXON.stringify({
connection.changesetJXON = function(tags) {
return {
osm: {
changeset: {
tag: _.map(tags, function(value, key) {
@@ -194,12 +194,12 @@ iD.Connection = function() {
'@generator': 'iD'
}
}
});
};
};
// Generate [osmChange](http://wiki.openstreetmap.org/wiki/OsmChange)
// XML. Returns a string.
connection.osmChangeXML = function(userid, changeset_id, changes) {
connection.osmChangeJXON = function(userid, changeset_id, changes) {
function nest(x) {
var groups = {};
for (var i = 0; i < x.length; i++) {
@@ -219,7 +219,7 @@ iD.Connection = function() {
return entity.asJXON(changeset_id);
}
return JXON.stringify({
return {
osmChange: {
'@version': 0.3,
'@generator': 'iD',
@@ -231,7 +231,7 @@ iD.Connection = function() {
return x;
})
}
});
};
};
connection.putChangeset = function(changes, comment, imagery_used, callback) {
@@ -239,18 +239,18 @@ iD.Connection = function() {
method: 'PUT',
path: '/api/0.6/changeset/create',
options: { header: { 'Content-Type': 'text/xml' } },
content: connection.changesetXML({
content: JXON.stringify(connection.changesetJXON({
imagery_used: imagery_used.join(';'),
comment: comment,
created_by: 'iD ' + (version || '')
})
}))
}, function (err, changeset_id) {
if (err) return callback(err);
oauth.xhr({
method: 'POST',
path: '/api/0.6/changeset/' + changeset_id + '/upload',
options: { header: { 'Content-Type': 'text/xml' } },
content: connection.osmChangeXML(user.id, changeset_id, changes)
content: JXON.stringify(connection.osmChangeJXON(user.id, changeset_id, changes))
}, function (err) {
if (err) return callback(err);
oauth.xhr({
+12 -4
View File
@@ -49,12 +49,20 @@ describe('iD.Connection', function () {
});
});
describe('#osmChangeXML', function() {
it('converts change data to XML', function() {
describe('#osmChangeJXON', function() {
it('converts change data to JXON', function() {
var node = iD.Node({ id: 'n-1', type: 'node', loc: [-77, 38] }),
way = iD.Way({ id: 'w-1', type: 'way', nodes: [] }),
xml = c.osmChangeXML('jfire', '1234', {created: [node], modified: [way], deleted: []});
expect(xml).to.eql('<osmChange version="0.3" generator="iD"><create><node id="-1" lon="-77" lat="38" version="0" changeset="1234"/></create><modify><way id="-1" version="0" changeset="1234"/></modify></osmChange>');
jxon = c.osmChangeJXON('jfire', '1234', {created: [node], modified: [way], deleted: []});
expect(jxon).to.eql({
osmChange: {
'@version': 0.3,
'@generator': 'iD',
'create': {node: [node.asJXON('1234').node]},
'modify': [way.asJXON('1234')],
'delete': []
}
});
});
});
});