|
1 | | -import { expect } from 'chai'; |
2 | 1 | import sinon from 'sinon'; |
3 | | -import { LocalStorage } from 'node-localstorage'; |
| 2 | +import { expect } from 'chai'; |
4 | 3 |
|
5 | | -import globular from './Globular'; |
6 | | -import ApplicationFactory from './modules/application'; |
7 | | -import isInterfaceImplemented from './util/isInterfaceImplemented'; |
8 | | -import isMethod from './util/isMethod'; |
| 4 | +import Globular from './Globular'; |
9 | 5 |
|
10 | | -describe('globular Framework', () => { |
11 | | - context('when no custom plugins defined', () => { |
12 | | - it('should create a new application', () => { |
13 | | - expect(isInterfaceImplemented(globular.initializeApp('sample-app'), ['getFeatures', 'getFeature', 'extendWithFeature', 'executeFeature'])).to.be.equal(true); |
14 | | - }); |
15 | | - it('should return application immediately when initialized', () => { |
16 | | - const initializedApp = globular.initializeApp('sample-app'); |
17 | | - const application = globular.app('sample-app'); |
18 | | - expect(application).to.equal(initializedApp); |
19 | | - }); |
20 | | - }); |
21 | | - context('when custom plugins defined', () => { |
22 | | - let FactoryStub; |
| 6 | +import ApplicationFactory from './modules/application/ApplicationFactory'; |
23 | 7 |
|
| 8 | +describe('Globular Framework', () => { |
| 9 | + context('when no API nor persitency passed', () => { |
24 | 10 | beforeEach(() => { |
25 | | - FactoryStub = sinon.stub(ApplicationFactory, 'produce'); |
| 11 | + sinon.stub(ApplicationFactory, 'produce').returns({ }); |
26 | 12 | }); |
| 13 | + |
27 | 14 | afterEach(() => { |
28 | | - FactoryStub.restore(); |
29 | | - }); |
30 | | - it('should pass Persistency Adapter to newly created application', () => { |
31 | | - const localStorageToInject = new LocalStorage('./tmp/localStorage'); |
32 | | - globular.initializeApp('sample-app', { persistency: localStorageToInject }); |
33 | | - expect(FactoryStub.calledOnce).to.be.equal(true); |
34 | | - expect(FactoryStub.lastCall.args[0].persistency).to.be.equal(localStorageToInject); |
| 15 | + ApplicationFactory.produce.restore(); |
35 | 16 | }); |
36 | | - it('should pass API Adapter to newly created application', () => { |
37 | | - const apiAdapterToInject = { pluginCall() {}, request() {} }; |
38 | | - globular.initializeApp('sample-app', { api: apiAdapterToInject }); |
39 | | - expect(FactoryStub.calledOnce).to.be.equal(true); |
40 | | - expect(FactoryStub.lastCall.args[0].api).to.be.equal(apiAdapterToInject); |
| 17 | + |
| 18 | + it('should indicate application factory to produce an app with API but with no persitency', () => { |
| 19 | + Globular.initializeApp('sampleApp'); |
| 20 | + |
| 21 | + const callArgs = ApplicationFactory.produce.firstCall.args; |
| 22 | + expect(ApplicationFactory.produce.calledOnce).to.be.equal(true); |
| 23 | + expect(callArgs[0].api).to.not.be.equal(undefined); |
| 24 | + expect(callArgs[0].persistency).to.be.equal(undefined); |
41 | 25 | }); |
42 | | - it('should pass default API Adapter instance to application when no Adapter defined', () => { |
43 | | - globular.initializeApp('sample-app1'); |
44 | | - expect(FactoryStub.lastCall.args[0].api).not.to.be.equal(undefined); |
45 | 26 |
|
46 | | - globular.initializeApp('sample-app2', {}); |
47 | | - expect(FactoryStub.lastCall.args[0].api).not.to.be.equal(undefined); |
| 27 | + it('should indicate application factory to produce an with persitency passed to', () => { |
| 28 | + const persistency = { }; |
| 29 | + Globular.initializeApp('sampleApp', { persistency }); |
48 | 30 |
|
49 | | - globular.initializeApp('sample-app3', { persistency: new LocalStorage('./tmp/localStorage') }); |
50 | | - expect(FactoryStub.lastCall.args[0].api).not.to.be.equal(undefined); |
| 31 | + const callArgs = ApplicationFactory.produce.firstCall.args; |
| 32 | + expect(ApplicationFactory.produce.calledOnce).to.be.equal(true); |
| 33 | + expect(callArgs[0].api).to.not.be.equal(undefined); |
| 34 | + expect(callArgs[0].persistency).to.be.equal(persistency); |
51 | 35 | }); |
52 | | - }); |
53 | 36 |
|
54 | | - context('when examining interface', () => { |
55 | | - it('should have expected overall interface', () => { |
56 | | - expect(isInterfaceImplemented(globular, ['initializeApp', 'app'])).to.be.equal(true); |
| 37 | + it('should indicate application factory to produce an with API passed to', () => { |
| 38 | + const api = { }; |
| 39 | + Globular.initializeApp('sampleApp', { api }); |
| 40 | + |
| 41 | + const callArgs = ApplicationFactory.produce.firstCall.args; |
| 42 | + expect(ApplicationFactory.produce.calledOnce).to.be.equal(true); |
| 43 | + expect(callArgs[0].api).to.be.equal(api); |
| 44 | + expect(callArgs[0].persistency).to.be.equal(undefined); |
57 | 45 | }); |
58 | | - it('should have expected API Adapter interface', () => { |
59 | | - expect(isMethod(globular.Api)).to.be.equal(true); |
| 46 | + |
| 47 | + it('should make newly created app to be available', () => { |
| 48 | + const app = Globular.initializeApp('sampleApp'); |
| 49 | + |
| 50 | + expect(Globular.app('sampleApp')).to.be.equal(app); |
60 | 51 | }); |
61 | 52 | }); |
62 | 53 | }); |
0 commit comments