| Conditions | 1 |
| Paths | 1 |
| Total Lines | 79 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | import chai from 'chai' |
||
| 17 | describe('coreUtils.file', function() { |
||
| 18 | |||
| 19 | /** |
||
| 20 | * coreUtils.file.addFolder |
||
| 21 | * |
||
| 22 | */ |
||
| 23 | it('coreUtils.file.addFolder()', function() { |
||
| 24 | this.sinon = sinon.sandbox.create(); |
||
| 25 | var stub = sinon.stub(mkdirp, 'mkdirP') |
||
| 26 | stub.returns({'test':'test'}); |
||
| 27 | var result = coreUtils.file.addFolder('path/to/folder') |
||
| 28 | chai.expect(result).to.be.a('string') |
||
| 29 | chai.expect(result).to.equal('path/to/folder') |
||
| 30 | mkdirp.mkdirP.restore() |
||
| 31 | }); |
||
| 32 | |||
| 33 | /** |
||
| 34 | * coreUtils.file.removeFolder |
||
| 35 | * |
||
| 36 | */ |
||
| 37 | it('coreUtils.file.removeFolder()', function() { |
||
| 38 | this.sinon = sinon.sandbox.create(); |
||
| 39 | var stub = sinon.stub(fse, 'remove') |
||
| 40 | stub.returns({}); |
||
| 41 | var result = coreUtils.file.removeFolder('path/to/folder') |
||
| 42 | chai.expect(result).to.be.a('string') |
||
| 43 | chai.expect(result).to.equal('path/to/folder') |
||
| 44 | fse.remove.restore() |
||
| 45 | }); |
||
| 46 | |||
| 47 | /** |
||
| 48 | * coreUtils.file.getDate |
||
| 49 | * |
||
| 50 | */ |
||
| 51 | it('coreUtils.file.getDate()', function() { |
||
| 52 | this.sinon = sinon.sandbox.create(); |
||
| 53 | var stub = sinon.stub(cmsData.fileAttr, 'get') |
||
| 54 | stub.returns({d: '2016-12-07T13:04:18.810Z'}); |
||
| 55 | var result = coreUtils.file.getDate(path.join(config.root, config.data.url, 'article-abe-d20161207T130418810Z.json')) |
||
| 56 | chai.expect(result.toString()).to.equal('Wed Dec 07 2016 14:04:18 GMT+0100 (CET)') |
||
| 57 | cmsData.fileAttr.get.restore() |
||
| 58 | }); |
||
| 59 | |||
| 60 | /** |
||
| 61 | * coreUtils.file.addDateIsoToRevisionPath |
||
| 62 | * |
||
| 63 | */ |
||
| 64 | it('coreUtils.file.addDateIsoToRevisionPath()', function() { |
||
| 65 | var date = '20161207T132049118Z' |
||
| 66 | var urlRevision = path.join(config.root, config.data.url, 'article-abe-d' + date + '.json') |
||
| 67 | this.sinon = sinon.sandbox.create(); |
||
| 68 | |||
| 69 | var stub = sinon.stub(cmsData.revision, 'removeStatusAndDateFromFileName') |
||
| 70 | stub.returns(date); |
||
| 71 | |||
| 72 | var stub2 = sinon.stub(cmsData.fileAttr, 'add') |
||
| 73 | stub2.returns(urlRevision); |
||
| 74 | |||
| 75 | var result = coreUtils.file.addDateIsoToRevisionPath(path.join(config.root, config.data.url, 'article.json'), 'draft') |
||
| 76 | chai.expect(result).to.be.a('string') |
||
| 77 | chai.expect(result).to.equal(urlRevision) |
||
| 78 | cmsData.revision.removeStatusAndDateFromFileName.restore() |
||
| 79 | cmsData.fileAttr.add.restore() |
||
| 80 | }); |
||
| 81 | |||
| 82 | /** |
||
| 83 | * coreUtils.file.exist |
||
| 84 | * |
||
| 85 | */ |
||
| 86 | it('coreUtils.file.exist()', function() { |
||
| 87 | this.sinon = sinon.sandbox.create(); |
||
| 88 | var stub = sinon.stub(fse, 'statSync') |
||
| 89 | stub.returns(''); |
||
| 90 | var result = coreUtils.file.exist('path/to/file') |
||
| 91 | chai.expect(result).to.be.true |
||
| 92 | fse.statSync.restore() |
||
| 93 | }); |
||
| 94 | |||
| 95 | }); |
||
| 96 |