Commit 6b773b25 authored by Patricio Bruna's avatar Patricio Bruna

Creating resources with attributes working

parent 3f589551
This diff is collapsed.
This diff is collapsed.
......@@ -190,7 +190,8 @@ class ZimbraAdminApi {
createAccount(name, password, attributes, callback) {
let resource_data = {
name: { '_content': name },
password: { '_content': password }
password: { '_content': password },
a: this.dictionary.attributesToArray(attributes)
};
this.create('Account', resource_data, callback);
}
......@@ -201,7 +202,8 @@ class ZimbraAdminApi {
createDomain(name, attributes, callback) {
let resource_data = {
name: { '_content': name }
name: { '_content': name },
a: this.dictionary.attributesToArray(attributes)
};
this.create('Domain', resource_data, callback);
}
......
......@@ -22,6 +22,16 @@ export default class Dictionary {
return 'name';
}
attributesToArray (attributes) {
if ($.isEmptyObject(attributes)) return [];
const result = []
const map = new Map(Object.entries(attributes));
map.forEach((key, value) => {
result.push({ 'n': value, '_content': key });
});
return result;
}
classFactory (resource, object) {
const class_name = this.resourceToClass(resource.toLowerCase());
return new class_name(object);
......
......@@ -177,6 +177,36 @@
});
});
it('should create and return Domain with attributes', function(done){
let resource_name = Date.now() + '.dev';
let resource_attributes = {
zimbraSkinLogoURL: 'http://www.zboxapp.com',
postOfficeBox: 'ZBoxApp'
};
let api = new ZimbraAdminApi(auth_data);
let callback = function(err, data){
if (err) return console.log(err);
expect(data.attrs.zimbraSkinLogoURL).to.equal('http://www.zboxapp.com');
expect(data.attrs.postOfficeBox).to.equal('ZBoxApp');
done();
};
api.createDomain(resource_name, resource_attributes, callback);
});
it('should create and return an account with extra attributes', function(done){
let account_name = Date.now() + '@zboxapp.dev';
let account_password = Date.now();
let account_attributes = { 'sn': 'Bruna', 'givenName': 'Patricio' };
let api = new ZimbraAdminApi(auth_data);
api.createAccount(account_name, account_password, account_attributes, function(err, data){
if (err) return console.log(err);
expect(data.attrs.sn).to.equal('Bruna');
expect(data.attrs.givenName).to.equal('Patricio');
done();
});
});
});
})();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment