fix: Websocket route names normalization (#7294)

This commit is contained in:
tom-marsh 2020-02-10 08:14:33 +00:00 committed by GitHub
parent 024146885a
commit 33291c8d08
2 changed files with 17 additions and 5 deletions

View File

@ -208,11 +208,11 @@ module.exports = {
getNormalizedWebsocketsRouteKey(route) {
return route
.replace('$', 'S') // dollar sign
.replace('/', 'Slash')
.replace('-', 'Dash')
.replace('_', 'Underscore')
.replace('.', 'Period');
.replace(/\$/g, 'S') // dollar sign
.replace(/\//g, 'Slash')
.replace(/-/g, 'Dash')
.replace(/_/g, 'Underscore')
.replace(/\./g, 'Period');
},
getWebsocketsRouteLogicalId(route) {

View File

@ -253,6 +253,18 @@ describe('#naming()', () => {
expect(sdk.naming.getNormalizedWebsocketsRouteKey('foo.bar')).to.equal('fooPeriodbar');
});
it('converts multiple `-` correctly', () => {
expect(sdk.naming.getNormalizedWebsocketsRouteKey('a-longer-path')).to.equal(
'aDashlongerDashpath'
);
});
it('converts multiple `-` and `_` correctly', () => {
expect(sdk.naming.getNormalizedWebsocketsRouteKey('a-long_er-path_still')).to.equal(
'aDashlongUnderscoreerDashpathUnderscorestill'
);
});
});
describe('#getWebsocketsRouteLogicalId()', () => {