From 8d2073b48595cbd2c1d2c030182cd79524e6ccd6 Mon Sep 17 00:00:00 2001 From: gonzaloriestra <14979109+gonzaloriestra@users.noreply.github.com> Date: Sun, 16 Aug 2026 00:27:50 +0000 Subject: [PATCH] [Tests] Add unit tests for deepStrict schema utility --- .../cli-kit/src/public/node/schema.test.ts | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/packages/cli-kit/src/public/node/schema.test.ts b/packages/cli-kit/src/public/node/schema.test.ts index 59ee3b86481..90f9d9a6e66 100644 --- a/packages/cli-kit/src/public/node/schema.test.ts +++ b/packages/cli-kit/src/public/node/schema.test.ts @@ -37,6 +37,59 @@ describe('deepStrict', () => { // Then expect(result.success).toBeTruthy() }) + + test('validates non-optional object schemas as strict', async () => { + // Given + const schema = z.object({ + name: z.string(), + }) + const validContent = {name: 'app'} + const invalidContent = {name: 'app', extra: 'field'} + + // When + const strictSchema = deepStrict(schema) + + // Then + expect(strictSchema.safeParse(validContent).success).toBe(true) + expect(strictSchema.safeParse(invalidContent).success).toBe(false) + }) + + test('validates deeply nested object structures as strict', async () => { + // Given + const schema = z.object({ + level1: z.object({ + level2: z.object({ + key: z.string(), + }), + }), + }) + const invalidContent = { + level1: { + level2: { + key: 'value', + unwanted: true, + }, + }, + } + + // When + const strictSchema = deepStrict(schema) + + // Then + expect(strictSchema.safeParse(invalidContent).success).toBe(false) + }) + + test('returns non-object schemas unchanged', async () => { + // Given + const stringSchema = z.string() + + // When + const resultSchema = deepStrict(stringSchema) + + // Then + expect(resultSchema.safeParse('hello').success).toBe(true) + expect(resultSchema.safeParse(123).success).toBe(false) + }) }) describe('errorsToString', () => {