Best JavaScript code snippet using fast-check-monorepo
jquery.cropzoom.js
Source:jquery.cropzoom.js
...131 $image = $('<img />');132 $image.attr('src', $options.image.source);133 $($image).css({134 'position': 'absolute',135 'left': getData('image').posX,136 'top': getData('image').posY,137 'width': getData('image').w,138 'height': getData('image').h139 });140 var ext = getExtensionSource();141 if (ext == 'png' || ext == 'gif')142 $image[0].style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"143 + $options.image.source144 + "',sizingMethod='scale');";145 $container.append($image);146 _self.append($container);147 calculateTranslationAndRotation();148 // adding draggable to the image149 $($image).draggable({150 refreshPositions: true,151 drag: function (event, ui) {152 getData('image').posY = ui.position.top153 getData('image').posX = ui.position.left154 if ($options.image.snapToContainer)155 limitBounds(ui);156 else157 calculateTranslationAndRotation();158 // Fire the callback159 if ($options.image.onImageDrag != null)160 $options.image.onImageDrag($image);161 },162 stop: function (event, ui) {163 if ($options.image.snapToContainer)164 limitBounds(ui);165 }166 });167 // Create the selector168 createSelector();169 // Add solid color to the selector170 _self.find('.ui-icon-gripsmall-diagonal-se').css({171 'background': '#FFF',172 'border': '1px solid #000',173 'width': 8,174 'height': 8175 });176 // Create the dark overlay177 createOverlay();178 if ($options.selector.startWithOverlay) {179 /* Make Overlays at Start */180 var ui_object = {181 position: {182 top: $selector.position().top,183 left: $selector.position().left184 }185 };186 makeOverlayPositions(ui_object);187 }188 /* End Make Overlay at start */189 // Create zoom control190 if ($options.enableZoom)191 createZoomSlider();192 // Create rotation control193 if ($options.enableRotation)194 createRotationSlider();195 if ($options.expose.elementMovement != '')196 createMovementControls();197 function limitBounds(ui) {198 if (ui.position.top > 0)199 getData('image').posY = 0;200 if (ui.position.left > 0)201 getData('image').posX = 0;202 var bottom = -(getData('image').h - ui.helper.parent()203 .parent().height()), right = -(getData('image').w - ui.helper204 .parent().parent().width());205 if (ui.position.top < bottom)206 getData('image').posY = bottom;207 if (ui.position.left < right)208 getData('image').posX = right;209 calculateTranslationAndRotation();210 }211 function getExtensionSource() {212 var parts = $options.image.source.split('.');213 return parts[parts.length - 1];214 }215 ;216 function calculateFactor() {217 getData('image').scaleX = ($options.width / getData('image').w);218 getData('image').scaleY = ($options.height / getData('image').h);219 }220 ;221 function getCorrectSizes() {222 if ($options.image.startZoom != 0) {223 var zoomInPx_width = (($options.image.width * Math224 .abs($options.image.startZoom)) / 100);225 var zoomInPx_height = (($options.image.height * Math226 .abs($options.image.startZoom)) / 100);227 getData('image').h = zoomInPx_height;228 getData('image').w = zoomInPx_width;229 //Checking if the position was set before230 if (getData('image').posY != 0231 && getData('image').posX != 0) {232 if (getData('image').h > $options.height)233 getData('image').posY = Math234 .abs(($options.height / 2)235 - (getData('image').h / 2));236 else237 getData('image').posY = (($options.height / 2) - (getData('image').h / 2));238 if (getData('image').w > $options.width)239 getData('image').posX = Math240 .abs(($options.width / 2)241 - (getData('image').w / 2));242 else243 getData('image').posX = (($options.width / 2) - (getData('image').w / 2));244 }245 } else {246 var scaleX = getData('image').scaleX;247 var scaleY = getData('image').scaleY;248 if (scaleY < scaleX) {249 getData('image').h = $options.height;250 getData('image').w = Math251 .round(getData('image').w * scaleY);252 } else {253 getData('image').h = Math254 .round(getData('image').h * scaleX);255 getData('image').w = $options.width;256 }257 }258 // Disable snap to container if is little259 if (getData('image').w < $options.width260 && getData('image').h < $options.height) {261 $options.image.snapToContainer = false;262 }263 calculateTranslationAndRotation();264 }265 ;266 function calculateTranslationAndRotation() {267 $(function () {268 adjustingSizesInRotation();269 // console.log(imageData.id);270 rotation = "rotate(" + getData('image').rotation + "deg)";271 $($image).css({272 'transform': rotation,273 '-webkit-transform': rotation,274 '-ms-transform': rotation,275 'msTransform': rotation,276 'top': getData('image').posY,277 'left': getData('image').posX278 });279 });280 }281 ;282 function createRotationSlider() {283 var rotationContainerSlider = $("<div />").attr('id',284 'rotationContainer').mouseover(function () {285 $(this).css('opacity', 1);286 }).mouseout(function () {287 $(this).css('opacity', 0.6);288 });289 var rotMin = $('<div />').attr('id', 'rotationMin')290 .html("0");291 var rotMax = $('<div />').attr('id', 'rotationMax')292 .html("360");293 var $slider = $("<div />").attr('id', 'rotationSlider');294 // Apply slider295 var orientation = 'vertical';296 var value = Math.abs(360 - $options.image.rotation);297 if ($options.expose.slidersOrientation == 'horizontal') {298 orientation = 'horizontal';299 value = $options.image.rotation;300 }301 $slider302 .slider({303 orientation: orientation,304 value: value,305 range: "max",306 min: 0,307 max: 360,308 step: (($options.rotationSteps > 360 || $options.rotationSteps < 0) ? 1309 : $options.rotationSteps),310 slide: function (event, ui) {311 getData('image').rotation = (value == 360 ? Math312 .abs(360 - ui.value)313 : Math.abs(ui.value));314 calculateTranslationAndRotation();315 if ($options.image.onRotate != null)316 $options.image.onRotate($slider,317 getData('image').rotation);318 }319 });320 rotationContainerSlider.append(rotMin);321 rotationContainerSlider.append($slider);322 rotationContainerSlider.append(rotMax);323 if ($options.expose.rotationElement != '') {324 $slider325 .addClass($options.expose.slidersOrientation);326 rotationContainerSlider327 .addClass($options.expose.slidersOrientation);328 rotMin.addClass($options.expose.slidersOrientation);329 rotMax.addClass($options.expose.slidersOrientation);330 $($options.expose.rotationElement).empty().append(331 rotationContainerSlider);332 } else {333 $slider.addClass('vertical');334 rotationContainerSlider.addClass('vertical');335 rotMin.addClass('vertical');336 rotMax.addClass('vertical');337 rotationContainerSlider.css({338 'position': 'absolute',339 'top': 5,340 'left': 5,341 'opacity': 0.6342 });343 _self.append(rotationContainerSlider);344 }345 }346 ;347 function createZoomSlider() {348 var zoomContainerSlider = $("<div />").attr('id',349 'zoomContainer').mouseover(function () {350 $(this).css('opacity', 1);351 }).mouseout(function () {352 $(this).css('opacity', 0.6);353 });354 var zoomMin = $('<div />').attr('id', 'zoomMin').html(355 "<b>-</b>");356 var zoomMax = $('<div />').attr('id', 'zoomMax').html(357 "<b>+</b>");358 var $slider = $("<div />").attr('id', 'zoomSlider');359 // Apply Slider360 $slider361 .slider({362 orientation: ($options.expose.zoomElement != '' ? $options.expose.slidersOrientation363 : 'vertical'),364 value: ($options.image.startZoom != 0 ? $options.image.startZoom365 : getPercentOfZoom(getData('image'))),366 min: ($options.image.useStartZoomAsMinZoom ? $options.image.startZoom367 : $options.image.minZoom),368 max: $options.image.maxZoom,369 step: (($options.zoomSteps > $options.image.maxZoom || $options.zoomSteps < 0) ? 1370 : $options.zoomSteps),371 slide: function (event, ui) {372 var value = ($options.expose.slidersOrientation == 'vertical' ? ($options.image.maxZoom - ui.value)373 : ui.value);374 var zoomInPx_width = ($options.image.width * Math.abs(value) / 100);375 var zoomInPx_height = ($options.image.height * Math.abs(value) / 100);376 $($image).css({377 'width': zoomInPx_width + "px",378 'height': zoomInPx_height + "px"379 });380 var difX = (getData('image').w / 2) - (zoomInPx_width / 2);381 var difY = (getData('image').h / 2) - (zoomInPx_height / 2);382 var newX = (difX > 0 ? getData('image').posX383 + Math.abs(difX)384 : getData('image').posX385 - Math.abs(difX));386 var newY = (difY > 0 ? getData('image').posY387 + Math.abs(difY)388 : getData('image').posY389 - Math.abs(difY));390 getData('image').posX = newX;391 getData('image').posY = newY;392 getData('image').w = zoomInPx_width;393 getData('image').h = zoomInPx_height;394 calculateFactor();395 calculateTranslationAndRotation();396 if ($options.image.onZoom != null) {397 $options.image.onZoom($image,398 getData('image'));399 }400 }401 });402 if ($options.slidersOrientation == 'vertical') {403 zoomContainerSlider.append(zoomMax);404 zoomContainerSlider.append($slider);405 zoomContainerSlider.append(zoomMin);406 } else {407 zoomContainerSlider.append(zoomMin);408 zoomContainerSlider.append($slider);409 zoomContainerSlider.append(zoomMax);410 }411 if ($options.expose.zoomElement != '') {412 zoomMin413 .addClass($options.expose.slidersOrientation);414 zoomMax415 .addClass($options.expose.slidersOrientation);416 $slider417 .addClass($options.expose.slidersOrientation);418 zoomContainerSlider419 .addClass($options.expose.slidersOrientation);420 $($options.expose.zoomElement).empty().append(421 zoomContainerSlider);422 } else {423 zoomMin.addClass('vertical');424 zoomMax.addClass('vertical');425 $slider.addClass('vertical');426 zoomContainerSlider.addClass('vertical');427 zoomContainerSlider.css({428 'position': 'absolute',429 'top': 5,430 'right': 5,431 'opacity': 0.6432 });433 _self.append(zoomContainerSlider);434 }435 }436 ;437 function getPercentOfZoom() {438 var percent = 0;439 if (getData('image').w > getData('image').h) {440 percent = $options.image.maxZoom441 - ((getData('image').w * 100) / $options.image.width);442 } else {443 percent = $options.image.maxZoom444 - ((getData('image').h * 100) / $options.image.height);445 }446 return percent;447 }448 ;449 function createSelector() {450 if ($options.selector.centered) {451 getData('selector').y = ($options.height / 2)452 - (getData('selector').h / 2);453 getData('selector').x = ($options.width / 2)454 - (getData('selector').w / 2);455 }456 $selector = $('<div/>')457 .attr('id', _self[0].id + '_selector')458 .css(459 {460 'width': getData('selector').w,461 'height': getData('selector').h,462 'top': getData('selector').y463 + 'px',464 'left': getData('selector').x465 + 'px',466 'border': '1px dashed '467 + $options.selector.borderColor,468 'position': 'absolute',469 'cursor': 'move'470 })471 .mouseover(472 function () {473 $(this)474 .css(475 {476 'border': '1px dashed '477 + $options.selector.borderColorHover478 })479 })480 .mouseout(481 function () {482 $(this)483 .css(484 {485 'border': '1px dashed '486 + $options.selector.borderColor487 })488 });489 // Add draggable to the selector490 $selector491 .draggable({492 containment: 'parent',493 iframeFix: true,494 refreshPositions: true,495 drag: function (event, ui) {496 // Update position of the overlay497 getData('selector').x = ui.position.left;498 getData('selector').y = ui.position.top;499 makeOverlayPositions(ui);500 showInfo();501 if ($options.selector.onSelectorDrag != null)502 $options.selector.onSelectorDrag(503 $selector,504 getData('selector'));505 },506 start: function (event, ui) {507 if ($options.selector.hideOverlayOnDragAndResize)508 hideOverlay();509 },510 stop: function (event, ui) {511 if ($options.selector.hideOverlayOnDragAndResize)512 showOverlay();513 if ($options.selector.onSelectorDragStop != null)514 $options.selector515 .onSelectorDragStop(516 $selector,517 getData('selector'));518 }519 });520 $selector521 .resizable({522 aspectRatio: $options.selector.aspectRatio,523 maxHeight: $options.selector.maxHeight,524 maxWidth: $options.selector.maxWidth,525 minHeight: $options.selector.h,526 minWidth: $options.selector.w,527 containment: 'parent',528 resize: function (event, ui) {529 // update ovelay position530 getData('selector').w = $selector531 .width();532 getData('selector').h = $selector533 .height();534 makeOverlayPositions(ui);535 showInfo();536 if ($options.selector.onSelectorResize != null)537 $options.selector.onSelectorResize(538 $selector,539 getData('selector'));540 },541 start: function (event, ui) {542 if ($options.selector.hideOverlayOnDragAndResize)543 hideOverlay();544 },545 stop: function (event, ui) {546 if ($options.selector.hideOverlayOnDragAndResize)547 showOverlay();548 if ($options.selector.onSelectorResizeStop != null)549 $options.selector550 .onSelectorResizeStop(551 $selector,552 getData('selector'));553 }554 });555 showInfo($selector);556 // add selector to the main container557 _self.append($selector);558 }559 ;560 function showInfo() {561 var _infoView = null;562 var alreadyAdded = false;563 if ($selector.find("#infoSelector").length > 0) {564 _infoView = $selector.find("#infoSelector");565 } else {566 _infoView = $('<div />')567 .attr('id', 'infoSelector')568 .css(569 {570 'position': 'absolute',571 'top': 0,572 'left': 0,573 'background': $options.selector.bgInfoLayer,574 'opacity': 0.6,575 'font-size': $options.selector.infoFontSize576 + 'px',577 'font-family': 'Arial',578 'color': $options.selector.infoFontColor,579 'width': '100%'580 });581 }582 if ($options.selector.showPositionsOnDrag) {583 _infoView.html("X:" + Math.round(getData('selector').x)584 + "px - Y:" + Math.round(getData('selector').y) + "px");585 alreadyAdded = true;586 }587 if ($options.selector.showDimetionsOnDrag) {588 if (alreadyAdded) {589 _infoView.html(_infoView.html() + " | W:"590 + getData('selector').w + "px - H:"591 + getData('selector').h + "px");592 } else {593 _infoView.html("W:" + getData('selector').w594 + "px - H:" + getData('selector').h595 + "px");596 }597 }598 $selector.append(_infoView);599 }600 ;601 function createOverlay() {602 var arr = [ 't', 'b', 'l', 'r' ];603 $.each(arr, function () {604 var divO = $("<div />").attr("id", this).css({605 'overflow': 'hidden',606 'background': $options.overlayColor,607 'opacity': 0.6,608 'position': 'absolute',609 'z-index': 2,610 'visibility': 'visible'611 });612 _self.append(divO);613 });614 }615 ;616 function makeOverlayPositions(ui) {617 _self.find("#t").css({618 "width": $options.width,619 'height': ui.position.top,620 'left': 0,621 'top': 0622 });623 _self.find("#b").css(624 {625 "width": $options.width,626 'height': $options.height,627 'top': (ui.position.top + $selector628 .height())629 + "px",630 'left': 0631 });632 _self.find("#l").css({633 'left': 0,634 'top': ui.position.top,635 'width': ui.position.left,636 'height': $selector.height()637 });638 _self.find("#r").css(639 {640 'top': ui.position.top,641 'left': (ui.position.left + $selector642 .width())643 + "px",644 'width': $options.width,645 'height': $selector.height() + "px"646 });647 }648 ;649 _self.makeOverlayPositions = makeOverlayPositions;650 function hideOverlay() {651 _self.find("#t").hide();652 _self.find("#b").hide();653 _self.find("#l").hide();654 _self.find("#r").hide();655 }656 function showOverlay() {657 _self.find("#t").show();658 _self.find("#b").show();659 _self.find("#l").show();660 _self.find("#r").show();661 }662 function setData(key, data) {663 _self.data(key, data);664 }665 ;666 function getData(key) {667 return _self.data(key);668 }669 ;670 function adjustingSizesInRotation() {671 var angle = getData('image').rotation * Math.PI / 180;672 var sin = Math.sin(angle);673 var cos = Math.cos(angle);674 // (0,0) stays as (0, 0)675 // (w,0) rotation676 var x1 = cos * getData('image').w;677 var y1 = sin * getData('image').w;678 // (0,h) rotation679 var x2 = -sin * getData('image').h;680 var y2 = cos * getData('image').h;681 // (w,h) rotation682 var x3 = cos * getData('image').w - sin * getData('image').h;683 var y3 = sin * getData('image').w + cos * getData('image').h;684 var minX = Math.min(0, x1, x2, x3);685 var maxX = Math.max(0, x1, x2, x3);686 var minY = Math.min(0, y1, y2, y3);687 var maxY = Math.max(0, y1, y2, y3);688 getData('image').rotW = maxX - minX;689 getData('image').rotH = maxY - minY;690 getData('image').rotY = minY;691 getData('image').rotX = minX;692 };693 function createMovementControls() {694 var table = $('<table>\695 <tr>\696 <td></td>\697 <td></td>\698 <td></td>\699 </tr>\700 <tr>\701 <td></td>\702 <td></td>\703 <td></td>\704 </tr>\705 <tr>\706 <td></td>\707 <td></td>\708 <td></td>\709 </tr>\710 </table>');711 var btns = [];712 btns.push($('<div />').addClass('mvn_no mvn'));713 btns.push($('<div />').addClass('mvn_n mvn'));714 btns.push($('<div />').addClass('mvn_ne mvn'));715 btns.push($('<div />').addClass('mvn_o mvn'));716 btns.push($('<div />').addClass('mvn_c'));717 btns.push($('<div />').addClass('mvn_e mvn'));718 btns.push($('<div />').addClass('mvn_so mvn'));719 btns.push($('<div />').addClass('mvn_s mvn'));720 btns.push($('<div />').addClass('mvn_se mvn'));721 for (var i = 0; i < btns.length; i++) {722 // for each buttons that were created above,723 // attach action listeners724 btns[i].mousedown(function () {725 moveImage(this);726 }).mouseup(function () {727 clearTimeout(tMovement);728 }).mouseout(function () {729 clearTimeout(tMovement);730 });731 // find the correct position in the placeholder table and add them732 table.find('td:eq(' + i + ')').append(btns[i]);733 }734 735 // find the container in the view, empty it up and append the table736 $($options.expose.elementMovement).empty().append(table);737 }738 ;739 function moveImage(obj) {740 if ($(obj).hasClass('mvn_no')) {741 getData('image').posX = (getData('image').posX - $options.expose.movementSteps);742 getData('image').posY = (getData('image').posY - $options.expose.movementSteps);743 } else if ($(obj).hasClass('mvn_n')) {744 getData('image').posY = (getData('image').posY - $options.expose.movementSteps);745 } else if ($(obj).hasClass('mvn_ne')) {746 getData('image').posX = (getData('image').posX + $options.expose.movementSteps);747 getData('image').posY = (getData('image').posY - $options.expose.movementSteps);748 } else if ($(obj).hasClass('mvn_o')) {749 getData('image').posX = (getData('image').posX - $options.expose.movementSteps);750 } else if ($(obj).hasClass('mvn_c')) {751 getData('image').posX = ($options.width / 2)752 - (getData('image').w / 2);753 getData('image').posY = ($options.height / 2)754 - (getData('image').h / 2);755 } else if ($(obj).hasClass('mvn_e')) {756 getData('image').posX = (getData('image').posX + $options.expose.movementSteps);757 } else if ($(obj).hasClass('mvn_so')) {758 getData('image').posX = (getData('image').posX - $options.expose.movementSteps);759 getData('image').posY = (getData('image').posY + $options.expose.movementSteps);760 } else if ($(obj).hasClass('mvn_s')) {761 getData('image').posY = (getData('image').posY + $options.expose.movementSteps);762 } else if ($(obj).hasClass('mvn_se')) {763 getData('image').posX = (getData('image').posX + $options.expose.movementSteps);764 getData('image').posY = (getData('image').posY + $options.expose.movementSteps);765 }766 if ($options.image.snapToContainer) {767 if (getData('image').posY > 0) {768 getData('image').posY = 0;769 }770 if (getData('image').posX > 0) {771 getData('image').posX = 0;772 }773 var bottom = -(getData('image').h - _self.height());774 var right = -(getData('image').w - _self.width());775 if (getData('image').posY < bottom) {776 getData('image').posY = bottom;777 }778 if (getData('image').posX < right) {779 getData('image').posX = right;780 }781 }782 calculateTranslationAndRotation();783 tMovement = setTimeout(function () {784 moveImage(obj);785 }, 100);786 };787 $.fn.cropzoom.updateOverlayPosition = function(ui){788 _self.makeOverlayPositions(ui);789 };790 $.fn.cropzoom.getParameters = function (_self, custom) {791 var image = _self.data('image');792 var selector = _self.data('selector');793 var fixed_data = {794 'viewPortW': _self.width(),795 'viewPortH': _self.height(),796 'imageX': image.posX,797 'imageY': image.posY,798 'imageRotate': image.rotation,799 'imageW': image.w,800 'imageH': image.h,801 'imageSource': image.source,802 'selectorX': selector.x,803 'selectorY': selector.y,804 'selectorW': selector.w,805 'selectorH': selector.h806 };807 return $.extend(fixed_data, custom);808 };809 $.fn.cropzoom.getSelf = function () {810 return _self;811 }812 /*$.fn.cropzoom.getOptions = function() {813 return _self.getData('options');814 }*/815 // Maintein Chaining816 return this;817 });818 };819 // Css Hooks820 /*821 * jQuery.cssHooks["MsTransform"] = { set: function( elem, value ) {822 * elem.style.msTransform = value; } };823 */824 $.fn.extend({825 // Function to set the selector position and sizes826 cropZoomSetSelector: function (x, y, w, h, animate) {827 var _self = $(this);...
cropzoom.js
Source:cropzoom.js
...129 $image = $('<img />');130 $image.attr('src', $options.image.source);131 $($image).css({132 'position': 'absolute',133 'left': getData('image').posX,134 'top': getData('image').posY,135 'width': getData('image').w,136 'height': getData('image').h137 });138 var ext = getExtensionSource();139 if (ext == 'png' || ext == 'gif')140 $image.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"141 + $options.image.source142 + "',sizingMethod='scale');";143 $container.append($image);144 _self.append($container);145 calculateTranslationAndRotation();146 // adding draggable to the image147 $($image).draggable({148 refreshPositions: true,149 drag: function (event, ui) {150 getData('image').posY = ui.position.top151 getData('image').posX = ui.position.left152 if ($options.image.snapToContainer)153 limitBounds(ui);154 else155 calculateTranslationAndRotation();156 // Fire the callback157 if ($options.image.onImageDrag != null)158 $options.image.onImageDrag($image);159 },160 stop: function (event, ui) {161 if ($options.image.snapToContainer)162 limitBounds(ui);163 }164 });165 // Create the selector166 createSelector();167 // Add solid color to the selector168 _self.find('.ui-icon-gripsmall-diagonal-se').css({169 'background': '#FFF',170 'border': '1px solid #000',171 'width': 8,172 'height': 8173 });174 // Create the dark overlay175 createOverlay();176 if ($options.selector.startWithOverlay) {177 /* Make Overlays at Start */178 var ui_object = {179 position: {180 top: $selector.position().top,181 left: $selector.position().left182 }183 };184 makeOverlayPositions(ui_object);185 }186 /* End Make Overlay at start */187 // Create zoom control188 if ($options.enableZoom)189 createZoomSlider();190 // Create rotation control191 if ($options.enableRotation)192 createRotationSlider();193 if ($options.expose.elementMovement != '')194 createMovementControls();195 function limitBounds(ui) {196 if (ui.position.top > 0)197 getData('image').posY = 0;198 if (ui.position.left > 0)199 getData('image').posX = 0;200 var bottom = -(getData('image').h - ui.helper.parent()201 .parent().height()), right = -(getData('image').w - ui.helper202 .parent().parent().width());203 if (ui.position.top < bottom)204 getData('image').posY = bottom;205 if (ui.position.left < right)206 getData('image').posX = right;207 calculateTranslationAndRotation();208 }209 function getExtensionSource() {210 var parts = $options.image.source.split('.');211 return parts[parts.length - 1];212 }213 ;214 function calculateFactor() {215 getData('image').scaleX = ($options.width / getData('image').w);216 getData('image').scaleY = ($options.height / getData('image').h);217 }218 ;219 function getCorrectSizes() {220 if ($options.image.startZoom != 0) {221 var zoomInPx_width = (($options.image.width * Math222 .abs($options.image.startZoom)) / 100);223 var zoomInPx_height = (($options.image.height * Math224 .abs($options.image.startZoom)) / 100);225 getData('image').h = zoomInPx_height;226 getData('image').w = zoomInPx_width;227 //Checking if the position was set before228 if (getData('image').posY != 0229 && getData('image').posX != 0) {230 if (getData('image').h > $options.height)231 getData('image').posY = Math232 .abs(($options.height / 2)233 - (getData('image').h / 2));234 else235 getData('image').posY = (($options.height / 2) - (getData('image').h / 2));236 if (getData('image').w > $options.width)237 getData('image').posX = Math238 .abs(($options.width / 2)239 - (getData('image').w / 2));240 else241 getData('image').posX = (($options.width / 2) - (getData('image').w / 2));242 }243 } else {244 var scaleX = getData('image').scaleX;245 var scaleY = getData('image').scaleY;246 if (scaleY < scaleX) {247 getData('image').h = $options.height;248 getData('image').w = Math249 .round(getData('image').w * scaleY);250 } else {251 getData('image').h = Math252 .round(getData('image').h * scaleX);253 getData('image').w = $options.width;254 }255 }256 // Disable snap to container if is little257 if (getData('image').w < $options.width258 && getData('image').h < $options.height) {259 $options.image.snapToContainer = false;260 }261 calculateTranslationAndRotation();262 }263 ;264 function calculateTranslationAndRotation() {265 $(function () {266 adjustingSizesInRotation();267 // console.log(imageData.id);268 rotation = "rotate(" + getData('image').rotation + "deg)";269 $($image).css({270 'transform': rotation,271 '-webkit-transform': rotation,272 '-ms-transform': rotation,273 'msTransform': rotation,274 'top': getData('image').posY,275 'left': getData('image').posX276 });277 });278 }279 ;280 function createRotationSlider() {281 var rotationContainerSlider = $("<div />").attr('id',282 'rotationContainer').mouseover(function () {283 $(this).css('opacity', 1);284 }).mouseout(function () {285 $(this).css('opacity', 0.6);286 });287 var rotMin = $('<div />').attr('id', 'rotationMin')288 .html("0");289 var rotMax = $('<div />').attr('id', 'rotationMax')290 .html("360");291 var $slider = $("<div />").attr('id', 'rotationSlider');292 // Apply slider293 var orientation = 'vertical';294 var value = Math.abs(360 - $options.image.rotation);295 if ($options.expose.slidersOrientation == 'horizontal') {296 orientation = 'horizontal';297 value = $options.image.rotation;298 }299 $slider300 .slider({301 orientation: orientation,302 value: value,303 range: "max",304 min: 0,305 max: 360,306 step: (($options.rotationSteps > 360 || $options.rotationSteps < 0) ? 1307 : $options.rotationSteps),308 slide: function (event, ui) {309 getData('image').rotation = (value == 360 ? Math310 .abs(360 - ui.value)311 : Math.abs(ui.value));312 calculateTranslationAndRotation();313 if ($options.image.onRotate != null)314 $options.image.onRotate($slider,315 getData('image').rotation);316 }317 });318 rotationContainerSlider.append(rotMin);319 rotationContainerSlider.append($slider);320 rotationContainerSlider.append(rotMax);321 if ($options.expose.rotationElement != '') {322 $slider323 .addClass($options.expose.slidersOrientation);324 rotationContainerSlider325 .addClass($options.expose.slidersOrientation);326 rotMin.addClass($options.expose.slidersOrientation);327 rotMax.addClass($options.expose.slidersOrientation);328 $($options.expose.rotationElement).empty().append(329 rotationContainerSlider);330 } else {331 $slider.addClass('vertical');332 rotationContainerSlider.addClass('vertical');333 rotMin.addClass('vertical');334 rotMax.addClass('vertical');335 rotationContainerSlider.css({336 'position': 'absolute',337 'top': 5,338 'left': 5,339 'opacity': 0.6340 });341 _self.append(rotationContainerSlider);342 }343 }344 ;345 function createZoomSlider() {346 var zoomContainerSlider = $("<div />").attr('id',347 'zoomContainer').mouseover(function () {348 $(this).css('opacity', 1);349 }).mouseout(function () {350 $(this).css('opacity', 0.6);351 });352 var zoomMin = $('<div />').attr('id', 'zoomMin').html(353 "<b>-</b>");354 var zoomMax = $('<div />').attr('id', 'zoomMax').html(355 "<b>+</b>");356 var $slider = $("<div />").attr('id', 'zoomSlider');357 // Apply Slider358 $slider359 .slider({360 orientation: ($options.expose.zoomElement != '' ? $options.expose.slidersOrientation361 : 'vertical'),362 value: ($options.image.startZoom != 0 ? $options.image.startZoom363 : getPercentOfZoom(getData('image'))),364 min: ($options.image.useStartZoomAsMinZoom ? $options.image.startZoom365 : $options.image.minZoom),366 max: $options.image.maxZoom,367 step: (($options.zoomSteps > $options.image.maxZoom || $options.zoomSteps < 0) ? 1368 : $options.zoomSteps),369 slide: function (event, ui) {370 var value = ($options.expose.slidersOrientation == 'vertical' ? ($options.image.maxZoom - ui.value)371 : ui.value);372 var zoomInPx_width = ($options.image.width * Math.abs(value) / 100);373 var zoomInPx_height = ($options.image.height * Math.abs(value) / 100);374 $($image).css({375 'width': zoomInPx_width + "px",376 'height': zoomInPx_height + "px"377 });378 var difX = (getData('image').w / 2) - (zoomInPx_width / 2);379 var difY = (getData('image').h / 2) - (zoomInPx_height / 2);380 var newX = (difX > 0 ? getData('image').posX381 + Math.abs(difX)382 : getData('image').posX383 - Math.abs(difX));384 var newY = (difY > 0 ? getData('image').posY385 + Math.abs(difY)386 : getData('image').posY387 - Math.abs(difY));388 getData('image').posX = newX;389 getData('image').posY = newY;390 getData('image').w = zoomInPx_width;391 getData('image').h = zoomInPx_height;392 calculateFactor();393 calculateTranslationAndRotation();394 if ($options.image.onZoom != null) {395 $options.image.onZoom($image,396 getData('image'));397 }398 }399 });400 if ($options.slidersOrientation == 'vertical') {401 zoomContainerSlider.append(zoomMax);402 zoomContainerSlider.append($slider);403 zoomContainerSlider.append(zoomMin);404 } else {405 zoomContainerSlider.append(zoomMin);406 zoomContainerSlider.append($slider);407 zoomContainerSlider.append(zoomMax);408 }409 if ($options.expose.zoomElement != '') {410 zoomMin411 .addClass($options.expose.slidersOrientation);412 zoomMax413 .addClass($options.expose.slidersOrientation);414 $slider415 .addClass($options.expose.slidersOrientation);416 zoomContainerSlider417 .addClass($options.expose.slidersOrientation);418 $($options.expose.zoomElement).empty().append(419 zoomContainerSlider);420 } else {421 zoomMin.addClass('vertical');422 zoomMax.addClass('vertical');423 $slider.addClass('vertical');424 zoomContainerSlider.addClass('vertical');425 zoomContainerSlider.css({426 'position': 'absolute',427 'top': 5,428 'right': 5,429 'opacity': 0.6430 });431 _self.append(zoomContainerSlider);432 }433 }434 ;435 function getPercentOfZoom() {436 var percent = 0;437 if (getData('image').w > getData('image').h) {438 percent = $options.image.maxZoom439 - ((getData('image').w * 100) / $options.image.width);440 } else {441 percent = $options.image.maxZoom442 - ((getData('image').h * 100) / $options.image.height);443 }444 return percent;445 }446 ;447 function createSelector() {448 if ($options.selector.centered) {449 getData('selector').y = ($options.height / 2)450 - (getData('selector').h / 2);451 getData('selector').x = ($options.width / 2)452 - (getData('selector').w / 2);453 }454 $selector = $('<div/>')455 .attr('id', _self[0].id + '_selector')456 .css(457 {458 'width': getData('selector').w,459 'height': getData('selector').h,460 'top': getData('selector').y461 + 'px',462 'left': getData('selector').x463 + 'px',464 'border': '1px dashed '465 + $options.selector.borderColor,466 'position': 'absolute',467 'cursor': 'move'468 })469 .mouseover(470 function () {471 $(this)472 .css(473 {474 'border': '1px dashed '475 + $options.selector.borderColorHover476 })477 })478 .mouseout(479 function () {480 $(this)481 .css(482 {483 'border': '1px dashed '484 + $options.selector.borderColor485 })486 });487 // Add draggable to the selector488 $selector489 .draggable({490 containment: 'parent',491 iframeFix: true,492 refreshPositions: true,493 drag: function (event, ui) {494 // Update position of the overlay495 getData('selector').x = ui.position.left;496 getData('selector').y = ui.position.top;497 makeOverlayPositions(ui);498 showInfo();499 if ($options.selector.onSelectorDrag != null)500 $options.selector.onSelectorDrag(501 $selector,502 getData('selector'));503 },504 stop: function (event, ui) {505 // hide overlay506 if ($options.selector.hideOverlayOnDragAndResize)507 hideOverlay();508 if ($options.selector.onSelectorDragStop != null)509 $options.selector510 .onSelectorDragStop(511 $selector,512 getData('selector'));513 }514 });515 $selector516 .resizable({517 aspectRatio: $options.selector.aspectRatio,518 maxHeight: $options.selector.maxHeight,519 maxWidth: $options.selector.maxWidth,520 minHeight: $options.selector.h,521 minWidth: $options.selector.w,522 containment: 'parent',523 resize: function (event, ui) {524 // update ovelay position525 getData('selector').w = $selector526 .width();527 getData('selector').h = $selector528 .height();529 makeOverlayPositions(ui);530 showInfo();531 if ($options.selector.onSelectorResize != null)532 $options.selector.onSelectorResize(533 $selector,534 getData('selector'));535 },536 stop: function (event, ui) {537 if ($options.selector.hideOverlayOnDragAndResize)538 hideOverlay();539 if ($options.selector.onSelectorResizeStop != null)540 $options.selector541 .onSelectorResizeStop(542 $selector,543 getData('selector'));544 }545 });546 showInfo($selector);547 // add selector to the main container548 _self.append($selector);549 }550 ;551 function showInfo() {552 var _infoView = null;553 var alreadyAdded = false;554 if ($selector.find("#infoSelector").length > 0) {555 _infoView = $selector.find("#infoSelector");556 } else {557 _infoView = $('<div />')558 .attr('id', 'infoSelector')559 .css(560 {561 'position': 'absolute',562 'top': 0,563 'left': 0,564 'background': $options.selector.bgInfoLayer,565 'opacity': 0.6,566 'font-size': $options.selector.infoFontSize567 + 'px',568 'font-family': 'Arial',569 'color': $options.selector.infoFontColor,570 'width': '100%'571 });572 }573 if ($options.selector.showPositionsOnDrag) {574 _infoView.html("X:" + Math.round(getData('selector').x)575 + "px - Y:" + Math.round(getData('selector').y) + "px");576 alreadyAdded = true;577 }578 if ($options.selector.showDimetionsOnDrag) {579 if (alreadyAdded) {580 _infoView.html(_infoView.html() + " | W:"581 + getData('selector').w + "px - H:"582 + getData('selector').h + "px");583 } else {584 _infoView.html("W:" + getData('selector').w585 + "px - H:" + getData('selector').h586 + "px");587 }588 }589 $selector.append(_infoView);590 }591 ;592 function createOverlay() {593 var arr = [ 't', 'b', 'l', 'r' ];594 $.each(arr, function () {595 var divO = $("<div />").attr("id", this).css({596 'overflow': 'hidden',597 'background': $options.overlayColor,598 'opacity': 0.6,599 'position': 'absolute',600 'z-index': 2,601 'visibility': 'visible'602 });603 _self.append(divO);604 });605 }606 ;607 function makeOverlayPositions(ui) {608 _self.find("#t").css({609 "display": "block",610 "width": $options.width,611 'height': ui.position.top,612 'left': 0,613 'top': 0614 });615 _self.find("#b").css(616 {617 "display": "block",618 "width": $options.width,619 'height': $options.height,620 'top': (ui.position.top + $selector621 .height())622 + "px",623 'left': 0624 });625 _self.find("#l").css({626 "display": "block",627 'left': 0,628 'top': ui.position.top,629 'width': ui.position.left,630 'height': $selector.height()631 });632 _self.find("#r").css(633 {634 "display": "block",635 'top': ui.position.top,636 'left': (ui.position.left + $selector637 .width())638 + "px",639 'width': $options.width,640 'height': $selector.height() + "px"641 });642 }643 ;644 _self.makeOverlayPositions = makeOverlayPositions;645 function hideOverlay() {646 _self.find("#t").hide();647 _self.find("#b").hide();648 _self.find("#l").hide();649 _self.find("#r").hide();650 }651 function setData(key, data) {652 _self.data(key, data);653 }654 ;655 function getData(key) {656 return _self.data(key);657 }658 ;659 function adjustingSizesInRotation() {660 var angle = getData('image').rotation * Math.PI / 180;661 var sin = Math.sin(angle);662 var cos = Math.cos(angle);663 // (0,0) stays as (0, 0)664 // (w,0) rotation665 var x1 = cos * getData('image').w;666 var y1 = sin * getData('image').w;667 // (0,h) rotation668 var x2 = -sin * getData('image').h;669 var y2 = cos * getData('image').h;670 // (w,h) rotation671 var x3 = cos * getData('image').w - sin * getData('image').h;672 var y3 = sin * getData('image').w + cos * getData('image').h;673 var minX = Math.min(0, x1, x2, x3);674 var maxX = Math.max(0, x1, x2, x3);675 var minY = Math.min(0, y1, y2, y3);676 var maxY = Math.max(0, y1, y2, y3);677 getData('image').rotW = maxX - minX;678 getData('image').rotH = maxY - minY;679 getData('image').rotY = minY;680 getData('image').rotX = minX;681 };682 function createMovementControls() {683 var table = $('<table>\684 <tr>\685 <td></td>\686 <td></td>\687 <td></td>\688 </tr>\689 <tr>\690 <td></td>\691 <td></td>\692 <td></td>\693 </tr>\694 <tr>\695 <td></td>\696 <td></td>\697 <td></td>\698 </tr>\699 </table>');700 var btns = [];701 btns.push($('<div />').addClass('mvn_no mvn'));702 btns.push($('<div />').addClass('mvn_n mvn'));703 btns.push($('<div />').addClass('mvn_ne mvn'));704 btns.push($('<div />').addClass('mvn_o mvn'));705 btns.push($('<div />').addClass('mvn_c'));706 btns.push($('<div />').addClass('mvn_e mvn'));707 btns.push($('<div />').addClass('mvn_so mvn'));708 btns.push($('<div />').addClass('mvn_s mvn'));709 btns.push($('<div />').addClass('mvn_se mvn'));710 711 for (var i = 0; i < btns.length; i++) {712 // for each buttons that were created above,713 // attach action listeners714 btns[i].mousedown(function () {715 moveImage(this);716 }).mouseup(function () {717 clearTimeout(tMovement);718 }).mouseout(function () {719 clearTimeout(tMovement);720 });721 // find the correct position in the placeholder table and add them722 table.find('td:eq(' + i + ')').append(btns[i]);723 }724 725 // find the container in the view, empty it up and append the table726 $($options.expose.elementMovement).empty().append(table);727 }728 ;729 function moveImage(obj) {730 if ($(obj).hasClass('mvn_no')) {731 getData('image').posX = (getData('image').posX - $options.expose.movementSteps);732 getData('image').posY = (getData('image').posY - $options.expose.movementSteps);733 } else if ($(obj).hasClass('mvn_n')) {734 getData('image').posY = (getData('image').posY - $options.expose.movementSteps);735 } else if ($(obj).hasClass('mvn_ne')) {736 getData('image').posX = (getData('image').posX + $options.expose.movementSteps);737 getData('image').posY = (getData('image').posY - $options.expose.movementSteps);738 } else if ($(obj).hasClass('mvn_o')) {739 getData('image').posX = (getData('image').posX - $options.expose.movementSteps);740 } else if ($(obj).hasClass('mvn_c')) {741 getData('image').posX = ($options.width / 2)742 - (getData('image').w / 2);743 getData('image').posY = ($options.height / 2)744 - (getData('image').h / 2);745 } else if ($(obj).hasClass('mvn_e')) {746 getData('image').posX = (getData('image').posX + $options.expose.movementSteps);747 } else if ($(obj).hasClass('mvn_so')) {748 getData('image').posX = (getData('image').posX - $options.expose.movementSteps);749 getData('image').posY = (getData('image').posY + $options.expose.movementSteps);750 } else if ($(obj).hasClass('mvn_s')) {751 getData('image').posY = (getData('image').posY + $options.expose.movementSteps);752 } else if ($(obj).hasClass('mvn_se')) {753 getData('image').posX = (getData('image').posX + $options.expose.movementSteps);754 getData('image').posY = (getData('image').posY + $options.expose.movementSteps);755 }756 if ($options.image.snapToContainer) {757 if (getData('image').posY > 0) {758 getData('image').posY = 0;759 }760 if (getData('image').posX > 0) {761 getData('image').posX = 0;762 }763 var bottom = -(getData('image').h - _self.height());764 var right = -(getData('image').w - _self.width());765 if (getData('image').posY < bottom) {766 getData('image').posY = bottom;767 }768 if (getData('image').posX < right) {769 getData('image').posX = right;770 }771 }772 calculateTranslationAndRotation();773 tMovement = setTimeout(function () {774 moveImage(obj);775 }, 100);776 };777 $.fn.cropzoom.updateOverlayPosition = function(ui){778 _self.makeOverlayPositions(ui);779 };780 $.fn.cropzoom.getParameters = function (_self, custom) {781 var image = _self.data('image');782 var selector = _self.data('selector');783 var fixed_data = {784 'viewPortW': _self.width(),785 'viewPortH': _self.height(),786 'imageX': image.posX,787 'imageY': image.posY,788 'imageRotate': image.rotation,789 'imageW': image.w,790 'imageH': image.h,791 'imageSource': image.source,792 'selectorX': selector.x,793 'selectorY': selector.y,794 'selectorW': selector.w,795 'selectorH': selector.h796 };797 return $.extend(fixed_data, custom);798 };799 $.fn.cropzoom.getSelf = function () {800 return _self;801 }802 /*$.fn.cropzoom.getOptions = function() {803 return _self.getData('options');804 }*/805 // Maintein Chaining806 return this;807 });808 };809 // Css Hooks810 /*811 * jQuery.cssHooks["MsTransform"] = { set: function( elem, value ) {812 * elem.style.msTransform = value; } };813 */814 $.fn.extend({815 // Function to set the selector position and sizes816 setSelector: function (x, y, w, h, animate) {817 var _self = $(this);...
actionTargets.spec.js
Source:actionTargets.spec.js
...66 }67 }, 1, 1 );68testSuite69 .describe('First user tries to creates AT1 action target with too short name.')70 .jwtAuthentication(function() { return this.getData('token1'); })71 .post({ url: '/v1/actionTargets' }, function() {72 return {73 body: {74 name: 'AT',75 organizationId: this.getData('organizationId1'),76 actionTargetTemplateId: this.getData('actionTargetTemplateId1'),77 configuration: {78 botId: ''79 }80 }81 };82 })83 .expectStatusCode(422)84 .expectJsonToHavePath('name.0')85 .expectJsonToBe({ name: [ 'The name must be at least 3 characters long' ]});86testSuite87 .describe('First user tries to creates AT1 action target in an organization he has no access.')88 .post({ url: '/v1/actionTargets' }, function() {89 return {90 body: {91 name: 'AT1',92 organizationId: this.getData('organizationId3'),93 actionTargetTemplateId: this.getData('actionTargetTemplateId3'),94 configuration: {95 botId: ''96 }97 }98 };99 })100 .expectStatusCode(422)101 .expectJsonToHavePath('organizationId.0')102 .expectJsonToBe({ organizationId: [ 'No organization found.' ]});103testSuite104 .describe('First user tries to create AT1 action target from an action target template he has no access.')105 .post({ url: '/v1/actionTargets' }, function() {106 return {107 body: {108 name: 'AT1',109 organizationId: this.getData('organizationId1'),110 actionTargetTemplateId: this.getData('actionTargetTemplateId3'),111 configuration: {112 botId: ''113 }114 }115 };116 })117 .expectStatusCode(422)118 .expectJsonToHavePath('actionTargetTemplateId.0')119 .expectJsonToBe({ actionTargetTemplateId: [ 'No action target template found.' ]});120testSuite121 .describe('First user tries to create AT1 action target with a wrong configuration.')122 .post({ url: '/v1/actionTargets' }, function() {123 return {124 body: {125 name: 'AT1',126 organizationId: this.getData('organizationId1'),127 actionTargetTemplateId: this.getData('actionTargetTemplateId1'),128 configuration: {129 wrongProperty: 'anyValue'130 }131 }132 };133 })134 .expectStatusCode(422)135 .expectJsonToHavePath('configuration')136 .expectJsonToBe({ configuration: [{137 wrongProperty: [ "additionalProperty 'wrongProperty' exists in instance when not allowed" ],138 botId: [ "requires property \"botId\"" ]139 }]});140testSuite141 .describe('First user tries to create AT1 action target without configuration when it is mandatory.')142 .post({ url: '/v1/actionTargets' }, function() {143 return {144 body: {145 name: 'AT1',146 organizationId: this.getData('organizationId1'),147 actionTargetTemplateId: this.getData('actionTargetTemplateId1')148 }149 };150 })151 .expectStatusCode(422)152 .expectJsonToHavePath('configuration')153 .expectJsonToBe({ configuration: [ 'The action target template requires an action target configured.' ] });154testSuite155 .describe('First user creates a AT1 action target for his second organization and first action target template.')156 .post({ url: '/v1/actionTargets' }, function() {157 return {158 body: {159 name: 'AT1',160 organizationId: this.getData('organizationId2'),161 public: true,162 actionTargetTemplateId: this.getData('actionTargetTemplateId1'),163 configuration: {164 botId: 'amazingSensor'165 }166 }167 };168 })169 .storeLocationAs('actionTarget', 1)170 .expectStatusCode(201)171 .expectLocationHeader('/v1/actionTargets/:id')172 .expectHeaderToBePresent('x-iflux-generated-id');173testSuite174 .describe('First user tries to re-create AT1 action target.')175 .post({ url: '/v1/actionTargets' }, function() {176 return {177 body: {178 name: 'AT1',179 organizationId: this.getData('organizationId2'),180 actionTargetTemplateId: this.getData('actionTargetTemplateId1'),181 configuration: {182 botId: 'amazingSensor'183 }184 }185 };186 })187 .expectStatusCode(422)188 .expectJsonToHavePath('name')189 .expectJsonToBe({ name: [ "Name is already taken for this action target template and this organization." ] });190testSuite191 .describe('First user tries to re-create AT1 action target but in a different action target template.')192 .post({ url: '/v1/actionTargets' }, function() {193 return {194 body: {195 name: 'AT1',196 organizationId: this.getData('organizationId2'),197 actionTargetTemplateId: this.getData('actionTargetTemplateId2'),198 configuration: {199 botId: 'amazingSensor'200 }201 }202 };203 })204 .storeLocationAs('actionTarget', 100)205 .expectStatusCode(201)206 .expectLocationHeader('/v1/actionTargets/:id')207 .expectHeaderToBePresent('x-iflux-generated-id');208testSuite209 .describe('First user tries to re-create AT1 action target but in a different organization.')210 .post({ url: '/v1/actionTargets' }, function() {211 return {212 body: {213 name: 'AT1',214 organizationId: this.getData('organizationId1'),215 actionTargetTemplateId: this.getData('actionTargetTemplateId1'),216 configuration: {217 botId: 'amazingSensor'218 }219 }220 };221 })222 .storeLocationAs('actionTarget', 101)223 .expectStatusCode(201)224 .expectLocationHeader('/v1/actionTargets/:id')225 .expectHeaderToBePresent('x-iflux-generated-id');226testSuite227 .describe('First user creates AT2 action target for his second organization and second action target template.')228 .post({ url: '/v1/actionTargets' }, function() {229 return {230 body: {231 name: 'AT2',232 organizationId: this.getData('organizationId2'),233 actionTargetTemplateId: this.getData('actionTargetTemplateId2')234 }235 };236 })237 .storeLocationAs('actionTarget', 2)238 .expectStatusCode(201)239 .expectLocationHeader('/v1/actionTargets/:id');240testSuite241 .describe('First user tries to create AT3 action target for his first organization and second action target template.')242 .post({ url: '/v1/actionTargets' }, function() {243 return {244 body: {245 name: 'AT3',246 organizationId: this.getData('organizationId1'),247 actionTargetTemplateId: this.getData('actionTargetTemplateId2'),248 configuration: {249 botId: 'amazingSensorForAT3'250 }251 }252 };253 })254 .expectStatusCode(422)255 .expectJsonToHavePath('actionTargetTemplateId.0')256 .expectJsonToBe({ actionTargetTemplateId: [ 'No action target template found.' ]});257testSuite258 .describe('First user creates AT3 action target for his first organization and first action target template.')259 .post({ url: '/v1/actionTargets' }, function() {260 return {261 body: {262 name: 'AT3',263 organizationId: this.getData('organizationId1'),264 actionTargetTemplateId: this.getData('actionTargetTemplateId1'),265 configuration: {266 botId: 'amazingSensorForAT3'267 }268 }269 };270 })271 .storeLocationAs('actionTarget', 3)272 .expectStatusCode(201)273 .expectLocationHeader('/v1/actionTargets/:id');274testSuite275 .describe('Second user creates AT4 action target for his organization and first action target template.')276 .jwtAuthentication(function() { return this.getData('token2'); })277 .post({ url: '/v1/actionTargets' }, function() {278 return {279 body: {280 name: 'AT4',281 public: true,282 organizationId: this.getData('organizationId3'),283 actionTargetTemplateId: this.getData('actionTargetTemplateId1'),284 configuration: {285 botId: 'amazingSensorForAT4'286 }287 }288 };289 })290 .storeLocationAs('actionTarget', 4)291 .expectStatusCode(201)292 .expectLocationHeader('/v1/actionTargets/:id');293testSuite294 .describe('Second user creates AT5 action target for his organization and third action target template.')295 .post({ url: '/v1/actionTargets' }, function() {296 return {297 body: {298 name: 'AT5',299 organizationId: this.getData('organizationId3'),300 actionTargetTemplateId: this.getData('actionTargetTemplateId3')301 }302 };303 })304 .storeLocationAs('actionTarget', 5)305 .expectStatusCode(201)306 .expectLocationHeader('/v1/actionTargets/:id');307testSuite308 .describe('Second user creates AT6 action target for his organization and template in a different organization.')309 .post({ url: '/v1/actionTargets' }, function() {310 return {311 body: {312 name: 'AT6',313 organizationId: this.getData('organizationId3'),314 actionTargetTemplateId: this.getData('actionTargetTemplateId1'),315 configuration: {316 botId: 'amazingSensorForAT6'317 }318 }319 };320 })321 .storeLocationAs('actionTarget', 6)322 .expectStatusCode(201)323 .expectLocationHeader('/v1/actionTargets/:id');324testSuite325 .describe('Second user retrieve AT6 action target.')326 .get({}, function() { return { url: '/v1/actionTargets?name=%6&actionTargetTemplateId=' + this.getData('actionTargetTemplateId1') }; })327 .expectStatusCode(200)328 .expectJsonCollectionToHaveSize(1)329 .expectJsonToBeAtLeast(function() {330 return [{331 name: 'AT6',332 organizationId: this.getData('organizationId3'),333 actionTargetTemplateId: this.getData('actionTargetTemplateId1'),334 configuration: {335 botId: 'amazingSensorForAT6'336 }337 }];338 });339testSuite340 .describe('Second user creates AT7 action target which is private.')341 .post({ url: '/v1/actionTargets' }, function() {342 return {343 body: {344 name: 'AT7',345 public: false,346 organizationId: this.getData('organizationId3'),347 actionTargetTemplateId: this.getData('actionTargetTemplateId1'),348 configuration: {349 botId: 'amazingSensorForAT7'350 }351 }352 };353 })354 .storeLocationAs('actionTarget', 7)355 .expectStatusCode(201)356 .expectLocationHeader('/v1/actionTargets/:id');357testSuite358 .describe('Second user retrieve all action targets that he has access.')359 .get({ url: '/v1/actionTargets' })360 .expectStatusCode(200)361 .expectJsonCollectionToHaveSize(5)362 .expectJsonToBeAtLeast(function() {363 return [{364 id: this.getData('actionTargetId1'),365 name: 'AT1',366 organizationId: this.getData('organizationId2'),367 actionTargetTemplateId: this.getData('actionTargetTemplateId1')368 }, {369 id: this.getData('actionTargetId4'),370 name: 'AT4',371 organizationId: this.getData('organizationId3'),372 actionTargetTemplateId: this.getData('actionTargetTemplateId1')373 }, {374 id: this.getData('actionTargetId5'),375 name: 'AT5',376 organizationId: this.getData('organizationId3'),377 actionTargetTemplateId: this.getData('actionTargetTemplateId3')378 }, {379 id: this.getData('actionTargetId6'),380 name: 'AT6',381 organizationId: this.getData('organizationId3'),382 actionTargetTemplateId: this.getData('actionTargetTemplateId1')383 }, {384 id: this.getData('actionTargetId7'),385 name: 'AT7',386 organizationId: this.getData('organizationId3'),387 actionTargetTemplateId: this.getData('actionTargetTemplateId1')388 }];389 });390testSuite391 .describe('Second user retrieve all public action targets.')392 .get({ url: '/v1/actionTargets?public' })393 .expectStatusCode(200)394 .expectJsonCollectionToHaveSize(2)395 .expectJsonToBeAtLeast(function() {396 return [{397 id: this.getData('actionTargetId1'),398 name: 'AT1',399 organizationId: this.getData('organizationId2'),400 actionTargetTemplateId: this.getData('actionTargetTemplateId1')401 }, {402 id: this.getData('actionTargetId4'),403 name: 'AT4',404 organizationId: this.getData('organizationId3'),405 actionTargetTemplateId: this.getData('actionTargetTemplateId1')406 }];407 });408testSuite409 .describe('First user retrieve all action targets that he has access.')410 .jwtAuthentication(function() { return this.getData('token1'); })411 .get({ url: '/v1/actionTargets' })412 .expectStatusCode(200)413 .expectJsonCollectionToHaveSize(6)414 .expectJsonToBeAtLeast(function() {415 return [{416 id: this.getData('actionTargetId1'),417 name: 'AT1',418 organizationId: this.getData('organizationId2'),419 actionTargetTemplateId: this.getData('actionTargetTemplateId1')420 }, {421 id: this.getData('actionTargetId100'),422 name: 'AT1',423 organizationId: this.getData('organizationId2'),424 actionTargetTemplateId: this.getData('actionTargetTemplateId2')425 }, {426 id: this.getData('actionTargetId101'),427 name: 'AT1',428 organizationId: this.getData('organizationId1'),429 actionTargetTemplateId: this.getData('actionTargetTemplateId1')430 }, {431 id: this.getData('actionTargetId2'),432 name: 'AT2',433 organizationId: this.getData('organizationId2'),434 actionTargetTemplateId: this.getData('actionTargetTemplateId2')435 }, {436 id: this.getData('actionTargetId3'),437 name: 'AT3',438 organizationId: this.getData('organizationId1'),439 actionTargetTemplateId: this.getData('actionTargetTemplateId1')440 }, {441 id: this.getData('actionTargetId4'),442 name: 'AT4',443 organizationId: this.getData('organizationId3'),444 actionTargetTemplateId: this.getData('actionTargetTemplateId1')445 }];446 });447testSuite448 .describe('First user retrieve all public action targets.')449 .jwtAuthentication(function() { return this.getData('token1'); })450 .get({ url: '/v1/actionTargets?public' })451 .expectStatusCode(200)452 .expectJsonCollectionToHaveSize(2)453 .expectJsonToBeAtLeast(function() {454 return [{455 id: this.getData('actionTargetId1'),456 name: 'AT1',457 organizationId: this.getData('organizationId2'),458 actionTargetTemplateId: this.getData('actionTargetTemplateId1')459 }, {460 id: this.getData('actionTargetId4'),461 name: 'AT4',462 organizationId: this.getData('organizationId3'),463 actionTargetTemplateId: this.getData('actionTargetTemplateId1')464 }];465 });466testSuite467 .describe('First user tries to mix different way to retrieve action targets (actionTargetTemplateId is used).')468 .get({}, function() {469 return {470 url: '/v1/actionTargets?allOrganizations&organizationId=' +471 this.getData('organizationId1') +472 '&actionTargetTemplateId=' +473 this.getData('actionTargetTemplateId1')474 };475 })476 .expectStatusCode(200)477 .expectJsonCollectionToHaveSize(3)478 .expectJsonToBeAtLeast(function() {479 return [{480 id: this.getData('actionTargetId1'),481 name: 'AT1',482 organizationId: this.getData('organizationId2'),483 actionTargetTemplateId: this.getData('actionTargetTemplateId1')484 }, {485 id: this.getData('actionTargetId3'),486 name: 'AT3',487 organizationId: this.getData('organizationId1'),488 actionTargetTemplateId: this.getData('actionTargetTemplateId1')489 }, {490 id: this.getData('actionTargetId101'),491 name: 'AT1',492 organizationId: this.getData('organizationId1'),493 actionTargetTemplateId: this.getData('actionTargetTemplateId1')494 }];495 });496testSuite497 .describe('First user tries to mix different way to retrieve action targets (organizationId is used).')498 .get({}, function() { return { url: '/v1/actionTargets?allOrganizations&organizationId=' + this.getData('organizationId1') }; })499 .expectStatusCode(200)500 .expectJsonCollectionToHaveSize(2)501 .expectJsonToBeAtLeast(function() {502 return [{503 id: this.getData('actionTargetId3'),504 name: 'AT3',505 organizationId: this.getData('organizationId1'),506 actionTargetTemplateId: this.getData('actionTargetTemplateId1')507 }, {508 id: this.getData('actionTargetId101'),509 name: 'AT1',510 organizationId: this.getData('organizationId1'),511 actionTargetTemplateId: this.getData('actionTargetTemplateId1')512 }];513 });514testSuite515 .describe('First user retrieves all action targets.')516 .get({ url: '/v1/actionTargets?allOrganizations' })517 .expectStatusCode(200)518 .expectJsonToHavePath([ '0.id', '1.id', '2.id', '0.name', '1.name', '2.name', '0.organizationId', '0.actionTargetTemplateId' ])519 .expectJsonCollectionToHaveSize(5)520 .expectJsonToBeAtLeast(function() {521 return [{522 id: this.getData('actionTargetId1'),523 name: 'AT1',524 organizationId: this.getData('organizationId2'),525 actionTargetTemplateId: this.getData('actionTargetTemplateId1'),526 configuration: { botId: 'amazingSensor' }527 }, {528 id: this.getData('actionTargetId2'),529 name: 'AT2',530 organizationId: this.getData('organizationId2'),531 actionTargetTemplateId: this.getData('actionTargetTemplateId2')532 }, {533 id: this.getData('actionTargetId3'),534 name: 'AT3',535 organizationId: this.getData('organizationId1'),536 actionTargetTemplateId: this.getData('actionTargetTemplateId1')537 }, {538 id: this.getData('actionTargetId100'),539 name: 'AT1',540 organizationId: this.getData('organizationId2'),541 actionTargetTemplateId: this.getData('actionTargetTemplateId2')542 }, {543 id: this.getData('actionTargetId101'),544 name: 'AT1',545 organizationId: this.getData('organizationId1'),546 actionTargetTemplateId: this.getData('actionTargetTemplateId1')547 }];548 });549testSuite550 .describe('First user retrieves all action targets filtered by name.')551 .get({ url: '/v1/actionTargets?allOrganizations&name=AT1' })552 .expectStatusCode(200)553 .expectJsonCollectionToHaveSize(3)554 .expectJsonToBeAtLeast(function() {555 return [{556 id: this.getData('actionTargetId1'),557 name: 'AT1',558 organizationId: this.getData('organizationId2'),559 actionTargetTemplateId: this.getData('actionTargetTemplateId1'),560 configuration: { botId: 'amazingSensor' }561 }, {562 id: this.getData('actionTargetId100'),563 name: 'AT1',564 organizationId: this.getData('organizationId2'),565 actionTargetTemplateId: this.getData('actionTargetTemplateId2')566 }, {567 id: this.getData('actionTargetId101'),568 name: 'AT1',569 organizationId: this.getData('organizationId1'),570 actionTargetTemplateId: this.getData('actionTargetTemplateId1')571 }];572 });573testSuite574 .describe('First user retrieves all action targets for his first organization.')575 .get({}, function() { return { url: '/v1/actionTargets?organizationId=' + this.getData('organizationId1') }; })576 .expectStatusCode(200)577 .expectJsonToHavePath([ '0.id', '0.name', '0.organizationId', '0.actionTargetTemplateId' ])578 .expectJsonCollectionToHaveSize(2)579 .expectJsonToBeAtLeast(function() {580 return [{581 id: this.getData('actionTargetId3'),582 name: 'AT3',583 organizationId: this.getData('organizationId1'),584 actionTargetTemplateId: this.getData('actionTargetTemplateId1')585 }, {586 id: this.getData('actionTargetId101'),587 name: 'AT1',588 organizationId: this.getData('organizationId1'),589 actionTargetTemplateId: this.getData('actionTargetTemplateId1')590 }];591 });592testSuite593 .describe('First user retrieves all action targets for his second organization.')594 .get({}, function() { return { url: '/v1/actionTargets?organizationId=' + this.getData('organizationId2') }; })595 .expectStatusCode(200)596 .expectJsonToHavePath([ '0.id', '1.id', '0.name', '1.name', '0.organizationId', '0.actionTargetTemplateId' ])597 .expectJsonCollectionToHaveSize(3)598 .expectJsonToBeAtLeast(function() {599 return [{600 id: this.getData('actionTargetId1'),601 name: 'AT1',602 organizationId: this.getData('organizationId2'),603 actionTargetTemplateId: this.getData('actionTargetTemplateId1'),604 configuration: {605 botId: 'amazingSensor'606 }607 }, {608 id: this.getData('actionTargetId2'),609 name: 'AT2',610 organizationId: this.getData('organizationId2'),611 actionTargetTemplateId: this.getData('actionTargetTemplateId2')612 }, {613 id: this.getData('actionTargetId100'),614 name: 'AT1',615 organizationId: this.getData('organizationId2'),616 actionTargetTemplateId: this.getData('actionTargetTemplateId2')617 }];618 });619testSuite620 .describe('First user retrieves all action targets for his second organization filtered by name.')621 .get({}, function() { return { url: '/v1/actionTargets?organizationId=' + this.getData('organizationId2') + '&name=%2'}; })622 .expectStatusCode(200)623 .expectJsonCollectionToHaveSize(1)624 .expectJsonToBeAtLeast(function() {625 return [{626 id: this.getData('actionTargetId2'),627 name: 'AT2',628 organizationId: this.getData('organizationId2'),629 actionTargetTemplateId: this.getData('actionTargetTemplateId2')630 }];631 });632testSuite633 .describe('First user retrieves all action targets for his first action target template.')634 .get({}, function() { return { url: '/v1/actionTargets?actionTargetTemplateId=' + this.getData('actionTargetTemplateId1') }; })635 .expectStatusCode(200)636 .expectJsonToHavePath([ '0.id', '1.id', '0.name', '1.name', '0.organizationId', '0.actionTargetTemplateId' ])637 .expectJsonCollectionToHaveSize(3)638 .expectJsonToBeAtLeast(function() {639 return [{640 id: this.getData('actionTargetId1'),641 name: 'AT1',642 organizationId: this.getData('organizationId2'),643 actionTargetTemplateId: this.getData('actionTargetTemplateId1'),644 configuration: {645 botId: 'amazingSensor'646 }647 }, {648 id: this.getData('actionTargetId3'),649 name: 'AT3',650 organizationId: this.getData('organizationId1'),651 actionTargetTemplateId: this.getData('actionTargetTemplateId1')652 }, {653 id: this.getData('actionTargetId101'),654 name: 'AT1',655 organizationId: this.getData('organizationId1'),656 actionTargetTemplateId: this.getData('actionTargetTemplateId1')657 }];658 });659testSuite660 .describe('First user retrieves all action targets for his first action target template filtered by name.')661 .get({}, function() { return { url: '/v1/actionTargets?actionTargetTemplateId=' + this.getData('actionTargetTemplateId1') + '&name=%3'}; })662 .expectStatusCode(200)663 .expectJsonCollectionToHaveSize(1)664 .expectJsonToBeAtLeast(function() {665 return [{666 id: this.getData('actionTargetId3'),667 name: 'AT3',668 organizationId: this.getData('organizationId1'),669 actionTargetTemplateId: this.getData('actionTargetTemplateId1')670 }];671 });672testSuite673 .describe('First user retrieves all action targets for his second action target template.')674 .get({}, function() { return { url: '/v1/actionTargets?actionTargetTemplateId=' + this.getData('actionTargetTemplateId2') }; })675 .expectStatusCode(200)676 .expectJsonToHavePath([ '0.id', '0.name', '0.organizationId', '0.actionTargetTemplateId' ])677 .expectJsonCollectionToHaveSize(2)678 .expectJsonToBeAtLeast(function() {679 return [{680 id: this.getData('actionTargetId2'),681 name: 'AT2',682 organizationId: this.getData('organizationId2'),683 actionTargetTemplateId: this.getData('actionTargetTemplateId2')684 }, {685 id: this.getData('actionTargetId100'),686 name: 'AT1',687 organizationId: this.getData('organizationId2'),688 actionTargetTemplateId: this.getData('actionTargetTemplateId2')689 }];690 });691testSuite692 .describe('Second user retrieves all action targets.')693 .jwtAuthentication(function() { return this.getData('token2'); })694 .get({ url: '/v1/actionTargets?allOrganizations' })695 .expectStatusCode(200)696 .expectJsonToHavePath([ '0.id', '1.id', '0.name', '1.name', '0.organizationId', '0.actionTargetTemplateId' ])697 .expectJsonCollectionToHaveSize(4)698 .expectJsonToBeAtLeast(function() {699 return [{700 id: this.getData('actionTargetId4'),701 name: 'AT4',702 organizationId: this.getData('organizationId3'),703 actionTargetTemplateId: this.getData('actionTargetTemplateId1')704 }, {705 id: this.getData('actionTargetId5'),706 name: 'AT5',707 organizationId: this.getData('organizationId3'),708 actionTargetTemplateId: this.getData('actionTargetTemplateId3')709 }, {710 id: this.getData('actionTargetId6'),711 name: 'AT6',712 organizationId: this.getData('organizationId3'),713 actionTargetTemplateId: this.getData('actionTargetTemplateId1')714 }, {715 id: this.getData('actionTargetId7'),716 name: 'AT7',717 organizationId: this.getData('organizationId3'),718 actionTargetTemplateId: this.getData('actionTargetTemplateId1')719 }];720 });721testSuite722 .describe('Second user retrieves all action targets for his organization.')723 .get({}, function() { return { url: '/v1/actionTargets?organizationId=' + this.getData('organizationId3') }; })724 .expectStatusCode(200)725 .expectJsonToHavePath([ '0.id', '1.id', '0.name', '1.name', '0.organizationId', '0.actionTargetTemplateId' ])726 .expectJsonCollectionToHaveSize(4)727 .expectJsonToBeAtLeast(function() {728 return [{729 id: this.getData('actionTargetId4'),730 name: 'AT4',731 organizationId: this.getData('organizationId3'),732 actionTargetTemplateId: this.getData('actionTargetTemplateId1')733 }, {734 id: this.getData('actionTargetId5'),735 name: 'AT5',736 organizationId: this.getData('organizationId3'),737 actionTargetTemplateId: this.getData('actionTargetTemplateId3')738 }, {739 id: this.getData('actionTargetId6'),740 name: 'AT6',741 organizationId: this.getData('organizationId3'),742 actionTargetTemplateId: this.getData('actionTargetTemplateId1')743 }, {744 id: this.getData('actionTargetId7'),745 name: 'AT7',746 organizationId: this.getData('organizationId3'),747 actionTargetTemplateId: this.getData('actionTargetTemplateId1')748 }];749 });750testSuite751 .describe('Second user retrieves all action targets for his action target template.')752 .get({}, function() { return { url: '/v1/actionTargets?actionTargetTemplateId=' + this.getData('actionTargetTemplateId3') }; })753 .expectStatusCode(200)754 .expectJsonToHavePath([ '0.id', '0.generatedIdentifier', '0.name', '0.organizationId', '0.actionTargetTemplateId' ])755 .expectJsonCollectionToHaveSize(1)756 .expectJsonToBeAtLeast(function() {757 return [{758 id: this.getData('actionTargetId5'),759 name: 'AT5',760 organizationId: this.getData('organizationId3'),761 actionTargetTemplateId: this.getData('actionTargetTemplateId3')762 }];763 });764testSuite765 .describe('First user tries to retrieve an action target that does not exist.')766 .jwtAuthentication(function() { return this.getData('token1'); })767 .get({}, function() { return { url: this.getData('locationActionTarget1') + '100' }; })768 .expectStatusCode(403);769testSuite770 .describe('First user tries to retrieve a public action target from an organization where he is not a member.')771 .get({}, function() { return { url: this.getData('locationActionTarget4') }; })772 .expectStatusCode(200);773testSuite774 .describe('First user tries to retrieve a private action target from an organization where he is not a member.')775 .get({}, function() { return { url: this.getData('locationActionTarget7') }; })776 .expectStatusCode(403);777testSuite778 .describe('First user retrieve ES1 (1) action target.')779 .get({}, function() { return { url: this.getData('locationActionTarget1') }; })780 .expectStatusCode(200)781 .expectJsonToBeAtLeast(function() {782 return {783 id: this.getData('actionTargetId1'),784 name: 'AT1',785 organizationId: this.getData('organizationId2'),786 actionTargetTemplateId: this.getData('actionTargetTemplateId1'),787 configuration: {788 botId: 'amazingSensor'789 }790 };791 });792testSuite793 .describe('First user updates AT1 (1) action target.')794 .patch({}, function() {795 return {796 url: this.getData('locationActionTarget1'),797 body: {798 name: 'AT1 renamed'799 }800 };801 })802 .expectStatusCode(201)803 .expectLocationHeader('/v1/actionTargets/:id')804 .expectHeaderToBePresent('x-iflux-generated-id');805testSuite806 .describe('AT1 not updated should let it unchanged.')807 .patch({}, function() {808 return {809 url: this.getData('locationActionTarget1'),810 body: {}811 };812 })813 .expectStatusCode(304)814 .expectLocationHeader('/v1/actionTargets/:id')815 .expectHeaderToBePresent('x-iflux-generated-id');816testSuite817 .describe('First user updates the configuration of AT1 (1) action target.')818 .patch({}, function() {819 return {820 url: this.getData('locationActionTarget1'),821 body: {822 configuration: {823 botId: 'SuperBot'824 }825 }826 };827 })828 .expectStatusCode(201)829 .expectLocationHeader('/v1/actionTargets/:id')830 .expectHeaderToBePresent('x-iflux-generated-id');831testSuite832 .describe('Check AT1 (1) action target has been correctly updated.')833 .get({}, function() {834 return {835 url: this.getData('locationActionTarget1')836 };837 })838 .expectStatusCode(200)839 .expectJsonToBeAtLeast({840 name: 'AT1 renamed',841 configuration: {842 botId: 'SuperBot'843 }844 });845testSuite846 .describe('First user updates AT1 (100) action target with a name used by AT2.')847 .patch({}, function() {848 return {849 url: this.getData('locationActionTarget100'),850 body: {851 name: 'AT2'852 }853 };854 })855 .expectStatusCode(422)856 .expectJsonToBe({ name: [ 'Name is already taken for this action target template and this organization.' ]});857testSuite858 .describe('First user updates AT1 (100) action target with a name used by AT3.')859 .patch({}, function() {860 return {861 url: this.getData('locationActionTarget100'),862 body: {863 name: 'AT3'864 }865 };866 })867 .expectStatusCode(201)868 .expectLocationHeader('/v1/actionTargets/:id')869 .expectHeaderToBePresent('x-iflux-generated-id');870testSuite871 .describe('First user updates AT1 (100) action target with a name used by AT1 (1).')872 .patch({}, function() {873 return {874 url: this.getData('locationActionTarget100'),875 body: {876 name: 'AT1 renamed'877 }878 };879 })880 .expectStatusCode(201)881 .expectLocationHeader('/v1/actionTargets/:id')882 .expectHeaderToBePresent('x-iflux-generated-id');883testSuite884 .describe('Second user tries to update AT1 action target of first user.')885 .jwtAuthentication(function() { return this.getData('token2'); })886 .patch({}, function() {887 return {888 url: this.getData('locationActionTarget1'),889 body: {890 name: 'AT1 renamed again'891 }892 };893 })894 .expectStatusCode(403);895testSuite896 .describe('First user creates AT7 action target with a configuration call to remote system.')897 .jwtAuthentication(function() { return this.getData('token1'); })898 .mockRequest({899 method: 'POST',900 path: '/configure',901 body: {902 type: 'JSON'903 }904 }, {905 statusCode: 200,906 body: {907 type: 'JSON',908 value: JSON.stringify({ message: 'Configuration done.' })909 }910 }, {911 remainingTimes: 1,912 unlimited: 1913 })914 .post({ url: '/v1/actionTargets' }, function() {915 return {916 body: {917 name: 'AT7',918 organizationId: this.getData('organizationId1'),919 actionTargetTemplateId: this.getData('actionTargetTemplateId4'),920 configuration: {921 test: 'niceStoryBro'922 }923 }924 };925 })926 .storeLocationAs('actionTarget', 200)927 .expectStatusCode(201)928 .expectLocationHeader('/v1/actionTargets/:id')929 .expectMockServerToHaveReceived(function() {930 return {931 method: 'POST',932 path: '/configure',933 body: {934 type: 'JSON',935 matchType: 'ONLY_MATCHING_FIELDS',936 value: JSON.stringify({937 properties: {938 test: 'niceStoryBro'939 }940 })941 }942 };943 });944testSuite945 .describe('First user creates AT8 action target with a configuration and a token call to remote system.')946 .mockRequest({947 method: 'POST',948 path: '/configure',949 body: {950 type: 'JSON'951 }952 }, {953 statusCode: 200,954 body: {955 type: 'JSON',956 value: JSON.stringify({ message: 'Configuration done.' })957 }958 }, {959 remainingTimes: 1,960 unlimited: 1961 })962 .post({ url: '/v1/actionTargets' }, function() {963 return {964 body: {965 name: 'AT8',966 organizationId: this.getData('organizationId1'),967 actionTargetTemplateId: this.getData('actionTargetTemplateId5'),968 configuration: {969 test: 'niceStoryBro'970 }971 }972 };973 })974 .storeLocationAs('actionTarget', 201)975 .expectStatusCode(201)976 .expectLocationHeader('/v1/actionTargets/:id')977 .expectMockServerToHaveReceived(function() {978 return {979 method: 'POST',980 path: '/configure',981 headers: [{982 name: 'Authorization',983 values: [ 'bearer jwtToken' ]984 }],985 body: {986 type: 'JSON',987 matchType: 'ONLY_MATCHING_FIELDS',988 value: JSON.stringify({989 properties: {990 test: 'niceStoryBro'991 }992 })993 }994 };995 });996testSuite997 .describe('First user updates AT8 action target with a configuration and a token call to remote system.')998 .mockRequest({999 method: 'POST',1000 path: '/configure',1001 body: {1002 type: 'JSON'1003 }1004 }, {1005 statusCode: 200,1006 body: {1007 type: 'JSON',1008 value: JSON.stringify({ message: 'Configuration done.' })1009 }1010 }, {1011 remainingTimes: 1,1012 unlimited: 11013 })1014 .patch({ }, function() {1015 return {1016 url: this.getData('locationActionTarget201'),1017 body: {1018 configuration: {1019 test: 'configuration updated'1020 }1021 }1022 };1023 })1024 .expectStatusCode(201)1025 .expectLocationHeader('/v1/actionTargets/:id')1026 .expectMockServerToHaveReceived(function() {1027 return {1028 method: 'POST',1029 path: '/configure',1030 headers: [{1031 name: 'Authorization',1032 values: [ 'bearer jwtToken' ]1033 }],1034 body: {1035 type: 'JSON',1036 matchType: 'ONLY_MATCHING_FIELDS',1037 value: JSON.stringify({1038 properties: {1039 test: 'configuration updated'1040 }1041 })1042 }1043 };1044 });1045testSuite1046 .describe('First user reconfigure AT8 action target.')1047 .mockRequest({1048 method: 'POST',1049 path: '/configure',1050 body: {1051 type: 'JSON'1052 }1053 }, {1054 statusCode: 200,1055 body: {1056 type: 'JSON',1057 value: JSON.stringify({ message: 'Configuration done.' })1058 }1059 }, {1060 remainingTimes: 1,1061 unlimited: 11062 })1063 .post({}, function() {1064 return {1065 url: this.getData('locationActionTarget201') + '/configure'1066 };1067 })1068 .expectStatusCode(200)1069 .expectMockServerToHaveReceived(function() {1070 return {1071 method: 'POST',1072 path: '/configure',1073 headers: [{1074 name: 'Authorization',1075 values: [ 'bearer jwtToken' ]1076 }],1077 body: {1078 type: 'JSON',1079 matchType: 'ONLY_MATCHING_FIELDS',1080 value: JSON.stringify({1081 properties: {1082 test: 'niceStoryBro'1083 }1084 })1085 }1086 };1087 });1088testSuite1089 .describe('First user tries to reconfigure AT2 action target that has no configuration.')1090 .post({}, function() {1091 return {1092 url: this.getData('locationActionTarget2') + '/configure'1093 };1094 })1095 .expectStatusCode(404);1096testSuite1097 .describe('First user remove AT1.')1098 .delete({}, function() { return { url: this.getData('locationActionTarget1') }; })1099 .expectStatusCode(204);1100testSuite1101 .describe('First user tries to retrieve AT1.')1102 .get({}, function() { return { url: this.getData('locationActionTarget1') }; })1103 .expectStatusCode(403);1104testSuite1105 .describe('First user tries to delete AT4 in an organization where he is not a member.')1106 .delete({}, function() { return { url: this.getData('locationActionTarget4') }; })1107 .expectStatusCode(403);...
eventSources.spec.js
Source:eventSources.spec.js
...66 }67 }, 1, 1);68testSuite69 .describe('First user tries to creates ES1 event source with too short name.')70 .jwtAuthentication(function() { return this.getData('token1'); })71 .post({ url: '/v1/eventSources' }, function() {72 return {73 body: {74 name: 'ES',75 organizationId: this.getData('organizationId1'),76 eventSourceTemplateId: this.getData('eventSourceTemplateId1'),77 configuration: {78 sensorId: 'sensorIdForES1'79 }80 }81 };82 })83 .expectStatusCode(422)84 .expectJsonToHavePath('name.0')85 .expectJsonToBe({ name: [ 'The name must be at least 3 characters long' ]});86testSuite87 .describe('First user tries to creates ES1 event source in an organization he has no access.')88 .jwtAuthentication(function() { return this.getData('token1'); })89 .post({ url: '/v1/eventSources' }, function() {90 return {91 body: {92 name: 'ES1',93 organizationId: this.getData('organizationId3'),94 eventSourceTemplateId: this.getData('eventSourceTemplateId3'),95 configuration: {96 sensorId: 'sensorIdForES1'97 }98 }99 };100 })101 .expectStatusCode(422)102 .expectJsonToHavePath('organizationId.0')103 .expectJsonToBe({ organizationId: [ 'No organization found.' ]});104testSuite105 .describe('First user tries to create ES1 event source from an event source template he has no access.')106 .post({ url: '/v1/eventSources' }, function() {107 return {108 body: {109 name: 'ES1',110 organizationId: this.getData('organizationId1'),111 eventSourceTemplateId: this.getData('eventSourceTemplateId3'),112 configuration: {113 sensorId: 'sensorIdForES1'114 }115 }116 };117 })118 .expectStatusCode(422)119 .expectJsonToHavePath('eventSourceTemplateId.0')120 .expectJsonToBe({ eventSourceTemplateId: [ 'No event source template found.' ]});121testSuite122 .describe('First user tries to create ES1 event source with a wrong configuration.')123 .post({ url: '/v1/eventSources' }, function() {124 return {125 body: {126 name: 'ES1',127 organizationId: this.getData('organizationId1'),128 eventSourceTemplateId: this.getData('eventSourceTemplateId1'),129 configuration: {130 wrongProperty: 'anyValue'131 }132 }133 };134 })135 .expectStatusCode(422)136 .expectJsonToHavePath('configuration')137 .expectJsonToBe({ configuration: [{138 wrongProperty: [ "additionalProperty 'wrongProperty' exists in instance when not allowed" ],139 sensorId: [ "requires property \"sensorId\"" ]140 }]});141testSuite142 .describe('First user tries to create ES1 event source without configuration.')143 .post({ url: '/v1/eventSources' }, function() {144 return {145 body: {146 name: 'ES1',147 organizationId: this.getData('organizationId1'),148 eventSourceTemplateId: this.getData('eventSourceTemplateId1')149 }150 };151 })152 .expectStatusCode(422)153 .expectJsonToHavePath('configuration')154 .expectJsonToBe({ configuration: [ 'The event source template requires an event source configured.' ] });155testSuite156 .describe('First user creates ES1 event source for his second organization and first event source template.')157 .post({ url: '/v1/eventSources' }, function() {158 return {159 body: {160 name: 'ES1',161 public: 1,162 organizationId: this.getData('organizationId2'),163 eventSourceTemplateId: this.getData('eventSourceTemplateId1'),164 configuration: {165 sensorId: 'amazingSensor'166 }167 }168 };169 })170 .storeLocationAs('eventSource', 1)171 .expectStatusCode(201)172 .expectLocationHeader('/v1/eventSources/:id')173 .expectHeaderToBePresent('x-iflux-generated-id');174testSuite175 .describe('First user tries to re-create ES1 event source.')176 .post({ url: '/v1/eventSources' }, function() {177 return {178 body: {179 name: 'ES1',180 organizationId: this.getData('organizationId2'),181 eventSourceTemplateId: this.getData('eventSourceTemplateId1'),182 configuration: {183 sensorId: 'amazingSensor'184 }185 }186 };187 })188 .expectStatusCode(422)189 .expectJsonToHavePath('name')190 .expectJsonToBe({ name: [ "Name is already taken for this event source template and this organization." ] });191testSuite192 .describe('First user tries to re-create ES1 event source but in a different event source template.')193 .post({ url: '/v1/eventSources' }, function() {194 return {195 body: {196 name: 'ES1',197 organizationId: this.getData('organizationId2'),198 eventSourceTemplateId: this.getData('eventSourceTemplateId2'),199 configuration: {200 sensorId: 'sensorIdForES1'201 }202 }203 };204 })205 .storeLocationAs('eventSource', 100)206 .expectStatusCode(201)207 .expectLocationHeader('/v1/eventSources/:id')208 .expectHeaderToBePresent('x-iflux-generated-id');209testSuite210 .describe('First user tries to re-create ES1 event source but in a different organization.')211 .post({ url: '/v1/eventSources' }, function() {212 return {213 body: {214 name: 'ES1',215 organizationId: this.getData('organizationId1'),216 eventSourceTemplateId: this.getData('eventSourceTemplateId1'),217 configuration: {218 sensorId: 'sensorIdForES1'219 }220 }221 };222 })223 .storeLocationAs('eventSource', 101)224 .expectStatusCode(201)225 .expectLocationHeader('/v1/eventSources/:id')226 .expectHeaderToBePresent('x-iflux-generated-id');227testSuite228 .describe('First user creates ES2 event source for his second organization and second event source template.')229 .post({ url: '/v1/eventSources' }, function() {230 return {231 body: {232 name: 'ES2',233 organizationId: this.getData('organizationId2'),234 eventSourceTemplateId: this.getData('eventSourceTemplateId2')235 }236 };237 })238 .storeLocationAs('eventSource', 2)239 .expectStatusCode(201)240 .expectLocationHeader('/v1/eventSources/:id');241testSuite242 .describe('First user tries to create ES3 event source for his first organization and second event source template.')243 .post({ url: '/v1/eventSources' }, function() {244 return {245 body: {246 name: 'ES3',247 organizationId: this.getData('organizationId1'),248 eventSourceTemplateId: this.getData('eventSourceTemplateId2')249 }250 };251 })252 .expectStatusCode(422)253 .expectJsonToHavePath('eventSourceTemplateId.0')254 .expectJsonToBe({ eventSourceTemplateId: [ 'No event source template found.' ]});255testSuite256 .describe('First user creates ES3 event source for his first organization and first event source template.')257 .post({ url: '/v1/eventSources' }, function() {258 return {259 body: {260 name: 'ES3',261 organizationId: this.getData('organizationId1'),262 eventSourceTemplateId: this.getData('eventSourceTemplateId1'),263 configuration: {264 sensorId: 'sensorIdForES3'265 }266 }267 };268 })269 .storeLocationAs('eventSource', 3)270 .expectStatusCode(201)271 .expectLocationHeader('/v1/eventSources/:id');272testSuite273 .describe('Second user creates ES4 event source for his organization and first event source template.')274 .jwtAuthentication(function() { return this.getData('token2'); })275 .post({ url: '/v1/eventSources' }, function() {276 return {277 body: {278 name: 'ES4',279 public: true,280 organizationId: this.getData('organizationId3'),281 eventSourceTemplateId: this.getData('eventSourceTemplateId1'),282 configuration: {283 sensorId: 'sensorIdForES4'284 }285 }286 };287 })288 .storeLocationAs('eventSource', 4)289 .expectStatusCode(201)290 .expectLocationHeader('/v1/eventSources/:id');291testSuite292 .describe('Second user creates ES5 event source for his organization and third event source template.')293 .post({ url: '/v1/eventSources' }, function() {294 return {295 body: {296 name: 'ES5',297 organizationId: this.getData('organizationId3'),298 eventSourceTemplateId: this.getData('eventSourceTemplateId3')299 }300 };301 })302 .storeLocationAs('eventSource', 5)303 .expectStatusCode(201)304 .expectLocationHeader('/v1/eventSources/:id');305testSuite306 .describe('Second user creates ES6 event source for his organization and template in a different organization.')307 .post({ url: '/v1/eventSources' }, function() {308 return {309 body: {310 name: 'ES6',311 organizationId: this.getData('organizationId3'),312 eventSourceTemplateId: this.getData('eventSourceTemplateId1'),313 configuration: {314 sensorId: 'sensorIdForES6'315 }316 }317 };318 })319 .storeLocationAs('eventSource', 6)320 .expectStatusCode(201)321 .expectLocationHeader('/v1/eventSources/:id');322testSuite323 .describe('Second user retrieve ES6 event source.')324 .get({}, function() { return { url: '/v1/eventSources?name=%6&eventSourceTemplateId=' + this.getData('eventSourceTemplateId1') }; })325 .expectStatusCode(200)326 .expectJsonCollectionToHaveSize(1)327 .expectJsonToBeAtLeast(function() {328 return [{329 name: 'ES6',330 organizationId: this.getData('organizationId3'),331 eventSourceTemplateId: this.getData('eventSourceTemplateId1')332 }];333 });334testSuite335 .describe('Second user creates ES7 event source which is priavate.')336 .post({ url: '/v1/eventSources' }, function() {337 return {338 body: {339 name: 'ES7',340 public: false,341 organizationId: this.getData('organizationId3'),342 eventSourceTemplateId: this.getData('eventSourceTemplateId1'),343 configuration: {344 sensorId: 'sensorIdForES7'345 }346 }347 };348 })349 .storeLocationAs('eventSource', 7)350 .expectStatusCode(201)351 .expectLocationHeader('/v1/eventSources/:id');352testSuite353 .describe('Second user retrieve all event sources that he has access.')354 .get({ url: '/v1/eventSources' })355 .expectStatusCode(200)356 .expectJsonCollectionToHaveSize(5)357 .expectJsonToBeAtLeast(function() {358 return [{359 id: this.getData('eventSourceId1'),360 name: 'ES1',361 organizationId: this.getData('organizationId2'),362 eventSourceTemplateId: this.getData('eventSourceTemplateId1')363 }, {364 id: this.getData('eventSourceId4'),365 name: 'ES4',366 organizationId: this.getData('organizationId3'),367 eventSourceTemplateId: this.getData('eventSourceTemplateId1')368 }, {369 id: this.getData('eventSourceId5'),370 name: 'ES5',371 organizationId: this.getData('organizationId3'),372 eventSourceTemplateId: this.getData('eventSourceTemplateId3')373 }, {374 id: this.getData('eventSourceId6'),375 name: 'ES6',376 organizationId: this.getData('organizationId3'),377 eventSourceTemplateId: this.getData('eventSourceTemplateId1')378 }, {379 id: this.getData('eventSourceId7'),380 name: 'ES7',381 organizationId: this.getData('organizationId3'),382 eventSourceTemplateId: this.getData('eventSourceTemplateId1')383 }];384 });385testSuite386 .describe('Second user retrieve all public event sources.')387 .get({ url: '/v1/eventSources?public' })388 .expectStatusCode(200)389 .expectJsonCollectionToHaveSize(2)390 .expectJsonToBeAtLeast(function() {391 return [{392 id: this.getData('eventSourceId1'),393 name: 'ES1',394 organizationId: this.getData('organizationId2'),395 eventSourceTemplateId: this.getData('eventSourceTemplateId1')396 }, {397 id: this.getData('eventSourceId4'),398 name: 'ES4',399 organizationId: this.getData('organizationId3'),400 eventSourceTemplateId: this.getData('eventSourceTemplateId1')401 }];402 });403testSuite404 .describe('First user retrieve all event sources that he has access.')405 .jwtAuthentication(function() { return this.getData('token1'); })406 .get({ url: '/v1/eventSources' })407 .expectStatusCode(200)408 .expectJsonCollectionToHaveSize(6)409 .expectJsonToBeAtLeast(function() {410 return [{411 id: this.getData('eventSourceId1'),412 name: 'ES1',413 organizationId: this.getData('organizationId2'),414 eventSourceTemplateId: this.getData('eventSourceTemplateId1')415 }, {416 id: this.getData('eventSourceId100'),417 name: 'ES1',418 organizationId: this.getData('organizationId2'),419 eventSourceTemplateId: this.getData('eventSourceTemplateId2')420 }, {421 id: this.getData('eventSourceId101'),422 name: 'ES1',423 organizationId: this.getData('organizationId1'),424 eventSourceTemplateId: this.getData('eventSourceTemplateId1')425 }, {426 id: this.getData('eventSourceId2'),427 name: 'ES2',428 organizationId: this.getData('organizationId2'),429 eventSourceTemplateId: this.getData('eventSourceTemplateId2')430 }, {431 id: this.getData('eventSourceId3'),432 name: 'ES3',433 organizationId: this.getData('organizationId1'),434 eventSourceTemplateId: this.getData('eventSourceTemplateId1')435 }, {436 id: this.getData('eventSourceId4'),437 name: 'ES4',438 organizationId: this.getData('organizationId3'),439 eventSourceTemplateId: this.getData('eventSourceTemplateId1')440 }];441 });442testSuite443 .describe('First user retrieve all public action targets.')444 .jwtAuthentication(function() { return this.getData('token1'); })445 .get({ url: '/v1/eventSources?public' })446 .expectStatusCode(200)447 .expectJsonCollectionToHaveSize(2)448 .expectJsonToBeAtLeast(function() {449 return [{450 id: this.getData('eventSourceId1'),451 name: 'ES1',452 organizationId: this.getData('organizationId2'),453 eventSourceTemplateId: this.getData('eventSourceTemplateId1')454 }, {455 id: this.getData('eventSourceId4'),456 name: 'ES4',457 organizationId: this.getData('organizationId3'),458 eventSourceTemplateId: this.getData('eventSourceTemplateId1')459 }];460 });461testSuite462 .describe('First user tries to mix different way to retrieve event sources (eventSourceTemplateId is used).')463 .get({}, function() {464 return {465 url: '/v1/eventSources?allOrganizations&organizationId=' +466 this.getData('organizationId1') +467 '&eventSourceTemplateId=' +468 this.getData('eventSourceTemplateId1')469 };470 })471 .expectStatusCode(200)472 .expectJsonCollectionToHaveSize(3)473 .expectJsonToBeAtLeast(function() {474 return [{475 id: this.getData('eventSourceId1'),476 name: 'ES1',477 organizationId: this.getData('organizationId2'),478 eventSourceTemplateId: this.getData('eventSourceTemplateId1')479 }, {480 id: this.getData('eventSourceId3'),481 name: 'ES3',482 organizationId: this.getData('organizationId1'),483 eventSourceTemplateId: this.getData('eventSourceTemplateId1')484 }, {485 id: this.getData('eventSourceId101'),486 name: 'ES1',487 organizationId: this.getData('organizationId1'),488 eventSourceTemplateId: this.getData('eventSourceTemplateId1')489 }];490 });491testSuite492 .describe('First user tries to mix different way to retrieve event sources (organizationId is used).')493 .get({}, function() { return { url: '/v1/eventSources?allOrganizations&organizationId=' + this.getData('organizationId1') }; })494 .expectStatusCode(200)495 .expectJsonCollectionToHaveSize(2)496 .expectJsonToBeAtLeast(function() {497 return [{498 id: this.getData('eventSourceId3'),499 name: 'ES3',500 organizationId: this.getData('organizationId1'),501 eventSourceTemplateId: this.getData('eventSourceTemplateId1')502 }, {503 id: this.getData('eventSourceId101'),504 name: 'ES1',505 organizationId: this.getData('organizationId1'),506 eventSourceTemplateId: this.getData('eventSourceTemplateId1')507 }];508 });509testSuite510 .describe('First user retrieves all event sources.')511 .get({ url: '/v1/eventSources?allOrganizations' })512 .expectStatusCode(200)513 .expectJsonToHavePath([ '0.id', '1.id', '2.id', '0.name', '1.name', '2.name', '0.organizationId', '0.eventSourceTemplateId' ])514 .expectJsonCollectionToHaveSize(5)515 .expectJsonToBeAtLeast(function() {516 return [{517 id: this.getData('eventSourceId1'),518 name: 'ES1',519 organizationId: this.getData('organizationId2'),520 eventSourceTemplateId: this.getData('eventSourceTemplateId1'),521 configuration: {522 sensorId: 'amazingSensor'523 }524 }, {525 id: this.getData('eventSourceId2'),526 name: 'ES2',527 organizationId: this.getData('organizationId2'),528 eventSourceTemplateId: this.getData('eventSourceTemplateId2')529 }, {530 id: this.getData('eventSourceId3'),531 name: 'ES3',532 organizationId: this.getData('organizationId1'),533 eventSourceTemplateId: this.getData('eventSourceTemplateId1')534 }, {535 id: this.getData('eventSourceId100'),536 name: 'ES1',537 organizationId: this.getData('organizationId2'),538 eventSourceTemplateId: this.getData('eventSourceTemplateId2')539 }, {540 id: this.getData('eventSourceId101'),541 name: 'ES1',542 organizationId: this.getData('organizationId1'),543 eventSourceTemplateId: this.getData('eventSourceTemplateId1')544 }];545 });546testSuite547 .describe('First user retrieves all event sources filtered by name.')548 .get({ url: '/v1/eventSources?allOrganizations&name=%1' })549 .expectStatusCode(200)550 .expectJsonCollectionToHaveSize(3)551 .expectJsonToBeAtLeast(function() {552 return [{553 id: this.getData('eventSourceId1'),554 name: 'ES1',555 organizationId: this.getData('organizationId2'),556 eventSourceTemplateId: this.getData('eventSourceTemplateId1'),557 configuration: {558 sensorId: 'amazingSensor'559 }560 }, {561 id: this.getData('eventSourceId100'),562 name: 'ES1',563 organizationId: this.getData('organizationId2'),564 eventSourceTemplateId: this.getData('eventSourceTemplateId2')565 }, {566 id: this.getData('eventSourceId101'),567 name: 'ES1',568 organizationId: this.getData('organizationId1'),569 eventSourceTemplateId: this.getData('eventSourceTemplateId1')570 }];571 });572testSuite573 .describe('First user retrieves all event sources for his first organization.')574 .get({}, function() { return { url: '/v1/eventSources?organizationId=' + this.getData('organizationId1') }; })575 .expectStatusCode(200)576 .expectJsonToHavePath([ '0.id', '0.name', '0.organizationId', '0.eventSourceTemplateId' ])577 .expectJsonCollectionToHaveSize(2)578 .expectJsonToBeAtLeast(function() {579 return [{580 id: this.getData('eventSourceId3'),581 name: 'ES3',582 organizationId: this.getData('organizationId1'),583 eventSourceTemplateId: this.getData('eventSourceTemplateId1')584 }, {585 id: this.getData('eventSourceId101'),586 name: 'ES1',587 organizationId: this.getData('organizationId1'),588 eventSourceTemplateId: this.getData('eventSourceTemplateId1')589 }];590 });591testSuite592 .describe('First user retrieves all event sources for his second organization.')593 .get({}, function() { return { url: '/v1/eventSources?organizationId=' + this.getData('organizationId2') }; })594 .expectStatusCode(200)595 .expectJsonToHavePath([ '0.id', '1.id', '0.name', '1.name', '0.organizationId', '0.eventSourceTemplateId', '0.configuration' ])596 .expectJsonCollectionToHaveSize(3)597 .expectJsonToBeAtLeast(function() {598 return [{599 id: this.getData('eventSourceId1'),600 name: 'ES1',601 organizationId: this.getData('organizationId2'),602 eventSourceTemplateId: this.getData('eventSourceTemplateId1'),603 configuration: {sensorId: 'amazingSensor'}604 }, {605 id: this.getData('eventSourceId2'),606 name: 'ES2',607 organizationId: this.getData('organizationId2'),608 eventSourceTemplateId: this.getData('eventSourceTemplateId2')609 }, {610 id: this.getData('eventSourceId100'),611 name: 'ES1',612 organizationId: this.getData('organizationId2'),613 eventSourceTemplateId: this.getData('eventSourceTemplateId2')614 }];615 });616testSuite617 .describe('First user retrieves all event sources for his second organization filtered by name.')618 .get({}, function() { return { url: '/v1/eventSources?organizationId=' + this.getData('organizationId2') + '&name=%2'}; })619 .expectStatusCode(200)620 .expectJsonCollectionToHaveSize(1)621 .expectJsonToBeAtLeast(function() {622 return [{623 id: this.getData('eventSourceId2'),624 name: 'ES2',625 organizationId: this.getData('organizationId2'),626 eventSourceTemplateId: this.getData('eventSourceTemplateId2')627 }];628 });629testSuite630 .describe('First user retrieves all event sources for his first event source template.')631 .get({}, function() { return { url: '/v1/eventSources?eventSourceTemplateId=' + this.getData('eventSourceTemplateId1') }; })632 .expectStatusCode(200)633 .expectJsonToHavePath([ '0.id', '1.id', '0.name', '1.name', '0.organizationId', '0.eventSourceTemplateId' ])634 .expectJsonCollectionToHaveSize(3)635 .expectJsonToBeAtLeast(function() {636 return [{637 id: this.getData('eventSourceId1'),638 name: 'ES1',639 organizationId: this.getData('organizationId2'),640 eventSourceTemplateId: this.getData('eventSourceTemplateId1'),641 configuration: {sensorId: 'amazingSensor'}642 }, {643 id: this.getData('eventSourceId3'),644 name: 'ES3',645 organizationId: this.getData('organizationId1'),646 eventSourceTemplateId: this.getData('eventSourceTemplateId1')647 }, {648 id: this.getData('eventSourceId101'),649 name: 'ES1',650 organizationId: this.getData('organizationId1'),651 eventSourceTemplateId: this.getData('eventSourceTemplateId1')652 }];653 });654testSuite655 .describe('First user retrieves all event sources for his first event source template filtered by name.')656 .get({}, function() { return { url: '/v1/eventSources?eventSourceTemplateId=' + this.getData('eventSourceTemplateId1') + '&name=%3' }; })657 .expectStatusCode(200)658 .expectJsonCollectionToHaveSize(1)659 .expectJsonToBeAtLeast(function() {660 return [{661 id: this.getData('eventSourceId3'),662 name: 'ES3',663 organizationId: this.getData('organizationId1'),664 eventSourceTemplateId: this.getData('eventSourceTemplateId1')665 }];666 });667testSuite668 .describe('First user retrieves all event sources for his second event source template.')669 .get({}, function() { return { url: '/v1/eventSources?eventSourceTemplateId=' + this.getData('eventSourceTemplateId2') }; })670 .expectStatusCode(200)671 .expectJsonToHavePath([ '0.id', '0.name', '0.organizationId', '0.eventSourceTemplateId' ])672 .expectJsonCollectionToHaveSize(2)673 .expectJsonToBeAtLeast(function() {674 return [{675 id: this.getData('eventSourceId2'),676 name: 'ES2',677 organizationId: this.getData('organizationId2'),678 eventSourceTemplateId: this.getData('eventSourceTemplateId2')679 }, {680 id: this.getData('eventSourceId100'),681 name: 'ES1',682 organizationId: this.getData('organizationId2'),683 eventSourceTemplateId: this.getData('eventSourceTemplateId2')684 }];685 });686testSuite687 .describe('Second user retrieves all event sources.')688 .jwtAuthentication(function() { return this.getData('token2'); })689 .get({ url: '/v1/eventSources?allOrganizations' })690 .expectStatusCode(200)691 .expectJsonToHavePath([ '0.id', '1.id', '0.name', '1.name', '0.organizationId', '0.eventSourceTemplateId' ])692 .expectJsonCollectionToHaveSize(4)693 .expectJsonToBeAtLeast(function() {694 return [{695 id: this.getData('eventSourceId4'),696 name: 'ES4',697 organizationId: this.getData('organizationId3'),698 eventSourceTemplateId: this.getData('eventSourceTemplateId1')699 }, {700 id: this.getData('eventSourceId5'),701 name: 'ES5',702 organizationId: this.getData('organizationId3'),703 eventSourceTemplateId: this.getData('eventSourceTemplateId3')704 }, {705 id: this.getData('eventSourceId6'),706 name: 'ES6',707 organizationId: this.getData('organizationId3'),708 eventSourceTemplateId: this.getData('eventSourceTemplateId1')709 }, {710 id: this.getData('eventSourceId7'),711 name: 'ES7',712 organizationId: this.getData('organizationId3'),713 eventSourceTemplateId: this.getData('eventSourceTemplateId1')714 }];715 });716testSuite717 .describe('Second user retrieves all event sources for his organization.')718 .get({}, function() { return { url: '/v1/eventSources?organizationId=' + this.getData('organizationId3') }; })719 .expectStatusCode(200)720 .expectJsonToHavePath([ '0.id', '1.id', '0.name', '1.name', '0.organizationId', '0.eventSourceTemplateId' ])721 .expectJsonCollectionToHaveSize(4)722 .expectJsonToBeAtLeast(function() {723 return [{724 id: this.getData('eventSourceId4'),725 name: 'ES4',726 organizationId: this.getData('organizationId3'),727 eventSourceTemplateId: this.getData('eventSourceTemplateId1')728 }, {729 id: this.getData('eventSourceId5'),730 name: 'ES5',731 organizationId: this.getData('organizationId3'),732 eventSourceTemplateId: this.getData('eventSourceTemplateId3')733 }, {734 id: this.getData('eventSourceId6'),735 name: 'ES6',736 organizationId: this.getData('organizationId3'),737 eventSourceTemplateId: this.getData('eventSourceTemplateId1')738 }, {739 id: this.getData('eventSourceId7'),740 name: 'ES7',741 organizationId: this.getData('organizationId3'),742 eventSourceTemplateId: this.getData('eventSourceTemplateId1')743 }];744 });745testSuite746 .describe('Second user retrieves all event sources for his event source template.')747 .get({}, function() { return { url: '/v1/eventSources?eventSourceTemplateId=' + this.getData('eventSourceTemplateId3') }; })748 .expectStatusCode(200)749 .expectJsonToHavePath([ '0.id', '0.generatedIdentifier', '0.name', '0.organizationId', '0.eventSourceTemplateId' ])750 .expectJsonCollectionToHaveSize(1)751 .expectJsonToBeAtLeast(function() {752 return [{753 id: this.getData('eventSourceId5'),754 name: 'ES5',755 organizationId: this.getData('organizationId3'),756 eventSourceTemplateId: this.getData('eventSourceTemplateId3')757 }];758 });759testSuite760 .describe('First user tries to retrieve an event source that does not exist.')761 .jwtAuthentication(function() { return this.getData('token1'); })762 .get({}, function() { return { url: this.getData('locationEventSource1') + '100' }; })763 .expectStatusCode(403);764testSuite765 .describe('First user tries to retrieve a public event source from an organization where he is not a member.')766 .get({}, function() { return { url: this.getData('locationEventSource4') }; })767 .expectStatusCode(200);768testSuite769 .describe('First user tries to retrieve a private event source from an organization where he is not a member.')770 .get({}, function() { return { url: this.getData('locationEventSource7') }; })771 .expectStatusCode(403);772testSuite773 .describe('First user retrieve ES1 (1) event source.')774 .get({}, function() { return { url: this.getData('locationEventSource1') }; })775 .expectStatusCode(200)776 .expectJsonToBeAtLeast(function() {777 return {778 id: this.getData('eventSourceId1'),779 name: 'ES1',780 organizationId: this.getData('organizationId2'),781 eventSourceTemplateId: this.getData('eventSourceTemplateId1'),782 configuration: {783 sensorId: 'amazingSensor'784 }785 };786 });787testSuite788 .describe('First user updates ES1 (1) event source.')789 .patch({}, function() {790 return {791 url: this.getData('locationEventSource1'),792 body: {793 name: 'ES1 renamed'794 }795 };796 })797 .expectStatusCode(201)798 .expectLocationHeader('/v1/eventSources/:id')799 .expectHeaderToBePresent('x-iflux-generated-id');800testSuite801 .describe('ES1 not updated should let it unchanged.')802 .patch({}, function() {803 return {804 url: this.getData('locationEventSource1'),805 body: {}806 };807 })808 .expectStatusCode(304)809 .expectLocationHeader('/v1/eventSources/:id')810 .expectHeaderToBePresent('x-iflux-generated-id');811testSuite812 .describe('First user updates the configuration ES1 (1) event source.')813 .patch({}, function() {814 return {815 url: this.getData('locationEventSource1'),816 body: {817 configuration: {818 sensorId: 'HighTemperatureSensor'819 }820 }821 };822 })823 .expectStatusCode(201)824 .expectLocationHeader('/v1/eventSources/:id')825 .expectHeaderToBePresent('x-iflux-generated-id');826testSuite827 .describe('Check ES1 (1) event source has been correctly updated.')828 .get({}, function() {829 return {830 url: this.getData('locationEventSource1')831 };832 })833 .expectStatusCode(200)834 .expectJsonToBeAtLeast({835 name: 'ES1 renamed',836 configuration: {837 sensorId: 'HighTemperatureSensor'838 }839 });840testSuite841 .describe('First user updates ES1 (100) event source with a name used by ES2.')842 .patch({}, function() {843 return {844 url: this.getData('locationEventSource100'),845 body: {846 name: 'ES2'847 }848 };849 })850 .expectStatusCode(422)851 .expectJsonToBe({ name: [ 'Name is already taken for this event source template and this organization.' ]});852testSuite853 .describe('First user updates ES1 (100) event source with a name used by ES3.')854 .patch({}, function() {855 return {856 url: this.getData('locationEventSource100'),857 body: {858 name: 'ES3'859 }860 };861 })862 .expectStatusCode(201)863 .expectLocationHeader('/v1/eventSources/:id')864 .expectHeaderToBePresent('x-iflux-generated-id');865testSuite866 .describe('First user updates ES1 (100) event source with a name used by ES1 (1).')867 .patch({}, function() {868 return {869 url: this.getData('locationEventSource100'),870 body: {871 name: 'ES1 renamed'872 }873 };874 })875 .expectStatusCode(201)876 .expectLocationHeader('/v1/eventSources/:id')877 .expectHeaderToBePresent('x-iflux-generated-id');878testSuite879 .describe('Second user tries to update ES1 event source of first user.')880 .jwtAuthentication(function() { return this.getData('token2'); })881 .patch({}, function() {882 return {883 url: this.getData('locationEventSource1'),884 body: {885 name: 'ES1 renamed again'886 }887 };888 })889 .expectStatusCode(403);890testSuite891 .describe('First user creates ES7 event source with a configuration call to remote system.')892 .jwtAuthentication(function() { return this.getData('token1'); })893 .mockRequest({894 method: 'POST',895 path: '/configure',896 body: {897 type: 'JSON'898 }899 }, {900 statusCode: 200,901 body: {902 type: 'JSON',903 value: JSON.stringify({ message: 'Configuration done.' })904 }905 }, {906 remainingTimes: 1,907 unlimited: 1908 })909 .post({ url: '/v1/eventSources' }, function() {910 return {911 body: {912 name: 'ES7',913 organizationId: this.getData('organizationId1'),914 eventSourceTemplateId: this.getData('eventSourceTemplateId4'),915 configuration: {916 test: 'niceStoryBro'917 }918 }919 };920 })921 .storeLocationAs('eventSource', 200)922 .expectStatusCode(201)923 .expectLocationHeader('/v1/eventSources/:id')924 .expectMockServerToHaveReceived(function() {925 return {926 method: 'POST',927 path: '/configure',928 body: {929 type: 'JSON',930 matchType: 'ONLY_MATCHING_FIELDS',931 value: JSON.stringify({932 properties: {933 test: 'niceStoryBro'934 }935 })936 }937 };938 });939testSuite940 .describe('First user creates ES8 event source with a configuration and a token call to remote system.')941 .mockRequest({942 method: 'POST',943 path: '/configure',944 body: {945 type: 'JSON'946 }947 }, {948 statusCode: 200,949 body: {950 type: 'JSON',951 value: JSON.stringify({ message: 'Configuration done.' })952 }953 }, {954 remainingTimes: 1,955 unlimited: 1956 })957 .post({ url: '/v1/eventSources' }, function() {958 return {959 body: {960 name: 'Source with configuration and token',961 organizationId: this.getData('organizationId1'),962 eventSourceTemplateId: this.getData('eventSourceTemplateId5'),963 configuration: {964 test: 'niceStoryBro'965 }966 }967 };968 })969 .storeLocationAs('eventSource', 201)970 .expectStatusCode(201)971 .expectLocationHeader('/v1/eventSources/:id')972 .expectMockServerToHaveReceived(function() {973 return {974 method: 'POST',975 path: '/configure',976 headers: [{977 name: 'Authorization',978 values: [ 'bearer jwtToken' ]979 }],980 body: {981 type: 'JSON',982 matchType: 'ONLY_MATCHING_FIELDS',983 value: JSON.stringify({984 properties: {985 test: 'niceStoryBro'986 }987 })988 }989 };990 });991testSuite992 .describe('First user updates ES8 event source with a configuration and a token call to remote system.')993 .mockRequest({994 method: 'POST',995 path: '/configure',996 body: {997 type: 'JSON'998 }999 }, {1000 statusCode: 200,1001 body: {1002 type: 'JSON',1003 value: JSON.stringify({ message: 'Configuration done.' })1004 }1005 }, {1006 remainingTimes: 1,1007 unlimited: 11008 })1009 .patch({ }, function() {1010 return {1011 url: this.getData('locationEventSource201'),1012 body: {1013 configuration: {1014 test: 'configuration updated'1015 }1016 }1017 };1018 })1019 .expectStatusCode(201)1020 .expectLocationHeader('/v1/eventSources/:id')1021 .expectMockServerToHaveReceived(function() {1022 return {1023 method: 'POST',1024 path: '/configure',1025 headers: [{1026 name: 'Authorization',1027 values: [ 'bearer jwtToken' ]1028 }],1029 body: {1030 type: 'JSON',1031 matchType: 'ONLY_MATCHING_FIELDS',1032 value: JSON.stringify({1033 properties: {1034 test: 'configuration updated'1035 }1036 })1037 }1038 };1039 });1040testSuite1041 .describe('First reconfigure ES8 event source.')1042 .mockRequest({1043 method: 'POST',1044 path: '/configure',1045 body: {1046 type: 'JSON'1047 }1048 }, {1049 statusCode: 200,1050 body: {1051 type: 'JSON',1052 value: JSON.stringify({ message: 'Configuration done.' })1053 }1054 }, {1055 remainingTimes: 1,1056 unlimited: 11057 })1058 .post({}, function() {1059 return {1060 url: this.getData('locationEventSource201') + '/configure'1061 };1062 })1063 .expectStatusCode(200)1064 .expectMockServerToHaveReceived(function() {1065 return {1066 method: 'POST',1067 path: '/configure',1068 headers: [{1069 name: 'Authorization',1070 values: [ 'bearer jwtToken' ]1071 }],1072 body: {1073 type: 'JSON',1074 matchType: 'ONLY_MATCHING_FIELDS',1075 value: JSON.stringify({1076 properties: {1077 test: 'niceStoryBro'1078 }1079 })1080 }1081 };1082 });1083testSuite1084 .describe('First tries to reconfigure ES2 event source that has no configuration.')1085 .post({}, function() {1086 return {1087 url: this.getData('locationEventSource2') + '/configure'1088 };1089 })1090 .expectStatusCode(404);1091testSuite1092 .describe('First user remove ES1.')1093 .delete({}, function() { return { url: this.getData('locationEventSource1') }; })1094 .expectStatusCode(204);1095testSuite1096 .describe('First user tries to retrieve ES1.')1097 .get({}, function() { return { url: this.getData('locationEventSource1') }; })1098 .expectStatusCode(403);1099testSuite1100 .describe('First user tries to delete ES4 in an organization where he is not a member.')1101 .delete({}, function() { return { url: this.getData('locationEventSource4') }; })1102 .expectStatusCode(403);...
rules.spec.js
Source:rules.spec.js
...3 baseTest = require('../base');4var testSuite = helpers.setup(baseTest('Rule resource'));5testSuite6 .describe('First user create first rule with [first orga, first event source, first event type, first action target, first action type].')7 .jwtAuthentication(function() { return this.getData('token1'); })8 .post({ url: '/v1/rules'}, function() {9 return {10 body: {11 name: 'First rule',12 active: true,13 organizationId: this.getData('organizationId1'),14 conditions: [{15 eventSourceId: this.getData('eventSourceId1'),16 eventTypeId: this.getData('eventTypeId1'),17 fn: {18 expression: 'return event.properties.temperature.old != event.properties.temperature.new',19 sampleEvent: {20 temperature: {21 old: 10,22 new: 1123 }24 }25 }26 }],27 transformations: [{28 actionTargetId: this.getData('actionTargetId1'),29 actionTypeId: this.getData('actionTypeId1'),30 fn: {31 expression: 'return "The new temperature is: " + event.properties.temperature;',32 sample: {33 event: {34 temperature: 1235 }36 }37 }38 }]39 }40 };41 })42 .storeLocationAs('rule', 1)43 .expectStatusCode(201)44 .expectLocationHeader('/v1/rules/:id');45testSuite46 .describe('First user create first rule with [second orga, first event source, first action target, first action type].')47 .post({ url: '/v1/rules'}, function() {48 return {49 body: {50 name: 'Second rule',51 active: true,52 organizationId: this.getData('organizationId2'),53 conditions: [{54 eventSourceId: this.getData('eventSourceId2')55 }],56 transformations: [{57 actionTargetId: this.getData('actionTargetId1'),58 actionTypeId: this.getData('actionTypeId1'),59 fn: {60 expression: 'return "Received event: " + event.name;',61 sample: {62 event: {63 }64 }65 }66 }]67 }68 };69 })70 .storeLocationAs('rule', 2)71 .expectStatusCode(201)72 .expectLocationHeader('/v1/rules/:id')73 .describe('First user create a rule with public event source, event type, action target and action type.')74 .post({ url: '/v1/rules'}, function() {75 return {76 body: {77 name: 'Rule with public data',78 active: true,79 organizationId: this.getData('organizationId2'),80 conditions: [{81 eventSourceId: this.getData('eventSourceId6'),82 eventTypeId: this.getData('eventTypeId4')83 }],84 transformations: [{85 actionTargetId: this.getData('actionTargetId6'),86 actionTypeId: this.getData('actionTypeId4')87 }]88 }89 };90 })91 .storeLocationAs('rule', 4)92 .expectStatusCode(201)93 .expectLocationHeader('/v1/rules/:id');94testSuite95 .describe('Second user create first rule with [third orga, fourth event source, fourth action target, fourth action type].')96 .jwtAuthentication(function() { return this.getData('token2'); })97 .post({ url: '/v1/rules'}, function() {98 return {99 body: {100 name: 'Third rule',101 active: true,102 organizationId: this.getData('organizationId3'),103 conditions: [{104 eventSourceId: this.getData('eventSourceId4')105 }],106 transformations: [{107 actionTargetId: this.getData('actionTargetId4'),108 actionTypeId: this.getData('actionTypeId4'),109 fn: {110 expression: 'return "Received event: " + event.name;',111 sample: {112 event: {113 }114 }115 }116 }]117 }118 };119 })120 .storeLocationAs('rule', 3)121 .expectStatusCode(201)122 .expectLocationHeader('/v1/rules/:id');123testSuite124 .describe('First user tries to retrieve rules.')125 .jwtAuthentication(function() { return this.getData('token1'); })126 .get({}, function() { return { url: '/v1/rules?organizationId=' + this.getData('organizationId1') + 100 }; })127 .expectStatusCode(403);128testSuite129 .describe('First user tries to retrieve rules in an organization where he is not a member.')130 .get({}, function() { return { url: '/v1/rules?organizationId=' + this.getData('organizationId3') }; })131 .expectStatusCode(403);132testSuite133 .describe('First user retrieve rules in his first organization.')134 .get({}, function() { return { url: '/v1/rules?organizationId=' + this.getData('organizationId1') }; })135 .expectStatusCode(200)136 .expectJsonCollectionToHaveSize(1)137 .expectJsonToHavePath([ '0.conditions.0.eventSource', '0.conditions.0.eventSource.id', '0.conditions.0.eventSource.generatedIdentifier', '0.conditions.0.eventType', '0.transformations.0.actionTarget', '0.transformations.0.actionType' ])138 .expectJsonToBeAtLeast(function() {139 return [{140 id: this.getData('ruleId1'),141 name: 'First rule',142 description: null,143 active: true,144 organizationId: this.getData('organizationId1'),145 conditions: [{146 eventSource: {147 id: this.getData('eventSourceId1'),148 },149 eventType: {150 id: this.getData('eventTypeId1')151 },152 fn: {153 expression: 'return event.properties.temperature.old != event.properties.temperature.new',154 sampleEvent: {155 temperature: {156 old: 10,157 new: 11158 }159 }160 }161 }],162 transformations: [{163 actionTarget: {164 id: this.getData('actionTargetId1'),165 },166 actionType: {167 id: this.getData('actionTypeId1')168 },169 fn: {170 expression: 'return "The new temperature is: " + event.properties.temperature;',171 sample: {172 event: {173 temperature: 12174 }175 }176 }177 }]178 }];179 });180testSuite181 .describe('First user retrieve rules in his first organization filtered by name.')182 .get({}, function() { return { url: '/v1/rules?organizationId=' + this.getData('organizationId1') + '&name=First%' }; })183 .expectStatusCode(200)184 .expectJsonCollectionToHaveSize(1)185 .expectJsonToBeAtLeast(function() {186 return [{187 id: this.getData('ruleId1'),188 name: 'First rule',189 description: null,190 active: true,191 organizationId: this.getData('organizationId1'),192 conditions: [{193 eventSource: {194 id: this.getData('eventSourceId1')195 },196 eventType: {197 id: this.getData('eventTypeId1')198 },199 fn: {200 expression: 'return event.properties.temperature.old != event.properties.temperature.new',201 sampleEvent: {202 temperature: {203 old: 10,204 new: 11205 }206 }207 }208 }],209 transformations: [{210 actionTarget: {211 id: this.getData('actionTargetId1')212 },213 actionType: {214 id: this.getData('actionTypeId1')215 },216 fn: {217 expression: 'return "The new temperature is: " + event.properties.temperature;',218 sample: {219 event: {220 temperature: 12221 }222 }223 }224 }]225 }];226 });227testSuite228 .describe('First user retrieve rules in his second organization.')229 .get({}, function() { return { url: '/v1/rules?organizationId=' + this.getData('organizationId2') }; })230 .expectStatusCode(200)231 .expectJsonCollectionToHaveSize(2)232 .expectJsonToHavePath([ '0.conditions.0.eventSource.generatedIdentifier', '0.transformations.0.actionTarget.generatedIdentifier', '0.transformations.0.actionType' ])233 .expectJsonToBeAtLeast(function() {234 return [{235 id: this.getData('ruleId2'),236 name: 'Second rule',237 active: true,238 organizationId: this.getData('organizationId2'),239 conditions: [{240 eventSource:{241 id: this.getData('eventSourceId2')242 }243 }],244 transformations: [{245 actionTarget:{246 id: this.getData('actionTargetId1')247 },248 actionType:{249 id: this.getData('actionTypeId1')250 },251 fn: {252 expression: 'return "Received event: " + event.name;',253 sample: {254 event: {255 }256 }257 }258 }]259 }, {260 id: this.getData('ruleId4'),261 name: 'Rule with public data',262 active: true,263 organizationId: this.getData('organizationId2'),264 conditions: [{265 eventSource: {266 id: this.getData('eventSourceId6')267 },268 eventType: {269 id: this.getData('eventTypeId4')270 }271 }],272 transformations: [{273 actionTarget: {274 id: this.getData('actionTargetId6')275 },276 actionType: {277 id: this.getData('actionTypeId4')278 }279 }]280 }];281 });282testSuite283 .describe('First user retrieve rules in all his organizations.')284 .get({ url: '/v1/rules' })285 .expectStatusCode(200)286 .expectJsonCollectionToHaveSize(3)287 .expectJsonToBeAtLeast(function() {288 return [{289 id: this.getData('ruleId1'),290 name: 'First rule',291 description: null,292 active: true,293 organizationId: this.getData('organizationId1'),294 conditions: [{295 eventSource: {296 id: this.getData('eventSourceId1')297 },298 eventType:{299 id: this.getData('eventTypeId1')300 },301 fn: {302 expression: 'return event.properties.temperature.old != event.properties.temperature.new',303 sampleEvent: {304 temperature: {305 old: 10,306 new: 11307 }308 }309 }310 }],311 transformations: [{312 actionTarget:{313 id: this.getData('actionTargetId1')314 },315 actionType:{316 id: this.getData('actionTypeId1')317 },318 fn: {319 expression: 'return "The new temperature is: " + event.properties.temperature;',320 sample: {321 event: {322 temperature: 12323 }324 }325 }326 }]327 }, {328 id: this.getData('ruleId2'),329 name: 'Second rule',330 active: true,331 organizationId: this.getData('organizationId2'),332 conditions: [{333 eventSource:{334 id: this.getData('eventSourceId2')335 }336 }],337 transformations: [{338 actionTarget:{339 id: this.getData('actionTargetId1')340 },341 actionType:{342 id: this.getData('actionTypeId1')343 },344 fn: {345 expression: 'return "Received event: " + event.name;',346 sample: {347 event: {348 }349 }350 }351 }]352 }, {353 id: this.getData('ruleId4'),354 name: 'Rule with public data',355 active: true,356 organizationId: this.getData('organizationId2'),357 conditions: [{358 eventSource: {359 id: this.getData('eventSourceId6')360 },361 eventType: {362 id: this.getData('eventTypeId4')363 }364 }],365 transformations: [{366 actionTarget: {367 id: this.getData('actionTargetId6')368 },369 actionType: {370 id: this.getData('actionTypeId4')371 }372 }]373 }];374 });375testSuite376 .describe('First user retrieve rules in all his organizations filtered by name.')377 .get({ url: '/v1/rules?name=Second%' })378 .expectStatusCode(200)379 .expectJsonCollectionToHaveSize(1)380 .expectJsonToBeAtLeast(function() {381 return [{382 id: this.getData('ruleId2'),383 name: 'Second rule',384 active: true,385 organizationId: this.getData('organizationId2'),386 conditions: [{387 eventSource:{388 id: this.getData('eventSourceId2')389 }390 }],391 transformations: [{392 actionTarget:{393 id: this.getData('actionTargetId1')394 },395 actionType:{396 id: this.getData('actionTypeId1')397 },398 fn: {399 expression: 'return "Received event: " + event.name;',400 sample: {401 event: {402 }403 }404 }405 }]406 }];407 });408testSuite409 .describe('Second user tries to retrieve rules in an organization where he is not a member.')410 .jwtAuthentication(function() { return this.getData('token2'); })411 .get({}, function() { return { url: '/v1/rules?organizationId=' + this.getData('organizationId1') }; })412 .expectStatusCode(403);413testSuite414 .describe('Second user retrieve rules in his organization.')415 .get({}, function() { return { url: '/v1/rules?organizationId=' + this.getData('organizationId3') }; })416 .expectStatusCode(200)417 .expectJsonCollectionToHaveSize(1)418 .expectJsonToHavePath([ '0.conditions.0.eventSource.generatedIdentifier', '0.transformations.0.actionTarget.generatedIdentifier', '0.transformations.0.actionType' ])419 .expectJsonToBeAtLeast(function() {420 return [{421 id: this.getData('ruleId3'),422 name: 'Third rule',423 active: true,424 organizationId: this.getData('organizationId3'),425 conditions: [{426 eventSource:{427 id: this.getData('eventSourceId4')428 }429 }],430 transformations: [{431 actionTarget:{432 id: this.getData('actionTargetId4')433 },434 actionType:{435 id: this.getData('actionTypeId4')436 },437 fn: {438 expression: 'return "Received event: " + event.name;',439 sample: {440 event: {441 }442 }443 }444 }]445 }];446 });447testSuite448 .describe('Second user retrieve rules in all his organizations.')449 .get({ url: '/v1/rules' })450 .expectStatusCode(200)451 .expectJsonCollectionToHaveSize(1)452 .expectJsonToBeAtLeast(function() {453 return [{454 id: this.getData('ruleId3'),455 name: 'Third rule',456 active: true,457 organizationId: this.getData('organizationId3'),458 conditions: [{459 eventSource:{460 id: this.getData('eventSourceId4')461 }462 }],463 transformations: [{464 actionTarget:{465 id: this.getData('actionTargetId4')466 },467 actionType:{468 id: this.getData('actionTypeId4')469 },470 fn: {471 expression: 'return "Received event: " + event.name;',472 sample: {473 event: {474 }475 }476 }477 }]478 }];479 });480testSuite481 .describe('First user tries to retrieve a rule that does not exist.')482 .jwtAuthentication(function() { return this.getData('token1'); })483 .get({}, function() { return { url: this.getData('locationRule1') + '100' }; })484 .expectStatusCode(403);485testSuite486 .describe('First user tries to retrieve a rule from an organization where he is not a member.')487 .get({}, function() { return { url: this.getData('locationRule3') }; })488 .expectStatusCode(403);489testSuite490 .describe('First user retrieve his first rule.')491 .get({}, function() { return { url: this.getData('locationRule1') }; })492 .expectStatusCode(200)493 .expectJsonToHavePath([ 'conditions.0.eventSource.generatedIdentifier', 'conditions.0.eventType', 'transformations.0.actionTarget.generatedIdentifier', 'transformations.0.actionType' ])494 .expectJsonToBeAtLeast(function() {495 return {496 id: this.getData('ruleId1'),497 name: 'First rule',498 description: null,499 active: true,500 organizationId: this.getData('organizationId1'),501 conditions: [{502 eventSource:{503 id: this.getData('eventSourceId1')504 },505 eventType:{506 id: this.getData('eventTypeId1')507 },508 fn: {509 expression: 'return event.properties.temperature.old != event.properties.temperature.new',510 sampleEvent: {511 temperature: {512 old: 10,513 new: 11514 }515 }516 }517 }],518 transformations: [{519 actionTarget:{520 id: this.getData('actionTargetId1')521 },522 actionType:{523 id: this.getData('actionTypeId1')524 },525 fn: {526 expression: 'return "The new temperature is: " + event.properties.temperature;',527 sample: {528 event: {529 temperature: 12530 }531 }532 }533 }]534 };535 });536testSuite537 .describe('First user updates hist first rule.')538 .patch({}, function() {539 return {540 url: this.getData('locationRule1'),541 body: {542 name: 'First rule renamed',543 description: 'Rule updated to check its body',544 conditions: [{545 eventSourceId: this.getData('eventSourceId2'),546 eventTypeId: this.getData('eventTypeId2')547 }],548 transformations: [{549 actionTargetId: this.getData('actionTargetId2'),550 actionTypeId: this.getData('actionTypeId2')551 }]552 }553 };554 })555 .expectStatusCode(201)556 .expectLocationHeader('/v1/rules/:id');557testSuite558 .describe('First user retrieve his first rule to check the update done correctly.')559 .get({}, function() { return { url: this.getData('locationRule1') }; })560 .expectStatusCode(200)561 .expectJsonToBeAtLeast(function() {562 return {563 id: this.getData('ruleId1'),564 name: 'First rule renamed',565 description: 'Rule updated to check its body',566 active: true,567 organizationId: this.getData('organizationId1'),568 conditions: [{569 eventSource:{570 id: this.getData('eventSourceId2')571 },572 eventType:{573 id: this.getData('eventTypeId2')574 }575 }],576 transformations: [{577 actionTarget:{578 id: this.getData('actionTargetId2')579 },580 actionType:{581 id: this.getData('actionTypeId2')582 }583 }]584 };585 });586testSuite587 .describe('First user updates hist first rule.')588 .patch({}, function() {589 return {590 url: this.getData('locationRule1'),591 body: {}592 };593 })594 .expectStatusCode(304)595 .expectLocationHeader('/v1/rules/:id');596testSuite597 .describe('Second user tries to update the first rule of first user.')598 .jwtAuthentication(function() { return this.getData('token2'); })599 .patch({}, function() {600 return {601 url: this.getData('locationRule1'),602 body: {603 name: 'First rule renamed by second user'604 }605 };606 })607 .expectStatusCode(403);608testSuite609 .describe('First user remove his first rule.')610 .jwtAuthentication(function() { return this.getData('token1'); })611 .delete({}, function() { return { url: this.getData('locationRule1') }; })612 .expectStatusCode(204);613testSuite614 .describe('First user tries to retrieve his deleted rule.')615 .get({}, function() { return { url: this.getData('locationRule1') }; })616 .expectStatusCode(403);617testSuite618 .describe('First user tries to delete a rule in an organization where he is not a member.')619 .get({}, function() { return { url: this.getData('locationRule3') }; })620 .expectStatusCode(403);...
params.js
Source:params.js
1/**2 * å°å¾åæ°3 * key为å°å¾ç±»å: {4 * loc: ä¸å¿ä½ç½®5 * box: ä¿å«çåï¼ç¼©æ¾åç
§ç³»6 * getData: å°å¾æ°æ®å è½½7 * } 8 */9define(function(require) {10 function decode(json){11 if (!json.UTF8Encoding) {12 return json;13 }14 var features = json.features;15 for (var f = 0; f < features.length; f++) {16 var feature = features[f];17 var coordinates = feature.geometry.coordinates;18 var encodeOffsets = feature.geometry.encodeOffsets;19 for (var c = 0; c < coordinates.length; c++) {20 var coordinate = coordinates[c];21 22 if (feature.geometry.type === 'Polygon') {23 coordinates[c] = decodePolygon(24 coordinate,25 encodeOffsets[c]26 );27 } else if (feature.geometry.type === 'MultiPolygon') {28 for (var c2 = 0; c2 < coordinate.length; c2++) {29 var polygon = coordinate[c2];30 coordinate[c2] = decodePolygon(31 polygon,32 encodeOffsets[c][c2]33 );34 }35 }36 }37 }38 // Has been decoded39 json.UTF8Encoding = false;40 return json;41 }42 function decodePolygon(coordinate, encodeOffsets) {43 var result = [];44 var prevX = encodeOffsets[0];45 var prevY = encodeOffsets[1];46 for (var i = 0; i < coordinate.length; i+=2) {47 var x = coordinate.charCodeAt(i) - 64;48 var y = coordinate.charCodeAt(i+1) - 64;49 // ZigZag decoding50 x = (x >> 1) ^ (-(x & 1));51 y = (y >> 1) ^ (-(y & 1));52 // Delta deocding53 x += prevX;54 y += prevY;55 prevX = x;56 prevY = y;57 // Dequantize58 result.push([x / 1024, y / 1024]);59 }60 return result;61 }62 //box is x, y, width, height when projection scale is 400063 return {64 'china': {65 loc: [102, 36.7],66 box: [67 -1174.6445229087194, -1437.3577680805693,68 3039.3970214233723, 2531.1958969818469 ],70 getData: function(callback) { 71 require(['./china/0'], function(md){72 callback(decode(md));73 });74 }75 },76 'æ°ç': {77 loc: [84.9023, 41.748],78 box: [79 -1174.9404317915883, -1136.0130934711678,80 1216.4169237052663, 939.436081838525181 ],82 getData: function(callback) { 83 require(['./china/65'], function(md){84 callback(decode(md));85 });86 }87 },88 '西è': {89 loc: [88.7695, 31.6846],90 box: [91 -1061.2905098655508, -273.40253896102865,92 1182.4138890465167, 728.476243421238593 ],94 getData: function(callback) { 95 require(['./china/54'], function(md){96 callback(decode(md));97 });98 }99 },100 'å
èå¤': {101 loc: [110.5977, 45.3408], // [117.5977, 44.3408]102 box: [103 81.92106433333947, -1404.5655158641246,104 1337.913665139638, 1168.7030286278964105 ],106 getData: function(callback) { 107 require(['./china/15'], function(md){108 callback(decode(md));109 });110 }111 },112 'éæµ·': {113 loc: [96.2402, 35.4199],114 box: [115 -398.0407413665446, -404.86540158240564,116 770.5429460357634, 553.4881569694239117 ],118 getData: function(callback) { 119 require(['./china/63'], function(md){120 callback(decode(md));121 });122 }123 },124 'åå·': {125 loc: [102.9199, 30.1904],126 box: [127 34.77351011413543, -24.727858097581816,128 654.265749584143, 581.5837904142871129 ],130 getData: function(callback) { 131 require(['./china/51'], function(md){132 callback(decode(md));133 });134 }135 },136 'é»é¾æ±': {137 loc: [128.1445, 48.5156],138 box: [139 1185.0861642873883, -1435.9087566254907,140 680.9449423479143, 618.3772597960831141 ],142 getData: function(callback) { 143 require(['./china/23'], function(md){144 callback(decode(md));145 });146 }147 },148 'çè': {149 loc: [99.7129, 37.866],// [95.7129, 40.166]150 box: [151 -197.5222870378875, -631.2015222269291,152 884.6861134736321, 734.2542202456989153 ],154 getData: function(callback) { 155 require(['./china/62'], function(md){156 callback(decode(md));157 });158 }159 },160 'äºå': {161 loc: [101.8652, 25.1807],162 box: [163 -4.030270169151834, 326.89754492870105,164 561.4971786143803, 565.9079094851168165 ],166 getData: function(callback) { 167 require(['./china/53'], function(md){168 callback(decode(md));169 });170 }171 },172 '广西': {173 loc: [108.2813, 23.6426],174 box: [175 444.4355364538484, 524.7911424174906,176 490.6548359068431, 384.1667316158848177 ],178 getData: function(callback) { 179 require(['./china/45'], function(md){180 callback(decode(md));181 });182 }183 },184 'æ¹å': {185 loc: [111.5332, 27.3779],186 box: [187 716.7125751678784, 265.3988842488122,188 346.1702652872375, 377.50144051998274189 ],190 getData: function(callback) { 191 require(['./china/43'], function(md){192 callback(decode(md));193 });194 }195 },196 'é西': {197 loc: [108.5996, 35.6396], // [109.5996, 35.6396]198 box: [199 508.5948583446903, -399.56997062473215,200 321.038690321553, 559.1002147021181201 ],202 getData: function(callback) { 203 require(['./china/61'], function(md){204 callback(decode(md));205 });206 }207 },208 '广ä¸': {209 loc: [113.4668, 22.8076],210 box: [211 790.2032875493967, 572.9640361040085,212 494.8279567104971, 388.7112686526252213 ],214 getData: function(callback) { 215 require(['./china/44'], function(md){216 callback(decode(md));217 });218 }219 },220 'åæ': {221 loc: [126.4746, 43.5938],222 box: [223 1287.5729431804648, -950.943295028444,224 504.33243011403374, 354.162667814153225 ],226 getData: function(callback) { 227 require(['./china/22'], function(md){228 callback(decode(md));229 });230 }231 },232 'æ²³å': {233 loc: [115.4004, 39.3688], //[115.4004, 37.9688]234 box: [235 940.0156020671719, -646.4007207319194,236 325.33903805510784, 477.4542727272415237 ],238 getData: function(callback) { 239 require(['./china/13'], function(md){240 callback(decode(md));241 });242 }243 },244 'æ¹å': {245 loc: [112.2363, 31.1572],246 box: [247 683.8325394595918, 45.82949601748078,248 468.66717545627034, 295.2142095820616249 ],250 getData: function(callback) { 251 require(['./china/42'], function(md){252 callback(decode(md));253 });254 }255 },256 'è´µå·': {257 loc: [106.6113, 26.9385],258 box: [259 392.5021834497175, 337.4483828727408,260 375.50579966539516, 320.9420464446699261 ],262 getData: function(callback) { 263 require(['./china/52'], function(md){264 callback(decode(md));265 });266 }267 },268 'å±±ä¸': {269 loc: [118.7402, 36.4307],270 box: [271 1035.7855473594757, -382.19242168799906,272 412.5747391303373, 313.152767793266273 ],274 getData: function(callback) { 275 require(['./china/37'], function(md){276 callback(decode(md));277 });278 }279 },280 'æ±è¥¿': {281 loc: [116.0156, 27.29],282 box: [283 1012.6841751377355, 236.50140310944056,284 295.599802392515, 400.86430917822287285 ],286 getData: function(callback) { 287 require(['./china/36'], function(md){288 callback(decode(md));289 });290 }291 },292 'æ²³å': {293 loc: [113.4668, 33.8818],294 box: [295 785.5419798731749, -185.2911232263814,296 362.6977821251186, 340.3902676066224297 ],298 getData: function(callback) { 299 require(['./china/41'], function(md){300 callback(decode(md));301 });302 }303 },304 'è¾½å®': {305 loc: [122.3438, 41.0889],306 box: [307 1203.0641741691293, -757.0946871553339,308 352.71788824534656, 357.71276541155214309 ],310 getData: function(callback) { 311 require(['./china/21'], function(md){312 callback(decode(md));313 });314 }315 },316 '山西': {317 loc: [112.4121, 37.6611],318 box: [319 776.5185040689469, -493.6204506126494,320 212.68572802329425, 448.08485211774945321 ],322 getData: function(callback) { 323 require(['./china/14'], function(md){324 callback(decode(md));325 });326 }327 },328 'å®å¾½': {329 loc: [117.2461, 32.0361],330 box: [331 1054.014965660052, -80.43770626104327,332 295.73127466484925, 352.03731065611606333 ],334 getData: function(callback) { 335 require(['./china/34'], function(md){336 callback(decode(md));337 });338 }339 },340 'ç¦å»º': {341 loc: [118.3008, 25.9277],342 box: [343 1172.0955040211252, 341.81292779438445,344 288.99462739279807, 339.42845011348845345 ],346 getData: function(callback) { 347 require(['./china/35'], function(md){348 callback(decode(md));349 });350 }351 },352 'æµæ±': {353 loc: [120.498, 29.0918],354 box: [355 1272.1789620983063, 123.46272678646208,356 286.17816622252326, 286.73860446060394357 ],358 getData: function(callback) { 359 require(['./china/33'], function(md){360 callback(decode(md));361 });362 }363 },364 'æ±è': {365 loc: [119.0586, 32.915], // [120.0586, 32.915]366 box: [367 1125.161343490302, -134.97368204682834,368 356.1806346879009, 291.4961628010442369 ],370 getData: function(callback) { 371 require(['./china/32'], function(md){372 callback(decode(md));373 });374 }375 },376 'éåº': {377 loc: [107.7539, 30.1904],378 box: [379 497.78832088614774, 127.0051229616378,380 291.91221530072164, 280.8880182020781381 ],382 getData: function(callback) { 383 require(['./china/50'], function(md){384 callback(decode(md));385 });386 }387 },388 'å®å¤': {389 loc: [105.9961, 37.3096],390 box: [391 441.193675072408, -376.31946967355213,392 183.76989823787306, 293.0024551112753393 ],394 getData: function(callback) { 395 require(['./china/64'], function(md){396 callback(decode(md));397 });398 }399 },400 'æµ·å': {401 loc: [109.9512, 19.2041],402 box: [403 723.8031601361929, 946.050886515855,404 183.33374783084207, 147.66048518654895405 ],406 getData: function(callback) { 407 require(['./china/46'], function(md){408 callback(decode(md));409 });410 }411 },412 'å°æ¹¾': {413 loc: [120.7254, 23.5986], //[121.0254, 23.5986]414 box: [415 1459.925544038912, 519.7445429876257,416 103.06085087505835, 237.80851484008463417 ],418 getData: function(callback) { 419 require(['./china/71'], function(md){420 callback(decode(md));421 });422 }423 },424 'å京': {425 loc: [116.4551, 40.2539],426 box: [427 1031.6052083127613, -530.1928574952913,428 103.23943439987329, 114.66079087790081429 ],430 getData: function(callback) { 431 require(['./china/11'], function(md){432 callback(decode(md));433 });434 }435 },436 '天津': {437 loc: [117.2219, 39.4189], //[117.4219, 39.4189]438 box: [439 1106.9649995752443, -479.16508616378724,440 71.21176554916747, 120.01987096046025441 ],442 getData: function(callback) { 443 require(['./china/12'], function(md){444 callback(decode(md));445 });446 }447 },448 'ä¸æµ·': {449 loc: [121.4648, 31.2891],450 box: [451 1420.334836525578, 71.79837578328207,452 70.41721601016525, 81.99461244072737453 ],454 getData: function(callback) { 455 require(['./china/31'], function(md){456 callback(decode(md));457 });458 }459 },460 'é¦æ¸¯': {461 loc: [114.2578, 22.3242],462 box: [463 1061.983645387268, 769.0837862603122,464 50.65584483626753, 32.17422147262721465 ],466 getData: function(callback) { 467 require(['./china/81'], function(md){468 callback(decode(md));469 });470 }471 },472 'æ¾³é¨': {473 loc: [113.5547, 22.1604], //[113.5547, 22.1484]474 box: [475 1043.1350056914507, 798.0786255550063,476 5.387452843479423, 7.564113979470676477 ],478 getData: function(callback) { 479 require(['./china/82'], function(md){480 callback(decode(md));481 });482 }483 }484 };...
websocket.js
Source:websocket.js
1var ws = null;2// console.log(document.location);3// var url= 'ws://'+document.location.host+'/web/websocket/ebox';4var url= 'ws://10.10.10.133:8008/web/websocket/2/3';5// var url= 'ws://localhost';6function websend_fpga(addr,val){7 ws.send(new Int8Array([0xff,0x04,0x00,0x0b,0x00,0x5a,0xa5,0x00,0x30,0xbb,((addr >> 8) & 0xff),(addr & 0xff),((val >> 8) & 0xff),(0xff & val),0x00,0x00]));8}9var getData = new Array();10var getTmp = new Array();11var getVal = new Array();12var serverstate = 0; //æå¡å¨å½åç¶ææ è¯ {0:å®éªä¸»çé¢;1:æ件ä¸ä¼ ;2:é»è¾åæ仪æ¾ç¤º;3:示波å¨æ¾ç¤º;}13var di = 0,dk = 0;14var ex_index = 0; //å®éªç®å½ {1:lcd,2:çµæº,3:key,4:adda,5:io}15//å建åæå¡å¨çWebSocket é¾æ¥ 16function createSocket(onSuccess) { 17 ws = new WebSocket(url); 18 ws.binaryType = "arraybuffer"; 19 // console.log(ws);20 ws.onopen = function () { 21 ws.send(new Int8Array([0xff,0x00]));22 fileuping = 1;23 serverstate = 1;24 console.log('connectedæå'); 25 if (onSuccess) 26 onSuccess(); 27 // alert("æ£å¨ä¸è½½FPGAæ件ï¼è¯·å¿æä½ï¼");28 } 29 30 ws.onmessage = function (e) {31 // console.log(e);32 getData = new Uint8Array(e.data);33 console.log("getData.length: "+getData.length);34 // console.log("getData: "+getData);35 var dend = 0; //æ¯å¦å°è¾¾æ°æ®ç»å°¾æ å¿36 di = 0;37 // console.log((getData[0] & 0xff),0xfe,getData[1]);38 if(serverstate == 2){39 if((getData[di] == 0xfe) && (getData[di+1] == 0x00))40 {41 // console.log(2);42 di += 2;43 if(di == getData.length)44 dend = 1;45 while(dend != 1){ //æªå°æ°æ®æ«å°¾ç»§ç»æ§è¡46 if(getTmp.length < 2048) //æ°æ®æ¥æ¶ç¼å²æªè¾¾å°2048é¿åº¦,继ç»å¡«å
47 {48 // console.log(5);49 while((dk != 2048) && (dend != 1))50 {51 if(getTmp.length == 0)52 {53 // console.log(0);54 if((getData[di] == 0x7e) && (getData[di+1] == 0xe7) && (getData[di+2] == 0xe7) && (getData[di+3] == 0x01)){55 // console.log(3);56 datastyle = 1;57 di += 4;58 dk = getTmp.length;59 for(;(dk < 2048) && (di < getData.length);di++,dk++)60 {61 getTmp[dk] = getData[di] ;62 }63 // console.log(di,getData.length);64 if(di == getData.length)65 {66 getData = new Array();67 di = 0;68 dend = 1;69 }70 }else{71 if(di < getData.length-3)72 di++;73 else74 {di=0;dend = 1;}75 }76 }77 else78 {79 dk = getTmp.length;80 for(;(dk < 2048) && (di < getData.length);di++,dk++)81 {82 getTmp[dk] = getData[di] ;83 }84 if(di == getData.length)85 {86 getData = new Array();87 di = 0;88 dend = 1;89 }90 }91 }92 }93 if(getTmp.length == 2048) //æ°æ®æ¥æ¶ç¼å²è¾¾å°2048é¿åº¦,æ¾ç¤º94 {95 // console.log(6);96 getVal = new Array();97 for(var s = 0,m = 0;m < 1024;s+=2,m++)98 getVal[m] = (getTmp[s]) + (getTmp[s+1] << 8);99 100 // console.log(getVal);101 getTmp = new Array();102 dk = 0;103 switch(serverstate){104 case 0:105 106 break;107 case 1:108 break;109 case 2:110 if(logicpause == 1)break;111 // console.log("æ¥æ¶å°æ°æ®");112 logicdrawline();113 if(ex_index == 5){114 // console.log("æ¶å°é»åæ°æ®ï¼0x%s",getVal[100].toString(16));115 $(".s51_led").each(function(){116 var i = parseInt($(this).attr("i"));117 if(iopsetted[i+16] == 0){$(this).attr("fill","transparent");return;}118 var k = (getVal[100] >> (8+i)) & 1;119 if(k == 0){120 $(this).attr("fill","transparent");121 }else{122 $(this).attr("fill","red");123 }124 });125 }else if(ex_index == 3){126 // console.log("æ¶å°é»åæ°æ®ï¼0x%s",getVal[100].toString(16));127 $(".s51_led").each(function(){128 var i = parseInt($(this).attr("i"));129 if(keypsetted[i+9] == 0){return;}130 var k = (getVal[100] >> (8+i)) & 1;131 if(k == 0){132 $(this).attr("fill","transparent");133 }else{134 $(this).attr("fill","red");135 }136 });137 }else if(ex_index == 4){138 // console.log("æ¶å°é»åæ°æ®ï¼0x%s",getVal[100].toString(16));139 ledshow("s51_led1",((getVal[100] >> 8) & 0x0f) & parseInt(""+addapsetted[10]+""+addapsetted[9]+""+addapsetted[8]+""+addapsetted[7],2));140 ledshow("s51_led2",(getVal[100] >> 12) & parseInt(""+addapsetted[14]+""+addapsetted[13]+""+addapsetted[12]+""+addapsetted[11],2));141 }142 break;143 // case 3:144 // oscdrawline();145 // console.log("æ¥åå°æ°æ®");146 // // console.log(getVal);147 // break;148 }149 }150 }151 return;152 }153 else if((getData[di] == 0xfe) && (getData[di+1] == 0xff)){154 di += 4;155 switch((getData[di+1]&0xFF)){156 case 0xF1:157 alert("ä¸ä¼ æ件æé®é¢");158 break;159 case 0xF9:160 alert("ä¹åä¸è½½æªå®æ");161 break;162 case 0xFA:163 alert("å®éªç®±ä¸è½½è¶
æ¶");164 break;165 case 0xFB:166 alert("åéæ°æ®æ误");167 break;168 case 0xFC:169 alert("æ件丢失");170 break;171 case 0xFD:172 alert("å®éªç®±ä¸è½½ä¸æ");173 break;174 case 0xFE:175 alert("å®éªç®±æå¼");176 break;177 case 0xFF:178 alert("å®éªç®±å¼å¸¸");179 break;180 }181 }182 }else if(serverstate == 1){183 // console.log(11);184 // FE 0F 00 06 XX PP æ件ä¸è½½è¿åº¦185 // 头 é¿åº¦ åºæ¿ç¼å· è¿åº¦%186 if(((getData[di] & 0xff) == 0xfe) && ((getData[di+1] & 0xff) == 0x0F) && ((getData[di+2] & 0xff) == 0x00) && ((getData[di+3] & 0xff) == 0x06))187 {188 // console.log(1);189 di += 4;190 // document.getElementById("Status").innerText = "ä¸è½½ä¸ï¼" + getData[di+1] + "%";191 // document.getElementById("progressOne").value = getData[di+1];192 }193 // FE 01 00 05 XX æ件ä¸è½½å®æ194 // 头 é¿åº¦ åºæ¿ç¼å·195 else if(((getData[di] & 0xff) == 0xfe) && ((getData[di+1] & 0xff) == 0x01) && ((getData[di+2] & 0xff) == 0x00) && ((getData[di+3] & 0xff) == 0x05))196 {197 di += 4;198 // console.log(12);199 // document.getElementById("Status").innerText = "ä¸è½½å®æ!";200 fileuping = 0;201 if(getData[di] == 0){202 $(".md02_t1").text("é
ç½®å®æ");203 setTimeout(function(){$("#module02").modal('hide');},500);204 }else{205 switch(ex_index){206 case 2:207 case 5:208 $(".fileprg").attr("width",120);209 $(".filetext").text("ä¸è½½ä¸ "+100+"%");210 break;211 case 1:212 case 3:213 case 4:214 $(".fileprg").attr("height",120);215 $(".filetext").text(100);216 break;217 }218 $(".fdl").each(function(){$(this).removeAttr("disabled").val("");});219 alert("ä¸è½½å®æ");220 $(".fpc").hide();221 switch(ex_index){222 case 2:223 case 5:224 $(".fileprg").attr("width",0);225 $(".filetext").text("ä¸è½½ä¸ "+0+"%");226 break;227 case 1:228 case 3:229 case 4:230 $(".fileprg").attr("height",0);231 $(".filetext").text(0);232 break;233 }234 if(ex_index == 3 || ex_index == 5 || ex_index == 4){serverstate = 2}235 clearInterval(setIntsign);236 filepercent = 0;237 websend_fpga(0x1001,0x0001);238 }239 }240 // FE FF LL LL YY XX å¼å¸¸241 // 头 é¿åº¦ å¼å¸¸ç¶æå· åºæ¿ç¼å·242 else if(((getData[di] & 0xff) == 0xFE) && ((getData[di+1] & 0xff) == 0xFF)){243 di += 4;244 switch((getData[di]&0xFF)){245 case 0xF1:246 $(".md02_t1").text("ä¸ä¼ æ件æé®é¢...请å·æ°éè¯");247 break;248 case 0xF9:249 $(".md02_t1").text("ä¹åä¸è½½æªå®æ...请å·æ°éè¯");250 break;251 case 0xFA:252 $(".md02_t1").text("å®éªç®±ä¸è½½è¶
æ¶...请å·æ°éè¯");253 break;254 case 0xFB:255 $(".md02_t1").text("åéæ°æ®æ误...请å·æ°éè¯");256 break;257 case 0xFC:258 $(".md02_t1").text("æ件丢失...请å·æ°éè¯");259 break;260 case 0xFD:261 $(".md02_t1").text("å®éªç®±ä¸è½½ä¸æ...请å·æ°éè¯");262 break;263 case 0xFE:264 $(".md02_t1").text("å®éªç®±æå¼...请å·æ°éè¯");265 break;266 case 0xFF:267 $(".md02_t1").text("å®éªç®±å¼å¸¸...请å·æ°éè¯");268 break;269 }270 filestop();271 // document.getElementById("progressOne").value = 0;272 // document.getElementById("Status").innerText = "ä¸è½½å¤±è´¥!";273 fileuping = 0;274 filepercent = 0;275 // $("#file_ms").removeAttr("disabled");276 $(".fdl").removeAttr("disabled");277 }278 di = 0;279 280 }else if(serverstate == 3){281 if((getData[di] == 0xfe) && (getData[di+1] == 0x00))282 {283 // console.log(2);284 di += 2;285 if(di == getData.length)286 dend = 1;287 while(dend != 1){ //æªå°æ°æ®æ«å°¾ç»§ç»æ§è¡288 if(getTmp.length < 2048) //æ°æ®æ¥æ¶ç¼å²æªè¾¾å°2048é¿åº¦,继ç»å¡«å
289 {290 // console.log(5);291 while((dk != 2048) && (dend != 1))292 {293 if(getTmp.length == 0)294 {295 // console.log(0);296 if((getData[di] == 0x7e) && (getData[di+1] == 0xe7) && (getData[di+2] == 0xe7) && (getData[di+3] == 0x02)){297 // console.log(3);298 datastyle = 1;299 di += 4;300 dk = getTmp.length;301 for(;(dk < 2048) && (di < getData.length);di++,dk++)302 {303 getTmp[dk] = getData[di] ;304 }305 // console.log(di,getData.length);306 if(di == getData.length)307 {308 getData = new Array();309 di = 0;310 dend = 1;311 }312 }else{313 if(di < getData.length-3)314 di++;315 else316 {di=0;dend = 1;}317 }318 }319 else320 {321 dk = getTmp.length;322 for(;(dk < 2048) && (di < getData.length);di++,dk++)323 {324 getTmp[dk] = getData[di] ;325 }326 if(di == getData.length)327 {328 getData = new Array();329 di = 0;330 dend = 1;331 }332 }333 }334 }335 if(getTmp.length == 2048) //æ°æ®æ¥æ¶ç¼å²è¾¾å°2048é¿åº¦,æ¾ç¤º336 {337 // console.log(6);338 getVal = new Array();339 for(var s = 0;s < 1024;s++)340 getVal[s] = getTmp[s];341 342 // console.log(getVal);343 getTmp = new Array();344 dk = 0;345 switch(ex_index){ 346 case 4: //51 adda347 oscdrawline_1();348 break;349 }350 }351 }352 return;353 }354 else if((getData[di] == 0xfe) && (getData[di+1] == 0xff)){355 di += 4;356 switch((getData[di+1]&0xFF)){357 case 0xF1:358 alert("ä¸ä¼ æ件æé®é¢");359 break;360 case 0xF9:361 alert("ä¹åä¸è½½æªå®æ");362 break;363 case 0xFA:364 alert("å®éªç®±ä¸è½½è¶
æ¶");365 break;366 case 0xFB:367 alert("åéæ°æ®æ误");368 break;369 case 0xFC:370 alert("æ件丢失");371 break;372 case 0xFD:373 alert("å®éªç®±ä¸è½½ä¸æ");374 break;375 case 0xFE:376 alert("å®éªç®±æå¼");377 break;378 case 0xFF:379 alert("å®éªç®±å¼å¸¸");380 break;381 }382 }383 }else{384 }385 } 386 ws.onclose = function (e) { 387 getVal = new Array();388 di = 0;389 switch(serverstate){390 case 0:391 break;392 case 1:393 alert("é¾æ¥æå¼ï¼è¯·éæ°è¿æ¥ï¼");394 break;395 case 2:396 break;397 case 3:398 break;399 }400 console.log('é¾æ¥æå¼'); 401 }402 403 ws.onerror = function (e) { 404 getVal = new Array();405 di = 0;406 switch(serverstate){407 case 0:408 break;409 case 1:410 filestop();411 break;412 case 2:413 break;414 case 3:415 break;416 } 417 console.info(e); 418 alert("æå¡å¨é¾æ¥å¼å¸¸ï¼å·²æå¼é¾æ¥");419 } ...
UserHandler.js
Source:UserHandler.js
...3 */4var handler = module.exports ;5handler.setData = function( msg ){6 $G.gSData.gCData = msg;7 if( handler.getData().account ){8 gLocalData.userInfo.account = handler.getData().account ;9 DataHelper.saveAllData();10 }11};12handler.getData = function(){13 return $G.gSData.gCData ;14};15handler.getId = function() {16 return handler.getData().id ? handler.getData().id : 0 ;17};18handler.getRecommender = function(){19 return handler.getData().agentId ;20};21handler.getAgentId = function(){22 return handler.getData().agentId;23};24handler.getAgentNick = function(){25 return handler.getData().agentNick ;26};27handler.getPhone = function(){28 return handler.getData().phone;29};30handler.getName = function(){31 return handler.getData().name ;32};33// ethåå¨è®°å½34handler.setDataRecordAll = function( recordAll ){35 handler.getData().recordAll = recordAll ;36};37handler.getDataRecordAll = function(){38 return handler.getData().recordAll;39};40// å
å¸è®°å½41handler.setDataRecordIn = function( recordIn ){42 handler.getData().recordIn = recordIn ;43};44handler.getDataRecordIn = function(){45 return handler.getData().recordIn;46};47// æå¸è®°å½48handler.setDataRecordOut = function( recordOut ){49 handler.getData().recordOut = recordOut ;50};51handler.getDataRecordOut = function(){52 return handler.getData().recordOut;53};54// å°å55handler.setAddress = function( address ){56 handler.getData().address = address ;57};58handler.getAddress = function(){59 return handler.getData().address;60};61// airdrop62handler.setVairdropType = function( VairdropType ){63 handler.getData().VairdropType = VairdropType ;64};65handler.getVairdropType = function(){66 return handler.getData().VairdropType;67};68// eth69handler.setEth = function( eth ){70 handler.getData().eth = eth ;71};72handler.getEth = function(){73 return handler.getData().eth;74};75// éå¸ï¼ GCoin ï¼76handler.setGold = function( Gold ){77 handler.getData().Gold = Gold ;78};79handler.getGold = function(){80 return handler.getData().Gold;81};82// æå¸æç»è´¹( wei )83handler.setFee = function( Fee ){84 handler.getData().Fee = Fee ;85};86handler.getFee = function(){87 return handler.getData().Fee;88};89handler.setRecommender = function(id){90 handler.getData().agentId = id;91};92handler.getToken = function(){93 return handler.getData().token ;94};95handler.getWxOpenID = function() {96 if( handler.getData().wx ){97 if( handler.getData().wx.openId ){98 return handler.getData().wx.openId ;99 }100 }101 return null;102};103handler.getIP = function() {104 return handler.getData().ip ? handler.getData().ip : 'no ip';105};106handler.getDesp = function() {107 return handler.getData().desp ? handler.getData().desp : '' ;108};109handler.setDesp = function(desp) {110 handler.getData().desp = desp;111};112handler.getNick = function() {113 cc.log("ãhandler.getData()ã",handler.getData().nick);114 return handler.getData().nick ? handler.getData().nick : handler.getData().account ;115};116handler.setNick = function(nick) {117 handler.getData().nick = nick ;118};119// 0 man 1 woman120handler.getSex = function(){121 return handler.getData().sex ;122};123// "" || url124handler.setHead = function(head){125 handler.getData().head = head ;126};127// "" || url128handler.getHead = function(){129 return handler.getData().head ;130};131handler.getDiamondsAll = function(){132 let card = handler.getData().bag[ 4 ] ? handler.getData().bag[ 4 ] : 0;133 let bindedCard = handler.getData().bag[ 5 ] ? handler.getData().bag[ 5 ] : 0;134 let count = card + bindedCard ;135 if( count == undefined || count == null ) count = 0 ;136 count = parseFloat( count.toFixed(3) ) ;137 return count ;138};139// æ£å¸¸çå¸140handler.getScore = function(){141 let count = handler.getData().bag[ 1 ] ? handler.getData().bag[ 1 ] : 0;142 return count ;143}144// æ»çå¸145handler.getRoomCardsAll= function(){146 // let card = handler.getData().bag[ 2 ] ? handler.getData().bag[ 2 ] : 0;147 let bindedCard = handler.getData().bag[ 3 ] ? handler.getData().bag[ 3 ] : 0;148 let count = bindedCard;149 if( count == undefined || count == null ) count = 0 ;150 return count ;151}152// æ£å¸¸çå¸153handler.getRoomCard = function(){154 let count = handler.getData().bag[ 2 ] ? handler.getData().bag[ 2 ] : 0;155 return count ;156}157// ç»å®çå¸158handler.getRoomCardBind= function(){159 let count = handler.getData().bag[ 3 ] ? handler.getData().bag[ 3 ] : 0;160 return count ;161}162// çé»163handler.getDiamond1 = function(){164 let count = handler.getData().bag[ 4 ] ? handler.getData().bag[ 4 ] : 0;165 return parseFloat( count.toFixed(3) ) ;166}167// ç»å®é»168handler.getDiamond2 = function(){169 let count = handler.getData().bag[ 5 ] ? handler.getData().bag[ 5 ] : 0;170 return parseFloat( count.toFixed(3) ) ;171}172handler.shouldReconnect = function(){173 if( handler.getData().room != null ) cc.currentGame = handler.getData().room.game ;174 return handler.getData().room != null ;175};176handler.shouldReconnectNow = function(){177 return ( handler.shouldReconnect() && handler.getData().room.playing ) ;178};179handler.getHistory = function(){180 return handler.getData().historys;181};182handler.addHistory = function( item ){183 if( _.size(handler.getHistory()) === 10 ) handler.getHistory().splice(0,1);184 handler.getHistory().push(item);185};186handler.setDataGiveDiamondsHistory = function(msg){187 handler.getData().giveDiamondsHistory = msg;188};189handler.getDataGiveDiamondsHistory = function(){190 return $G.gSData.gCData.giveDiamondsHistory ;191};192//é®ä»¶193handler.getDataEmailData = function(){194 handler.getData().redShow;195};196/***197 * init198 */199handler.initNetListeners = function(){200 handler.removeNetListeners();201 SocketHelper.onNetListener( ServerRouters.OnAction_User.ROUTE , handler._onHandleUser );202 SocketHelper.onNetListener( ServerRouters.OnAction_Item.ROUTE , handler._onHandleItem );203 SocketHelper.onNetListener( ServerRouters.OnAction_Broadcast.ROUTE , handler._onHandleBroadcast );204 SocketHelper.onNetListener( ServerRouters.OnAction_Broadcast.ACTION , handler._onBroadcastACTION );205 SocketHelper.onNetListener( ServerRouters.OnAction_History.ROUTE , handler._onHandleHistory );206 //email207 SocketHelper.onNetListener( ServerRouters.OnAction_Broadcast.EMAIL , handler._onEmailReceive );208 SocketHelper.onNetListener( ServerRouters.RoomAction.DISMISS_VOTE , handler._onVoteReceive );209 // RecordsHandler.initNetListeners();210 // GroupHandler.initNetListeners();211};212/***213 * remove214 */215handler.removeNetListeners = function(){216 SocketHelper.offNetListener( ServerRouters.OnAction_User.ROUTE , handler._onHandleUser );217 SocketHelper.offNetListener( ServerRouters.OnAction_Item.ROUTE , handler._onHandleItem );218 SocketHelper.offNetListener( ServerRouters.OnAction_Broadcast.ROUTE , handler._onHandleBroadcast );219 SocketHelper.offNetListener( ServerRouters.OnAction_Broadcast.ACTION , handler._onBroadcastACTION );220 SocketHelper.offNetListener( ServerRouters.RqRoom.dismissVote , handler._onHandleHistory );221 //email222 SocketHelper.offNetListener( ServerRouters.OnAction_Broadcast.EMAIL , handler._onEmailReceive );223 SocketHelper.offNetListener( ServerRouters.RqRoom.dismissVote , handler._onVoteReceive );224 // RecordsHandler.removeNetListeners();225 // GroupHandler.removeNetListeners();226};227/***228 * _onHandleUser229 */230handler._onHandleUser = function( action ){231 let OnAction = ServerRouters.OnAction_User;232 cc.log('@@@@ OnAction : ' + action );233 cc.log( action );234 // let keys = _.keys( action.msg );235 _.each( action.msg , ( v , k ) =>{236 cc.log(v+k)237 handler.getData()[k] = v ;238 });239};240/***241 * _onHandleItem242 */243 /////////////////////////////////////////////////////////////////////////////////////////244handler._onHandleItem = function( action ){245 cc.log('@@@_onHandleItem : from ' + handler.getData().bag[ action.msg.id ] + ' to ' + action.msg.count );246 cc.log( action );247 //data248 handler.getData().bag[ action.msg.id ] = action.msg.count ;249 NotifyHelper.notify( NOTIFY_UPDATE_ROOMCARD );250};251/***252 * _onHandleBroadcast253 * 254 * id: 170, title: "ç³»ç»æ¶æ¯", message: "欢è¿æ¥ååå æ¯èµ", timestamp: 1488461181230, items: Object}255 */256handler._onHandleBroadcast = function( action ){257 cc.log('@@@Broadcast :');258 cc.log( action );259 MsgHelper.pushTopInfo( action.content );260};261/**262 * _onHandleHistory263 * 264 * {room: "45", users: [gold,id,nick], timestamp: 1495095369879}265 */266handler._onHandleHistory = function( action ){267 cc.log('@@@Histroy :');268 cc.log( action );269 UserHandler.addHistory( action );270};271/**272 * _onBroadcastACTION273 * 274 * nameå为广æé¢é msgæ¯å符串275 */276handler._onBroadcastACTION = function( action ){277 cc.log('@@@Histroy :');278 cc.log( action );279 // UserHandler.addHistory( action );280 MsgHelper.pushTopInfo( action.msg );281};282/***283 * æ¥æ¶é®ä»¶æ¶æ¯ å¤çæ¶æ¯284 */285 /////////////////////////////////////////////////////////////////////////////////////////286 handler._onEmailReceive = function(){287 handler.getData().redPoint.mail = true;288 NotifyHelper.notify( NOTIFY_UPDATE_EMAIL);289 cc.log("é®ä»¶æ¶æ¯æ¶å°");290};291/***292 * æ¥æ¶ç©å®¶è«æ±è§£æ£æ¿é293 */294 /////////////////////////////////////////////////////////////////////////////////////////295 handler._onVoteReceive = function(){296 // handler.getData().redPoint.mail = true;297 // NotifyHelper.notify( NOTIFY_UPDATE_EMAIL);298 cc.log("ãè«æ±è§£æ£æ¿é´ã");...
Using AI Code Generation
1const { getData } = require('fast-check-monorepo');2console.log(getData());3const { getData } = require('fast-check-monorepo');4console.log(getData());5const { getData } = require('fast-check-monorepo');6console.log(getData());7const { getData } = require('fast-check-monorepo');8console.log(getData());9const { getData } = require('fast-check-monorepo');10console.log(getData());11const { getData } = require('fast-check-monorepo');12console.log(getData());13const { getData } = require('fast-check-monorepo');14console.log(getData());15const { getData } = require('fast-check-monorepo');16console.log(getData());17const { getData } = require('fast-check-monorepo');18console.log(getData());19const { getData } = require('fast-check-monorepo');20console.log(getData());21const { getData } = require('fast-check-monorepo');22console.log(getData());23const { getData } = require('fast-check-monorepo');24console.log(getData());25const { getData } = require('fast-check-monorepo');26console.log(getData());27const { getData }
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!