diff --git a/packages/core/src/code_assist/schema.test.ts b/packages/core/src/code_assist/schema.test.ts new file mode 100644 index 0000000000..dc7dc5ee4d --- /dev/null +++ b/packages/core/src/code_assist/schema.test.ts @@ -0,0 +1,51 @@ +/** + * @license + * Copyright 2025 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +import { describe, it, expect } from 'vitest'; +import { LoadCodeAssistResponseSchema } from './types.js'; + +describe('LoadCodeAssistResponseSchema', () => { + it('should allow missing showNotice in privacyNotice and default to false', () => { + const data = { + currentTier: { + id: 'standard-tier', + privacyNotice: { + noticeText: 'Some notice', + }, + }, + allowedTiers: [ + { + id: 'free-tier', + privacyNotice: {}, + }, + { + id: 'standard-tier', + privacyNotice: { + showNotice: true, + }, + }, + ], + }; + + const parsed = LoadCodeAssistResponseSchema.parse(data); + + expect(parsed.currentTier?.privacyNotice?.showNotice).toBe(false); + expect(parsed.allowedTiers?.[0].privacyNotice?.showNotice).toBe(false); + expect(parsed.allowedTiers?.[1].privacyNotice?.showNotice).toBe(true); + }); + + it('should allow missing privacyNotice altogether', () => { + const data = { + currentTier: { + id: 'standard-tier', + }, + }; + + const parsed = LoadCodeAssistResponseSchema.parse(data); + + expect(parsed.currentTier?.privacyNotice).toBeUndefined(); + }); +}); diff --git a/packages/core/src/code_assist/types.ts b/packages/core/src/code_assist/types.ts index a2447575c4..a24927a97d 100644 --- a/packages/core/src/code_assist/types.ts +++ b/packages/core/src/code_assist/types.ts @@ -63,7 +63,7 @@ export type UserTierId = (typeof UserTierId)[keyof typeof UserTierId] | string; * privacy notice. */ export const PrivacyNoticeSchema = z.object({ - showNotice: z.boolean(), + showNotice: z.boolean().optional().default(false), noticeText: z.string().optional(), }); export type PrivacyNotice = z.infer;