Skip to content

Commit 1db90d5

Browse files
strip input csv to only need clientName & APIM ID
1 parent 1e68b4d commit 1db90d5

12 files changed

Lines changed: 27 additions & 26 deletions

packages/event-builder/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ CLI tool for client configuration using events.
2121

2222
**Note:** All headers in the CSV file must be provided with values:
2323

24-
- `Client ID` - the ID of the client you want to create. This can be generated with an online UUID generator.
2524
- `Client Name` - the name of the client.
2625
- `APIM ID` - the APIM Application ID for the client.
2726

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
Client ID,Client Name,APIM ID
2-
test-client-id-1,Test Client,test-apim-id-1
1+
Client Name,APIM ID
2+
Test Client,test-apim-id-1

packages/event-builder/src/__tests__/build-client-changed-event.spec.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { buildEvent } from "../event-builder";
33
describe("test clientChangedEvent builder function", () => {
44
it("should successfully build a clientChangedEvent", () => {
55
const testInput = {
6-
clientId: "test-client-id",
76
clientName: "Test Client",
87
apimId: "test-apim-id",
98
};
@@ -14,7 +13,6 @@ describe("test clientChangedEvent builder function", () => {
1413
"type",
1514
"uk.nhs.notify.client-config.ClientChanged.v1",
1615
);
17-
expect(event.data.id).toBe("test-client-id");
1816
expect(event.data.name).toBe("Test Client");
1917
expect(event.data.apimApplication).toEqual(
2018
expect.objectContaining({

packages/event-builder/src/__tests__/convert-csv-to-client-input.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { convertCSV } from "../csv-to-client-input";
44
const invalidCases = [
55
{ type: "invalid headers", relativePath: "test-data/invalid-headers.csv", msg: "CSV headers do not match expected." },
66
{ type: "empty rows", relativePath: "test-data/empty-rows.csv", msg: "No client data provided." },
7-
{ type: "missing data in row", relativePath: "test-data/missing-data.csv", msg: "Missing data in row for client ID: client-id-1." }
7+
{ type: "missing data in row", relativePath: "test-data/missing-data.csv", msg: "Missing data in row for client: Test Client 1." }
88
]
99

1010
describe("test that csv inputs get parsed as expected", () => {
@@ -17,7 +17,7 @@ describe("test that csv inputs get parsed as expected", () => {
1717
expect(() => convertCSV(filePath)).not.toThrow();
1818

1919
expect(result).toHaveLength(4);
20-
expect(result.map(item => item.clientId)).toEqual((["1","2","3","4"]));
20+
expect(result.map(item => item.clientName)).toEqual(["Test Client 1", "Test Client 2", "Test Client 3", "Test Client 4"]);
2121
});
2222

2323
it.each(invalidCases)('should throw error: "%s" for case: %s:', ({ msg, type, relativePath }) => {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Client ID,Client Name,APIM ID
1+
Client Name,APIM ID
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
Invalid ID,Client Name,APIM ID
2-
client-id-1,Test Client 1,test-apim-id-1
1+
Invalid Name,APIM ID
2+
Test Client 1,test-apim-id-1
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
Client ID,Client Name,APIM ID
2-
client-id-1,Test Client 1,
1+
Client Name,APIM ID
2+
Test Client 1,
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
Client ID,Client Name,APIM ID
2-
1,Test Client 1,test-apim-id-1
3-
2,Test Client 2,test-apim-id-2
4-
3,Test Client 3,test-apim-id-3
5-
4,Test Client 4,test-apim-id-4
1+
Client Name,APIM ID
2+
Test Client 1,test-apim-id-1
3+
Test Client 2,test-apim-id-2
4+
Test Client 3,test-apim-id-3
5+
Test Client 4,test-apim-id-4

packages/event-builder/src/cli/index.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ async function main() {
3535
.option('format', {
3636
type: 'string',
3737
choices: ['json', 'table'],
38-
default: 'json',
38+
default: 'table',
3939
global: true,
4040
demandOption: false,
4141
})
@@ -62,7 +62,13 @@ async function main() {
6262

6363
sendSQSBatchMessages(results)
6464
.then(() => {
65-
print("Event(s) successfully sent to queue");
65+
const outputs = results.map(r => ({
66+
"Client": r.data.name,
67+
"ID": r.data.id
68+
}));
69+
70+
console.log("Event(s) successfully sent to queue");
71+
print(outputs);
6672
})
6773

6874
} catch (err) {

packages/event-builder/src/csv-to-client-input.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@ import { parse } from "csv-parse/sync";
33
import { ClientInput } from './input'
44

55
type csvRow = {
6-
'Client ID': string;
76
'Client Name': string;
87
'APIM ID': string;
98
};
109

1110
const csvHeaders = [
12-
"Client ID",
1311
"Client Name",
1412
"APIM ID"
1513
]
@@ -35,11 +33,10 @@ const generateInputs = (input: string): ClientInput[] => {
3533

3634
fileData.forEach((row: csvRow) => {
3735
if(!validateRow(row)) {
38-
throw new Error(`Missing data in row for client ID: ${row["Client ID"]}.`)
36+
throw new Error(`Missing data in row for client: ${row["Client Name"]}.`)
3937
}
4038

4139
clients.push({
42-
clientId: row["Client ID"],
4340
clientName: row["Client Name"],
4441
apimId: row["APIM ID"]
4542
});

0 commit comments

Comments
 (0)