summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorDaniel Calviño Sánchez <danxuliu@gmail.com>2017-04-24 21:18:29 +0200
committerDaniel Calviño Sánchez <danxuliu@gmail.com>2017-04-24 21:24:30 +0200
commit488020cf2efaa84f80bf5d39a0065b602b6d0a12 (patch)
tree47ef4e36344ee35318f7e264d8ee1c926a39d3f7 /core
parent726c6c73f4f89ba280a3232f60b7ace121c0056b (diff)
downloadnextcloud-server-488020cf2efaa84f80bf5d39a0065b602b6d0a12.tar.gz
nextcloud-server-488020cf2efaa84f80bf5d39a0065b602b6d0a12.zip
Add "complete" callback support for updateShare
Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
Diffstat (limited to 'core')
-rw-r--r--core/js/shareitemmodel.js4
-rw-r--r--core/js/tests/specs/shareitemmodelSpec.js51
2 files changed, 55 insertions, 0 deletions
diff --git a/core/js/shareitemmodel.js b/core/js/shareitemmodel.js
index bff006f7ef3..c2f7c78f6ce 100644
--- a/core/js/shareitemmodel.js
+++ b/core/js/shareitemmodel.js
@@ -208,6 +208,10 @@
url: this._getUrl('shares/' + encodeURIComponent(shareId)),
data: attrs,
dataType: 'json'
+ }).always(function() {
+ if (_.isFunction(options.complete)) {
+ options.complete(self);
+ }
}).done(function() {
self.fetch({
success: function() {
diff --git a/core/js/tests/specs/shareitemmodelSpec.js b/core/js/tests/specs/shareitemmodelSpec.js
index 9305b56b711..5c5aa9608b2 100644
--- a/core/js/tests/specs/shareitemmodelSpec.js
+++ b/core/js/tests/specs/shareitemmodelSpec.js
@@ -737,6 +737,29 @@ describe('OC.Share.ShareItemModel', function() {
permissions: '' + (OC.PERMISSION_READ | OC.PERMISSION_SHARE)
});
});
+ it('calls complete handler before refreshing the model', function() {
+ var completeStub = sinon.stub();
+ model.updateShare(123, {
+ permissions: OC.PERMISSION_READ | OC.PERMISSION_SHARE
+ }, {
+ complete: completeStub
+ });
+
+ expect(fakeServer.requests.length).toEqual(1);
+ fakeServer.requests[0].respond(
+ 200,
+ { 'Content-Type': 'application/json' },
+ JSON.stringify({ })
+ );
+
+ expect(completeStub.calledOnce).toEqual(true);
+ expect(completeStub.lastCall.args[0]).toEqual(model);
+
+ fetchReshareDeferred.resolve(makeOcsResponse([]));
+ fetchSharesDeferred.resolve(makeOcsResponse([]));
+
+ expect(completeStub.calledOnce).toEqual(true);
+ });
it('calls success handler after refreshing the model', function() {
var successStub = sinon.stub();
model.updateShare(123, {
@@ -760,6 +783,34 @@ describe('OC.Share.ShareItemModel', function() {
expect(successStub.calledOnce).toEqual(true);
expect(successStub.lastCall.args[0]).toEqual(model);
});
+ it('calls complete handler before error handler', function() {
+ var completeStub = sinon.stub();
+ var errorStub = sinon.stub();
+ model.updateShare(123, {
+ permissions: OC.PERMISSION_READ | OC.PERMISSION_SHARE
+ }, {
+ complete: completeStub,
+ error: errorStub
+ });
+
+ expect(fakeServer.requests.length).toEqual(1);
+ fakeServer.requests[0].respond(
+ 400,
+ { 'Content-Type': 'application/json' },
+ JSON.stringify({
+ ocs: {
+ meta: {
+ message: 'Some error message'
+ }
+ }
+ })
+ );
+
+ expect(completeStub.calledOnce).toEqual(true);
+ expect(completeStub.lastCall.args[0]).toEqual(model);
+ expect(errorStub.calledOnce).toEqual(true);
+ expect(completeStub.calledBefore(errorStub)).toEqual(true);
+ });
it('calls error handler with error message', function() {
var errorStub = sinon.stub();
model.updateShare(123, {