|
| 1 | +import { expect } from 'chai'; |
| 2 | + |
| 3 | +import Reporter from './index.js'; |
| 4 | + |
| 5 | +describe('Reporter', () => { |
| 6 | + describe('#normalizeConfig', () => { |
| 7 | + context('with current config format', () => { |
| 8 | + it('returns the config as is', () => { |
| 9 | + const config = { repositories: { declarations: 'owner/repo' } }; |
| 10 | + const normalizedConfig = Reporter.normalizeConfig(config); |
| 11 | + |
| 12 | + expect(normalizedConfig).to.deep.equal(config); |
| 13 | + }); |
| 14 | + }); |
| 15 | + |
| 16 | + context('with old config format where githubIssues is nested under reporter', () => { |
| 17 | + it('returns a normalized config', () => { |
| 18 | + const config = { githubIssues: { repositories: { declarations: 'owner/repo' } } }; |
| 19 | + const expectedConfig = { |
| 20 | + type: 'github', |
| 21 | + repositories: { declarations: 'owner/repo' }, |
| 22 | + }; |
| 23 | + const normalizedConfig = Reporter.normalizeConfig(config); |
| 24 | + |
| 25 | + expect(normalizedConfig).to.deep.equal(expectedConfig); |
| 26 | + }); |
| 27 | + }); |
| 28 | + }); |
| 29 | + |
| 30 | + describe('#validateConfiguration', () => { |
| 31 | + context('with valid configuration', () => { |
| 32 | + it('does not throw an error', () => { |
| 33 | + const repositories = { declarations: 'owner/repo' }; |
| 34 | + |
| 35 | + expect(() => { |
| 36 | + Reporter.validateConfiguration(repositories); |
| 37 | + }).not.to.throw(); |
| 38 | + }); |
| 39 | + }); |
| 40 | + |
| 41 | + context('with invalid configuration', () => { |
| 42 | + context('when declarations key is missing', () => { |
| 43 | + it('throws an error', () => { |
| 44 | + const repositories = {}; |
| 45 | + |
| 46 | + expect(() => { |
| 47 | + Reporter.validateConfiguration(repositories); |
| 48 | + }).to.throw('Required configuration key "reporter.repositories.declarations" was not found; issues on the declarations repository cannot be created'); |
| 49 | + }); |
| 50 | + }); |
| 51 | + |
| 52 | + context('when repository format is incorrect', () => { |
| 53 | + it('throws an error', () => { |
| 54 | + const repositories = { declarations: 'invalidFormat' }; |
| 55 | + |
| 56 | + expect(() => { |
| 57 | + Reporter.validateConfiguration(repositories); |
| 58 | + }).to.throw('Configuration entry "reporter.repositories.declarations" is expected to be a string in the format <owner>/<repo>, but received: "invalidFormat"'); |
| 59 | + }); |
| 60 | + }); |
| 61 | + }); |
| 62 | + }); |
| 63 | +}); |
0 commit comments