"use strict"
/**
 * Created by menzhongxin on 2016/11/15.
 */
var sm = require('../lib/index.js')
  , middleware = require('./middleware.js')
  , utils = require('../lib/utils.js')
  , app = require('koa')()
  , router = require('koa-router')()
  , request = require('supertest')
  , should = require('should')
  , req




describe('utils', () => {

  it("isArray", done => {
    utils.isArray({}).should.be.false()
    utils.isArray([]).should.be.true()
    utils.isArray('').should.be.false()
    utils.isArray(1).should.be.false()
    utils.isArray(true).should.be.false()
    utils.isArray(() => {}).should.be.false()
    done()
  })
})

describe('autoLoading', () => {

  beforeEach(() => {
    var ignore = __dirname + '/routers/book/book.js'
    sm.autoLoading(__dirname + '/routers', {router: router, rules: middleware, ignore: [ignore]})
    app.use(router.routes())
    req = request(app.listen())
  })
  it('should return /list', done => {
    req.get('/list')
      .expect(200)
      .end((err, res) => {
        should.not.exist(err)
        console.log(res.text)
        res.text.should.be.eql('_m_1_m_2_m_3_m_4/list_end_4_end_3_end_2_end_1')
        done()
      })
  })

  it('should return /open/user', done => {
    req.get('/open/user')
      .expect(200)
      .end((err, res) => {
        should.not.exist(err)
        console.log(res.text)
        res.text.should.be.eql('_m_1/open/user_end_1')
        done()
      })
  })

  it('should return /open/book/', done => {
    
    req.get('/open/book/list')
      .expect(200)
      .end( (err, res) => {
        should.not.exist(err)
        res.text.should.be.eql('_m_1/book/list_end_1')
        done()
      })
  })

  it('ignore test', done => {

    req.get('/open/book/delete')
      .end((err, res) => {
        should.not.exist(err)
        res.statusCode.should.be.eql(404)
        res.text.should.be.eql('Not Found')
        done()
      })
  })
})


@@ -197,24 +197,51 @@
 re('koa')()%0A
+  , path = require('path')%0A
   , router =
@@ -344,36 +344,1060 @@
 eq%0A%0A
-%0A%0A%0Adescribe('utils', () =%3E %7B
+describe('util test', () =%3E %7B%0A  let routers,config,fakeUrl%0A  beforeEach( () =%3E %7B%0A    routers = path.join(__dirname, '/routers')%0A    config = path.join(__dirname, './middleware.js')%0A    fakeUrl = path.join(__dirname, '/fake')%0A  %7D)%0A%0A  it('throw err', (done) =%3E %7B%0A    utils.load('', (err, rs) =%3E %7B%0A      err.message.should.be.equal(%22ENOENT: no such file or directory, scandir ''%22)%0A      done()%0A    %7D)%0A  %7D)%0A%0A  it('exists', (done) =%3E %7B%0A    utils.exists(routers).should.be.true()%0A    utils.exists(fakeUrl).should.be.false()%0A    done()%0A  %7D)%0A%0A  it('isDir', (done) =%3E %7B%0A    utils.isDir(routers).should.be.true()%0A    utils.isDir(config).should.be.false()%0A    done()%0A  %7D)%0A%0A  it('isFile', (done) =%3E %7B%0A    utils.isFile(routers).should.be.false()%0A    utils.isFile(config).should.be.true()%0A    done()%0A  %7D)%0A%0A  it('load a file', (done) =%3E %7B%0A    utils.load(config, (err, rs) =%3E %7B%0A      rs.length.should.be.equal(0)%0A      done()%0A    %7D)%0A  %7D)%0A%0A  it('load a dir', (done) =%3E %7B%0A    utils.load(routers, (err, rs) =%3E %7B%0A      rs.length.should.be.equal(2)%0A      done()%0A    %7D)%0A  %7D)
 %0A%0A  
@@ -1682,20 +1682,22 @@
 ()%0A  %7D)%0A
+%0A
 %7D)%0A%0A
+%0A
 describe

add ignore