/*
 * Copyright (c) 2014-2020 Bjoern Kimminich.
 * SPDX-License-Identifier: MIT
 */

const config = require('config')

describe('/chatbot', () => {
  let username, submitButton, messageBox
  protractor.beforeEach.login({ email: 'admin@' + config.get('application.domain'), password: 'admin123' })

  describe('challenge "killChatbot"', () => {
    it('should be possible to kill the chatbot by setting the process to null', () => {
      browser.waitForAngularEnabled(false)
      browser.get(protractor.basePath + '/profile')
      username = element(by.id('username'))
      submitButton = element(by.id('submit'))
      username.sendKeys('admin"); process=null; users.addUser("1337", "test')
      submitButton.click()
      browser.driver.sleep(5000)
      browser.waitForAngularEnabled(true)

      browser.get(protractor.basePath + '/#/chatbot')
      messageBox = element(by.id('message-input'))
      messageBox.sendKeys('hi')
      browser.actions().sendKeys(protractor.Key.ENTER).perform()
      messageBox.sendKeys('...')
      browser.actions().sendKeys(protractor.Key.ENTER).perform()
      messageBox.sendKeys('bye')
      browser.actions().sendKeys(protractor.Key.ENTER).perform()
    })
    protractor.expect.challengeSolved({ challenge: 'Kill Chatbot' })
  })
})

@@ -110,16 +110,57 @@
 config')
+%0Aconst utils = require('../../lib/utils')
 %0A%0Adescri
@@ -1310,12 +1310,1446 @@
  %7D)%0A  %7D)
+%0A%0A  describe('challenge %22bullyChatbot%22', () =%3E %7B%0A    it('should be possible to make the chatbot hand out a coupon code', () =%3E %7B%0A      const trainingData = require(%60../../data/chatbot/$%7Butils.extractFilename(config.get('application.chatBot.trainingData'))%7D%60)%0A      const couponIntent = trainingData.data.filter(data =%3E data.intent === 'queries.couponCode')%5B0%5D%0A%0A      browser.waitForAngularEnabled(false)%0A      browser.get(protractor.basePath + '/profile')%0A      username = element(by.id('username'))%0A      submitButton = element(by.id('submit'))%0A      username.sendKeys('admin%22); process=(query, token)=%3E%7B if (users.get(token)) %7B return model.process(trainingSet.lang, query) %7D else %7B return %7B action: %5C'unrecognized%5C', body: %5C'user does not exist%5C' %7D%7D%7D; users.addUser(%221337%22, %22test')%0A      submitButton.click()%0A      browser.driver.sleep(5000)%0A      browser.waitForAngularEnabled(true)%0A%0A      browser.get(protractor.basePath + '/#/chatbot')%0A      messageBox = element(by.id('message-input'))%0A      messageBox.sendKeys('hi')%0A      browser.actions().sendKeys(protractor.Key.ENTER).perform()%0A      messageBox.sendKeys('...')%0A      browser.actions().sendKeys(protractor.Key.ENTER).perform()%0A      for (let i=0; i%3C100; i++) %7B%0A        messageBox.sendKeys(couponIntent.utterances%5B0%5D)%0A        browser.actions().sendKeys(protractor.Key.ENTER).perform()%0A      %7D%0A    %7D)%0A    protractor.expect.challengeSolved(%7B challenge: 'Bully Chatbot' %7D)%0A  %7D)
 %0A%7D)%0A

Add e2e test for "Bully Chatbot" challenge