Skip to content
This repository has been archived by the owner on Feb 28, 2022. It is now read-only.

Commit

Permalink
feat(api): createChangeset take an author params (#2)
Browse files Browse the repository at this point in the history
which is not required
  • Loading branch information
kewang authored and toutpt committed Nov 17, 2016
1 parent 8b37086 commit 8dd888c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/api/api.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,13 @@ class OSMAPI {
* @param {string} comment the comment assiociated to the changeset
* @returns {Promise} $http response
*/
createChangeset(comment) {
createChangeset(comment, author) {
var self = this;
var deferred = this.$q.defer();
var changeset = {osm: {
changeset: {
tag: [
{_k:'created_by', _v: 'Angular-OSM'},
{_k:'created_by', _v: author || 'Angular-OSM'},
{_k:'comment', _v: comment},
]
}
Expand Down
29 changes: 28 additions & 1 deletion src/api/api.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ ngDescribe({
};
deps.osmAPI.setAuthAdapter(adapter);
};

it('should have URL configured', function() {
var url = 'http://api.openstreetmap.org/api';
expect(deps.osmAPI.url).toBe(url);
});

it('should access to oauth dependency if set', function() {
var oauthDep = {};
expect(deps.osmAPI._oauth).toBe(null);
Expand Down Expand Up @@ -112,6 +114,7 @@ ngDescribe({
deps.$rootScope.$digest();
deps.$httpBackend.flush();
});

it('should put works (case of create node) to return id', function() {
setHTTPAdapter(deps);
var method = '/0.6/node/create';
Expand Down Expand Up @@ -139,6 +142,7 @@ ngDescribe({
deps.$rootScope.$digest();
deps.$httpBackend.flush();
});

it('should delete works', function() {
setHTTPAdapter(deps);
var method = '/0.6/node/132134';
Expand All @@ -153,6 +157,7 @@ ngDescribe({
deps.$rootScope.$digest();
deps.$httpBackend.flush();
});

it('should createChangeset works', function() {
setHTTPAdapter(deps);
var method = '/0.6/changeset/create';
Expand All @@ -173,6 +178,27 @@ ngDescribe({
deps.$httpBackend.flush();
});

it('should createChangeset via specific author name works', function() {
setHTTPAdapter(deps);
var method = '/0.6/changeset/create';
var comment = 'my changeset';
var author = "foobar";
var url = deps.osmAPI.url + method;
var response = '3147'; //The ID of the newly created changeset
var xml = '<osm>';
xml += '<changeset><tag k="created_by" v="foobar" />';
xml += '<tag k="comment" v="my changeset" />';
xml += '</changeset></osm>';
deps.$httpBackend.expectPUT(url, xml).respond(200, response);
deps.osmAPI.createChangeset(comment, author)
.then(function (data) {
expect(typeof data).toBe('string');
expect(data).toBe(response);
});
deps.$rootScope.$digest();
deps.$httpBackend.flush();
});

it('should getLastOpenedChangesetId works', function() {
setHTTPAdapter(deps);
var method = '/0.6/changesets?open=true&user=1';
Expand All @@ -190,6 +216,7 @@ ngDescribe({
deps.$rootScope.$digest();
deps.$httpBackend.flush();
});

it('should closeChangeset works', function() {
setHTTPAdapter(deps);
var id = '1234';
Expand All @@ -206,4 +233,4 @@ ngDescribe({

}

});
});

0 comments on commit 8dd888c

Please sign in to comment.