Best JavaScript code snippet using cypress
uiCommunicateModel.js
Source:uiCommunicateModel.js
...598 this.AUTHENTICATION_TOKEN_REFRESH = function () {599 var deferred = $q.defer();600601 var refreshTokenData = uiCommunicate.createData().AUTHENTICATION_TOKEN_REFRESH();602 uiCommunicate.callWeb(uiCommunicate.getCaller().AUTHENTICATION, uiCommunicate.getActions(uiCommunicate.getCaller().AUTHENTICATION).TOKEN_REFRESH, refreshTokenData).then(function (_data) {603 checkErrors(_data);604 check_AUTHENTICATION_TOKEN_REFRESH(_data);605606 //Set token always for the user, the token for the engine is set by other processes607 if (_data.DATA && _data.DATA.TOKEN) {608 uiUser.setToken(_data.DATA.TOKEN);609 }610 deferred.resolve(_data);611 },612 function (_data) {613 checkErrors(_data);614 check_AUTHENTICATION_TOKEN_REFRESH(_data);615 deferred.reject(_data);616 }617 );618 return deferred.promise;619 };620621622 /**623 * Logout the current user with or without token624 * @method625 * @param {string} [_token=""]626 * @constructor627 */628 this.AUTHENTICATION_LOGOUT = function (_token) {629 var deferred = $q.defer();630 uiCommunicate.logout(uiCommunicate.getCaller().AUTHENTICATION, uiCommunicate.getActions(uiCommunicate.getCaller().AUTHENTICATION).LOGOUT, {}, _token).then(function (_data) {631 checkErrors(_data);632 check_AUTHENTICATION_LOGOUT(_data);633 deferred.resolve(_data);634 },635 function (_data) {636 checkErrors(_data);637 check_AUTHENTICATION_LOGOUT(_data);638 deferred.reject(_data);639 }640 );641 return deferred.promise;642 };643644 this.UNIGINE_CLOSE = function () {645 var deferred = $q.defer();646 uiCommunicate.callEngine(uiCommunicate.getCaller().UNIGINE, uiCommunicate.getActions(uiCommunicate.getCaller().UNIGINE).CLOSE, {}).then(function (_data) {647 checkErrors(_data);648 check_UNIGINE_CLOSE(_data);649 deferred.resolve(_data);650 },651 function (_data) {652 checkErrors(_data);653 check_UNIGINE_CLOSE(_data);654 deferred.reject(_data);655 }656 );657 return deferred.promise;658 };659660661 this.CHARACTER_CREATE = function (_nickname, _forename, _surname, _locationId) {662 var createCharacterData = uiCommunicate.createData().CHARACTER_CREATE(_nickname, _forename, _surname, _locationId);663 var deferred = $q.defer();664 uiCommunicate.callWeb(uiCommunicate.getCaller().CHARACTER, uiCommunicate.getActions(uiCommunicate.getCaller().CHARACTER).CREATE, createCharacterData).then(function (_data) {665 checkErrors(_data);666 check_CHARACTER_CREATE(_data);667 deferred.resolve(_data);668 },669 function (_data) {670 checkErrors(_data);671 check_CHARACTER_CREATE(_data);672 deferred.reject(_data);673 }674 );675 return deferred.promise;676 };677678 this.CHARACTER_GUI_SELECTION = function () {679 var selectionGUIData = uiCommunicate.createData().CHARACTER_GUI_SELECTION();680 var deferred = $q.defer();681 uiCommunicate.callEngine(uiCommunicate.getCaller().CHARACTER, uiCommunicate.getActions(uiCommunicate.getCaller().CHARACTER).GUI_SELECTION, selectionGUIData).then(function (_data) {682 checkErrors(_data);683 check_CHARACTER_GUI_SELECTION(_data);684 deferred.resolve(_data);685 },686 function (_data) {687 deferred.reject(_data);688 }689 );690 return deferred.promise;691 };692693694 this.UNIGINE_UI_ENTER = function () {695 var deferred = $q.defer();696 uiCommunicate.callEngine(uiCommunicate.getCaller().UNIGINE, uiCommunicate.getActions(uiCommunicate.getCaller().UNIGINE).UI_ENTER, {}).then(function (_data) {697 deferred.resolve(_data);698 },699 function (_data) {700 deferred.reject(_data);701 }702 );703 return deferred.promise;704 };705 this.UNIGINE_UI_LEAVE = function () {706 var deferred = $q.defer();707 uiCommunicate.callEngine(uiCommunicate.getCaller().UNIGINE, uiCommunicate.getActions(uiCommunicate.getCaller().UNIGINE).UI_LEAVE, {}).then(function (_data) {708 deferred.resolve(_data);709 },710 function (_data) {711 deferred.reject(_data);712 }713 );714 return deferred.promise;715 };716717718 this.ACCOUNT_SETTINGS_GET = function () {719720 var deferred = $q.defer();721 uiCommunicate.callWeb(uiCommunicate.getCaller().ACCOUNT, uiCommunicate.getActions(uiCommunicate.getCaller().ACCOUNT).SETTINGS_GET, uiCommunicate.createData().ACCOUNT_SETTINGS_GET())722 .then(function (_data) {723 checkErrors(_data);724 check_ACCOUNT_SETTINGS_GET(_data);725 deferred.resolve(_data);726 },727 function (_data) {728 checkErrors(_data);729 check_ACCOUNT_SETTINGS_GET(_data);730 deferred.reject(_data);731 }732 );733 return deferred.promise;734 };735736 this.ACCOUNT_SETTINGS_SET = function (_callEngine, _data) {737 if (!_data) {738 _data = {};739 }740 var deferred = $q.defer();741 if (_callEngine) {742 uiCommunicate.callEngine(uiCommunicate.getCaller().ACCOUNT, uiCommunicate.getActions(uiCommunicate.getCaller().ACCOUNT).SETTINGS_SET,743 _data)744 .then(function (_data) {745 deferred.resolve(_data);746 },747 function (_data) {748 deferred.reject(_data);749 }750 );751 }752 else {753 uiCommunicate.callWeb(uiCommunicate.getCaller().ACCOUNT, uiCommunicate.getActions(uiCommunicate.getCaller().ACCOUNT).SETTINGS_SET,754 _data)755 .then(function (_data) {756 checkErrors(_data);757 check_ACCOUNT_SETTINGS_SET(_data);758 deferred.resolve(_data);759 },760 function (_data) {761 checkErrors(_data);762 check_ACCOUNT_SETTINGS_SET(_data);763 deferred.reject(_data);764 }765 );766 }767 return deferred.promise;768 };769770771 this.CHANNEL_LEAVE = function (_channelId) {772 var deferred = $q.defer();773 uiCommunicate.callWeb(uiCommunicate.getCaller().CHANNEL, uiCommunicate.getActions(uiCommunicate.getCaller().CHANNEL).LEAVE, {UUID: _channelId}).then(774 function (_data) {775 checkErrors(_data);776 check_CHANNEL_LEAVE(_data);777 deferred.resolve(_data);778 },779 function (_data) {780 checkErrors(_data);781 check_CHANNEL_LEAVE(_data);782 deferred.reject(_data);783 });784 return deferred.promise;785 };786787 this.CHANNEL_GET_USER_LIST = function (_channelId) {788 var deferred = $q.defer();789 uiCommunicate.callWeb(uiCommunicate.getCaller().CHANNEL, uiCommunicate.getActions(uiCommunicate.getCaller().CHANNEL).GET_USER_LIST, {UUID: _channelId}).then(790 function (_data) {791 checkErrors(_data);792 check_CHANNEL_GET_USER_LIST(_data);793 deferred.resolve(_data);794 },795 function (_data) {796 checkErrors(_data);797 check_CHANNEL_GET_USER_LIST(_data);798 deferred.reject(_data);799 });800 return deferred.promise;801 };802803 this.UNIGINE_SET_STATE = function (_id, _data) {804 var deferred = $q.defer();805 uiCommunicate.callEngine(uiCommunicate.getCaller().UNIGINE, uiCommunicate.getActions(uiCommunicate.getCaller().UNIGINE).SET_STATE, {806 KEY: _id,807 DATA: _data808 }).then(809 function (_data) {810 deferred.resolve(_data);811 },812 function (_data) {813 deferred.reject(_data);814 });815 return deferred.promise;816 };817818 this.UNIGINE_GET_STATE = function (_id) {819 var deferred = $q.defer();820 uiCommunicate.callEngine(uiCommunicate.getCaller().UNIGINE, uiCommunicate.getActions(uiCommunicate.getCaller().UNIGINE).GET_STATE, {KEY: _id}).then(821 function (_data) {822 deferred.resolve(_data);823 },824 function (_data) {825 deferred.reject(_data);826 });827 return deferred.promise;828 };829830 this.CHARACTER_UNSTUCK = function () {831 var deferred = $q.defer();832 uiCommunicate.callEngine(uiCommunicate.getCaller().CHARACTER, uiCommunicate.getActions(uiCommunicate.getCaller().CHARACTER).UNSTUCK, {}).then(833 function (_data) {834 deferred.resolve(_data);835 },836 function (_data) {837 deferred.reject(_data);838 });839 return deferred.promise;840 };841842843 /**844 *845 * @param {boolean} _callEngine846 * @param _characterId847 * @param _token848 * @returns {promise|*|d.promise}849 * @constructor850 */851 this.CHARACTER_SPAWN = function (_callEngine, _characterId, _token) {852 var deferred = $q.defer();853854 if (_callEngine) {855 uiCommunicate.callEngine(uiCommunicate.getCaller().CHARACTER, uiCommunicate.getActions(uiCommunicate.getCaller().CHARACTER).SPAWN,856 uiCommunicate.createData().CHARACTER_SPAWN(_characterId, _token))857 .then(function (_data) {858859 deferred.resolve(_data);860 },861 function (_data) {862863 deferred.reject(_data);864 }865 );866 }867 else {868 uiCommunicate.callWeb(uiCommunicate.getCaller().CHARACTER, uiCommunicate.getActions(uiCommunicate.getCaller().CHARACTER).SPAWN,869 uiCommunicate.createData().CHARACTER_SPAWN(_characterId, _token))870 .then(function (_data) {871 checkErrors(_data);872 check_CHARACTER_SPAWN(_data);873 deferred.resolve(_data);874 },875 function (_data) {876 checkErrors(_data);877 check_CHARACTER_SPAWN(_data);878 deferred.reject(_data);879 }880 );881 }882883 return deferred.promise;884 };885886887 /**888 *889 * @param {boolean} _callEngine890 * @param _characterId891 * @returns {promise|*|d.promise}892 * @constructor893 */894 this.CHARACTER_DELETE = function (_callEngine, _characterId) {895 var deferred = $q.defer();896 if (_callEngine) {897 uiCommunicate.callEngine(uiCommunicate.getCaller().CHARACTER, uiCommunicate.getActions(uiCommunicate.getCaller().CHARACTER).DELETE,898 uiCommunicate.createData().CHARACTER_DELETE(_characterId))899 .then(function (_data) {900 deferred.resolve(_data);901 },902 function (_data) {903 deferred.reject(_data);904 }905 );906 }907 else {908 uiCommunicate.callWeb(uiCommunicate.getCaller().CHARACTER, uiCommunicate.getActions(uiCommunicate.getCaller().CHARACTER).DELETE,909 uiCommunicate.createData().CHARACTER_DELETE(_characterId))910 .then(function (_data) {911 checkErrors(_data);912 check_CHARACTER_DELETE(_data);913 deferred.resolve(_data);914 },915 function (_data) {916 checkErrors(_data);917 check_CHARACTER_DELETE(_data);918 deferred.reject(_data);919 }920 );921 }922923 return deferred.promise;924 };925926 this.SYNC_TIME_WEATHER = function (_callEngine, _data) {927928 if (!_data) {929 _data = {};930931 }932933 var deferred = $q.defer();934 if (_callEngine) {935 uiCommunicate.callEngine(uiCommunicate.getCaller().SYNC, uiCommunicate.getActions(uiCommunicate.getCaller().SYNC).TIME_WEATHER, _data)936 .then(function (_data) {937 deferred.resolve(_data);938 },939 function (_data) {940 deferred.reject(_data);941 }942 );943 }944 else {945946 uiCommunicate.callWeb(uiCommunicate.getCaller().SYNC, uiCommunicate.getActions(uiCommunicate.getCaller().SYNC).TIME_WEATHER, _data)947 .then(function (_data) {948 checkErrors(_data);949 check_SYNC_TIME_WEATHER(_data);950 deferred.resolve(_data);951 },952 function (_data) {953 checkErrors(_data);954 check_SYNC_TIME_WEATHER(_data);955 deferred.reject(_data);956 }957 );958 }959960 return deferred.promise;961 };962963964 this.SPAWN_RESOURCES = function (_data) {965966 if (!_data) {967 _data = {};968 }969970 var deferred = $q.defer();971 uiCommunicate.callWeb(uiCommunicate.getCaller().SYNC, uiCommunicate.getActions(uiCommunicate.getCaller().SYNC).SPAWN_RESOURCES, _data)972 .then(function (_data) {973 checkErrors(_data);974 check_SPAWN_RESOURCES(_data);975 deferred.resolve(_data);976 },977 function (_data) {978 checkErrors(_data);979 check_SPAWN_RESOURCES(_data);980 deferred.reject(_data);981 }982 );983984 return deferred.promise;985 };986987 this.DESPAWN_RESOURCES = function (_data) {988989 if (!_data) {990 _data = {};991 }992993 var deferred = $q.defer();994 uiCommunicate.callWeb(uiCommunicate.getCaller().SYNC, uiCommunicate.getActions(uiCommunicate.getCaller().SYNC).DESPAWN_RESOURCES, _data)995 .then(function (_data) {996 checkErrors(_data);997 check_DESPAWN_RESOURCES(_data);998 deferred.resolve(_data);999 },1000 function (_data) {1001 checkErrors(_data);1002 check_DESPAWN_RESOURCES(_data);1003 deferred.reject(_data);1004 }1005 );10061007 return deferred.promise;1008 };10091010 this.SPAWN_RESOURCES_INIT = function (_callEngine, _data) {10111012 if (!_data) {1013 _data = {};1014 }10151016 var deferred = $q.defer();1017 if (_callEngine) {1018 uiCommunicate.callEngine(uiCommunicate.getCaller().SYNC, uiCommunicate.getActions(uiCommunicate.getCaller().SYNC).SPAWN_RESOURCES_INIT, _data)1019 .then(function (_data) {1020 deferred.resolve(_data);1021 },1022 function (_data) {1023 deferred.reject(_data);1024 }1025 );1026 }1027 else {10281029 uiCommunicate.callWeb(uiCommunicate.getCaller().SYNC, uiCommunicate.getActions(uiCommunicate.getCaller().SYNC).SPAWN_RESOURCES_INIT, _data)1030 .then(function (_data) {1031 checkErrors(_data);1032 check_SPAWN_RESOURCES_INIT(_data);1033 deferred.resolve(_data);1034 },1035 function (_data) {1036 checkErrors(_data);1037 check_SPAWN_RESOURCES_INIT(_data);1038 deferred.reject(_data);1039 }1040 );1041 }10421043 return deferred.promise;1044 };104510461047 this.CHANNEL_GET_BY_NAME = function (_channelName) {1048 var deferred = $q.defer();10491050 var channelNameData = uiCommunicate.createChannelData().GET_CHANNEL_NAME(_channelName);1051 uiCommunicate.callWeb(uiCommunicate.getCaller().CHANNEL, uiCommunicate.getActions(uiCommunicate.getCaller().CHANNEL).GET_BY_NAME, channelNameData).then(function (_data) {1052 checkErrors(_data);1053 check_CHANNEL_GET_BY_NAME(_data);1054 deferred.resolve(_data);1055 },1056 function (_data) {1057 checkErrors(_data);1058 check_CHANNEL_GET_BY_NAME(_data);1059 deferred.reject(_data);1060 }1061 );1062 return deferred.promise;10631064 };10651066 this.CHANNEL_GET_LIST = function () {1067 var deferred = $q.defer();10681069 var getListData = uiCommunicate.createChannelData().GET_LIST();1070 uiCommunicate.callWeb(uiCommunicate.getCaller().CHANNEL, uiCommunicate.getActions(uiCommunicate.getCaller().CHANNEL).GET_LIST, getListData).then(function (_data) {1071 checkErrors(_data);1072 check_CHANNEL_GET_LIST(_data);1073 deferred.resolve(_data);1074 },1075 function (_data) {1076 checkErrors(_data);1077 check_CHANNEL_GET_LIST(_data);1078 deferred.reject(_data);1079 }1080 );1081 return deferred.promise;1082 };108310841085 this.CHARACTER_SELECT = function (_characterId, _slotId) {1086 var deferred = $q.defer();108710881089 uiCommunicate.callEngine(uiCommunicate.getCaller().CHARACTER, uiCommunicate.getActions(uiCommunicate.getCaller().CHARACTER).SELECT,1090 uiCommunicate.createData().CHARACTER_SELECT(_characterId, _slotId)).then(function (_data) {1091 checkErrors(_data);1092 check_CHARACTER_SELECT(_data);1093 deferred.resolve(_data);1094 },1095 function (_data) {1096 checkErrors(_data);1097 check_CHARACTER_SELECT(_data);1098 deferred.reject(_data);1099 }1100 );1101 return deferred.promise;1102 };1103 /**1104 * Login1105 * @param _username1106 * @param _password1107 * @returns {promise|*|d.promise}1108 * @method1109 */1110 this.AUTHENTICATION_LOGIN = function (_username, _password) {1111 var deferred = $q.defer();1112 uiCommunicate.login(uiCommunicate.getCaller().AUTHENTICATION, uiCommunicate.getActions(uiCommunicate.getCaller().AUTHENTICATION).LOGIN,1113 uiCommunicate.createData().AUTHENTICATION_LOGIN(_username, _password)).then(function (_data) {1114 checkErrors(_data);1115 check_AUTHENTICATION_LOGIN(_data);1116 deferred.resolve(_data);1117 },1118 function (_data) {1119 checkErrors(_data);1120 check_AUTHENTICATION_LOGIN(_data);1121 deferred.reject(_data);1122 }1123 );1124 return deferred.promise;1125 };1126 /**1127 *1128 * @param _data1129 * @returns {promise|*|d.promise}1130 * @method1131 */1132 this.UNIGINE_GET_TOKEN = function (_data) {1133 if (!_data) {1134 _data = {};1135 }1136 var deferred = $q.defer();1137 uiCommunicate.callEngine(uiCommunicate.getCaller().UNIGINE, uiCommunicate.getActions(uiCommunicate.getCaller().UNIGINE).GET_TOKEN, _data).then(function (_data) {1138 deferred.resolve(_data);1139 },1140 function (_data) {1141 deferred.reject(_data);1142 }1143 );1144 return deferred.promise;1145 };11461147 /**1148 *1149 * @param _data1150 * @returns {promise|*|d.promise}1151 * @method1152 */1153 this.UNIGINE_SET_TOKEN = function (_token) {1154 if (!_token) {1155 _token = "";1156 }1157 var deferred = $q.defer();1158 uiCommunicate.callEngine(uiCommunicate.getCaller().UNIGINE, uiCommunicate.getActions(uiCommunicate.getCaller().UNIGINE).SET_TOKEN, {"TOKEN": _token}).then(function (_data) {1159 deferred.resolve(_data);1160 },1161 function (_data) {1162 deferred.reject(_data);1163 }1164 );1165 return deferred.promise;1166 };1167 this.UNIGINE_SET_GUI_STATE = function (_state) {1168 if (!_state) {1169 _state = {};1170 }1171 var deferred = $q.defer();1172 uiCommunicate.callEngine(uiCommunicate.getCaller().UNIGINE, uiCommunicate.getActions(uiCommunicate.getCaller().UNIGINE).SET_GUI_STATE, _state).then(function (_data) {1173 deferred.resolve(_data);1174 },1175 function (_data) {1176 deferred.reject(_data);1177 }1178 );1179 return deferred.promise;1180 };118111821183 this.UNIGINE_GET_GUI_STATE = function () {1184 var deferred = $q.defer();1185 uiCommunicate.callEngine(uiCommunicate.getCaller().UNIGINE, uiCommunicate.getActions(uiCommunicate.getCaller().UNIGINE).GET_GUI_STATE, {}).then(function (_data) {1186 deferred.resolve(_data);1187 },1188 function (_data) {1189 deferred.reject(_data);1190 }1191 );1192 return deferred.promise;1193 };119411951196 /**1197 *1198 * @param _token1199 * @returns {promise|*|d.promise}1200 * @method1201 */1202 this.AUTHENTICATION_LOGIN_BY_TOKEN = function (_token) {1203 var deferred = $q.defer();1204 uiCommunicate.callWeb(uiCommunicate.getCaller().AUTHENTICATION, uiCommunicate.getActions(uiCommunicate.getCaller().AUTHENTICATION).LOGIN_BY_TOKEN,1205 uiCommunicate.createData().AUTHENTICATION_LOGIN_BY_TOKEN(_token))1206 .then(function (_data) {1207 checkErrors(_data);1208 check_AUTHENTICATION_LOGIN_BY_TOKEN(_data);1209 deferred.resolve(_data);1210 },1211 function (_data) {1212 checkErrors(_data);1213 check_AUTHENTICATION_LOGIN_BY_TOKEN(_data);1214 deferred.reject(_data);1215 }1216 );1217 return deferred.promise;1218 };12191220 this.UNIGINE_AJS_READY = function (_data) {1221 if (!_data) {1222 _data = {};1223 }1224 var deferred = $q.defer();1225 uiCommunicate.callEngine(uiCommunicate.getCaller().UNIGINE, uiCommunicate.getActions(uiCommunicate.getCaller().UNIGINE).AJS_READY, _data).then(function (_data) {1226 deferred.resolve(_data);1227 },1228 function (_data) {1229 deferred.reject(_data);1230 }1231 );1232 return deferred.promise;1233 };123412351236 /**1237 *1238 * @param _data1239 * @returns {promise|*|d.promise}1240 * @method1241 */1242 this.CHARACTER_LIST = function (_data) {1243 if (!_data) {1244 _data = {};1245 }1246 var deferred = $q.defer();1247 uiCommunicate.callWeb(uiCommunicate.getCaller().CHARACTER, uiCommunicate.getActions(uiCommunicate.getCaller().CHARACTER).LIST, uiCommunicate.createData().CHARACTER_LIST()).then(function (_data) {1248 deferred.resolve(_data);1249 checkErrors(_data);1250 check_CHARACTER_LIST(_data);1251 },1252 function (_data) {1253 checkErrors(_data);1254 check_CHARACTER_LIST(_data);1255 deferred.reject(_data);1256 }1257 );1258 return deferred.promise;1259 };12601261 /**1262 *1263 * @param _data1264 * @returns {promise|*|d.promise}1265 * @method1266 */1267 this.CHARACTER_SLOT_STATE = function (_data) {1268 if (!_data) {1269 _data = {};1270 }1271 var deferred = $q.defer();1272 uiCommunicate.callEngine(uiCommunicate.getCaller().CHARACTER, uiCommunicate.getActions(uiCommunicate.getCaller().CHARACTER).SLOT_STATE, _data).then(function (_data) {1273 checkErrors(_data);1274 check_CHARACTER_SLOT_STATE(_data);1275 deferred.resolve(_data);1276 },1277 function (_data) {1278 checkErrors(_data);1279 check_CHARACTER_SLOT_STATE(_data);1280 deferred.reject(_data);1281 }1282 );1283 return deferred.promise;1284 };12851286 this.CHARACTER_GUI_CREATE = function () {1287 var createGUIData = uiCommunicate.createData().CHARACTER_GUI_CREATE();1288 var deferred = $q.defer();1289 uiCommunicate.callEngine(uiCommunicate.getCaller().CHARACTER, uiCommunicate.getActions(uiCommunicate.getCaller().CHARACTER).GUI_CREATE, createGUIData).then(function (_data) {1290 checkErrors(_data);1291 check_CHARACTER_GUI_CREATE(_data);1292 deferred.resolve(_data);1293 },1294 function (_data) {1295 checkErrors(_data);1296 check_CHARACTER_GUI_CREATE(_data);1297 deferred.reject(_data);1298 }1299 );1300 return deferred.promise;1301 };13021303 /**1304 *1305 * @param _minigameId1306 * @param _itemId1307 * @param _layerId1308 * @param _value1309 * @returns {promise|*|d.promise}1310 * @example1311 * [1312 {1313 STORAGE: ID1314 ITEMS: [{"IS_STACKED":true,"WIDTH":1,"WEIGHT":0,"NAME":"StackingBagItem","TEMPLATE":4,"SLOT":10,"IS_BANK":false,"ID":8,"HEIGHT":1}]1315 }1316 ] 1317 * @constructor1318 */1319 this.GATHERING_RESULT = function (_minigameId, _itemId, _layerId, _value) {1320 var gatheringResultData = uiCommunicate.createData().GATHERING_RESULT(_minigameId, _itemId, _layerId, _value);1321 var deferred = $q.defer();1322 uiCommunicate.callWeb(uiCommunicate.getCaller().GATHERING, uiCommunicate.getActions(uiCommunicate.getCaller().GATHERING).RESULT, gatheringResultData).then(function (_data) {1323 checkErrors(_data);1324 check_GATHERING_RESULT(_data);1325 deferred.resolve(_data);1326 },1327 function (_data) {1328 checkErrors(_data);1329 check_GATHERING_RESULT(_data);1330 deferred.reject(_data);1331 }1332 );1333 return deferred.promise;1334 };133513361337 this.EQUIP_TORCH = function(_state){1338 ///TODO Remove in next version for equip main hand.1339 var torchData = uiCommunicate.createData().CHARACTER_TORCH(_state);1340 var deferred = $q.defer();1341 uiCommunicate.callEngine(uiCommunicate.getCaller().CHARACTER, uiCommunicate.getActions(uiCommunicate.getCaller().CHARACTER).TORCH, torchData).then(function (_data) {1342 checkErrors(_data);1343 //check_EQUIP_MAIN_HAND(_data);1344 deferred.resolve(_data);1345 },1346 function (_data) {1347 checkErrors(_data);1348 //check_EQUIP_MAIN_HAND(_data);1349 deferred.reject(_data);1350 }1351 );1352 return deferred.promise;1353 };13541355 this.EQUIP_MAIN_HAND = function (_id) {1356 var gatheringResultData = uiCommunicate.createData().EQUIP_MAIN_HAND(_id);1357 var deferred = $q.defer();1358 uiCommunicate.callEngine(uiCommunicate.getCaller().CHARACTER, uiCommunicate.getActions(uiCommunicate.getCaller().CHARACTER).EQUIP_MAIN_HAND, gatheringResultData).then(function (_data) {1359 checkErrors(_data);1360 check_EQUIP_MAIN_HAND(_data);1361 deferred.resolve(_data);1362 },1363 function (_data) {1364 checkErrors(_data);1365 check_EQUIP_MAIN_HAND(_data);1366 deferred.reject(_data);1367 }1368 );1369 return deferred.promise;1370 };1371 /************************************************************** Public - PROPERTIES - START ***********************************************************/1372
...
implementation_spec.js
Source:implementation_spec.js
...141 calledCount++;142 return [{ getFileName: noop }];143 },144 getCaller = _implementation(null, null, callsite).getCaller;145 getCaller();146 expect(calledCount, 'callsite is called once').to.equal(1);147 });148 it('returns current caller', function () {149 var calledCount = 0,150 callsite = function () {151 calledCount++;152 return [153 {154 getFileName: function () {155 return 'foo';156 }157 }, {158 getFileName: function () {159 return 'bar';160 }161 }162 ];163 },164 getCaller = _implementation(null, null, callsite).getCaller,165 result = getCaller();166 expect(result).to.equal('bar');167 expect(calledCount, 'callsite is called once').to.equal(1);168 });169 it('returns undefined if cannot obtain current caller', function () {170 var calledCount = 0,171 callsite = function () {172 calledCount++;173 return [174 {175 getFileName: function () {176 return 'foo';177 }178 }179 ];180 },181 getCaller = _implementation(null, null, callsite).getCaller,182 result = getCaller();183 expect(result).to.be.an('undefined');184 expect(calledCount, 'callsite is called once').to.equal(1);185 });186 });187 describe('exceptions', function () {188 it('thrown for invalid input', function () {189 var implementation = _implementation();190 expect(191 implementation,192 'throws an exception for non-string input'193 ).to.throw('Module path must be a string');194 });195 it('thrown when cannot determine caller', function () {196 var implementation = _implementation();...
err.js
Source:err.js
...17 throwError: (fxName = 'unknown function', paramName = 'unknown parameter', expectation = 'to be defined') => {18 throw ['@', fxName, '(): Expected parameter \'', paramName, '\' ', expectation].join('');19 },20 isUndefined: (paramName = '<unknown parameter>', param) => {21 if ([null, undefined].indexOf(param) > -1) err.throwError(err.getCaller(2), paramName);22 },23 isFalsy: (paramName = '<unknown parameter>', param) => {24 if (!param) err.throwError(err.getCaller(2), paramName);25 },26 isNoneOf: (paramName = '<unknown parameter>', param, contains = []) => {27 if (contains.indexOf(param) === -1) err.throwError(err.getCaller(2), paramName, 'to be any of' + JSON.stringify(contains));28 },29 isAnyOf: (paramName = '<unknown parameter>', param, contains = []) => {30 if (contains.indexOf(param) > -1) err.throwError(err.getCaller(2), paramName, 'not to be any of' + JSON.stringify(contains));31 },32 isNotType: (paramName = '<unknown parameter>', param, type = '') => {33 if (getType(param) !== type.toLowerCase()) err.throwError(err.getCaller(2), paramName, 'to be type ' + type.toLowerCase());34 },35 isAnyTypeOf: (paramName = '<unknown parameter>', param, types = []) => {36 types.forEach(type => {37 if (getType(param) === type) err.throwError(err.getCaller(2), paramName, 'not to be type of ' + type.toLowerCase());38 });39 },40 missingKey: (paramName = '<unknown parameter>', param, keyName = '') => {41 err.isUndefined(paramName, param);42 if (Object.keys(param).indexOf(keyName) === -1) err.throwError(err.getCaller(2), paramName, 'to contain \'' + keyName + '\' key');43 },44 missingAnyKeys: (paramName = '<unknown parameter>', param, keyNames = ['']) => {45 err.isUndefined(paramName, param);46 const keyList = Object.keys(param);47 keyNames.forEach(keyName => {48 if (keyList.indexOf(keyName) === -1) err.throwError(err.getCaller(2), paramName, 'to contain \'' + keyName + '\' key');49 });50 },51 containsUndefined: (paramName = '<unknown parameter>', param) => {52 [undefined, null].forEach(value => {53 const location = locate(param, value);54 if (location) err.throwError(err.getCaller(2), paramName, 'not to contain \'' + JSON.stringify(value) + '\' at ' + location);55 });56 },57 isInvalidPath: (paramName = '<unknown parameter>', param) => {58 err.isUndefined(paramName, param);59 err.isNotType(paramName, param, 'string');60 err.isAnyOf(paramName, param, ['', '/']);61 '.$[]#'.split().forEach(invalidChar => {62 if (param.indexOf(invalidChar) > -1) err.throwError(err.getCaller(2), paramName, 'not to contain invalid character \'' + invalidChar + '\'');63 });64 if (param.match(/\/{2,}/g)) err.throwError(err.getCaller(2), paramName, 'not to contain consecutive forward slash characters');65 },66 isInvalidWriteData: (paramName = '<unknown parameter>', param) => {67 err.isUndefined(paramName, param);68 err.containsUndefined(paramName, param);69 }70};...
javaScriptBottlenecks.js
Source:javaScriptBottlenecks.js
...29 }30 // spy calls to eval()31 if (spyEval) {32 phantomas.spy(window, 'eval', function(code) {33 report('eval() called directly', phantomas.getCaller(), phantomas.getBacktrace(), 'evalCalls');34 phantomas.log('eval\'ed code: ' + (code || '').substring(0, 150) + '(...)');35 });36 }37 // spy calls to setTimeout / setInterval with string passed instead of a function38 phantomas.spy(window, 'setTimeout', function(fn, interval) {39 if (typeof fn !== 'string') return;40 report('eval() called via setTimeout("' + fn + '")', phantomas.getCaller(), phantomas.getBacktrace(), 'evalCalls');41 });42 phantomas.spy(window, 'setInterval', function(fn, interval) {43 if (typeof fn !== 'string') return;44 report('eval() called via setInterval("' + fn + '")', phantomas.getCaller(), phantomas.getBacktrace(), 'evalCalls');45 });46 // spy document.write(ln)47 phantomas.spy(document, 'write', function(arg) {48 report('document.write() used', phantomas.getCaller(), phantomas.getBacktrace(), 'documentWriteCalls');49 });50 phantomas.spy(document, 'writeln', function(arg) {51 report('document.writeln() used', phantomas.getCaller(), phantomas.getBacktrace(), 'documentWriteCalls');52 });53 })(window.__phantomas);54 }, spyEval);55 });...
index.js
Source:index.js
...16 that._caller = caller;17}18function doSetDB() {19 bcLog('#### Receive is', this.getReceiver());20 bcLog('#### caller is', this.getCaller());21 assert.equal(this.getReceiver(), this.getCaller());22 bcLog('#### DB create ret is', bcDBCreate('IotDemo'));23 return true;24}25function doUnlock() {26 bcLog('before bcDBGet');27 let owner = bcDBGet('IotDemo', 'owner');28 assert.equal(owner, this.getCaller());29 assert.equal(bcDBSet('IotDemo', 'state', 'unlock'), true);30 return true;31}32function doLock() {33 let owner = bcDBGet('IotDemo', 'owner');34 assert.equal(owner, this.getCaller());35 assert.equal(bcDBSet('IotDemo', 'state', 'lock'), true);36 return true;37}38function doSetOwner() {39 assert.equal(bcDBSet('IotDemo', 'owner', this.getCaller()), true);40 assert.equal(bcDBSet('IotDemo', 'state', 'lock'), true);41 return true;42}43Contract.prototype.getReceiver = function() {44 return this._receiver;45}46Contract.prototype.getCaller = function() {47 return this._caller;48}49Contract.prototype.doTransfer = doTransfer;50Contract.prototype.doSetDB = doSetDB;51Contract.prototype.doSetOwner = doSetOwner;52Contract.prototype.doUnlock = doUnlock;53Contract.prototype.doLock = doLock;...
ExpressLogger.js
Source:ExpressLogger.js
...7}8/**9 * @param {import("express").Request} req10 */11function getCaller(req) {12 return `${req.method.toUpperCase()} ${req.path} HTTP/${req.httpVersion} ${req.socket.remoteAddress} ${req.headers["user-agent"]}`;13}14/**15 * @param {import("./Logger")} logger16 * @param {import("express").Request} req17 */18function logInitial(logger, req) {19 logger.debug(getCaller(req));20}21/**22 * @param {import("./Logger")} logger23 * @param {import("express").Request} req24 * @param {import("express").Response} res25 * @param {[number, number]} stamp26 */27function logFinal(logger, req, res, stamp) {28 logger.onAccess(`${getCaller(req)} >> FINAL ${res.statusCode} ${getTiming(stamp)}ms`);29}30/**31 * @param {import("./Logger")} logger32 * @param {import("express").Request} req33 * @param {import("express").Response} res34 * @param {[number, number]} stamp35 */36function logPremature(logger, req, res, stamp) {37 logger.onAccess(`${getCaller(req)} >> PREMATURE ${res.statusCode} ${getTiming(stamp)}ms`);38}39/**40 * @param {import("./Logger")} logger41 */42module.exports = (logger) => {43 /**44 * @param {import("express").Request} req45 * @param {import("express").Response} res46 * @param {import("express").NextFunction} next47 */48 const fn = (req, res, next) => {49 const stampStart = process.hrtime();50 logInitial(logger, req);51 req.on("close", () => logPremature(logger, req, res, stampStart));...
CallerTest.js
Source:CallerTest.js
...15 * @extends Core.abstract.Component16 */17class CallerTest extends Core.cls( "Core.abstract.Component" ) {18 methodEntryPoint() {19 return this.getCaller();20 }21 get getterEntryPoint() {22 return this.getCaller();23 }24 set setterEntryPoint( ignoredValue ) {25 this._setterCaller = this.getCaller();26 }27 getCaller() {28 return Core.debugInspector.getCaller();29 }30 // ----31 static staticMethodEntryPoint() {32 return this.getStaticCaller();33 }34 static get staticGetterEntryPoint() {35 return this.getStaticCaller();36 }37 static set staticSetterEntryPoint( ignoredValue ) {38 this._staticSetterCaller = this.getStaticCaller();39 }40 static getStaticCaller() {41 return Core.debugInspector.getCaller();42 }43}...
Group.js
Source:Group.js
...15 if (obj) {16 obj.highlight(sub);17 this.highlighted++;18 if (this.getCaller) {19 this.getCaller().getNode().addClass('field-statut-invalid');20 }21 }22 return obj;23 },24 downlight : function() {25 this.highlighted--;26 if (!this.highlighted) {27 this.getParent().downlight();28 if (this.getCaller) {29 this.getCaller().getNode().removeClass('field-statut-invalid');30 }31 }32 }...
Using AI Code Generation
1describe('My First Test', function() {2 it('Does not do much!', function() {3 cy.get('.home-list > :nth-child(1) > a').click()4 cy.get('#query-btn').click()5 cy.get('.query-table').should('be.visible')6 cy.get('.query-table').contains('td', 'type').should('be.visible')
Using AI Code Generation
1Cypress.Commands.add("getCaller", () => {2 return Cypress._.last(Cypress.mocha.getRunner().suite.ctx.test.parent.tests).title;3});4Cypress.Commands.add("getCaller", () => {5 return Cypress._.last(Cypress.mocha.getRunner().suite.ctx.test.parent.tests).title;6});7Cypress.Commands.add("getCaller", () => {8 return Cypress._.last(Cypress.spec.specType).description;9});10Cypress.Commands.add("getCaller", () => {11 return Cypress._.last(Cypress.spec.specType).description;12});13Cypress.Commands.add("getCaller", () => {14 return Cypress._.last(Cypress.spec.specType).title;15});16Cypress.Commands.add("getCaller", () => {17 return Cypress._.last(Cypress.spec.specType).title;18});19Cypress.Commands.add("getCaller", () => {20 return Cypress._.last(Cypress.spec.specType).name;21});22Cypress.Commands.add("getCaller", () => {23 return Cypress._.last(Cypress.spec.specType).name;24});25Cypress.Commands.add("getCaller", () => {26 return Cypress._.last(Cypress.mocha.getRunner().suite.ctx.test.parent.tests).title;27});28Cypress.Commands.add("getCaller", () => {29 return Cypress._.last(Cypress.spec.specType).description;30});31Cypress.Commands.add("getCaller", () => {32 return Cypress._.last(Cypress.spec.specType).description;33});34Cypress.Commands.add("getCaller", () => {35 return Cypress._.last(Cypress.spec.specType).title;36});37Cypress.Commands.add("getCaller", () => {38 return Cypress._.last(Cypress.spec.specType).title;39});40Cypress.Commands.add("getCaller", () => {
Using AI Code Generation
1Cypress.Commands.add("getCaller", () => {2 const stack = new Error().stack;3 const caller = stack.split("at ")[3].trim();4 return caller;5});6Cypress.Commands.add("getCaller", () => {7 const stack = new Error().stack;8 const caller = stack.split("at ")[3].trim();9 return caller;10});11Cypress.Commands.add("getCaller", () => {12 const stack = new Error().stack;13 const caller = stack.split("at ")[3].trim();14 return caller;15});16Cypress.Commands.add("getCaller", () => {17 const stack = new Error().stack;18 const caller = stack.split("at ")[3].trim();19 return caller;20});21Cypress.Commands.add("getCaller", () => {22 const stack = new Error().stack;23 const caller = stack.split("at ")[3].trim();24 return caller;25});26Cypress.Commands.add("getCaller", () => {27 const stack = new Error().stack;28 const caller = stack.split("at ")[3].trim();29 return caller;30});31Cypress.Commands.add("getCaller", () => {32 const stack = new Error().stack;33 const caller = stack.split("at ")[3].trim();34 return caller;35});36Cypress.Commands.add("getCaller", () => {37 const stack = new Error().stack;38 const caller = stack.split("at ")[3].trim();39 return caller;40});41Cypress.Commands.add("getCaller", () => {42 const stack = new Error().stack;43 const caller = stack.split("at ")[3].trim();44 return caller;45});46Cypress.Commands.add("getCaller", () => {47 const stack = new Error().stack;48 const caller = stack.split("at ")[3].trim();49 return caller;50});51Cypress.Commands.add("getCaller", () => {52 const stack = new Error().stack
Using AI Code Generation
1Cypress.Commands.add('getCaller', () => {2 const stack = new Error().stack;3 const caller = stack.split('at ')[3].trim();4 return caller;5});6Cypress.Commands.add('getCaller', () => {7 const stack = new Error().stack;8 const caller = stack.split('at ')[2].trim();9 return caller;10});11Cypress.Commands.add('getCaller', () => {12 const stack = new Error().stack;13 const caller = stack.split('at ')[2].trim();14 return caller;15});16Cypress.Commands.add('getCaller', () => {17 const stack = new Error().stack;18 const caller = stack.split('at ')[3].trim();19 return caller;20});21Cypress.Commands.add('getCaller', () => {22 const stack = new Error().stack;23 const caller = stack.split('at ')[2].trim();24 return caller;25});26Cypress.Commands.add('getCaller', () => {27 const stack = new Error().stack;28 const caller = stack.split('at ')[2].trim();29 return caller;30});31Cypress.Commands.add('getCaller', () => {32 const stack = new Error().stack;33 const caller = stack.split('at ')[3].trim();34 return caller;35});36Cypress.Commands.add('getCaller', () => {37 const stack = new Error().stack;38 const caller = stack.split('at ')[2].trim();39 return caller;40});41Cypress.Commands.add('getCaller', () => {42 const stack = new Error().stack;43 const caller = stack.split('at ')[2].trim();44 return caller;45});46Cypress.Commands.add('getCaller', () => {47 const stack = new Error().stack;48 const caller = stack.split('at ')[3].trim();
Using AI Code Generation
1const path = require('path');2const fs = require('fs');3const getCaller = (err) => {4 const stack = err.stack.split('\n');5 let caller = stack[1];6 caller = caller.replace(' at ', '');7 caller = caller.replace(' (', ':');8 caller = caller.replace(')', '');9 return caller;10};11const err = new Error('test');12const caller = getCaller(err);13console.log(caller);14const path = require('path');15const fs = require('fs');16const getCaller = (err) => {17 const stack = err.stack.split('\n');18 let caller = stack[1];19 caller = caller.replace(' at ', '');20 caller = caller.replace(' (', ':');21 caller = caller.replace(')', '');22 return caller;23};24const err = new Error('test');25const caller = getCaller(err);26console.log(caller);27const path = require('path');28const fs = require('fs');29const getCaller = (err) => {30 const stack = err.stack.split('\n');31 let caller = stack[1];32 caller = caller.replace(' at ', '');33 caller = caller.replace(' (', ':');34 caller = caller.replace(')', '');35 return caller;36};37const err = new Error('test');38const caller = getCaller(err);39console.log(caller);40const path = require('path');41const fs = require('fs');42const getCaller = (err) => {43 const stack = err.stack.split('\n');44 let caller = stack[1];45 caller = caller.replace(' at ', '');46 caller = caller.replace(' (', ':');47 caller = caller.replace(')', '');48 return caller;49};50const err = new Error('test');51const caller = getCaller(err);52console.log(caller);53const path = require('path');54const fs = require('fs');55const getCaller = (err) => {56 const stack = err.stack.split('\n');57 let caller = stack[1];58 caller = caller.replace(' at ', '');
Cypress is a renowned Javascript-based open-source, easy-to-use end-to-end testing framework primarily used for testing web applications. Cypress is a relatively new player in the automation testing space and has been gaining much traction lately, as evidenced by the number of Forks (2.7K) and Stars (42.1K) for the project. LambdaTest’s Cypress Tutorial covers step-by-step guides that will help you learn from the basics till you run automation tests on LambdaTest.
You can elevate your expertise with end-to-end testing using the Cypress automation framework and stay one step ahead in your career by earning a Cypress certification. Check out our Cypress 101 Certification.
Watch this 3 hours of complete tutorial to learn the basics of Cypress and various Cypress commands with the Cypress testing at LambdaTest.
Get 100 minutes of automation test minutes FREE!!