Add unit tests for sending e-mail for link shares
This commit is contained in:
parent
4bf19d4472
commit
08600a7ed5
|
@ -380,16 +380,6 @@ describe('OC.Share.ShareDialogView', function() {
|
||||||
dialog.$el.find('[name=expirationCheckbox]').click();
|
dialog.$el.find('[name=expirationCheckbox]').click();
|
||||||
expect(dialog.$el.find('[name=expirationCheckbox]').prop('checked')).toEqual(true);
|
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() {
|
it('sets picker minDate to today and no maxDate by default', function() {
|
||||||
dialog.render();
|
dialog.render();
|
||||||
dialog.$el.find('[name=linkCheckbox]').click();
|
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));
|
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() {
|
describe('check for avatar', function() {
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
|
|
|
@ -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');
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue