nock = require 'nock'
expect = require("chai").should()

Asjon = require '../asjon-testing.coffee'
asjon = undefined

describe 'modulo memes', ->
  before (done) ->
    # Inizializzo robot
    Asjon (assa) ->
      asjon = assa
      after asjon.after
      afterEach asjon.clear
      require('../scripts/memes.coffee')(asjon.robot)
      done()

  it "dovrebbe generare correttamente l'url dell'immagine", (done) ->
    questions = [
      "asjon meme fry, not sure if this works, or not"
      "asjon meme doge, special characters?, underscore_ dash-"
      "asjon meme icanhas, i can has, Upper CaSes?"
    ]
    replies = [
      'http://memegen.link/fry/not-sure-if-this-works/or-not.jpg'
      'http://memegen.link/doge/special-characters~q/underscore__-dash--.jpg'
      'http://memegen.link/icanhas/i-can-has/upper-cases~q.jpg'
    ]
    acc = 0
    asjon.receive (e,l) ->
      l.join().should.equal replies[acc]
      acc++
      if acc is questions.length then done()
    questions.map (q) -> asjon.send q

  it 'dovrebbe rispondere correttamente quando la domanda è malformata', (done) ->
    questions = [
      "asjon meme a, b, c, d,e"
      "asjon meme ciao"
    ]
    acc = 0
    asjon.receive (e,l) ->
      l.join().should.match /^non si usa così/g
      acc++
      if acc is questions.length then done()
    questions.map (q) -> asjon.send q

  # not testing '-v' mode as it takes too much time
  it 'dovrebbe fornire un elenco di memes', (done) ->
    questions = [
      'asjon memes'
    ]
    acc = 0
    asjon.receive (e,l) ->
      l.join().should.match /^guarda qui:/g
      acc++
      if acc is questions.length then done()
    questions.map (q) -> asjon.send q