Skip to content

Commit

Permalink
chore: added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kanishkkatara committed May 23, 2024
1 parent 732fbf4 commit e6a3dbb
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 0 deletions.
57 changes: 57 additions & 0 deletions test/__tests__/data/user_transformation_input_credentials.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
[
{
"message": {
"channel": "web",
"context": {
"app": {
"build": "1.0.0",
"name": "RudderLabs JavaScript SDK",
"namespace": "com.rudderlabs.javascript",
"version": "1.0.0"
},
"traits": {
"email": "[email protected]",
"anonymousId": "12345"
},
"library": {
"name": "RudderLabs JavaScript SDK",
"version": "1.0.0"
},
"userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36",
"locale": "en-US",
"ip": "0.0.0.0",
"os": {
"name": "",
"version": ""
},
"screen": {
"density": 2
}
},
"type": "track",
"messageId": "ec5481b6-a926-4d2e-b293-0b3a77c4d3be",
"originalTimestamp": "2019-10-14T11:15:18.300Z",
"anonymousId": "00000000000000000000000000",
"userId": "12345",
"event": "test track event GA3",
"properties": {
"user_actual_role": "system_admin, system_user",
"user_actual_id": 12345
},
"integrations": {
"All": true
},
"sentAt": "2019-10-14T11:15:53.296Z"
},
"destination": {
"Config": {
"trackingID": "UA-149602794-1"
},
"Enabled": true
},
"credentials": {
"key1": "value1",
"key2": "value2"
}
}
]
28 changes: 28 additions & 0 deletions test/__tests__/user_transformation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,34 @@ describe("User transformation", () => {
expect(output[0].transformedEvent.dummy_key).toEqual(secrets.dummy_key);
});

it(`Simple ${name} Test with credentials for codeVersion 1`, async () => {
const versionId = randomID();

const inputData = require(`./data/${integration}_input_credentials.json`);

const respBody = {
versionId: versionId,
codeVersion: "1",
name,
code: `
export function transformEvent(event, metadata) {
event.credentialValue = credentials("key1");
return event;
}
`
};
fetch.mockResolvedValue({
status: 200,
json: jest.fn().mockResolvedValue(respBody)
});

const output = await userTransformHandler(inputData, versionId, []);
expect(fetch).toHaveBeenCalledWith(
`https://api.rudderlabs.com/transformation/getByVersionId?versionId=${versionId}`
);
expect(output[0].transformedEvent.credentialValue).toEqual("value1");
});

it(`Simple async ${name} FetchV2 Test for V0 transformation`, async () => {
const versionId = randomID();
const inputData = require(`./data/${integration}_input.json`);
Expand Down

0 comments on commit e6a3dbb

Please sign in to comment.