Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate mock-observations to builtins #710

Merged
merged 21 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
0024777
feat(lib): move readme into builtins/mock-observations
jmcook1186 May 10, 2024
82fc57e
feat(lib): export mock-observatons from builtins
jmcook1186 May 10, 2024
f28c487
feat(lib): add interfaces to mock-observations
jmcook1186 May 10, 2024
d05573c
feat(lib): add types/helpers
jmcook1186 May 10, 2024
ebbf48f
feat(lib): add util/helpers
jmcook1186 May 10, 2024
7f132b3
feat(lib): add types/common to builtins
jmcook1186 May 10, 2024
ef71594
feat(lib): add rand-int generator
jmcook1186 May 10, 2024
2a2abfb
feat(lib): add common generator
jmcook1186 May 10, 2024
9797f7f
feat(lib): add types to mock-observations
jmcook1186 May 10, 2024
3d723f0
feat(lib): add plugin source code to builtins
jmcook1186 May 10, 2024
81b9376
test(lib): add unit tests
jmcook1186 May 10, 2024
63c95da
Update src/builtins/mock-observations/README.md
jmcook1186 May 20, 2024
73bcfbb
Apply suggestions from code review
jmcook1186 May 21, 2024
2ab4aed
Merge branch 'main' into migrate-mock-obs-to-builtins
jmcook1186 May 21, 2024
c38e4a5
fix(lib): fix duplicate entries
jmcook1186 May 21, 2024
bcaceea
Merge branch 'main' into migrate-mock-obs-to-builtins
jmcook1186 May 21, 2024
6395b91
Merge branch 'main' into migrate-mock-obs-to-builtins
jmcook1186 May 24, 2024
c5e31c2
fix(lib): remove unused vars
jmcook1186 May 24, 2024
8d9916d
Merge branch 'migrate-mock-obs-to-builtins' of https://github.com/Gre…
jmcook1186 May 24, 2024
677cfd3
Merge branch 'main' into migrate-mock-obs-to-builtins
jmcook1186 May 24, 2024
80063fc
fix(builtins): remove unused param
narekhovhannisyan May 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions src/__tests__/unit/builtins/CommonGenerator.test.ts
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',
});
});
});
});
71 changes: 71 additions & 0 deletions src/__tests__/unit/builtins/RandIntGenerator.test.ts
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);
});
});
});
Loading