-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
108 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export { prefixMessage } from './errorModifier' | ||
export * from './errorModifier' | ||
export * from './serverTypeError' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { ServerTypeError } from './serverTypeError' | ||
import { ServerType } from '../types' | ||
|
||
describe('ServerTypeError', () => { | ||
it('should include valid server type', () => { | ||
const validServerType = ServerType.Sas9 | ||
const error = new ServerTypeError([validServerType]) | ||
|
||
expect(error).toBeInstanceOf(ServerTypeError) | ||
expect(error.name).toEqual('ServerTypeError') | ||
expect(error.message).toEqual( | ||
`Invalid server type: valid option is ${validServerType}` | ||
) | ||
}) | ||
|
||
it('should include 2 valid server types', () => { | ||
const validServerType1 = ServerType.Sas9 | ||
const validServerType2 = ServerType.SasViya | ||
const error = new ServerTypeError([validServerType1, validServerType2]) | ||
|
||
expect(error.message).toEqual( | ||
`Invalid server type: valid options are ${validServerType1} and ${validServerType2}` | ||
) | ||
}) | ||
|
||
it('should include 3 valid server types', () => { | ||
const validServerType1 = ServerType.Sas9 | ||
const validServerType2 = ServerType.SasViya | ||
const validServerType3 = ServerType.Sasjs | ||
const error = new ServerTypeError([ | ||
validServerType1, | ||
validServerType2, | ||
validServerType3 | ||
]) | ||
|
||
expect(error.message).toEqual( | ||
`Invalid server type: valid options are ${validServerType1}, ${validServerType2} and ${validServerType3}` | ||
) | ||
}) | ||
|
||
it('should include unique server types only', () => { | ||
const validServerType1 = ServerType.Sas9 | ||
const validServerType2 = ServerType.SasViya | ||
const validServerType3 = ServerType.Sasjs | ||
const validServerType4 = ServerType.Sasjs | ||
const error = new ServerTypeError([ | ||
validServerType1, | ||
validServerType2, | ||
validServerType3, | ||
validServerType4 | ||
]) | ||
|
||
expect(error.message).toEqual( | ||
`Invalid server type: valid options are ${validServerType1}, ${validServerType2} and ${validServerType3}` | ||
) | ||
}) | ||
|
||
it('should include all supported server types if server type was not provided', () => { | ||
const error = new ServerTypeError() | ||
|
||
expect(error.message).toEqual( | ||
`Invalid server type: valid options are ${ServerType.SasViya}, ${ServerType.Sas9} and ${ServerType.Sasjs}` | ||
) | ||
}) | ||
|
||
// TODO: test if super was called | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { ServerType } from '../types' | ||
|
||
export class ServerTypeError extends Error { | ||
constructor(validOptions: ServerType[] = []) { | ||
validOptions = [...new Set(validOptions)] | ||
|
||
let options = validOptions.length | ||
? validOptions.join(', ').trim() | ||
: [ServerType.SasViya, ServerType.Sas9, ServerType.Sasjs] | ||
.join(', ') | ||
.trim() | ||
|
||
options = options.replace(/,\s([^,]*)$/, ' and $1') | ||
|
||
super( | ||
`Invalid server type: valid option${ | ||
validOptions.length !== 1 ? 's' : '' | ||
} ${validOptions.length !== 1 ? 'are' : 'is'} ${options}` | ||
) | ||
|
||
this.name = 'ServerTypeError' | ||
|
||
Object.setPrototypeOf(this, ServerTypeError.prototype) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export enum ServerType { | ||
SasViya = 'SASVIYA', | ||
Sas9 = 'SAS9' | ||
Sas9 = 'SAS9', | ||
Sasjs = 'SASJS' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters