/* eslint-env mocha */

const { expect } = require('chai')

const { cleanup, clientConnect, startService } = require('./testutils')

const { cleanupTimeout, user1, roomName1 } = require('./config')

module.exports = function () {
  let chatService = null
  let socket1 = null
  let socket2 = null
  let socket3 = null

  afterEach(function (cb) {
    this.timeout(cleanupTimeout)
    cleanup(chatService, [socket1, socket2, socket3], cb)
    chatService = socket1 = socket2 = socket3 = null
  })

  it('should return raw error objects', function (done) {
    chatService = startService({ useRawErrorObjects: true })
    socket1 = clientConnect(user1)
    socket1.on('loginConfirmed', () => {
      socket1.emit('roomGetAccessList', roomName1, 'nolist', function (error) {
        expect(error.name).equal('noRoom')
        expect(error.args).length.above(0)
        expect(error.args[0]).equal('room1')
        done()
      })
    })
  })

  it('should validate message argument types', function (done) {
    chatService = startService({ enableRoomsManagement: true })
    socket1 = clientConnect(user1)
    socket1.on('loginConfirmed', u => {
      socket1.emit('roomCreate', null, false, function (error, data) {
        expect(error).ok
        expect(data).not.ok
        done()
      })
    })
  })

  it('should have a message validator instance', function (done) {
    chatService = startService()
    chatService.validator.checkArguments(
      'roomGetAccessList', roomName1, 'userlist', function (error) {
        expect(error).not.ok
        done()
      })
  })

  it('should check for unknown commands', function (done) {
    chatService = startService()
    chatService.validator.checkArguments('cmd', function (error) {
      expect(error).ok
      done()
    })
  })

  it('should validate a message argument count', function (done) {
    chatService = startService({ enableRoomsManagement: true })
    socket1 = clientConnect(user1)
    socket1.on('loginConfirmed', u => {
      socket1.emit('roomCreate', function (error, data) {
        expect(error).ok
        expect(data).not.ok
        done()
      })
    })
  })

  it('should have a server messages and user commands fields', function (done) {
    chatService = startService()
    for (var k in chatService.serverMessages) {
      var fn = chatService.serverMessages[k]
      fn()
    }
    for (k in chatService.userCommands) {
      fn = chatService.userCommands[k]
      fn()
    }
    for (k in chatService.HooksInterface) {
      fn = chatService.HooksInterface[k]
      fn()
    }
    process.nextTick(done)
  })
}

@@ -2133,464 +2133,7 @@
   %7D)
-%0A%0A  it('should have a server messages and user commands fields', function (done) %7B%0A    chatService = startService()%0A    for (var k in chatService.serverMessages) %7B%0A      var fn = chatService.serverMessages%5Bk%5D%0A      fn()%0A    %7D%0A    for (k in chatService.userCommands) %7B%0A      fn = chatService.userCommands%5Bk%5D%0A      fn()%0A    %7D%0A    for (k in chatService.HooksInterface) %7B%0A      fn = chatService.HooksInterface%5Bk%5D%0A      fn()%0A    %7D%0A    process.nextTick(done)%0A  %7D)
 %0A%7D%0A

Remove useless test.