|
| 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); |
0 commit comments