<commit_before>should = require 'should'
async = require 'async'
_ = require 'lodash'
logger = require 'torch'
{focus} = require 'qi'
{join} = require 'path'

bus = require '../lib/bus'
core = require '../lib/core'

mockRetriever = require './helpers/mockRetriever'

initCore = (axiomConfig, runService) ->
  retriever = mockRetriever()
  retriever.packages.axiom = axiomConfig
  retriever.packages.node_modules['axiom-server'] =
    services:
      run: runService

  core.init {timeout: 20}, retriever

describe 'core.request', ->

  afterEach ->
    core.reset()

  it 'should expose the app config in a service', (done) ->

    # Given an Axiom config with an 'app' section defined
    axiomConfig =
      app:
        serverPort: 4000
        apiPort: 4001

    # And a run service
    runService = (args, fin) ->
      should.exist @app
      @app.should.eql axiomConfig.app
      fin()

    # When core is initialized
    initCore axiomConfig, runService

    # And the service is called
    core.request 'server.run', {}, (err, result) ->

      # It should return without its assertions failing
      should.not.exist err
      done()

  it 'should expose an empty object for the app config', (done) ->

    # Given an Axiom config with an 'app' section defined
    axiomConfig = {}

    # And a run service
    runService = (args, fin) ->
      should.exist @app
      @app.should.eql {}
      fin()

    # When core is initialized
    initCore axiomConfig, runService

    # And the service is called
    core.request 'server.run', {}, (err, result) ->

      # It should return without its assertions failing
      should.not.exist err
      done()<commit_msg>added test that base services should receive app config<commit_after>should = require 'should'
_ = require 'lodash'
logger = require 'torch'
{join} = require 'path'

core = require '../lib/core'
mockRetriever = require './helpers/mockRetriever'

initCore = (packages) ->
  retriever = mockRetriever()
  retriever.package =
    dependencies:
      'axiom-server': '*'
  _.merge retriever.packages, packages
  core.init {timeout: 20}, retriever

describe 'application config', ->

  afterEach ->
    core.reset()

  it 'should expose the app config in a service', (done) ->

    # Given an Axiom config with an 'app' section defined
    axiomConfig =
      app:
        serverPort: 4000
        apiPort: 4001

    # And a run service
    runService = (args, fin) ->
      should.exist @app
      @app.should.eql axiomConfig.app
      fin()

    # When core is initialized
    initCore {
      axiom: axiomConfig
      node_modules:
        'axiom-server':
          services:
            run: runService
    }

    # And the service is called
    core.request 'server.run', {}, (err, result) ->

      # It should return without its assertions failing
      should.not.exist err
      done()

  it 'should expose an empty object for the app config', (done) ->

    # Given an Axiom config with an 'app' section defined
    axiomConfig = {}

    # And a run service
    runService = (args, fin) ->
      should.exist @app
      @app.should.eql {}
      fin()

    # When core is initialized
    initCore {
      axiom: axiomConfig
      node_modules:
        'axiom-server':
          services:
            run: runService
    }

    # And the service is called
    core.request 'server.run', {}, (err, result) ->

      # It should return without its assertions failing
      should.not.exist err
      done()

  it 'should expose app config to a base script', (done) ->

    # Given an Axiom config with an 'app' section defined
    axiomConfig =
      app:
        serverPort: 4000
        apiPort: 4001

    # And a run service that inherits from a base
    baseService = (args, next) ->
      should.exist @app
      @app.should.eql axiomConfig.app
      next()

    # When core is initialized
    initCore {
      axiom: axiomConfig
      node_modules:
        'axiom-server':
          config:
            run:
              base: 'runtime'
        'axiom-base':
          {
            services:
              runtime: baseService
          }
    }

    # And the service is called
    core.request 'server.run', {}, (err, result) ->

      # It should return without its assertions failing
      should.not.exist err
      done()
{'fraction_non_alphanumeric': 0.10146273508242395, 'fraction_numerical': 0.00650104481077316, 'mean_word_length': 2.2611657834973506, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2052529', 'n_tokens_mistral': 1334, 'n_tokens_neox': 1251, 'n_words': 418}