-
Notifications
You must be signed in to change notification settings - Fork 41
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 #710 from Green-Software-Foundation/migrate-mock-o…
…bs-to-builtins Migrate `mock-observations` to `builtins`
- Loading branch information
Showing
12 changed files
with
869 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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import {KeyValuePair} from '../../../types/common'; | ||
|
||
import {ERRORS} from '../../../util/errors'; | ||
|
||
import {CommonGenerator} from '../../../builtins/mock-observations/helpers/common-generator'; | ||
|
||
const {InputValidationError} = ERRORS; | ||
|
||
describe('lib/mock-observations/CommonGenerator: ', () => { | ||
describe('initialize: ', () => { | ||
it('throws an error when config is not empty object.', async () => { | ||
const commonGenerator = CommonGenerator({}); | ||
|
||
expect.assertions(1); | ||
|
||
try { | ||
commonGenerator.next([]); | ||
} catch (error) { | ||
expect(error).toEqual( | ||
new InputValidationError( | ||
'CommonGenerator: Config must not be null or empty.' | ||
) | ||
); | ||
} | ||
}); | ||
}); | ||
|
||
describe('next(): ', () => { | ||
it('returns a result with valid data.', async () => { | ||
const config: KeyValuePair = { | ||
key1: 'value1', | ||
key2: 'value2', | ||
}; | ||
const commonGenerator = CommonGenerator(config); | ||
|
||
expect.assertions(1); | ||
|
||
expect(commonGenerator.next([])).toStrictEqual({ | ||
key1: 'value1', | ||
key2: 'value2', | ||
}); | ||
}); | ||
}); | ||
}); |
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,71 @@ | ||
import {KeyValuePair} from '../../../types/common'; | ||
|
||
import {ERRORS} from '../../../util/errors'; | ||
|
||
import {RandIntGenerator} from '../../../builtins/mock-observations/helpers/rand-int-generator'; | ||
|
||
const {InputValidationError} = ERRORS; | ||
|
||
describe('lib/mock-observations/RandIntGenerator: ', () => { | ||
describe('initialize', () => { | ||
it('throws an error when the generator name is empty string.', async () => { | ||
expect.assertions(1); | ||
try { | ||
RandIntGenerator('', {}); | ||
} catch (error) { | ||
expect(error).toEqual( | ||
new InputValidationError( | ||
'RandIntGenerator: `name` is empty or all spaces.' | ||
) | ||
); | ||
} | ||
}); | ||
|
||
it('throws an error when config is empty object.', async () => { | ||
expect.assertions(1); | ||
try { | ||
RandIntGenerator('generator-name', {}); | ||
} catch (error) { | ||
expect(error).toEqual( | ||
new InputValidationError( | ||
'RandIntGenerator: Config must not be null or empty.' | ||
) | ||
); | ||
} | ||
}); | ||
|
||
it('throws an error `min` is missing from the config.', async () => { | ||
const config = {max: 90}; | ||
|
||
expect.assertions(1); | ||
|
||
try { | ||
RandIntGenerator('random', config); | ||
} catch (error) { | ||
expect(error).toEqual( | ||
new InputValidationError( | ||
'RandIntGenerator: Config is missing min or max.' | ||
) | ||
); | ||
} | ||
}); | ||
}); | ||
|
||
describe('next(): ', () => { | ||
it('returns a result with valid data.', async () => { | ||
const config: KeyValuePair = { | ||
min: 10, | ||
max: 90, | ||
}; | ||
const randIntGenerator = RandIntGenerator('random', config); | ||
const result = randIntGenerator.next([]) as {random: number}; | ||
|
||
expect.assertions(4); | ||
|
||
expect(result).toBeInstanceOf(Object); | ||
expect(result).toHaveProperty('random'); | ||
expect(result.random).toBeGreaterThanOrEqual(10); | ||
expect(result.random).toBeLessThanOrEqual(90); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.