@syngrisi/syngrisi
Version:
Syngrisi - Visual Testing Tool
429 lines (425 loc) • 13 kB
JavaScript
// src/server/schemas/Client.schema.ts
import { z as z3 } from "zod";
// src/server/schemas/utils/commonValidations.ts
import { z as z2 } from "zod";
import { extendZodWithOpenApi as extendZodWithOpenApi2 } from "@asteasolutions/zod-to-openapi";
// src/server/schemas/common/Version.schema.ts
import { z } from "zod";
import { extendZodWithOpenApi } from "@asteasolutions/zod-to-openapi";
extendZodWithOpenApi(z);
var VersionBaseSchema = z.string().regex(/^\d+\.\d+\.\d+$/, 'Version must be in the format "x.y.z"');
var VersionSchema = VersionBaseSchema.transform((value) => {
const parts = value.split(".");
return {
major: parseInt(parts[0]),
minor: parseInt(parts[1]),
patch: parseInt(parts[2])
};
});
// src/server/schemas/utils/commonValidations.ts
extendZodWithOpenApi2(z2);
var mongooseIdRegex = /^[0-9a-fA-F]{24}$/;
var id = z2.string().regex(mongooseIdRegex, {
message: "Invalid Mongoose ObjectId format: /^[0-9a-fA-F]{24}$/"
}).openapi({
description: "baseline ID",
example: "6bbF35cAB3C59dA969edAe79"
});
var commonValidations = {
id,
version: VersionBaseSchema.openapi({ example: "1.1.2" }),
positiveNumberString: z2.string().refine((value) => {
const num = Number(value);
return Number.isInteger(num) && num >= 0;
}, {
message: "String must be a positive number or 0"
}),
password: z2.string().min(6).regex(/(?=.*[0-9])/, "Password must include a number").regex(/(?=.*[a-z])/, "Password must include a lowercase letter").regex(/(?=.*[A-Z])/, "Password must include an uppercase letter").refine((value) => {
return /(?=.*[!@#$%^&*(),.?":{}|<>-])/.test(value);
}, {
message: "Password must include a special symbol"
}).openapi({ example: "Aa1!IJASSNOJ" }),
username: z2.string().min(1).openapi({ example: "john.doe@example.com" }),
// TODO: workaround TBD
date: z2.string().refine((val) => {
const date = new Date(val);
return !isNaN(date.getTime());
}, {
message: "Invalid date format"
}),
paramsId: { params: z2.object({ id }) },
paramsTestId: { params: z2.object({ testid: id }) },
success: z2.object({
message: z2.literal("success")
})
};
// src/server/schemas/Client.schema.ts
var ClientStartSessionSchema = z3.object({
name: z3.string().min(1).openapi({
description: "Name of the session",
example: "Login test"
}),
app: z3.string().min(1).openapi({
description: "Application name",
example: "My project"
}),
tags: z3.string().openapi({
description: "Tags associated with the session",
example: '["@smoke", "@PJ-231"]'
}).optional(),
branch: z3.string().min(1).openapi({
description: "Branch name",
example: "master"
}),
viewport: z3.string().min(1).openapi({
description: "Viewport size",
example: "1366x768"
}),
browser: z3.string().min(1).openapi({
description: "Browser name",
example: "chrome"
}),
browserVersion: z3.string().min(1).openapi({
description: "Browser version",
example: "125"
}),
browserFullVersion: z3.string().min(1).openapi({
description: "Browser full version",
example: "125.12.56.001"
}).optional(),
os: z3.string().min(1).openapi({
description: "Operating system",
example: "macOS"
}),
run: z3.string().min(1).openapi({
description: "Run name",
example: "Build #123"
}),
runident: z3.string().min(1).openapi({
description: "Run identifier",
example: "978ee42c-78f8-40f4-8954-51ebc08d1718"
}),
suite: z3.string().min(1).openapi({
description: "Suite name",
example: "Smoke tests"
})
});
var ClientStartSessionResponseSchema = z3.object({
name: z3.string().openapi({
description: "Name of the session",
example: "Login test"
}),
status: z3.string().openapi({
description: "Status of the session",
example: "Running"
}),
browserName: z3.string().openapi({
description: "Browser name",
example: "chrome"
}),
browserVersion: z3.string().openapi({
description: "Browser version",
example: "125"
}),
branch: z3.string().openapi({
description: "Branch name",
example: "master"
}),
tags: z3.array(z3.string()).openapi({
description: "Tags associated with the session",
example: ["@smoke", "@PJ-231"]
}),
viewport: z3.string().openapi({
description: "Viewport size",
example: "1366x768"
}),
os: z3.string().openapi({
description: "Operating system",
example: "macOS"
}),
app: z3.string().openapi({
description: "Application identifier",
example: "666b3b82db17d34ecdbd06f6"
}),
blinking: z3.number().openapi({
description: "Blinking count",
example: 0
}),
updatedDate: z3.string().openapi({
description: "Last updated date",
example: "2024-06-13T18:34:28.121Z"
}),
startDate: z3.string().openapi({
description: "Start date of the session",
example: "2024-06-13T18:34:28.121Z"
}),
checks: z3.array(z3.any()).openapi({
description: "Checks associated with the session",
example: []
}),
suite: z3.string().openapi({
description: "Suite identifier",
example: "666b3b828833d0cf24a670d7"
}),
run: z3.string().openapi({
description: "Run identifier",
example: "666b244a70a6fb0a4368b59e"
}),
_id: commonValidations.id.openapi({
description: "Identifier of the session",
example: "666b3bb49e0c25666d76e0c4"
}),
id: commonValidations.id.openapi({
description: "Identifier of the session",
example: "666b3bb49e0c25666d76e0c4"
})
});
var ClientEndSessionSchema = z3.object({
testid: commonValidations.id
});
var ClientCreateCheckSchema = z3.object({
testid: commonValidations.id.openapi({
description: "Test identifier",
example: "666b2e1e93ca920ef5985b47"
}),
name: z3.string().openapi({
description: "Name of the check",
example: "Login page"
}),
appName: z3.string().openapi({
description: "Application name",
example: "My App"
}),
branch: z3.string().openapi({
description: "Branch name",
example: "master"
}),
suitename: z3.string().openapi({
description: "Suite name",
example: "Smoke tests"
}),
viewport: z3.string().openapi({
description: "Viewport size",
example: "1366x768"
}),
browserName: z3.string().openapi({
description: "Browser name",
example: "chrome"
}),
browserVersion: z3.string().openapi({
description: "Browser version",
example: "125"
}),
browserFullVersion: z3.string().openapi({
description: "Full browser version",
example: "125.0.6422.142"
}),
os: z3.string().openapi({
description: "Operating system",
example: "macOS"
}),
hashcode: z3.string().openapi({
description: "Hash of the snapshot - In the first phase, only the hash is sent, in case the snapshot is already in the Syngrisi database",
example: "ef6ff7c6e6fd536de877c02cf61381e5a1111a24c9d21c1c2a0c0c06fdd2f01271da8880da80a1caa7c123ce3256068c40055753d70bd1dbc558d088f90cd398"
}),
toleranceThreshold: z3.coerce.number().min(0).max(100).optional().openapi({
description: "Mismatch tolerance threshold in percent to apply to baseline for this ident",
example: 0.6
})
});
var SnapshotSchema = z3.object({
name: z3.string().openapi({
description: "Name of the snapshot",
example: "Login page"
}),
filename: z3.string().openapi({
description: "Filename of the snapshot",
example: "666b12d859ac872b495af4b0.png"
}),
imghash: z3.string().openapi({
description: "Image hash of the snapshot",
example: "ef6ff7c6e6fd536de877c02cf61381e5a1111a24c9d21c1c2a0c0c06fdd2f01271da8880da80a1caa7c123ce3256068c40055753d70bd1dbc558d088f90cd398"
}),
_id: commonValidations.id.openapi({
description: "Identifier of the snapshot",
example: "666b4ebc421977cbf466b478"
}),
createdDate: z3.string().openapi({
description: "Creation date",
example: "2024-06-13T19:55:40.068Z"
}),
id: commonValidations.id.openapi({
description: "Identifier of the snapshot",
example: "666b4ebc421977cbf466b478"
})
});
var ClientCreateCheckResponseSchema = z3.object({
name: z3.string().openapi({
description: "Name of the check",
example: "Login page"
}),
test: commonValidations.id.openapi({
description: "Test identifier",
example: "666b4e74421977cbf466b446"
}),
suite: commonValidations.id.openapi({
description: "Suite identifier",
example: "666b3b828833d0cf24a670d7"
}),
app: commonValidations.id.openapi({
description: "Application identifier",
example: "6651dd45b9c3e1e0b8c1ce26"
}),
branch: z3.string().openapi({
description: "Branch name",
example: "master"
}),
baselineId: commonValidations.id.openapi({
description: "Baseline identifier",
example: "666b4ebc421977cbf466b478"
}),
actualSnapshotId: commonValidations.id.openapi({
description: "Actual snapshot identifier",
example: "666b4ebc421977cbf466b478"
}),
updatedDate: z3.string().openapi({
description: "Last updated date",
example: "2024-06-13T19:55:40.061Z"
}),
status: z3.array(z3.string()).openapi({
description: "Status of the check",
example: ["new"]
}),
browserName: z3.string().openapi({
description: "Browser name",
example: "chrome"
}),
browserVersion: z3.string().openapi({
description: "Browser version",
example: "125"
}),
browserFullVersion: z3.string().openapi({
description: "Full browser version",
example: "125.0.6422.142"
}),
viewport: z3.string().openapi({
description: "Viewport size",
example: "1366x768"
}),
os: z3.string().openapi({
description: "Operating system",
example: "macOS"
}),
result: z3.string().openapi({
description: "Result of the check",
example: "{}"
}),
run: commonValidations.id.openapi({
description: "Run identifier",
example: "666b4e74421977cbf466b443"
}),
creatorId: commonValidations.id.openapi({
description: "Creator identifier",
example: "66519e582c2c701cc438ce59"
}),
creatorUsername: z3.string().openapi({
description: "Creator username",
example: "Guest"
}),
failReasons: z3.array(z3.any()).openapi({
description: "Reasons for failure",
example: []
}),
_id: commonValidations.id.openapi({
description: "Identifier of the check",
example: "666b4ebc421977cbf466b47c"
}),
createdDate: z3.string().openapi({
description: "Creation date",
example: "2024-06-13T19:55:40.082Z"
}),
currentSnapshot: SnapshotSchema,
expectedSnapshot: SnapshotSchema,
lastSuccess: commonValidations.id.openapi({
description: "Identifier of the last successful check",
example: "666b4ebc421977cbf466b47c"
})
});
var ClientGetIdentSchema = z3.array(z3.string()).openapi({
description: "Set of fields that identify checks and baselines",
example: ["name", "viewport", "browserName", "os", "app", "branch"]
});
var ClientGetBaselinesSchema = z3.object({
baselines: z3.array(z3.object({
id: commonValidations.id,
name: z3.string().openapi({
description: "Name of the baseline",
example: "A-A-A"
}),
app: commonValidations.id.openapi({
description: "Application identifier",
example: "6651dd45b9c3e1e0b8c1ce26"
}),
branch: z3.string().openapi({
description: "Branch name",
example: "master"
}),
browserName: z3.string().openapi({
description: "Browser name",
example: "chrome"
}),
viewport: z3.string().openapi({
description: "Viewport size",
example: "1366x768"
}),
os: z3.string().openapi({
description: "Operating system",
example: "macOS"
}),
createdDate: z3.string().openapi({
description: "Creation date",
example: "2024-06-13T15:59:44.479Z"
}),
lastMarkedDate: z3.string().openapi({
description: "Last marked date",
example: "2024-06-13T15:59:44.381Z"
}),
markedAs: z3.string().openapi({
description: "Marked status",
example: "accepted"
}),
markedById: commonValidations.id.openapi({
description: "Identifier of the user who marked the baseline",
example: "66519e1682764a892a1a0031"
}),
markedByUsername: z3.string().openapi({
description: "Username of the user who marked the baseline",
example: "Administrator"
}),
snapshootId: commonValidations.id.openapi({
description: "Snapshot identifier",
example: "666b12d859ac872b495af4b0"
}),
_id: commonValidations.id.openapi({
description: "Identifier of the baseline",
example: "666b177059ac872b495af63d"
})
}))
});
var ClientGetSnapshotsSchema = z3.object({
snapshots: z3.array(z3.object({
id: commonValidations.id,
name: z3.string()
}))
});
export {
ClientCreateCheckResponseSchema,
ClientCreateCheckSchema,
ClientEndSessionSchema,
ClientGetBaselinesSchema,
ClientGetIdentSchema,
ClientGetSnapshotsSchema,
ClientStartSessionResponseSchema,
ClientStartSessionSchema
};
//# sourceMappingURL=Client.schema.js.map