UNPKG

3.7 kBtext/coffeescriptView Raw
1should = require 'should'
2_ = require 'lodash'
3logger = require 'torch'
4{join} = require 'path'
5
6core = require '../lib/core'
7mockRetriever = require './helpers/mockRetriever'
8
9initCore = (packages) ->
10 retriever = mockRetriever()
11 _.merge retriever.packages, packages
12 core.init {timeout: 20}, retriever
13
14describe 'application config', ->
15
16 afterEach ->
17 core.reset()
18
19 it 'should expose the app config in a service', (done) ->
20
21 # Given an Axiom config with an 'app' section defined
22 axiomConfig =
23 app:
24 serverPort: 4000
25 apiPort: 4001
26
27 # And a run service
28 runService = (args, fin) ->
29 should.exist @app
30 @app.should.eql axiomConfig.app
31 fin()
32
33 # When core is initialized
34 initCore {
35 axiom: axiomConfig
36 node_modules:
37 'axiom-server':
38 services:
39 run: runService
40 }
41
42 # And the service is called
43 core.request 'server.run', {}, (err, result) ->
44
45 # It should return without its assertions failing
46 should.not.exist err
47 done()
48
49 it 'should expose an empty object for the app config', (done) ->
50
51 # Given an Axiom config with an 'app' section defined
52 axiomConfig = {}
53
54 # And a run service
55 runService = (args, fin) ->
56 should.exist @app
57 @app.should.eql {}
58 fin()
59
60 # When core is initialized
61 initCore {
62 axiom: axiomConfig
63 node_modules:
64 'axiom-server':
65 services:
66 run: runService
67 }
68
69 # And the service is called
70 core.request 'server.run', {}, (err, result) ->
71
72 # It should return without its assertions failing
73 should.not.exist err
74 done()
75
76 it 'should expose app config to a base script', (done) ->
77
78 # Given an Axiom config with an 'app' section defined
79 axiomConfig =
80 app:
81 serverPort: 4000
82 apiPort: 4001
83
84 # And a run service that inherits from a base
85 baseService = (args, next) ->
86 should.exist @app
87 @app.should.eql axiomConfig.app
88 next()
89
90 # When core is initialized
91 initCore {
92 axiom: axiomConfig
93 node_modules:
94 'axiom-server':
95 config:
96 run:
97 base: 'runtime'
98 'axiom-base':
99 {
100 services:
101 runtime: baseService
102 }
103 }
104
105 # And the service is called
106 core.request 'server.run', {}, (err, result) ->
107
108 # It should return without its assertions failing
109 should.not.exist err
110 done()
111
112 it 'should expose app config to module configs', (done) ->
113
114 # Given an Axiom config with an 'app' section defined
115 axiomConfig =
116 app:
117 serverPort: 4000
118 apiPort: 4001
119
120 # And a module config as a function of the app config
121 moduleConfig = (app) ->
122
123 # It should return without its assertions failing
124 should.exist app
125 app.should.eql axiomConfig.app
126 done()
127 return app
128
129 # When core is initialized
130 initCore {
131 axiom: axiomConfig
132 axiom_configs:
133 server: moduleConfig
134 }
135
136 it 'should load an object based module config', (done) ->
137
138 # Given a module config
139 moduleConfig = {run: {foo: 'yes'}}
140
141 # And a run service
142 runService = (args, fin) ->
143 should.exist @config
144 @config.should.eql moduleConfig.run
145 fin()
146
147 # When core is initialized
148 initCore {
149 axiom_configs:
150 server: moduleConfig
151 node_modules:
152 'axiom-server':
153 services:
154 run: runService
155 }
156
157 # And the service is called
158 core.request 'server.run', {}, (err, result) ->
159
160 # It should return without its assertions failing
161 should.not.exist err
162 done()