/*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ import assert from 'assert'; import { NumberPolicy } from '../policies/numberPolicy.ts'; import { type LanguageTranslations, PolicyType } from '../policies/types.ts'; import type { CategoryDto, PolicyDto } from '../policies/policyDto.ts'; suite('NumberPolicy', () => { const mockCategory: CategoryDto = { key: 'test.category', name: { value: 'Category1', key: 'test.category' }, }; const mockPolicy: PolicyDto = { key: 'test.number.policy', name: 'TestNumberPolicy', category: 'Category1', minimumVersion: '1.0', type: 'number', default: 42, localization: { description: { key: 'test.policy.description', value: 'Test number policy description' } } }; test('should create NumberPolicy from factory method', () => { const policy = NumberPolicy.from(mockCategory, mockPolicy); assert.ok(policy); assert.strictEqual(policy.name, 'TestNumberPolicy'); assert.strictEqual(policy.minimumVersion, '1.0'); assert.strictEqual(policy.category.name.nlsKey, mockCategory.name.key); assert.strictEqual(policy.category.name.value, mockCategory.name.value); assert.strictEqual(policy.type, PolicyType.Number); }); test('should render ADMX elements correctly', () => { const policy = NumberPolicy.from(mockCategory, mockPolicy); assert.ok(policy); const admx = policy.renderADMX('TestKey'); assert.deepStrictEqual(admx, [ '', '\t', '\t', '\t', '', '\t', '' ]); }); test('should render ADML strings correctly', () => { const policy = NumberPolicy.from(mockCategory, mockPolicy); assert.ok(policy); const admlStrings = policy.renderADMLStrings(); assert.deepStrictEqual(admlStrings, [ 'TestNumberPolicy', 'Test number policy description' ]); }); test('should render ADML strings with translations', () => { const policy = NumberPolicy.from(mockCategory, mockPolicy); assert.ok(policy); const translations: LanguageTranslations = { '': { 'test.policy.description': 'Translated description' } }; const admlStrings = policy.renderADMLStrings(translations); assert.deepStrictEqual(admlStrings, [ 'TestNumberPolicy', 'Translated description' ]); }); test('should render ADML presentation correctly', () => { const policy = NumberPolicy.from(mockCategory, mockPolicy); assert.ok(policy); const presentation = policy.renderADMLPresentation(); assert.strictEqual(presentation, 'TestNumberPolicy'); }); test('should render JSON value correctly', () => { const policy = NumberPolicy.from(mockCategory, mockPolicy); assert.ok(policy); const jsonValue = policy.renderJsonValue(); assert.strictEqual(jsonValue, 42); }); test('should render profile value correctly', () => { const policy = NumberPolicy.from(mockCategory, mockPolicy); assert.ok(policy); const profileValue = policy.renderProfileValue(); assert.strictEqual(profileValue, '42'); }); test('should render profile correctly', () => { const policy = NumberPolicy.from(mockCategory, mockPolicy); assert.ok(policy); const profile = policy.renderProfile(); assert.strictEqual(profile.length, 2); assert.strictEqual(profile[0], 'TestNumberPolicy'); assert.strictEqual(profile[1], '42'); }); test('should render profile manifest value correctly', () => { const policy = NumberPolicy.from(mockCategory, mockPolicy); assert.ok(policy); const manifestValue = policy.renderProfileManifestValue(); assert.strictEqual(manifestValue, 'pfm_default\n42\npfm_description\nTest number policy description\npfm_name\nTestNumberPolicy\npfm_title\nTestNumberPolicy\npfm_type\ninteger'); }); test('should render profile manifest value with translations', () => { const policy = NumberPolicy.from(mockCategory, mockPolicy); assert.ok(policy); const translations: LanguageTranslations = { '': { 'test.policy.description': 'Translated manifest description' } }; const manifestValue = policy.renderProfileManifestValue(translations); assert.strictEqual(manifestValue, 'pfm_default\n42\npfm_description\nTranslated manifest description\npfm_name\nTestNumberPolicy\npfm_title\nTestNumberPolicy\npfm_type\ninteger'); }); test('should render profile manifest correctly', () => { const policy = NumberPolicy.from(mockCategory, mockPolicy); assert.ok(policy); const manifest = policy.renderProfileManifest(); assert.strictEqual(manifest, '\npfm_default\n42\npfm_description\nTest number policy description\npfm_name\nTestNumberPolicy\npfm_title\nTestNumberPolicy\npfm_type\ninteger\n'); }); });