Skip to content

Commit 4019465

Browse files
committed
Add test for getDefaultConfig() + tweak exception
1 parent 037f8cb commit 4019465

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

index.js

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -188,27 +188,21 @@ async function parseV1SocketConfig (parsedV1Content) {
188188
return v2
189189
}
190190

191-
/**
192-
*
193-
* @returns {SocketYml}
194-
*/
191+
/** @returns {SocketYml} */
195192
function getDefaultConfig () {
196193
const config = { version: 2 }
194+
197195
if (!validate(config)) {
198-
throw new SocketValidationError(
199-
'Invalid config definition',
200-
validate.errors || [],
201-
config
202-
)
196+
throw new Error('Unexpectedly invalid default config')
203197
}
204198

205199
return config
206200
}
207201

208202
module.exports = {
203+
getDefaultConfig,
209204
parseSocketConfig,
210205
readSocketConfig,
211206
SocketValidationError,
212207
socketYmlSchema,
213-
getDefaultConfig
214208
}

test/parse.spec.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,17 @@ const chai = require('chai')
77
const chaiAsPromised = require('chai-as-promised')
88

99
const {
10+
getDefaultConfig,
1011
parseSocketConfig,
1112
SocketValidationError,
1213
} = require('../index.js')
1314

1415
chai.use(chaiAsPromised)
1516
chai.should()
1617

18+
/** @type {import('../index.js').SocketYml} */
1719
const defaults = {
20+
'version': 2,
1821
'githubApp': {
1922
'enabled': true,
2023
'projectReportsEnabled': true,
@@ -82,7 +85,7 @@ bar: {{ def }} {{ efg }}
8285
version: 2
8386
foo: true
8487
`)
85-
.should.eventually.become({ version: 2, ...defaults })
88+
.should.eventually.become(defaults)
8689
})
8790

8891
it('should coerce types', async () => {
@@ -91,9 +94,14 @@ version: 2
9194
projectIgnorePaths: foobar
9295
`)
9396
.should.eventually.become({
94-
version: 2,
9597
...defaults,
9698
projectIgnorePaths: ['foobar'],
9799
})
98100
})
99101
})
102+
103+
describe('getDefaultConfig()', () => {
104+
it('should return a default config', () => {
105+
getDefaultConfig().should.deep.equal(defaults)
106+
})
107+
})

0 commit comments

Comments
 (0)