You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

versionmodelSpec.js 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * Copyright (c) 2015
  3. *
  4. * This file is licensed under the Affero General Public License version 3
  5. * or later.
  6. *
  7. * See the COPYING-README file.
  8. *
  9. */
  10. describe('OCA.Versions.VersionModel', function() {
  11. var VersionModel = OCA.Versions.VersionModel;
  12. var model;
  13. beforeEach(function() {
  14. model = new VersionModel({
  15. id: 10000000,
  16. timestamp: 10000000,
  17. fullPath: '/subdir/some file.txt',
  18. name: 'some file.txt',
  19. size: 150
  20. });
  21. });
  22. it('returns the full path', function() {
  23. expect(model.getFullPath()).toEqual('/subdir/some file.txt');
  24. });
  25. it('returns the preview url', function() {
  26. expect(model.getPreviewUrl())
  27. .toEqual(OC.generateUrl('/apps/files_versions/preview') +
  28. '?file=%2Fsubdir%2Fsome%20file.txt&version=10000000'
  29. );
  30. });
  31. it('returns the download url', function() {
  32. expect(model.getDownloadUrl())
  33. .toEqual(OC.generateUrl('/apps/files_versions/download.php') +
  34. '?file=%2Fsubdir%2Fsome%20file.txt&revision=10000000'
  35. );
  36. });
  37. describe('reverting', function() {
  38. var revertEventStub;
  39. var successStub;
  40. var errorStub;
  41. beforeEach(function() {
  42. revertEventStub = sinon.stub();
  43. errorStub = sinon.stub();
  44. successStub = sinon.stub();
  45. model.on('revert', revertEventStub);
  46. model.on('error', errorStub);
  47. });
  48. it('tells the server to revert when calling the revert method', function() {
  49. model.revert({
  50. success: successStub
  51. });
  52. expect(fakeServer.requests.length).toEqual(1);
  53. expect(fakeServer.requests[0].url)
  54. .toEqual(
  55. OC.generateUrl('/apps/files_versions/ajax/rollbackVersion.php') +
  56. '?file=%2Fsubdir%2Fsome+file.txt&revision=10000000'
  57. );
  58. fakeServer.requests[0].respond(
  59. 200,
  60. { 'Content-Type': 'application/json' },
  61. JSON.stringify({
  62. status: 'success',
  63. })
  64. );
  65. expect(revertEventStub.calledOnce).toEqual(true);
  66. expect(successStub.calledOnce).toEqual(true);
  67. expect(errorStub.notCalled).toEqual(true);
  68. });
  69. it('triggers error event when server returns a failure', function() {
  70. model.revert({
  71. success: successStub
  72. });
  73. expect(fakeServer.requests.length).toEqual(1);
  74. fakeServer.requests[0].respond(
  75. 200,
  76. { 'Content-Type': 'application/json' },
  77. JSON.stringify({
  78. status: 'error',
  79. })
  80. );
  81. expect(revertEventStub.notCalled).toEqual(true);
  82. expect(successStub.notCalled).toEqual(true);
  83. expect(errorStub.calledOnce).toEqual(true);
  84. });
  85. });
  86. });