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

Commit 8dd888c

Browse files
kewangtoutpt
authored andcommitted
feat(api): createChangeset take an author params (#2)
which is not required
1 parent 8b37086 commit 8dd888c

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

src/api/api.service.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,13 @@ class OSMAPI {
128128
* @param {string} comment the comment assiociated to the changeset
129129
* @returns {Promise} $http response
130130
*/
131-
createChangeset(comment) {
131+
createChangeset(comment, author) {
132132
var self = this;
133133
var deferred = this.$q.defer();
134134
var changeset = {osm: {
135135
changeset: {
136136
tag: [
137-
{_k:'created_by', _v: 'Angular-OSM'},
137+
{_k:'created_by', _v: author || 'Angular-OSM'},
138138
{_k:'comment', _v: comment},
139139
]
140140
}

src/api/api.spec.js

+28-1
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,12 @@ ngDescribe({
3131
};
3232
deps.osmAPI.setAuthAdapter(adapter);
3333
};
34+
3435
it('should have URL configured', function() {
3536
var url = 'http://api.openstreetmap.org/api';
3637
expect(deps.osmAPI.url).toBe(url);
3738
});
39+
3840
it('should access to oauth dependency if set', function() {
3941
var oauthDep = {};
4042
expect(deps.osmAPI._oauth).toBe(null);
@@ -112,6 +114,7 @@ ngDescribe({
112114
deps.$rootScope.$digest();
113115
deps.$httpBackend.flush();
114116
});
117+
115118
it('should put works (case of create node) to return id', function() {
116119
setHTTPAdapter(deps);
117120
var method = '/0.6/node/create';
@@ -139,6 +142,7 @@ ngDescribe({
139142
deps.$rootScope.$digest();
140143
deps.$httpBackend.flush();
141144
});
145+
142146
it('should delete works', function() {
143147
setHTTPAdapter(deps);
144148
var method = '/0.6/node/132134';
@@ -153,6 +157,7 @@ ngDescribe({
153157
deps.$rootScope.$digest();
154158
deps.$httpBackend.flush();
155159
});
160+
156161
it('should createChangeset works', function() {
157162
setHTTPAdapter(deps);
158163
var method = '/0.6/changeset/create';
@@ -173,6 +178,27 @@ ngDescribe({
173178
deps.$httpBackend.flush();
174179
});
175180

181+
it('should createChangeset via specific author name works', function() {
182+
setHTTPAdapter(deps);
183+
var method = '/0.6/changeset/create';
184+
var comment = 'my changeset';
185+
var author = "foobar";
186+
var url = deps.osmAPI.url + method;
187+
var response = '3147'; //The ID of the newly created changeset
188+
var xml = '<osm>';
189+
xml += '<changeset><tag k="created_by" v="foobar" />';
190+
xml += '<tag k="comment" v="my changeset" />';
191+
xml += '</changeset></osm>';
192+
deps.$httpBackend.expectPUT(url, xml).respond(200, response);
193+
deps.osmAPI.createChangeset(comment, author)
194+
.then(function (data) {
195+
expect(typeof data).toBe('string');
196+
expect(data).toBe(response);
197+
});
198+
deps.$rootScope.$digest();
199+
deps.$httpBackend.flush();
200+
});
201+
176202
it('should getLastOpenedChangesetId works', function() {
177203
setHTTPAdapter(deps);
178204
var method = '/0.6/changesets?open=true&user=1';
@@ -190,6 +216,7 @@ ngDescribe({
190216
deps.$rootScope.$digest();
191217
deps.$httpBackend.flush();
192218
});
219+
193220
it('should closeChangeset works', function() {
194221
setHTTPAdapter(deps);
195222
var id = '1234';
@@ -206,4 +233,4 @@ ngDescribe({
206233

207234
}
208235

209-
});
236+
});

0 commit comments

Comments
 (0)