Skip to content

Commit

Permalink
chore(models): require slug for organization and project, better desc…
Browse files Browse the repository at this point in the history
…riptions
  • Loading branch information
Tlacenka committed Jan 12, 2024
1 parent 093af6f commit 76dbd89
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 10 deletions.
2 changes: 1 addition & 1 deletion packages/models/src/lib/audit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const pluginAuditsSchema = z
// helper for validator: audit slugs are unique
function duplicateSlugsInAuditsErrorMsg(audits: Audit[]) {
const duplicateRefs = getDuplicateSlugsInAudits(audits);
return `In plugin audits the slugs are not unique: ${errorItems(
return `In plugin audits the following slugs are not unique: ${errorItems(
duplicateRefs,
)}`;
}
Expand Down
4 changes: 3 additions & 1 deletion packages/models/src/lib/group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ function getDuplicateRefsInGroups(groups: WeightedRef[]) {
// helper for validator: group refs are unique
function duplicateSlugsInGroupsErrorMsg(groups: Group[] | undefined) {
const duplicateRefs = getDuplicateSlugsInGroups(groups);
return `In groups the slugs are not unique: ${errorItems(duplicateRefs)}`;
return `In groups the following slugs are not unique: ${errorItems(
duplicateRefs,
)}`;
}

function getDuplicateSlugsInGroups(groups: Group[] | undefined) {
Expand Down
2 changes: 1 addition & 1 deletion packages/models/src/lib/plugin-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const pluginMetaSchema = packageVersionSchema()
)
.merge(
z.object({
slug: slugSchema('References plugin. ID (unique within core config)'),
slug: slugSchema('Unique plugin slug within core config'),
icon: materialIconSchema,
}),
);
Expand Down
10 changes: 3 additions & 7 deletions packages/models/src/lib/upload-config.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
import { z } from 'zod';
import { urlSchema } from './implementation/schemas';
import { slugSchema, urlSchema } from './implementation/schemas';

export const uploadConfigSchema = z.object({
server: urlSchema('URL of deployed portal API'),
apiKey: z.string({
description:
'API key with write access to portal (use `process.env` for security)',
}),
organization: z.string({
description: 'Organization in code versioning system',
}),
project: z.string({
description: 'Project in code versioning system',
}),
organization: slugSchema('Organization slug from Code PushUp portal'),
project: slugSchema('Project slug from Code PushUp portal'),
});

export type UploadConfig = z.infer<typeof uploadConfigSchema>;
22 changes: 22 additions & 0 deletions packages/models/src/lib/upload-config.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,26 @@ describe('uploadConfigSchema', () => {
} satisfies UploadConfig),
).toThrow('Invalid url');
});

it('should throw for a PascalCase organization name', () => {
expect(() =>
uploadConfigSchema.parse({
apiKey: 'API-K3Y',
organization: 'CodePushUp',
project: 'cli',
server: '-invalid-/url',
} satisfies UploadConfig),
).toThrow('slug has to follow the pattern');
});

it('should throw for a project with uppercase letters', () => {
expect(() =>
uploadConfigSchema.parse({
apiKey: 'API-K3Y',
organization: 'code-pushup',
project: 'Code-PushUp-CLI',
server: '-invalid-/url',
} satisfies UploadConfig),
).toThrow('slug has to follow the pattern');
});
});

0 comments on commit 76dbd89

Please sign in to comment.