| 1 |  |  | import chai from 'chai' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | import path from 'path' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | import sinonChai from'sinon-chai' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  | chai.use(sinonChai) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | import sinon from 'sinon' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | import execPromise from 'child-process-promise' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | import mkdirp from 'mkdirp' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | import events from 'events' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | import { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |   cmsStructure, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |   abeExtend, | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |   config | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | } from '../../../src/cli' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | config.set({root: path.join(process.cwd(), 'test','fixtures')}) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | describe('cmsStructure', function() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |   var folderPath = '/my/folder/path' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |    | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |   /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |    * cmsStructure.structure.addFolder | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |    *  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |    */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |   it('cmsStructure.structure.addFolder()', function() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |     this.sinon = sinon.sandbox.create(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |     //TODO: find how to stub function litteral "mkdirp" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |     // var stub = sinon.stub(mkdirp, "") | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |     // var stub = sinon.createStubInstance(mkdirp); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |     // var result = cmsStructure.structure.addFolder(folderPath) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |     // chai.expect(result).to.not.be.undefined | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |     // chai.expect(result).to.be.a('string') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |     // chai.expect(result).to.equal(folderPath) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |     // chai.expect(result).to.equal(path.join(config.root, config.publish.url, '/myImageFolder')) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |     // sinon.assert.calledOnce(mkdirp) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |     // mkdirp.restore() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |   }); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |   /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |    * cmsStructure.structure.removeFolder | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |    *  | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 43 |  |  |    */ | 
            
                                                                        
                            
            
                                    
            
            
                | 44 |  |  |   it('cmsStructure.structure.removeFolder()', function() { | 
            
                                                                        
                            
            
                                    
            
            
                | 45 |  |  |     this.sinon = sinon.sandbox.create(); | 
            
                                                                        
                            
            
                                    
            
            
                | 46 |  |  |     var stub = sinon.stub(execPromise, "exec") | 
            
                                                                        
                            
            
                                    
            
            
                | 47 |  |  |     stub.returns(Promise.resolve({ | 
            
                                                                        
                            
            
                                    
            
            
                | 48 |  |  |       'stdout': null, | 
            
                                                                        
                            
            
                                    
            
            
                | 49 |  |  |       'stderr': null | 
            
                                                                        
                            
            
                                    
            
            
                | 50 |  |  |     })); | 
            
                                                                        
                            
            
                                    
            
            
                | 51 |  |  |     var result = cmsStructure.structure.removeFolder(folderPath) | 
            
                                                                        
                            
            
                                    
            
            
                | 52 |  |  |     chai.expect(result).to.not.be.undefined | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 53 |  |  |     chai.expect(result).to.equal(folderPath) | 
            
                                                                        
                            
            
                                    
            
            
                | 54 |  |  |     sinon.assert.calledOnce(execPromise.exec) | 
            
                                                                        
                            
            
                                    
            
            
                | 55 |  |  |     execPromise.exec.restore() | 
            
                                                                        
                            
            
                                    
            
            
                | 56 |  |  |   }); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |   /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |    * cmsStructure.structure.editStructure | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |    *  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |    */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |   it('cmsStructure.structure.editStructure()', function() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |     this.sinon = sinon.sandbox.create(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |     var stub = sinon.stub(cmsStructure.structure, "removeFolder") | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |     stub.returns('') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |     var result = cmsStructure.structure.editStructure('remove', folderPath) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |     chai.expect(result).to.not.be.undefined | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |     chai.expect(result).to.equal(folderPath) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |     sinon.assert.calledOnce(cmsStructure.structure.removeFolder) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |     cmsStructure.structure.removeFolder.restore() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |   }); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |  | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 73 |  |  | }); | 
            
                                                        
            
                                    
            
            
                | 74 |  |  |  |