Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ga user delete support #1531

Merged
merged 24 commits into from
Nov 24, 2022
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
0adfdc7
feat: regulation api support for universal analytics initial commit
Oct 30, 2022
60d9db3
modify deleteUsers api to include errorCategory, auth to send delete …
Oct 31, 2022
5489a5c
Merge branch 'master' of github.com:rudderlabs/rudder-transformer int…
Oct 31, 2022
3762c5d
- correctly getting status code while error is thrown (using ErrorBui…
Nov 2, 2022
af49cc3
adding secret validation
Nov 2, 2022
693cd27
remove unnecessary code
Nov 2, 2022
13e75c5
Merge branches 'feat.ga-reg-support' and 'master' of github.com:rudde…
Nov 2, 2022
d9e07fb
Merge branch 'master' of github.com:rudderlabs/rudder-transformer int…
Nov 3, 2022
a07d9bb
add first successful test-case for ga delete support
Nov 3, 2022
50ddc91
Merge branch 'master' of github.com:rudderlabs/rudder-transformer int…
Nov 8, 2022
a8dabcb
remove comment
Nov 8, 2022
646c553
Merge branch 'master' of github.com:rudderlabs/rudder-transformer int…
Nov 9, 2022
184e932
rename variable
Nov 10, 2022
da3e0e3
new convention of parsing responses
Nov 10, 2022
dc6ca1c
feat: move deleteusers tests to a separate file (#1551)
sanpj2292 Nov 14, 2022
7d8c899
Merge branch 'master' of github.com:rudderlabs/rudder-transformer int…
Nov 14, 2022
1e4f1a9
Merge branch 'feat.ga-reg-support' of github.com:rudderlabs/rudder-tr…
Nov 14, 2022
002f837
extending common validations functions in all delete users supported …
Nov 15, 2022
35076b0
Merge branch 'master' of github.com:rudderlabs/rudder-transformer int…
Nov 15, 2022
4dba63f
add test-case for erreneous scenario in a deleteUser request
Nov 15, 2022
a5f13f5
support for exclusion of destination for troubleshooting
Nov 16, 2022
7bcde13
Merge branch 'master' of github.com:rudderlabs/rudder-transformer int…
Nov 17, 2022
310d6c3
Merge branch 'master' of github.com:rudderlabs/rudder-transformer int…
Nov 22, 2022
02c0896
Merge branch 'master' of github.com:rudderlabs/rudder-transformer int…
Nov 23, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 87 additions & 0 deletions __mocks__/gen-axios.mock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
const axios = require("axios");
const logger = require("../logger");
const { isHttpStatusSuccess } = require("../v0/util");
jest.mock("axios");

/**
* Forms the mock axios client
* This client is used in cases where each response is returned almost immediately
*
* **Limitations**:
* - This mock client would not be useful for scenarios where parallel requests will be made(with randomly responding to requests)
* - This mock client would not be useful in-case there are delays needed in responding to requests
*
* @param {Array<{type: 'constructor'|'get'|'post'|'delete', response: any }>} responsesData
* @returns
*/
const formAxiosMock = responsesData => {
const returnVal = ({ resp, mockInstance }) => {
if (isHttpStatusSuccess(resp.response.status)) {
mockInstance.mockResolvedValueOnce(resp.response);
} else {
mockInstance.mockRejectedValueOnce(resp.response);
}
};


if (Array.isArray(responsesData)) {
const constructorMock = jest.fn();
const postMock = jest.fn();
const getMock = jest.fn();
const deleteMock = jest.fn();
responsesData.flat().forEach(resp => {
let mockInstance;
switch (resp.type) {
case "constructor":
mockInstance = constructorMock;
break;
case "get":
mockInstance = getMock;
break;
case "delete":
mockInstance = deleteMock;
break;

default:
mockInstance = postMock;
break;
}
let methodParams = { resp, mockInstance };
// validateMockClientReqParams(methodParams);
returnVal(methodParams);
});
axios.get = getMock;
axios.post = postMock;
axios.delete = deleteMock;
axios.mockImplementation(constructorMock);
}
return axios;
};

const validateMockAxiosClientReqParams = ({ resp }) => {
let mockInstance;
switch (resp.type) {
case "constructor":
mockInstance = axios;
break;
case "get":
mockInstance = axios.get;
break;
case "delete":
mockInstance = axios.delete;
break;

default:
mockInstance = axios.post;
break;
}
if (Array.isArray(resp?.reqParams)) {
try {
expect(mockInstance).toHaveBeenCalledWith(...resp.reqParams);
} catch (error) {
logger.error(`Validate request parameters error ${resp.type} for mock axios client: ${error}`)
}
}
}

module.exports = { formAxiosMock, validateMockAxiosClientReqParams };
34 changes: 34 additions & 0 deletions __tests__/deleteUsers/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# DeleteUsers Tests

All the tests data for deleteUsers are to be present in __tests__/data/deleteUsers/${destination}/

### Files and their significance
- __`handler_input.json`__ - Input data for `handleDeletionOfUsers` function in `versionedRouter.js`(alias for `_deleteUsers_proxy_input.json`)
- __`handler_output.json`__ - Output of `handleDeletionOfUsers` function in `versionedRouter.js`(alias for `_deleteUsers_proxy_output.json`)
- __`nw_client_data.json`__ - the mock http responses(An example can be seen in the case of `ga`)

### Fields in new files

#### nw_client_data.json

- Type: Array<Array<object>>
- The array of object is how many responses have to be sent back
- Each of the object contains below mentioned fields
- type:
- Indicates what type of http client invocation it is
- Recommended to be sent
- Supported values:
- post
- get
- delete
- constructor
- if nothing is mentioned, `post` is considered by default
- reqParams:
- Type: Array<any>
- Optional
- Indicates the expected arguments that are to be sent to the http client instance
- We would `recommend` to also add this as part of your `nw_client_data.json`
- response:
- Type: object
- Required
- The response that needs to be returned from the http client
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
],
[
{
"statusCode": 400,
"statusCode": 500,
"error": "androidAppId is required for android_advertising_id type identifier"
}
],
[
{
"statusCode": 400,
"statusCode": 500,
"error": "appleAppId is required for ios_advertising_id type identifier"
}
],
Expand Down
83 changes: 83 additions & 0 deletions __tests__/deleteUsers/data/ga/handler_input.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
[
{
"getValue": {
"x-rudder-dest-info": "{\"secret\": { \"access_token\": \"valid_token\" }}"
},
"request": {
"body": [
{
"destType": "GA",
"userAttributes": [
{
"userId": "test_user_1"
},
{
"userId": "test_user_2"
}
],
"config": {
"trackingID": "UA-123456789-5",
"useNativeSDK": false
}
}
]
}
},
{
"getValue": {
"x-rudder-dest-info": "{\"secret\": { \"access_token\": \"expired_token\" }}"
},
"request": {
"body": [
{
"destType": "GA",
"userAttributes": [
{
"userId": "test_user_3"
},
{
"userId": "test_user_4"
}
],
"config": {
"trackingID": "UA-123456789-6",
"useNativeSDK": false
}
}
]
}
},
{
"getValue": {
"x-rudder-dest-info": "{\"secret\": { \"access_token\": \"valid_token_1\" }}"
},
"request": {
"body": [
{
"destType": "GA",
"userAttributes": [
{
"userId": "test_user_5"
},
{
"userId": "test_user_6"
},
{
"userId": "test_user_7"
},
{
"userId": "test_user_8"
},
{
"userId": "test_user_9"
}
],
"config": {
"trackingID": "UA-123456789-7",
"useNativeSDK": false
}
}
]
}
}
]
21 changes: 21 additions & 0 deletions __tests__/deleteUsers/data/ga/handler_output.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[
[
{
"statusCode": 200,
"status": "successful"
}
],
[
{
"statusCode": 500,
"authErrorCategory": "REFRESH_TOKEN",
"error": "[GA] invalid credentials"
}
],
[
{
"statusCode": 403,
"error": "[GA] Error occurred while completing deletion request: [dummy response] The parameter used to query is not correct"
}
]
]
Loading