Skip to content

Commit

Permalink
chore: 1
Browse files Browse the repository at this point in the history
  • Loading branch information
Chandra shekar Varkala committed Feb 6, 2024
1 parent c7c3110 commit b13f017
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 2 deletions.
11 changes: 10 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@
"ua-parser-js": "^1.0.37",
"unset-value": "^2.0.1",
"uuid": "^9.0.0",
"valid-url": "^1.0.9"
"valid-url": "^1.0.9",
"zod": "^3.22.4"
},
"devDependencies": {
"@commitlint/config-conventional": "^17.6.3",
Expand Down
99 changes: 99 additions & 0 deletions test/integrations/testTypes.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { AxiosResponse } from 'axios';
import { ZodTypeAny, z } from 'zod';
import MockAdapter from 'axios-mock-adapter';
import { FEATURES } from '../../src/v0/util/tags';

export interface requestType {
method: string;
Expand Down Expand Up @@ -44,3 +46,100 @@ export type MockHttpCallsData = {
httpReq: Record<string, any>;
httpRes: Partial<AxiosResponse>;
};

export const arrayOrSingleElement = (schema: ZodTypeAny) => z.union([z.array(schema), schema]);

export const formElementSchema = arrayOrSingleElement(
z.union([z.string(), z.number(), z.boolean()]),
);

export const eventResponseSchema = z.union([
z.object({
error: z.string(),
statTags: z
.object({
destType: z.string().optional(),
errorCategory: z.string().optional(),
errorType: z.string().optional(),
feature: z.nativeEnum(FEATURES).optional(),
implementation: z.string().optional(),
module: z.string().optional(),
})
.optional(),
statusCode: z.number().optional(),
}),
z.object({
output: z
.object({
version: z.string().optional(),
type: z.string().optional(),
method: z.string().optional(),
endpoint: z.string().optional(),
headers: z.record(z.string(), z.string()).optional(),
params: z.record(z.string(), z.any()).optional(),
body: z
.object({
JSON: z.record(z.string(), z.any()).optional(),
XML: z
.object({
payload: z.string().optional(),
})
.optional(),
JSON_ARRAY: z
.object({
batch: z.any().optional(),
})
.optional(),
FORM: z.record(z.string(), formElementSchema).optional(),
GZIP: z
.object({
payload: z.string().optional(),
})
.optional(),
})
.optional(),
files: z.record(z.string(), z.any()).optional(),
userId: z.string().optional(),
})
.optional(),
metadata: z.record(z.string(), z.any()).optional(),
statusCode: z.number().optional(),
}),
]);

export const batchTransformSchema = z.array(
z.object({
batchedRequest: arrayOrSingleElement(eventResponseSchema).optional(),
metadata: z.array(z.record(z.string(), z.any())).optional(),
destination: z
.object({
ID: z.string().optional(),
Name: z.string().optional(),
DestinationDefinition: z
.object({
ID: z.string().optional(),
Name: z.string().optional(),
DisplayName: z.string().optional(),
Config: z.any().optional(),
ResponseRules: z.any().optional(),
})
.optional(),
Config: z.any().optional(),
Enabled: z.boolean().optional(),
WorkspaceID: z.string().optional(),
Transformations: z.any().optional(),
IsProcessorEnabled: z.boolean().optional(),
RevisionID: z.string().optional(),
})
.optional(),
batched: z.boolean().optional(),
statusCode: z.number().optional(),
error: z.string().optional(),
}),
);

export const routerTransformSchema = z.object({
output: batchTransformSchema,
});

export const processorTransformSchema = z.array(eventResponseSchema);

0 comments on commit b13f017

Please sign in to comment.