Skip to content
Snippets Groups Projects
Unverified Commit 33487018 authored by Christoph Wurst's avatar Christoph Wurst
Browse files

add unit tests for AccountService::createAccount

parent 0084076e
No related branches found
No related tags found
No related merge requests found
/**
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
*
* Mail
*
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License, version 3,
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
define([
'service/accountservice',
'OC',
'radio',
], function(AccountService, OC, Radio) {
beforeEach(function() {
jasmine.Ajax.install();
});
afterEach(function() {
jasmine.Ajax.uninstall();
});
describe('AccountService', function() {
it('creates a new account on the server', function() {
spyOn(OC, 'generateUrl').and.returnValue('index.php/apps/mail/accounts');
var promise = AccountService.createAccount({
email: 'email@example.com',
password: '12345'
});
expect(OC.generateUrl).toHaveBeenCalledWith('apps/mail/accounts');
expect(promise.state())
.toBe('pending');
expect(jasmine.Ajax.requests.count())
.toBe(1);
expect(jasmine.Ajax.requests.mostRecent().url)
.toBe('index.php/apps/mail/accounts');
jasmine.Ajax.requests.mostRecent().respondWith({
'status': 200,
'contentType': 'application/json',
'responseText': '{}'
});
expect(promise.state())
.toBe('resolved');
});
it('handle account creation errors correctly', function() {
spyOn(OC, 'generateUrl').and.returnValue('index.php/apps/mail/accounts');
var promise = AccountService.createAccount({
email: 'email@example.com',
password: '12345'
});
expect(OC.generateUrl).toHaveBeenCalledWith('apps/mail/accounts');
expect(promise.state())
.toBe('pending');
expect(jasmine.Ajax.requests.count())
.toBe(1);
expect(jasmine.Ajax.requests.mostRecent().url)
.toBe('index.php/apps/mail/accounts');
jasmine.Ajax.requests.mostRecent().respondWith({
'status': 500,
'contentType': 'application/json',
'responseText': '{}'
});
expect(promise.state())
.toBe('rejected');
});
});
});
......@@ -14,6 +14,13 @@ Object.keys(window.__karma__.files).forEach(function(file) {
}
});
window.t = function(app, text) {
if (app !== 'mail') {
throw new 'wrong app used to for translation';
}
return text;
}
OC = {
Notification: {
......
......@@ -5,7 +5,7 @@ module.exports = function(config) {
config.set({
// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['jasmine', 'requirejs'],
frameworks: ['jasmine-ajax', 'jasmine', 'requirejs'],
// list of files / patterns to load in the browser
files: [
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment