import Skypager from '.'

describe('Defining Routes', function () {
  before(function() {
    if (!this.project) {
      this.project = Skypager.load(process.cwd(), {
        sync: false
      })
    }
  })

  it('creates an interface function for a group of routes', function() {
    const iface = this.project.createRouteMap('helpers', {
      projectTypes: 'src/document-types/*',
      middlewares: 'src/middlewares/*',
    })

    const { projectTypes, middlewares } = iface

    projectTypes.should.not.be.empty
    middlewares.should.not.be.empty
  })

  it('creates functions which will apply a route', function() {
    const project = this.project
    const fn = project.createRouteFunction('src/helpers/*')

    fn.should.be.a('function')
      fn().should.be.an('array').that.is.not.empty

    project.createRouteFunction({patterns:'src/utils/*'})().should.have.property('length', 1)
   })

  it('will apply a transform function to the results', function() {
    const project = this.project
    const fn = project.createRouteFunction({
      patterns: 'src/helpers/*',
      transform(result) {
        return result.id
      }
    })

    fn().should.contain('src/helpers/document-type.js')
  })
})
