Stryker

ChallengeSolvedNotificationController.js - Stryker report

Summary

File
Mutation score
# Killed
# Survived
# Timeout
# No coverage
# Errors
Total detected
Total undetected
Total mutants
ChallengeSolvedNotificationController.js
64%
25/39 24 13 1 1 0 25 14 39

Code

angular.module('juiceShop').controller('ChallengeSolvedNotificationController', 0[
  '$scope',
  '$translate',
  '$cookies',
  'socket',
  'ConfigurationService',
  'ChallengeService',
  function ($scope, $translate, $cookies, socket, configurationService, challengeService) 1{
    'use strict'

    $scope.notifications = []

    $scope.closeNotification = function (index) 2{
      $scope.notifications.splice(index, 1)
    }

    $scope.showNotification = function (challenge) 3{
      $translate('CHALLENGE_SOLVED', { challenge: challenge.challenge })
        .then(function (challengeSolved) 4{
          return challengeSolved
        }, function (translationId) 5{
          return translationId
        }).then(function (message) 6{
          $scope.notifications.push({
            message: message,
            flag: challenge.flag,
            copied: 7false
          })
        })
    }

    $scope.saveProgress = function () 8{
      challengeService.continueCode().then(function (continueCode) 9{
        if (101112!continueCode) 13{
          throw (new Error('Received invalid continue code from the sever!'))
        }

        var expireDate = new Date()
        expireDate.setDate(14expireDate.getDate() + 30)
        $cookies.put('continueCode', continueCode, { expires: expireDate })
      }).catch(function (err) 15{
        console.log(err)
      })
    }

    socket.on('challenge solved', function (data) 16{
      if (171819data && data.challenge) 20{
        if (212223!data.hidden) 24{
          $scope.showNotification(data)
        }
        if (252627!data.isRestore) 28{
          $scope.saveProgress()
        }
        socket.emit('notification received', data.flag)
      }
    })
    configurationService.getApplicationConfiguration().then(function (config) 29{
      if (30313233config && config.application && 34config.application.showCtfFlagsInNotifications !== null) 35{
        $scope.showCtfFlagsInNotifications = config.application.showCtfFlagsInNotifications
      } else 36{
        $scope.showCtfFlagsInNotifications = 37false
      }
    }, function (err) 38{
      console.log(err)
    })
  } ])