Skip to content

Instantly share code, notes, and snippets.

@cmcdevitt
Created December 10, 2013 03:01
Show Gist options
  • Save cmcdevitt/7885111 to your computer and use it in GitHub Desktop.
Save cmcdevitt/7885111 to your computer and use it in GitHub Desktop.
Jasmine Helper is a support class for the Jasmine Test Suite in ServiceNow implemented by Fruition Partners Test Runner
//Version 0.01 12/09/2013
//ServiceNow / Fruition Partners Test Runner
//Supporting Class for Jasamine Test Suites
var JasmineHelper = Class.create();
JasmineHelper.prototype = {
initialize: function() {
},
getSysID: function(itemName,tableName){
//Note: Does not work for User
//Todo: add varable incase the 'name' field is not correct
//var dc = gs.getDisplayColumn(tableName);
//gs.log("The display name for " + tableName + " is: " + dc, "Chris");
var gdRec = new GlideRecord(tableName);
gdRec.addQuery('name', '=', itemName);
gdRec.query();
if(gdRec.next()){
return gdRec.sys_id;
}else{
return null;
}
},
getUserSysID: function(userName){
var gdRec = new GlideRecord('sys_user');
gdRec.addQuery('user_name', '=', userName);
gdRec.query();
if(gdRec.next()){
return gdRec.sys_id;
}else{
return null;
}
},
addUserToGroup: function(userName, groupName){
var user = this.getUserSysID(userName);
var group = this.getSysID(groupName,'sys_user_group');
var gdRec = new GlideRecord('sys_user_grmember');
//Check to see if user is already in group
gdRec.addQuery('user','=', user);
gdRec.addQuery('group','=', group);
gdRec.query();
if(gdRec.next()){
//Found it, so don't insert it
//gs.log("User already in group" + gdRec.user, "Chris");
return true;
}else{
gdRec.initialize();
gdRec.group = group;
gdRec.user = user;
gdRec.insert(); //Todo:Returns the sys_id of the record or null if not inserted.
//gs.log("Inserting User into Group...", "Chris");
return true;
}
},
remUserFromGroup: function(userName, groupName){
var user = this.getUserSysID(userName);
var group = this.getSysID(groupName,'sys_user_group');
var gdRec = new GlideRecord('sys_user_grmember');
//Find Record
gdRec.addQuery('user','=', user);
gdRec.addQuery('group','=', group);
gdRec.query();
if(gdRec.next()){
return gdRec.deleteRecord();
}else{
//Nothing to delete!
return true;
}
},
addNotifToDevice: function(userName,notifName){
//Table: Notification Messages [cmn_notif_message]
//cmn_notif_device
},
remNotifFromDevice: function(userName,notifName){
//Table: Notification Messages [cmn_notif_message]
},
type: 'JasmineHelper'
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment