-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #162 from reportportal/develop
Release 5.0.12
- Loading branch information
Showing
12 changed files
with
522 additions
and
185 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
5.0.11 | ||
5.0.12-SNAPSHOT |
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,61 @@ | ||
const { ReportPortalRequiredOptionError, ReportPortalValidationError } = require('./errors'); | ||
|
||
const getRequiredOption = (options, optionName) => { | ||
if (!Object.prototype.hasOwnProperty.call(options, optionName) || !options[optionName]) { | ||
throw new ReportPortalRequiredOptionError(optionName); | ||
} | ||
|
||
return options[optionName]; | ||
}; | ||
|
||
const getApiKey = ({ apiKey, token }) => { | ||
let calculatedApiKey = apiKey; | ||
if (!calculatedApiKey) { | ||
calculatedApiKey = token; | ||
if (!calculatedApiKey) { | ||
throw new ReportPortalRequiredOptionError('apiKey'); | ||
} else { | ||
console.warn(`Option 'token' is deprecated. Use 'apiKey' instead.`); | ||
} | ||
} | ||
|
||
return calculatedApiKey; | ||
}; | ||
|
||
const getClientConfig = (options) => { | ||
let calculatedOptions = options; | ||
try { | ||
if (typeof options !== 'object') { | ||
throw new ReportPortalValidationError('`options` must be an object.'); | ||
} | ||
const apiKey = getApiKey(options); | ||
const project = getRequiredOption(options, 'project'); | ||
const endpoint = getRequiredOption(options, 'endpoint'); | ||
|
||
calculatedOptions = { | ||
apiKey, | ||
project, | ||
endpoint, | ||
launch: options.launch, | ||
debug: options.debug, | ||
isLaunchMergeRequired: | ||
options.isLaunchMergeRequired === undefined ? false : options.isLaunchMergeRequired, | ||
headers: options.headers, | ||
restClientConfig: options.restClientConfig, | ||
attributes: options.attributes, | ||
mode: options.mode, | ||
description: options.description, | ||
}; | ||
} catch (error) { | ||
// don't throw the error up to not break the entire process | ||
console.dir(error); | ||
} | ||
|
||
return calculatedOptions; | ||
}; | ||
|
||
module.exports = { | ||
getClientConfig, | ||
getRequiredOption, | ||
getApiKey, | ||
}; |
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,29 @@ | ||
class ReportPortalError extends Error { | ||
constructor(message) { | ||
const basicMessage = `\nReportPortal client error: ${message}`; | ||
super(basicMessage); | ||
this.name = 'ReportPortalError'; | ||
} | ||
} | ||
|
||
class ReportPortalValidationError extends ReportPortalError { | ||
constructor(message) { | ||
const basicMessage = `\nValidation failed. Please, check the specified parameters: ${message}`; | ||
super(basicMessage); | ||
this.name = 'ReportPortalValidationError'; | ||
} | ||
} | ||
|
||
class ReportPortalRequiredOptionError extends ReportPortalValidationError { | ||
constructor(propertyName) { | ||
const basicMessage = `\nProperty '${propertyName}' must not be empty.`; | ||
super(basicMessage); | ||
this.name = 'ReportPortalRequiredOptionError'; | ||
} | ||
} | ||
|
||
module.exports = { | ||
ReportPortalError, | ||
ReportPortalValidationError, | ||
ReportPortalRequiredOptionError, | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
const { getClientConfig, getRequiredOption, getApiKey } = require('../lib/commons/config'); | ||
const { | ||
ReportPortalRequiredOptionError, | ||
ReportPortalValidationError, | ||
} = require('../lib/commons/errors'); | ||
|
||
describe('Config commons test suite', () => { | ||
describe('getRequiredOption', () => { | ||
it('should return option if it presented in options and has value', () => { | ||
const option = getRequiredOption({ project: 1 }, 'project'); | ||
|
||
expect(option).toBe(1); | ||
}); | ||
|
||
it('should throw ReportPortalRequiredOptionError in case of empty option', () => { | ||
let error; | ||
try { | ||
getRequiredOption({ project: undefined }, 'project'); | ||
} catch (e) { | ||
error = e; | ||
} | ||
expect(error).toBeDefined(); | ||
expect(error).toBeInstanceOf(ReportPortalRequiredOptionError); | ||
}); | ||
|
||
it( | ||
'should throw ReportPortalRequiredOptionError in case of option ' + 'not present in options', | ||
() => { | ||
let error; | ||
try { | ||
getRequiredOption({ other: 1 }, 'project'); | ||
} catch (e) { | ||
error = e; | ||
} | ||
expect(error).toBeDefined(); | ||
expect(error).toBeInstanceOf(ReportPortalRequiredOptionError); | ||
}, | ||
); | ||
}); | ||
|
||
describe('getApiKey', () => { | ||
it('should return apiKey if it presented in options and has value', () => { | ||
const apiKey = getApiKey({ apiKey: '1' }); | ||
|
||
expect(apiKey).toBe('1'); | ||
}); | ||
|
||
it('should return apiKey if it provided in options via deprecated token option', () => { | ||
const apiKey = getApiKey({ token: '1' }); | ||
|
||
expect(apiKey).toBe('1'); | ||
}); | ||
|
||
it('should print warning to console if deprecated token option used', () => { | ||
spyOn(console, 'warn'); | ||
|
||
getApiKey({ token: '1' }); | ||
|
||
expect(console.warn).toHaveBeenCalledWith( | ||
`Option 'token' is deprecated. Use 'apiKey' instead.`, | ||
); | ||
}); | ||
|
||
it('should throw ReportPortalRequiredOptionError in case of no one option present', () => { | ||
let error; | ||
try { | ||
getApiKey({}); | ||
} catch (e) { | ||
error = e; | ||
} | ||
expect(error).toBeDefined(); | ||
expect(error).toBeInstanceOf(ReportPortalRequiredOptionError); | ||
}); | ||
}); | ||
|
||
describe('getClientConfig', () => { | ||
it('should print ReportPortalValidationError error to the console in case of options is not an object type', () => { | ||
spyOn(console, 'dir'); | ||
getClientConfig('options'); | ||
|
||
expect(console.dir).toHaveBeenCalledWith( | ||
new ReportPortalValidationError('`options` must be an object.'), | ||
); | ||
}); | ||
|
||
it('should print ReportPortalRequiredOptionError to the console in case of "endpoint" option missed', () => { | ||
spyOn(console, 'dir'); | ||
getClientConfig({ | ||
apiKey: '123', | ||
project: 'prj', | ||
}); | ||
|
||
expect(console.dir).toHaveBeenCalledWith(new ReportPortalRequiredOptionError('endpoint')); | ||
}); | ||
|
||
it('should print ReportPortalRequiredOptionError to the console in case of "project" option missed', () => { | ||
spyOn(console, 'dir'); | ||
getClientConfig({ | ||
apiKey: '123', | ||
endpoint: 'https://abc.com', | ||
}); | ||
|
||
expect(console.dir).toHaveBeenCalledWith(new ReportPortalRequiredOptionError('project')); | ||
}); | ||
|
||
it('should print ReportPortalRequiredOptionError to the console in case of "apiKey" option missed', () => { | ||
spyOn(console, 'dir'); | ||
getClientConfig({ | ||
project: 'prj', | ||
endpoint: 'https://abc.com', | ||
}); | ||
|
||
expect(console.dir).toHaveBeenCalledWith(new ReportPortalRequiredOptionError('apiKey')); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.