1 | path = require 'path'
|
2 | should = require 'should'
|
3 | _ = require 'lodash'
|
4 | logger = require 'torch'
|
5 |
|
6 | core = require '../lib/core'
|
7 |
|
8 | proj1Dir = path.join __dirname, '../sample/project1'
|
9 |
|
10 | describe 'core.init', ->
|
11 | before ->
|
12 | @retriever =
|
13 | root: proj1Dir
|
14 |
|
15 | beforeEach (done) ->
|
16 | core.reset(done)
|
17 |
|
18 | it 'should dynamically load a module based on name', (done) ->
|
19 | data = {greeting: 'hello!'}
|
20 | config =
|
21 | extensions:
|
22 | sample: '*'
|
23 | core.init config, @retriever
|
24 |
|
25 | core.request 'sample.echo', data, (err, result) ->
|
26 | should.not.exist err
|
27 | should.exist result
|
28 | result.should.eql data
|
29 | done()
|
30 |
|
31 | it "should load the project export as a config", (done) ->
|
32 | internal = require '../lib/core/internal'
|
33 | projectConfig = require proj1Dir
|
34 | should.exist projectConfig
|
35 | core.init {}, @retriever
|
36 | internal.config.should.include projectConfig
|
37 | done()
|
38 |
|
39 | it "should load a config override from the config folder", (done) ->
|
40 | core.init {extensions: {sample: '*'}}, @retriever
|
41 |
|
42 | sampleExtension = require path.join(proj1Dir, 'node_modules/axiom-sample')
|
43 |
|
44 |
|
45 | defaultSampleConfig = sampleExtension.config
|
46 | should.exist defaultSampleConfig
|
47 |
|
48 |
|
49 | overrideConfig = require path.join(proj1Dir, 'config/sample')
|
50 | should.exist overrideConfig
|
51 |
|
52 | expectedConfig = _.merge {}, defaultSampleConfig, overrideConfig
|
53 |
|
54 |
|
55 | core.request 'sample.whatsMyContext', {}, (err, config) ->
|
56 | should.not.exist err
|
57 |
|
58 |
|
59 | should.exist config
|
60 | config.should.eql expectedConfig
|
61 |
|
62 | done()
|
63 |
|
64 | it "should expose an injected 'retriever'", (done) ->
|
65 | defaultRetriever = @retriever
|
66 |
|
67 |
|
68 | mockRetriever =
|
69 | root: ''
|
70 | retrieve: (name...) -> {}
|
71 | retrieveExtension: (name...) -> {}
|
72 |
|
73 |
|
74 | server =
|
75 | services:
|
76 | "run/prepare": (args, fin) ->
|
77 |
|
78 |
|
79 | @root.should.eql 'domain/server'
|
80 | (typeof @rel).should.eql 'function'
|
81 | (typeof @retrieve).should.eql 'function'
|
82 |
|
83 | fin()
|
84 |
|
85 |
|
86 | core.init {}, mockRetriever
|
87 |
|
88 |
|
89 | core.load "server", server
|
90 |
|
91 |
|
92 | core.request "server.run/prepare", {}, (err, result) ->
|
93 |
|
94 |
|
95 | should.not.exist err
|
96 | done()
|
97 |
|
98 | it "should link two channels", (done) ->
|
99 |
|
100 | config =
|
101 | extensions:
|
102 |
|
103 | greeting:
|
104 | services:
|
105 | hello: (args, done) ->
|
106 | done null, {message: 'Hello, world!'}
|
107 |
|
108 | routes: [
|
109 | ['link', 'outside.hello', 'greeting.hello']
|
110 | ]
|
111 |
|
112 | core.init config, @retriever
|
113 |
|
114 | core.request 'outside.hello', {}, (err, result) ->
|
115 | should.not.exist err
|
116 | should.exist result
|
117 | result.should.eql {message: 'Hello, world!'}
|
118 | done()
|