File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -7,6 +7,11 @@ It supports two event types, each invoked as a subcommand:
77- ** ` supplier-api-letter-event ` ** – generates ` SupplierApiLetterEvent ` events (mirrors the ` LetterEvent ` consumed by ` print-status-handler ` )
88- ** ` paper-letter-opt-out-event ` ** – generates ` PaperLetterOptedOut ` channel status events, reading input from a CSV file
99
10+ To execute the commands you need to:
11+
12+ - Be located in the scripts/nft-event-generator directory
13+ - Have an active ` aws sso login ` in the account you want (e.g. ` NHS Notify Suppliers Nonprod ` )
14+
1015## Common features
1116
1217- Custom environments (e.g. ` pr293 ` , ` main ` , ` nft ` )
@@ -88,13 +93,13 @@ The `messageReference` field in each generated event is built as `<senderId>_<me
8893Send opt-out events from a CSV file to the ` nft ` environment:
8994
9095``` shell
91- npm start -- paper-letter-opt-out-event --environment nft --csvFile . /opt-outs.csv
96+ npm start -- paper-letter-opt-out-event --environment nft --csvFile /home/notify/git/nhs-notify-digital-letters/scripts/nft-event-generator /opt-outs.csv
9297```
9398
9499Send to a PR environment with a custom batch interval:
95100
96101``` shell
97- npm start -- paper-letter-opt-out-event --environment pr293 --csvFile . /opt-outs.csv --interval 500
102+ npm start -- paper-letter-opt-out-event --environment pr293 --csvFile /home/notify/git/nhs-notify-digital-letters/scripts/nft-event-generator /opt-outs.csv --interval 500
98103```
99104
100105---
Original file line number Diff line number Diff line change @@ -4,6 +4,12 @@ import { readCsvFile } from 'utils/csv-reader';
44const SAMPLE_CSV = path . join ( __dirname , '../fixtures' , 'sample-opt-outs.csv' ) ;
55
66describe ( 'readCsvFile' , ( ) => {
7+ it ( 'should throw for a non-csv path' , ( ) => {
8+ expect ( ( ) => readCsvFile ( '/etc/passwd' ) ) . toThrow (
9+ 'Invalid file path: must be a .csv file' ,
10+ ) ;
11+ } ) ;
12+
713 it ( 'should parse a CSV file into CsvRow objects' , ( ) => {
814 const rows = readCsvFile ( SAMPLE_CSV ) ;
915
Original file line number Diff line number Diff line change 11import { parse } from 'csv-parse/sync' ;
22import { readFileSync } from 'node:fs' ;
3+ import path from 'node:path' ;
34
45export type PaperLetterOptOutRow = {
56 messageReference : string ;
67 senderId : string ;
78} ;
89
910export function readCsvFile ( filePath : string ) : PaperLetterOptOutRow [ ] {
10- const fileContent = readFileSync ( filePath , 'utf8' ) ;
11+ const resolvedPath = path . resolve ( filePath ) ;
12+
13+ if ( ! resolvedPath . endsWith ( '.csv' ) ) {
14+ throw new Error ( `Invalid file path: must be a .csv file` ) ;
15+ }
16+
17+ // eslint-disable-next-line security/detect-non-literal-fs-filename -- path is validated above
18+ const fileContent = readFileSync ( resolvedPath , 'utf8' ) ;
1119
1220 return parse ( fileContent , {
1321 columns : [ 'messageReference' , 'senderId' ] ,
Original file line number Diff line number Diff line change 2424 "lint" : " eslint nft-event-generator/" ,
2525 "lint:fix" : " eslint nft-event-generator/ --fix" ,
2626 "start" : " tsx nft-event-generator/src/cli.ts" ,
27- "start:nft" : " npm start -- supplier-api-letter-event --environment nft --numberOfEvents 2 --interval 2000" ,
2827 "test:unit" : " jest" ,
2928 "typecheck" : " tsc --noEmit"
3029 },
You can’t perform that action at this time.
0 commit comments