fix(core): make showNotice optional in PrivacyNoticeSchema

This commit is contained in:
Christian Gunderman
2026-02-09 17:01:05 -08:00
parent 48f4d0391e
commit 9537d9dabd
2 changed files with 52 additions and 1 deletions

View File

@@ -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();
});
});

View File

@@ -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<typeof PrivacyNoticeSchema>;