summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoeland Jago Douma <rullzer@owncloud.com>2015-10-08 12:21:38 +0200
committerRoeland Jago Douma <rullzer@owncloud.com>2015-10-08 16:39:25 +0200
commit08600a7ed5f41cfe18a9d11cf6874cb51d741009 (patch)
treed3023e66b4e428596d6ded71de86b1057cff2e6c
parent4bf19d4472c5dbaa22c0f365cf6d39bc74b3538a (diff)
downloadnextcloud-server-08600a7ed5f41cfe18a9d11cf6874cb51d741009.tar.gz
nextcloud-server-08600a7ed5f41cfe18a9d11cf6874cb51d741009.zip
Add unit tests for sending e-mail for link shares
-rw-r--r--core/js/tests/specs/sharedialogviewSpec.js80
-rw-r--r--core/js/tests/specs/shareitemmodelSpec.js100
2 files changed, 170 insertions, 10 deletions
diff --git a/core/js/tests/specs/sharedialogviewSpec.js b/core/js/tests/specs/sharedialogviewSpec.js
index 22ae63e796a..fe4cf8e8c2b 100644
--- a/core/js/tests/specs/sharedialogviewSpec.js
+++ b/core/js/tests/specs/sharedialogviewSpec.js
@@ -380,16 +380,6 @@ describe('OC.Share.ShareDialogView', function() {
dialog.$el.find('[name=expirationCheckbox]').click();
expect(dialog.$el.find('[name=expirationCheckbox]').prop('checked')).toEqual(true);
});
- it('displayes email form when sending emails is enabled', function() {
- $('input[name=mailPublicNotificationEnabled]').val('yes');
- dialog.render();
- expect(dialog.$('#emailPrivateLink').length).toEqual(1);
- });
- it('not renders email form when sending emails is disabled', function() {
- $('input[name=mailPublicNotificationEnabled]').val('no');
- dialog.render();
- expect(dialog.$('#emailPrivateLink').length).toEqual(0);
- });
it('sets picker minDate to today and no maxDate by default', function() {
dialog.render();
dialog.$el.find('[name=linkCheckbox]').click();
@@ -422,6 +412,76 @@ describe('OC.Share.ShareDialogView', function() {
expect($.datepicker._defaults.maxDate).toEqual(new Date(2014, 0, 27, 0, 0, 0, 0));
});
});
+ describe('send link by email', function() {
+ var sendEmailPrivateLinkStub;
+ var clock;
+
+ beforeEach(function() {
+ configModel.set({
+ isMailPublicNotificationEnabled: true
+ });
+
+ shareModel.set('linkShare', {
+ isLinkShare: true,
+ token: 'tehtoken',
+ permissions: OC.PERMISSION_READ,
+ expiration: null
+ });
+
+ sendEmailPrivateLinkStub = sinon.stub(dialog.model, "sendEmailPrivateLink");
+ clock = sinon.useFakeTimers();
+ });
+ afterEach(function() {
+ sendEmailPrivateLinkStub.restore();
+ clock.restore();
+ });
+
+ it('displayes form when sending emails is enabled', function() {
+ $('input[name=mailPublicNotificationEnabled]').val('yes');
+ dialog.render();
+ expect(dialog.$('#emailPrivateLink').length).toEqual(1);
+ });
+ it('form not rendered when sending emails is disabled', function() {
+ $('input[name=mailPublicNotificationEnabled]').val('no');
+ dialog.render();
+ expect(dialog.$('#emailPrivateLink').length).toEqual(0);
+ });
+ it('input cleared on success', function() {
+ var defer = $.Deferred();
+ sendEmailPrivateLinkStub.returns(defer.promise());
+
+ $('input[name=mailPublicNotificationEnabled]').val('yes');
+ dialog.render();
+
+ dialog.$el.find('#emailPrivateLink #email').val('a@b.c');
+ dialog.$el.find('#emailPrivateLink').trigger('submit');
+
+ expect(sendEmailPrivateLinkStub.callCount).toEqual(1);
+ expect(dialog.$el.find('#emailPrivateLink #email').val()).toEqual('Sending ...');
+
+ defer.resolve();
+ expect(dialog.$el.find('#emailPrivateLink #email').val()).toEqual('Email sent');
+
+ clock.tick(2000);
+ expect(dialog.$el.find('#emailPrivateLink #email').val()).toEqual('');
+ });
+ it('input not cleared on failure', function() {
+ var defer = $.Deferred();
+ sendEmailPrivateLinkStub.returns(defer.promise());
+
+ $('input[name=mailPublicNotificationEnabled]').val('yes');
+ dialog.render();
+
+ dialog.$el.find('#emailPrivateLink #email').val('a@b.c');
+ dialog.$el.find('#emailPrivateLink').trigger('submit');
+
+ expect(sendEmailPrivateLinkStub.callCount).toEqual(1);
+ expect(dialog.$el.find('#emailPrivateLink #email').val()).toEqual('Sending ...');
+
+ defer.reject();
+ expect(dialog.$el.find('#emailPrivateLink #email').val()).toEqual('a@b.c');
+ });
+ });
});
describe('check for avatar', function() {
beforeEach(function() {
diff --git a/core/js/tests/specs/shareitemmodelSpec.js b/core/js/tests/specs/shareitemmodelSpec.js
index b4403e28475..28daf860393 100644
--- a/core/js/tests/specs/shareitemmodelSpec.js
+++ b/core/js/tests/specs/shareitemmodelSpec.js
@@ -378,5 +378,105 @@ describe('OC.Share.ShareItemModel', function() {
});
});
+
+ describe('sendEmailPrivateLink', function() {
+ it('succeeds', function() {
+ loadItemStub.yields({
+ shares: [{
+ displayname_owner: 'root',
+ expiration: null,
+ file_source: 123,
+ file_target: '/folder',
+ id: 20,
+ item_source: '123',
+ item_type: 'folder',
+ mail_send: '0',
+ parent: null,
+ path: '/folder',
+ permissions: OC.PERMISSION_READ,
+ share_type: OC.Share.SHARE_TYPE_LINK,
+ share_with: null,
+ stime: 1403884258,
+ storage: 1,
+ token: 'tehtoken',
+ uid_owner: 'root'
+ }]
+ });
+ model.fetch();
+
+ var res = model.sendEmailPrivateLink('foo@bar.com');
+
+ expect(res.state()).toEqual('pending');
+ expect(fakeServer.requests.length).toEqual(1);
+ expect(fakeServer.requests[0].url).toEqual(OC.generateUrl('core/ajax/share.php'));
+ expect(OC.parseQueryString(fakeServer.requests[0].requestBody)).toEqual(
+ {
+ action: 'email',
+ toaddress: 'foo@bar.com',
+ link: model.get('linkShare').link,
+ itemType: 'file',
+ itemSource: '123',
+ file: 'shared_file_name.txt',
+ expiration: ''
+ }
+ )
+
+ fakeServer.requests[0].respond(
+ 200,
+ { 'Content-Type': 'application/json' },
+ JSON.stringify({status: 'success'})
+ );
+ expect(res.state()).toEqual('resolved');
+ });
+
+ it('fails', function() {
+ loadItemStub.yields({
+ shares: [{
+ displayname_owner: 'root',
+ expiration: null,
+ file_source: 123,
+ file_target: '/folder',
+ id: 20,
+ item_source: '123',
+ item_type: 'folder',
+ mail_send: '0',
+ parent: null,
+ path: '/folder',
+ permissions: OC.PERMISSION_READ,
+ share_type: OC.Share.SHARE_TYPE_LINK,
+ share_with: null,
+ stime: 1403884258,
+ storage: 1,
+ token: 'tehtoken',
+ uid_owner: 'root'
+ }]
+ });
+ model.fetch();
+
+ var res = model.sendEmailPrivateLink('foo@bar.com');
+
+ expect(res.state()).toEqual('pending');
+ expect(fakeServer.requests.length).toEqual(1);
+ expect(fakeServer.requests[0].url).toEqual(OC.generateUrl('core/ajax/share.php'));
+ expect(OC.parseQueryString(fakeServer.requests[0].requestBody)).toEqual(
+ {
+ action: 'email',
+ toaddress: 'foo@bar.com',
+ link: model.get('linkShare').link,
+ itemType: 'file',
+ itemSource: '123',
+ file: 'shared_file_name.txt',
+ expiration: ''
+ }
+ )
+
+ fakeServer.requests[0].respond(
+ 200,
+ { 'Content-Type': 'application/json' },
+ JSON.stringify({data: {message: 'fail'}, status: 'error'})
+ );
+ expect(res.state()).toEqual('rejected');
+ });
+ });
});