Skip to content

Commit

Permalink
fix: add test coverage for processMetadata function (#1567)
Browse files Browse the repository at this point in the history
  • Loading branch information
utsabc authored Nov 14, 2022
1 parent 0ecf278 commit b438daa
Show file tree
Hide file tree
Showing 8 changed files with 257 additions and 3 deletions.
17 changes: 17 additions & 0 deletions __tests__/azure_event_hub.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ const outputDataFile = fs.readFileSync(
path.resolve(__dirname, `./data/${integration}_output.json`)
);

const dataWithMetadata = fs.readFileSync(
path.resolve(__dirname, `./data/${integration}_with_metadata.json`)
);

const inputData = JSON.parse(inputDataFile);
const expectedData = JSON.parse(outputDataFile);

Expand All @@ -27,3 +31,16 @@ inputData.forEach((input, index) => {
}
});
});

test(`${name} Metadata parse test`, done => {
const inputData = JSON.parse(dataWithMetadata);
inputData.forEach(async (data, _) => {
try {
const output = transformer.processMetadata(data.input);
expect(output).toEqual(data.output);
done();
} catch (error) {
done(error);
}
});
});
17 changes: 17 additions & 0 deletions __tests__/confluent_cloud.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ const outputDataFile = fs.readFileSync(
path.resolve(__dirname, `./data/${integration}_output.json`)
);

const dataWithMetadata = fs.readFileSync(
path.resolve(__dirname, `./data/${integration}_with_metadata.json`)
);

const inputData = JSON.parse(inputDataFile);
const expectedData = JSON.parse(outputDataFile);

Expand All @@ -27,3 +31,16 @@ inputData.forEach((input, index) => {
}
});
});

test(`${name} Metadata parse test`, done => {
const inputData = JSON.parse(dataWithMetadata);
inputData.forEach(async (data, _) => {
try {
const output = transformer.processMetadata(data.input);
expect(output).toEqual(data.output);
done();
} catch (error) {
done(error);
}
});
});
64 changes: 64 additions & 0 deletions __tests__/data/azure_event_hub_with_metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
[
{
"input": {
"outputEvent": {
"message": {
"anonymousId": "b255896a-94cd-4bf9-98d5-40389e4b70b8",
"channel": "web",
"event": "Purchase",
"messageId": "522224fe-9c65-4036-8f1f-980e39c6b342",
"originalTimestamp": "2020-05-14T06:54:08.745Z",
"properties": {
"currency": "USD",
"revenue": 100
},
"receivedAt": "2020-05-14T12:24:08.781+05:30",
"request_ip": "[::1]:53194",
"sentAt": "2020-05-14T06:54:08.746Z",
"timestamp": "2020-05-14T12:24:08.780+05:30",
"type": "track",
"userId": "user-12345"
},
"userId": "user-12345",
"topic": "default-topic"
},
"inputEvent": {
"message": {
"val": "add boilerplate values if needed"
},
"destination": {
"ID": "1bqCbmPnO0T7dTE159ho8wiyPlD",
"Name": "Azure Event Hub",
"DestinationDefinition": {},
"Config": {
"bootstrapServer": "pkc-4kgmg.us-east4.gcp.confluent.cloud:9092",
"topic": "default-topic",
"eventHubsConnectionString": "skajdkjaskdjkasio"
},
"Enabled": true,
"Transformations": [],
"IsProcessorEnabled": true
}
},
"metadata": {
"anonymousId": "b255896a-94cd-4bf9-98d5-40389e4b70b8",
"destinationId": "1bqCbmPnO0T7dTE159ho8wiyPlD",
"destinationType": "AZURE_EVENT_HUB",
"jobId": 12,
"messageId": "522224fe-9c65-4036-8f1f-980e39c6b342",
"sourceId": "1bqCEGibwCvR7F0acuLzbEMQYIC",
"rudderId": "b255896a-94cd-4bf9-98d5-40389e4b70b8<<>>user-12345"
}
},
"output": {
"anonymousId": "b255896a-94cd-4bf9-98d5-40389e4b70b8",
"destinationId": "1bqCbmPnO0T7dTE159ho8wiyPlD",
"destinationType": "AZURE_EVENT_HUB",
"jobId": 12,
"messageId": "522224fe-9c65-4036-8f1f-980e39c6b342",
"sourceId": "1bqCEGibwCvR7F0acuLzbEMQYIC",
"rudderId": "b255896a-94cd-4bf9-98d5-40389e4b70b8<<>>user-12345<<>>default-topic"
}
}
]

64 changes: 64 additions & 0 deletions __tests__/data/confluent_cloud_with_metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
[
{
"input": {
"outputEvent": {
"message": {
"anonymousId": "b255896a-94cd-4bf9-98d5-40389e4b70b8",
"channel": "web",
"event": "Purchase",
"messageId": "522224fe-9c65-4036-8f1f-980e39c6b342",
"originalTimestamp": "2020-05-14T06:54:08.745Z",
"properties": {
"currency": "USD",
"revenue": 100
},
"receivedAt": "2020-05-14T12:24:08.781+05:30",
"request_ip": "[::1]:53194",
"sentAt": "2020-05-14T06:54:08.746Z",
"timestamp": "2020-05-14T12:24:08.780+05:30",
"type": "track",
"userId": "user-12345"
},
"userId": "user-12345",
"topic": "default-topic"
},
"inputEvent": {
"message": {
"val": "add boilerplate values if needed"
},
"destination": {
"ID": "1bqCbmPnO0T7dTE159ho8wiyPlD",
"Name": "Confluent Cloud",
"DestinationDefinition": {},
"Config": {
"bootstrapServer": "pkc-4kgmg.us-east4.gcp.confluent.cloud:9092",
"topic": "default-topic",
"apiKey": "API_KEY",
"apiSecret": "API_SECRET"
},
"Enabled": true,
"Transformations": [],
"IsProcessorEnabled": true
}
},
"metadata": {
"anonymousId": "b255896a-94cd-4bf9-98d5-40389e4b70b8",
"destinationId": "1bqCbmPnO0T7dTE159ho8wiyPlD",
"destinationType": "CONFLUENT_CLOUD",
"jobId": 12,
"messageId": "522224fe-9c65-4036-8f1f-980e39c6b342",
"sourceId": "1bqCEGibwCvR7F0acuLzbEMQYIC",
"rudderId": "b255896a-94cd-4bf9-98d5-40389e4b70b8<<>>user-12345"
}
},
"output": {
"anonymousId": "b255896a-94cd-4bf9-98d5-40389e4b70b8",
"destinationId": "1bqCbmPnO0T7dTE159ho8wiyPlD",
"destinationType": "CONFLUENT_CLOUD",
"jobId": 12,
"messageId": "522224fe-9c65-4036-8f1f-980e39c6b342",
"sourceId": "1bqCEGibwCvR7F0acuLzbEMQYIC",
"rudderId": "b255896a-94cd-4bf9-98d5-40389e4b70b8<<>>user-12345<<>>default-topic"
}
}
]
76 changes: 76 additions & 0 deletions __tests__/data/kafka_with_metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
[
{
"input": {
"outputEvent": {
"message":{
"anonymousId": "b255896a-94cd-4bf9-98d5-40389e4b70b8",
"channel": "web",
"event": "Purchase",
"integrations": {
"All": true,
"KAFKA": {
"topic": "specific-topic"
}
},
"messageId": "522224fe-9c65-4036-8f1f-980e39c6b342",
"originalTimestamp": "2020-05-14T06:54:08.745Z",
"properties": {
"currency": "USD",
"revenue": 100
},
"receivedAt": "2020-05-14T12:24:08.781+05:30",
"request_ip": "[::1]:53194",
"sentAt": "2020-05-14T06:54:08.746Z",
"timestamp": "2020-05-14T12:24:08.780+05:30",
"type": "track",
"userId": "user-12345"
},
"userId": "user-12345",
"topic": "specific-topic"
},
"inputEvent": {
"message": {
"val": "add boilerplate values if needed"
},
"destination": {
"ID": "1bqCbmPnO0T7dTE159ho8wiyPlD",
"Name": "Kafka",
"DestinationDefinition": {},
"Config": {
"caCertificate": "",
"hostName": "localhost",
"password": "password",
"port": "29092",
"saslType": "sha256",
"sslEnabled": true,
"topic": "default-topic",
"useSASL": true,
"username": "username"
},
"Enabled": true,
"Transformations": [],
"IsProcessorEnabled": true
}
},
"metadata": {
"anonymousId": "b255896a-94cd-4bf9-98d5-40389e4b70b8",
"destinationId": "1bqCbmPnO0T7dTE159ho8wiyPlD",
"destinationType": "KAFKA",
"jobId": 15,
"messageId": "522224fe-9c65-4036-8f1f-980e39c6b342",
"sourceId": "1bqCEGibwCvR7F0acuLzbEMQYIC",
"rudderId": "b255896a-94cd-4bf9-98d5-40389e4b70b8<<>>user-12345"
}

},
"output": {
"anonymousId": "b255896a-94cd-4bf9-98d5-40389e4b70b8",
"destinationId": "1bqCbmPnO0T7dTE159ho8wiyPlD",
"destinationType": "KAFKA",
"jobId": 15,
"messageId": "522224fe-9c65-4036-8f1f-980e39c6b342",
"sourceId": "1bqCEGibwCvR7F0acuLzbEMQYIC",
"rudderId": "b255896a-94cd-4bf9-98d5-40389e4b70b8<<>>user-12345<<>>specific-topic"
}
}
]
19 changes: 19 additions & 0 deletions __tests__/kafka.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ const batchOutputDataFile = fs.readFileSync(
path.resolve(__dirname, `./data/${integration}_batch_output.json`)
);

const dataWithMetadata = fs.readFileSync(
path.resolve(__dirname, `./data/${integration}_with_metadata.json`)
)



describe("Tests", () => {
test(`${name} Tests`, () => {
const inputDataFile = fs.readFileSync(
Expand All @@ -36,4 +42,17 @@ describe("Tests", () => {
expect(Array.isArray(output)).toEqual(true);
expect(output).toEqual(batchExpectedData);
});

test(`${name} Metadata parse test`, done => {
const inputData = JSON.parse(dataWithMetadata);
inputData.forEach(async (data, _) => {
try {
const output = transformer.processMetadata(data.input);
expect(output).toEqual(data.output);
done();
} catch (error) {
done(error);
}
});
})
});
1 change: 0 additions & 1 deletion v0/destinations/azure_event_hub/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,5 @@ function processMetadata(input) {
}
return clonedMetadata;
}
exports.process = process;

module.exports = { process, processMetadata };
2 changes: 0 additions & 2 deletions v0/destinations/confluent_cloud/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,3 @@ function processMetadata(input) {
return clonedMetadata;
}
module.exports = { process, processMetadata };

exports.process = process;

0 comments on commit b438daa

Please sign in to comment.