1
0
mirror of https://github.com/moparisthebest/mail synced 2024-11-16 06:05:07 -05:00
mail/test/unit/newsletter-service-test.js
Tankred Hase cf1f60fbf9 [WO-649] clean up login pages
* add spinners to all login pages
* use inline error messages in all form instead of scope.onError
* create newsletter service
2014-11-12 16:12:26 +01:00

76 lines
2.2 KiB
JavaScript

'use strict';
var mocks = angular.mock;
require('../../src/js/service/newsletter');
describe('Newsletter Service unit test', function() {
var newsletter;
beforeEach(function() {
angular.module('newsletter-test', ['woServices']);
mocks.module('newsletter-test');
mocks.inject(function($injector) {
newsletter = $injector.get('newsletter');
});
});
afterEach(function() {});
describe('signup', function() {
var xhrMock, requests;
beforeEach(function() {
xhrMock = sinon.useFakeXMLHttpRequest();
requests = [];
xhrMock.onCreate = function(xhr) {
requests.push(xhr);
};
});
afterEach(function() {
xhrMock.restore();
});
it('should not signup if user has not agreed', inject(function($rootScope) {
newsletter.signup('text@example.com', false).then(function(result) {
expect(result).to.be.false;
});
$rootScope.$apply();
expect(requests.length).to.equal(0);
}));
it('should not signup due to invalid email address', inject(function($rootScope) {
newsletter.signup('textexample.com', true).catch(function(err) {
expect(err.message).to.contain('Invalid');
});
$rootScope.$apply();
expect(requests.length).to.equal(0);
}));
it('should fail', inject(function($rootScope) {
newsletter.signup('text@example.com', true).catch(function(err) {
expect(err).to.exist;
});
requests[0].onerror('err');
$rootScope.$apply();
expect(requests.length).to.equal(1);
}));
it('should work', inject(function($rootScope) {
newsletter.signup('text@example.com', true).then(function(result) {
expect(result).to.exist;
});
requests[0].respond(200, {
"Content-Type": "text/plain"
}, 'foobar!');
$rootScope.$apply();
expect(requests.length).to.equal(1);
}));
});
});