fix: validate managed user timeFormat (#16783)

This commit is contained in:
Lauris Skraucis authored and GitHub committed 2024-09-24 13:32:54 +03:00
1 parent 7936709644
commit 6de454b071
2 files changed
+18 -2

No files matched your search

@@ -159,6 +159,21 @@ describe("OAuth Client Users Endpoints", () => {
.expect(400);
});
it(`should fail /POST with incorrect timeFormat`, async () => {
const requestBody = {
email: userEmail,
timeZone: userTimeZone,
name: "Alice Smith",
timeFormat: 100,
};
await request(app.getHttpServer())
.post(`/api/v2/oauth-clients/${oAuthClient.id}/users`)
.set("x-cal-secret-key", oAuthClient.secret)
.send(requestBody)
.expect(400);
});
it(`/POST`, async () => {
const requestBody: CreateManagedUserInput = {
email: userEmail,
@@ -1,7 +1,7 @@
import { Locales } from "@/lib/enums/locales";
import { CapitalizeTimeZone } from "@/lib/inputs/capitalize-timezone";
import { ApiProperty } from "@nestjs/swagger";
import { IsOptional, IsTimeZone, IsString, IsEnum } from "class-validator";
import { IsOptional, IsTimeZone, IsString, IsEnum, IsIn } from "class-validator";
export type WeekDay = "Monday" | "Tuesday" | "Wednesday" | "Thursday" | "Friday" | "Saturday" | "Sunday";
export type TimeFormat = 12 | 24;
@@ -15,7 +15,8 @@ export class CreateManagedUserInput {
name!: string;
@IsOptional()
@ApiProperty({ example: 12, enum: [12, 24], description: "Must be 12 or 24" })
@IsIn([12, 24], { message: "timeFormat must be a number either 12 or 24" })
@ApiProperty({ example: 12, enum: [12, 24], description: "Must be a number 12 or 24" })
timeFormat?: TimeFormat;
@IsOptional()