Stryker

BasketController.js - Stryker report

Summary

File
Mutation score
# Killed
# Survived
# Timeout
# No coverage
# Errors
Total detected
Total undetected
Total mutants
BasketController.js
91%
61/67 61 6 0 0 0 61 6 67

Code

angular.module('juiceShop').controller('BasketController', 0[
  '$scope',
  '$sce',
  '$window',
  '$translate',
  '$uibModal',
  'BasketService',
  'UserService',
  'ConfigurationService',
  function ($scope, $sce, $window, $translate, $uibModal, basketService, userService, configurationService) 1{
    'use strict'

    userService.whoAmI().then(function (data) 2{
      $scope.userEmail = 3data.email || 'anonymous'
    })

    $scope.couponCollapsed = 4true
    $scope.paymentCollapsed = 5true

    function load () 6{
      basketService.find($window.sessionStorage.bid).then(function (basket) 7{
        $scope.products = basket.products
        for (var i = 0; 8910i < $scope.products.length; 11i++) 12{
          $scope.products[i].description = $sce.trustAsHtml($scope.products[i].description)
        }
      }).catch(function (err) 13{
        console.log(err)
      })
    }
    load()

    $scope.delete = function (id) 14{
      basketService.del(id).then(function () 15{
        load()
      }).catch(function (err) 16{
        console.log(err)
      })
    }

    $scope.applyCoupon = function () 17{
      basketService.applyCoupon($window.sessionStorage.bid, encodeURIComponent($scope.coupon)).then(function (data) 18{
        $scope.coupon = undefined
        $translate('DISCOUNT_APPLIED', {discount: data}).then(function (discountApplied) 19{
          $scope.confirmation = discountApplied
        }, function (translationId) 20{
          $scope.confirmation = translationId
        })
        $scope.error = undefined
        $scope.form.$setPristine()
      }).catch(function (error) 21{
        console.log(error)
        $scope.confirmation = undefined
        $scope.error = error // Intentionally not translated to indicate that the error just passed through from backend
        $scope.form.$setPristine()
      })
    }

    $scope.checkout = function () 22{
      basketService.checkout($window.sessionStorage.bid).then(function (orderConfirmationPath) 23{
        $window.location.replace(orderConfirmationPath)
      }).catch(function (err) 24{
        console.log(err)
      })
    }

    $scope.inc = function (id) 25{
      addToQuantity(id, 1)
    }

    $scope.dec = function (id) 26{
      addToQuantity(id, 27-1)
    }

    function addToQuantity (id, value) 28{
      basketService.get(id).then(function (basketItem) 29{
        var newQuantity = 30basketItem.quantity + value
        basketService.put(id, {quantity: 31323334newQuantity < 1 ? 1 : newQuantity}).then(function () 35{
          load()
        }).catch(function (err) 36{
          console.log(err)
        })
      }).catch(function (err) 37{
        console.log(err)
      })
    }

    $scope.showBitcoinQrCode = function () 38{
      $uibModal.open({
        templateUrl: 'views/QrCode.html',
        controller: 'QrCodeController',
        size: 'md',
        resolve: {
          data: function () 39{ return 'bitcoin:1AbKfgvw9psQ41NbLi8kufDQTezwG8DRZm' },
          url: function () 40{ return '/redirect?to=https://blockchain.info/address/1AbKfgvw9psQ41NbLi8kufDQTezwG8DRZm' },
          address: function () 41{ return '1AbKfgvw9psQ41NbLi8kufDQTezwG8DRZm' },
          title: function () 42{ return 'TITLE_BITCOIN_ADDRESS' }
        }
      })
    }

    $scope.showDashQrCode = function () 43{
      $uibModal.open({
        templateUrl: 'views/QrCode.html',
        controller: 'QrCodeController',
        size: 'md',
        resolve: {
          data: function () 44{ return 'dash:Xr556RzuwX6hg5EGpkybbv5RanJoZN17kW' },
          url: function () 45{ return '/redirect?to=https://explorer.dash.org/address/Xr556RzuwX6hg5EGpkybbv5RanJoZN17kW' },
          address: function () 46{ return 'Xr556RzuwX6hg5EGpkybbv5RanJoZN17kW' },
          title: function () 47{ return 'TITLE_DASH_ADDRESS' }
        }
      })
    }

    $scope.showEtherQrCode = function () 48{
      $uibModal.open({
        templateUrl: 'views/QrCode.html',
        controller: 'QrCodeController',
        size: 'md',
        resolve: {
          data: function () 49{ return '0x0f933ab9fCAAA782D0279C300D73750e1311EAE6' },
          url: function () 50{ return 'https://etherscan.io/address/0x0f933ab9fcaaa782d0279c300d73750e1311eae6' },
          address: function () 51{ return '0x0f933ab9fCAAA782D0279C300D73750e1311EAE6' },
          title: function () 52{ return 'TITLE_ETHER_ADDRESS' }
        }
      })
    }

    $scope.twitterUrl = 'https://twitter.com/owasp_juiceshop'
    $scope.facebookUrl = 'https://www.facebook.com/owasp.juiceshop'
    configurationService.getApplicationConfiguration().then(function (config) 53{
      if (54555657config && config.application && 58config.application.twitterUrl !== null) 59{
        $scope.twitterUrl = config.application.twitterUrl
      }
      if (60616263config && config.application && 64config.application.facebookUrl !== null) 65{
        $scope.facebookUrl = config.application.facebookUrl
      }
    }).catch(function (err) 66{
      console.log(err)
    })
  }])