forked from kristijorgji/redis-playground
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata.js
30 lines (25 loc) · 751 Bytes
/
data.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
const fs = require('fs');
const path = require('path');
const M_TYPES = [
'OutOfStockRemoval',
'SomethingElse',
'PriceChanged'
];
function makeMessage() {
return JSON.stringify({
type: M_TYPES[Math.round(Math.random() * (M_TYPES.length - 1))],
data: {
sku: `${Math.round(Math.random() * 100)}`,
product: Math.round(Math.random() * 5) === 1 ? readFixture('lineItem') : 'changeNotRelatedToProduct',
}
})
}
function _rstring(length) {
return (Math.random().toString(length || 36)+'00000000000000000')
}
module.exports = {
makeMessage,
}
function readFixture(name) {
return JSON.parse(fs.readFileSync(path.resolve(__dirname, `fixtures/${name}.json`)).toString());
}