diff options
Diffstat (limited to 'apps/files_versions/tests/js/versionmodelSpec.js')
-rw-r--r-- | apps/files_versions/tests/js/versionmodelSpec.js | 59 |
1 files changed, 31 insertions, 28 deletions
diff --git a/apps/files_versions/tests/js/versionmodelSpec.js b/apps/files_versions/tests/js/versionmodelSpec.js index 0f1c06581d5..7ee239cd94a 100644 --- a/apps/files_versions/tests/js/versionmodelSpec.js +++ b/apps/files_versions/tests/js/versionmodelSpec.js @@ -10,14 +10,23 @@ describe('OCA.Versions.VersionModel', function() { var VersionModel = OCA.Versions.VersionModel; var model; + var uid = OC.currentUser = 'user'; beforeEach(function() { model = new VersionModel({ id: 10000000, + fileId: 10, timestamp: 10000000, fullPath: '/subdir/some file.txt', name: 'some file.txt', - size: 150 + size: 150, + user: 'user', + client: new OC.Files.Client({ + host: 'localhost', + port: 80, + root: '/remote.php/dav/versions/user', + useHTTPS: OC.getProtocol() === 'https' + }) }); }); @@ -32,8 +41,8 @@ describe('OCA.Versions.VersionModel', function() { }); it('returns the download url', function() { expect(model.getDownloadUrl()) - .toEqual(OC.generateUrl('/apps/files_versions/download.php') + - '?file=%2Fsubdir%2Fsome%20file.txt&revision=10000000' + .toEqual(OC.linkToRemoteBase('dav') + '/versions/' + uid + + '/versions/10/10000000' ); }); describe('reverting', function() { @@ -50,46 +59,40 @@ describe('OCA.Versions.VersionModel', function() { model.on('error', errorStub); }); it('tells the server to revert when calling the revert method', function() { - model.revert({ + var promise = model.revert({ success: successStub }); expect(fakeServer.requests.length).toEqual(1); - expect(fakeServer.requests[0].url) + var request = fakeServer.requests[0]; + expect(request.url) .toEqual( - OC.generateUrl('/apps/files_versions/ajax/rollbackVersion.php') + - '?file=%2Fsubdir%2Fsome+file.txt&revision=10000000' + OC.linkToRemoteBase('dav') + '/versions/user/versions/10/10000000' ); + expect(request.requestHeaders.Destination).toEqual(OC.getRootPath() + '/remote.php/dav/versions/user/restore/target'); + request.respond(201); - fakeServer.requests[0].respond( - 200, - { 'Content-Type': 'application/json' }, - JSON.stringify({ - status: 'success', - }) - ); + promise.then(function() { + expect(revertEventStub.calledOnce).toEqual(true); + expect(successStub.calledOnce).toEqual(true); + expect(errorStub.notCalled).toEqual(true); + }); - expect(revertEventStub.calledOnce).toEqual(true); - expect(successStub.calledOnce).toEqual(true); - expect(errorStub.notCalled).toEqual(true); + return promise; }); it('triggers error event when server returns a failure', function() { - model.revert({ + var promise = model.revert({ success: successStub }); expect(fakeServer.requests.length).toEqual(1); - fakeServer.requests[0].respond( - 200, - { 'Content-Type': 'application/json' }, - JSON.stringify({ - status: 'error', - }) - ); + fakeServer.requests[0].respond(404); - expect(revertEventStub.notCalled).toEqual(true); - expect(successStub.notCalled).toEqual(true); - expect(errorStub.calledOnce).toEqual(true); + promise.then(function() { + expect(revertEventStub.notCalled).toEqual(true); + expect(successStub.notCalled).toEqual(true); + expect(errorStub.calledOnce).toEqual(true); + }); }); }); }); |