Skip to content

Commit

Permalink
refactor(chore): improvements testing (#46)
Browse files Browse the repository at this point in the history
This PR includes:
- a refactoring for the test helper to mock schemas
- updated imports
- adoptions to the schemas (removes `label`)
  • Loading branch information
BioPhoton committed Sep 16, 2023
1 parent 10f2a57 commit caa2cfa
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions packages/models/src/lib/implementation/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export function weightSchema(
export function positiveIntSchema(description: string) {
return z.number({ description }).int().nonnegative();
}

/**
* Schema for a unixFilePath
* @param description
Expand All @@ -89,6 +90,24 @@ export function unixFilePathSchema(description: string) {
return z.string({ description }).regex(unixFilePathRegex);
}

export function packageVersionSchema(options?: {
versionDescription?: string;
optional?: boolean;
}) {
let { versionDescription, optional } = options || {};
versionDescription = versionDescription || 'NPM version of the package';
optional = !!optional;
const packageSchema = z.string({ description: 'NPM package name' });
const versionSchema = z.string({ description: versionDescription });
return z.object(
{
package: optional ? packageSchema.optional() : packageSchema,
version: optional ? versionSchema.optional() : versionSchema,
},
{ description: 'NPM package name and version of a published package' },
);
}

export function weightedRefSchema(
description: string,
slugDescription: string,
Expand Down

0 comments on commit caa2cfa

Please sign in to comment.