@@ -45,7 +45,8 @@ describe('registry : domain : components-cache', () => {
4545 './components-list' : injectr (
4646 '../../dist/registry/domain/components-cache/components-list.js' ,
4747 {
48- 'oc-get-unix-utc-timestamp' : getTimestamp
48+ 'oc-get-unix-utc-timestamp' : getTimestamp ,
49+ '../events-handler' : eventsHandlerStub
4950 }
5051 ) . default
5152 } ,
@@ -59,10 +60,27 @@ describe('registry : domain : components-cache', () => {
5960 } ;
6061
6162 describe ( 'when library does not contain components.json' , ( ) => {
63+ describe ( 'when getting the json fails' , ( ) => {
64+ let error ;
65+ before ( done => {
66+ mockedCdn . getJson = sinon . stub ( ) ;
67+ mockedCdn . getJson . rejects ( new Error ( 'FILE_ERROR' ) ) ;
68+ initialise ( ) ;
69+ componentsCache
70+ . load ( )
71+ . catch ( err => ( error = err ) )
72+ . finally ( done ) ;
73+ } ) ;
74+
75+ it ( 'should throw with the error message' , ( ) => {
76+ expect ( error . message ) . to . equal ( 'FILE_ERROR' ) ;
77+ } ) ;
78+ } ) ;
6279 describe ( 'when initialising the cache' , ( ) => {
6380 before ( done => {
6481 mockedCdn . getJson = sinon . stub ( ) ;
65- mockedCdn . getJson . rejects ( 'not_found' ) ;
82+ mockedCdn . getJson . resolves ( { } ) ;
83+ mockedCdn . getJson . onFirstCall ( 0 ) . rejects ( { code : 'file_not_found' } ) ;
6684 mockedCdn . listSubDirectories = sinon . stub ( ) ;
6785 mockedCdn . listSubDirectories . onCall ( 0 ) . resolves ( [ 'hello-world' ] ) ;
6886 mockedCdn . listSubDirectories . onCall ( 1 ) . resolves ( [ '1.0.0' , '1.0.2' ] ) ;
@@ -72,11 +90,17 @@ describe('registry : domain : components-cache', () => {
7290 componentsCache . load ( ) . finally ( done ) ;
7391 } ) ;
7492
75- it ( 'should try fetching the components.json' , ( ) => {
76- expect ( mockedCdn . getJson . calledOnce ) . to . be . true ;
93+ it ( 'should try fetching the components.json and check components ' , ( ) => {
94+ expect ( mockedCdn . getJson . calledThrice ) . to . be . true ;
7795 expect ( mockedCdn . getJson . args [ 0 ] [ 0 ] ) . to . be . equal (
7896 'component/components.json'
7997 ) ;
98+ expect ( mockedCdn . getJson . args [ 1 ] [ 0 ] ) . to . be . equal (
99+ 'component/hello-world/1.0.0/package.json'
100+ ) ;
101+ expect ( mockedCdn . getJson . args [ 2 ] [ 0 ] ) . to . be . equal (
102+ 'component/hello-world/1.0.2/package.json'
103+ ) ;
80104 } ) ;
81105
82106 it ( 'should scan for directories to fetch components and versions' , ( ) => {
@@ -106,24 +130,48 @@ describe('registry : domain : components-cache', () => {
106130 before ( done => {
107131 mockedCdn . getJson = sinon . stub ( ) ;
108132 mockedCdn . getJson . resolves ( baseResponse ( ) ) ;
133+ mockedCdn . getJson
134+ . withArgs ( 'component/hello-world/3.0.0/package.json' )
135+ . rejects ( 'ERROR' ) ;
109136 mockedCdn . listSubDirectories = sinon . stub ( ) ;
110137 mockedCdn . listSubDirectories . onCall ( 0 ) . resolves ( [ 'hello-world' ] ) ;
111138 mockedCdn . listSubDirectories
112139 . onCall ( 1 )
113- . resolves ( [ '1.0.0' , '1.0.2' , '2.0.0' ] ) ;
140+ . resolves ( [ '1.0.0' , '1.0.2' , '2.0.0' , '3.0.0' ] ) ;
114141 mockedCdn . putFileContent = sinon . stub ( ) ;
115142 mockedCdn . putFileContent . resolves ( 'ok' ) ;
116143 initialise ( ) ;
117144 componentsCache . load ( ) . finally ( done ) ;
118145 } ) ;
119146
120147 it ( 'should fetch the components.json' , ( ) => {
121- expect ( mockedCdn . getJson . calledOnce ) . to . be . true ;
122148 expect ( mockedCdn . getJson . args [ 0 ] [ 0 ] ) . to . be . equal (
123149 'component/components.json'
124150 ) ;
125151 } ) ;
126152
153+ it ( 'should verify new versions' , ( ) => {
154+ expect ( mockedCdn . getJson . calledThrice ) . to . be . true ;
155+ expect ( mockedCdn . getJson . args [ 1 ] [ 0 ] ) . to . be . equal (
156+ 'component/hello-world/2.0.0/package.json'
157+ ) ;
158+ expect ( mockedCdn . getJson . args [ 2 ] [ 0 ] ) . to . be . equal (
159+ 'component/hello-world/3.0.0/package.json'
160+ ) ;
161+ } ) ;
162+
163+ it ( 'should ignore corrupted versions and generate an error event' , ( ) => {
164+ expect ( eventsHandlerStub . fire . called ) . to . be . true ;
165+ expect ( eventsHandlerStub . fire . args [ 0 ] [ 0 ] ) . to . equal ( 'error' ) ;
166+ expect ( eventsHandlerStub . fire . args [ 0 ] [ 1 ] . code ) . to . equal (
167+ 'corrupted_version'
168+ ) ;
169+ expect ( eventsHandlerStub . fire . args [ 0 ] [ 1 ] . message ) . to . contain (
170+ 'hello-world'
171+ ) ;
172+ expect ( eventsHandlerStub . fire . args [ 0 ] [ 1 ] . message ) . to . contain ( '3.0.0' ) ;
173+ } ) ;
174+
127175 it ( 'should scan for directories to fetch components and versions' , ( ) => {
128176 expect ( mockedCdn . listSubDirectories . calledTwice ) . to . be . true ;
129177 } ) ;
0 commit comments