Skip to content
This repository was archived by the owner on Aug 31, 2022. It is now read-only.

Commit 93542f1

Browse files
author
ANISHA SWAIN
authored
Add a unique key generator to utils for mock API
Adds index to controller name for generating consistent result name. Generates casual words for controller names.
1 parent 9261499 commit 93542f1

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

mock/api.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
11
import moment from 'moment';
22
import casual from 'casual';
3+
import createUniqueKey from '../src/utils/uniqueKey_generator';
34

45
const DEFAULT_SIZE = 100;
56

67
export const mockIndices = new Array(1).fill().map(() => moment().format('YYYY-MM'));
78

89
export const mockControllers = new Array(DEFAULT_SIZE).fill().map((value, index) => ({
910
controller: `${casual.word}.${casual.word}.com`,
10-
key: casual.ip,
11+
key: createUniqueKey(),
1112
last_modified_string: moment().valueOf(moment.utc()),
1213
last_modified_value: moment.utc() + index,
1314
results: casual.integer(1, DEFAULT_SIZE),
1415
}));
1516

1617
export const mockResults = hostname =>
17-
new Array(DEFAULT_SIZE).fill().map(() => ({
18+
new Array(DEFAULT_SIZE).fill().map((value, index) => ({
1819
'@metadata.controller_dir': hostname,
1920
config: casual.word,
2021
controller: hostname,
2122
end: moment.utc(),
2223
// Since dataset id is a long hex string, removed "-" characters here to make it look like real data
2324
id: casual.uuid.replace(/-/g, ''),
24-
result: casual.word,
25+
result: `${index}${hostname.slice(0, -6)}${index}`,
2526
start: moment.utc(),
2627
}));
2728

src/utils/uniqueKey_generator.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export default function createUniqueKey() {
2+
const dt = new Date().getTime();
3+
const tempStr = 'xxxxxx.yxyxxyxy.xxxyyy';
4+
// eslint-disable-next-line func-names
5+
const uuid = tempStr.replace(/[xy]/g, function(c) {
6+
/* eslint no-bitwise: ["error", { "int32Hint": true }] */
7+
const r = ((dt + Math.random() * 16) & 0xf) | 0;
8+
/* eslint no-bitwise: ["error", { "allow": ["&", "|"] }] */
9+
return (c === 'x' ? r : (r & 0x3) | 0x8).toString(16);
10+
});
11+
return uuid;
12+
}

0 commit comments

Comments
 (0)