Skip to content

Commit f15daf9

Browse files
committed
Add useful script for generating Bloomreach import data
1 parent 8ed8a76 commit f15daf9

5 files changed

Lines changed: 98 additions & 0 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules/
2+
*.csv

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@
33
This repo contains different shareable tooling and other pieces of common code or similar for Martech engineers.
44
Currently, there is a team-wide `eslint-config` available on the `eslint-config-martech` branch. The `main` branch is an orphaned branch, so contains different content from our `eslint`-related branch.
55

6+
The main branch also contains useful scripts.
7+
68
## Contents
79

810
- [Contents](#contents)
911
- [Branches](#branches)
1012
- [Contact](#contact)
1113

14+
1215
## Branches
1316

1417
The idea is that we can create orphan branches for use as `npm` packages, so we consolidate and can easily share common tooling for our different repos and projects.

scripts/create-consent-csv.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
This script is useful for generating test data to do bulk imports into Bloomreach.
3+
(to simulate Purchase List uploads, or consent uploads they do in FT Forums/FT BDP).
4+
5+
Why would we want to do this? When testing our consent sync flow, as described here:
6+
https://lucid.app/lucidchart/7b014227-4cc1-4cf9-beb3-1c952245cc40/view
7+
8+
In particular, load testing the following two apps, whose input comes (indirectly) from Bloomreach.
9+
(hence needing to load Bloomreach with test data that can be easily identified and torn down after the test)
10+
11+
ip-martech-register-users
12+
ip-martech-cdp-exponea-to-scs-sync
13+
14+
USAGE:
15+
If you want to create files each with 10,000 records:
16+
17+
node ./create-consent-csv.js 10000
18+
*/
19+
20+
const fs = require("fs");
21+
const { v4: uuid } = require('uuid');
22+
const now = new Date();
23+
24+
const createCsv = (numberOfRows) => {
25+
console.log("Starting process...");
26+
const consentFields =
27+
`marketing-email,accept,${now / 1000},unlimited`;
28+
29+
console.log(`Creating email data. ${numberOfRows} records...`);
30+
31+
const csvEmailData = Array.from(Array(numberOfRows)).map((row) => {
32+
return [(`${now.getDate()}-${now.getMonth()+1}-${uuid()}-test@test.com`)];
33+
});
34+
35+
console.log("Writing to file...");
36+
const fileEmail = fs.createWriteStream("email.csv");
37+
const fileConsent = fs.createWriteStream("consent.csv");
38+
39+
fileEmail.write("email" + "\n");
40+
fileConsent.write("email,category,action,timestamp,valid_until" + "\n");
41+
csvEmailData.forEach(function (v) {
42+
fileEmail.write(v.join(",") + "\n");
43+
fileConsent.write(v.join(",") + ',' + consentFields + "\n");
44+
});
45+
fileEmail.end();
46+
fileConsent.end();
47+
console.log("Completed!!");
48+
};
49+
console.log(process.argv[2]);
50+
const count = process.argv[2] ? process.argv[2] : 10;
51+
createCsv(+count);

scripts/package-lock.json

Lines changed: 28 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/package.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "create-csv",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "create-consent-csv.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"author": "",
10+
"license": "ISC",
11+
"dependencies": {
12+
"uuid": "^9.0.1"
13+
}
14+
}

0 commit comments

Comments
 (0)