-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: update proxy tests for cm360 (#3039)
- Loading branch information
Showing
17 changed files
with
2,257 additions
and
811 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
import { z } from 'zod'; | ||
import { isDefinedAndNotNullAndNotEmpty } from '@rudderstack/integrations-lib'; | ||
import { isHttpStatusSuccess } from '../v0/util'; | ||
|
||
export const ProxyMetadataSchema = z.object({ | ||
jobId: z.number(), | ||
attemptNum: z.number(), | ||
userId: z.string(), | ||
sourceId: z.string(), | ||
destinationId: z.string(), | ||
workspaceId: z.string(), | ||
secret: z.record(z.unknown()), | ||
destInfo: z.object({}).optional(), | ||
omitempty: z.record(z.unknown()).optional(), | ||
dontBatch: z.boolean(), | ||
}); | ||
|
||
export const ProxyV0RequestSchema = z.object({ | ||
version: z.string(), | ||
type: z.string(), | ||
method: z.string(), | ||
endpoint: z.string(), | ||
userId: z.string(), | ||
headers: z.record(z.unknown()).optional(), | ||
params: z.record(z.unknown()).optional(), | ||
body: z | ||
.object({ | ||
JSON: z.record(z.unknown()).optional(), | ||
JSON_ARRAY: z.record(z.unknown()).optional(), | ||
XML: z.record(z.unknown()).optional(), | ||
FORM: z.record(z.unknown()).optional(), | ||
}) | ||
.optional(), | ||
files: z.record(z.unknown()).optional(), | ||
metadata: ProxyMetadataSchema, | ||
destinationConfig: z.record(z.unknown()), | ||
}); | ||
|
||
export const ProxyV1RequestSchema = z.object({ | ||
version: z.string(), | ||
type: z.string(), | ||
method: z.string(), | ||
endpoint: z.string(), | ||
userId: z.string(), | ||
headers: z.record(z.unknown()).optional(), | ||
params: z.record(z.unknown()).optional(), | ||
body: z | ||
.object({ | ||
JSON: z.record(z.unknown()).optional(), | ||
JSON_ARRAY: z.record(z.unknown()).optional(), | ||
XML: z.record(z.unknown()).optional(), | ||
FORM: z.record(z.unknown()).optional(), | ||
}) | ||
.optional(), | ||
files: z.record(z.unknown()).optional(), | ||
metadata: z.array(ProxyMetadataSchema), | ||
destinationConfig: z.record(z.unknown()), | ||
}); | ||
|
||
const validateStatTags = (data: any) => { | ||
if (!isHttpStatusSuccess(data.status)) { | ||
return isDefinedAndNotNullAndNotEmpty(data.statTags); | ||
} | ||
return true; | ||
}; | ||
|
||
const validateAuthErrorCategory = (data: any) => { | ||
if (!isHttpStatusSuccess(data.status)) { | ||
return isDefinedAndNotNullAndNotEmpty(data.authErrorCategory); | ||
} | ||
return true; | ||
}; | ||
|
||
export const DeliveryV0ResponseSchema = z | ||
.object({ | ||
status: z.number(), | ||
message: z.string(), | ||
destinationResponse: z.unknown(), | ||
statTags: z.record(z.unknown()).optional(), | ||
authErrorCategory: z.string().optional(), | ||
}) | ||
.refine(validateStatTags, { | ||
// eslint-disable-next-line sonarjs/no-duplicate-string | ||
message: "statTags can't be empty when status is not a 2XX", | ||
path: ['statTags'], // Pointing out which field is invalid | ||
}); | ||
|
||
export const DeliveryV0ResponseSchemaForOauth = z | ||
.object({ | ||
status: z.number(), | ||
message: z.string(), | ||
destinationResponse: z.unknown(), | ||
statTags: z.record(z.unknown()).optional(), | ||
authErrorCategory: z.string().optional(), | ||
}) | ||
.refine(validateStatTags, { | ||
message: "statTags can't be empty when status is not a 2XX", | ||
path: ['statTags'], // Pointing out which field is invalid | ||
}) | ||
.refine(validateAuthErrorCategory, { | ||
message: "authErrorCategory can't be empty when status is not a 2XX", | ||
path: ['authErrorCategory'], // Pointing out which field is invalid | ||
}); | ||
|
||
const DeliveryJobStateSchema = z.object({ | ||
error: z.string(), | ||
statusCode: z.number(), | ||
metadata: ProxyMetadataSchema, | ||
}); | ||
|
||
export const DeliveryV1ResponseSchema = z | ||
.object({ | ||
status: z.number(), | ||
message: z.string(), | ||
statTags: z.record(z.unknown()).optional(), | ||
authErrorCategory: z.string().optional(), | ||
response: z.array(DeliveryJobStateSchema), | ||
}) | ||
.refine(validateStatTags, { | ||
message: "statTags can't be empty when status is not a 2XX", | ||
path: ['statTags'], // Pointing out which field is invalid | ||
}); | ||
|
||
export const DeliveryV1ResponseSchemaForOauth = z | ||
.object({ | ||
status: z.number(), | ||
message: z.string(), | ||
statTags: z.record(z.unknown()).optional(), | ||
authErrorCategory: z.string().optional(), | ||
response: z.array(DeliveryJobStateSchema), | ||
}) | ||
.refine(validateStatTags, { | ||
message: "statTags can't be empty when status is not a 2XX", | ||
path: ['statTags'], // Pointing out which field is invalid | ||
}) | ||
.refine(validateAuthErrorCategory, { | ||
message: "authErrorCategory can't be empty when status is not a 2XX", | ||
path: ['authErrorCategory'], // Pointing out which field is invalid | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
// Ads API | ||
// Ref: https://developers.google.com/google-ads/api/docs/get-started/common-errors | ||
|
||
export const networkCallsData = [ | ||
{ | ||
description: 'Mock response depicting CREDENTIALS_MISSING error', | ||
httpReq: { | ||
method: 'post', | ||
url: 'https://googleapis.com/test_url_for_credentials_missing', | ||
}, | ||
httpRes: { | ||
data: { | ||
error: { | ||
code: 401, | ||
message: | ||
'Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.', | ||
errors: [ | ||
{ | ||
message: 'Login Required.', | ||
domain: 'global', | ||
reason: 'required', | ||
location: 'Authorization', | ||
locationType: 'header', | ||
}, | ||
], | ||
status: 'UNAUTHENTICATED', | ||
details: [ | ||
{ | ||
'@type': 'type.googleapis.com/google.rpc.ErrorInfo', | ||
reason: 'CREDENTIALS_MISSING', | ||
domain: 'googleapis.com', | ||
metadata: { | ||
method: 'google.ads.xfa.op.v4.DfareportingConversions.Batchinsert', | ||
service: 'googleapis.com', | ||
}, | ||
}, | ||
], | ||
}, | ||
}, | ||
status: 401, | ||
}, | ||
}, | ||
{ | ||
description: 'Mock response depicting ACCESS_TOKEN_SCOPE_INSUFFICIENT error', | ||
httpReq: { | ||
method: 'post', | ||
url: 'https://googleapis.com/test_url_for_access_token_scope_insufficient', | ||
}, | ||
httpRes: { | ||
data: { | ||
error: { | ||
code: 403, | ||
message: 'Request had insufficient authentication scopes.', | ||
errors: [ | ||
{ | ||
message: 'Insufficient Permission', | ||
domain: 'global', | ||
reason: 'insufficientPermissions', | ||
}, | ||
], | ||
status: 'PERMISSION_DENIED', | ||
details: [ | ||
{ | ||
'@type': 'type.googleapis.com/google.rpc.ErrorInfo', | ||
reason: 'ACCESS_TOKEN_SCOPE_INSUFFICIENT', | ||
domain: 'googleapis.com', | ||
metadata: { | ||
service: 'gmail.googleapis.com', | ||
method: 'caribou.api.proto.MailboxService.GetProfile', | ||
}, | ||
}, | ||
], | ||
}, | ||
}, | ||
status: 403, | ||
}, | ||
}, | ||
{ | ||
description: 'Mock response for google.auth.exceptions.RefreshError invalid_grant error', | ||
httpReq: { | ||
method: 'post', | ||
url: 'https://googleapis.com/test_url_for_invalid_grant', | ||
}, | ||
httpRes: { | ||
data: { | ||
error: { | ||
code: 403, | ||
message: 'invalid_grant', | ||
error_description: 'Bad accesss', | ||
}, | ||
}, | ||
status: 403, | ||
}, | ||
}, | ||
{ | ||
description: 'Mock response for google.auth.exceptions.RefreshError refresh_token error', | ||
httpReq: { | ||
method: 'post', | ||
url: 'https://googleapis.com/test_url_for_refresh_error', | ||
}, | ||
httpRes: { | ||
data: { | ||
error: 'unauthorized', | ||
error_description: 'Access token expired: 2020-10-20T12:00:00.000Z', | ||
}, | ||
status: 401, | ||
}, | ||
}, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
export const networkCallsData = [ | ||
{ | ||
description: 'Mock response depicting SERVICE NOT AVAILABLE error', | ||
httpReq: { | ||
method: 'post', | ||
url: 'https://random_test_url/test_for_service_not_available', | ||
}, | ||
httpRes: { | ||
data: { | ||
error: { | ||
message: 'Service Unavailable', | ||
description: | ||
'The server is currently unable to handle the request due to temporary overloading or maintenance of the server. Please try again later.', | ||
}, | ||
}, | ||
status: 503, | ||
}, | ||
}, | ||
{ | ||
description: 'Mock response depicting INTERNAL SERVER ERROR error', | ||
httpReq: { | ||
method: 'post', | ||
url: 'https://random_test_url/test_for_internal_server_error', | ||
}, | ||
httpRes: { | ||
data: 'Internal Server Error', | ||
status: 500, | ||
}, | ||
}, | ||
{ | ||
description: 'Mock response depicting GATEWAY TIME OUT error', | ||
httpReq: { | ||
method: 'post', | ||
url: 'https://random_test_url/test_for_gateway_time_out', | ||
}, | ||
httpRes: { | ||
data: 'Gateway Timeout', | ||
status: 504, | ||
}, | ||
}, | ||
{ | ||
description: 'Mock response depicting null response', | ||
httpReq: { | ||
method: 'post', | ||
url: 'https://random_test_url/test_for_null_response', | ||
}, | ||
httpRes: { | ||
data: null, | ||
status: 500, | ||
}, | ||
}, | ||
{ | ||
description: 'Mock response depicting null and no status', | ||
httpReq: { | ||
method: 'post', | ||
url: 'https://random_test_url/test_for_null_and_no_status', | ||
}, | ||
httpRes: { | ||
data: null, | ||
}, | ||
}, | ||
]; |
Oops, something went wrong.