secrets.test.ts 1.1 KB

123456789101112131415161718192021222324
  1. import { describe, it, expect } from 'vitest';
  2. import { SECRET_PLACEHOLDER, secretsToReenter } from '../../utils/secrets';
  3. const DESTINATIONS = { mqtt_password: ['mqtt_broker', 'mqtt_port'], ha_token: ['ha_url'] } as const;
  4. describe('secretsToReenter', () => {
  5. const saved = { mqtt_broker: 'b', mqtt_port: 1883, mqtt_password: SECRET_PLACEHOLDER, ha_url: 'u', ha_token: SECRET_PLACEHOLDER };
  6. it('names a kept secret whose destination changed', () => {
  7. expect(secretsToReenter(saved, { ...saved, mqtt_port: 8883 }, DESTINATIONS)).toEqual(['mqtt_password']);
  8. });
  9. it('leaves a secret entered again alone', () => {
  10. expect(secretsToReenter(saved, { ...saved, mqtt_broker: 'x', mqtt_password: 'new' }, DESTINATIONS)).toEqual([]);
  11. });
  12. it('leaves a kept secret whose destination did not change alone', () => {
  13. expect(secretsToReenter(saved, { ...saved }, DESTINATIONS)).toEqual([]);
  14. });
  15. it('treats a number and its text as the same value', () => {
  16. expect(secretsToReenter(saved, { ...saved, mqtt_port: '1883' }, DESTINATIONS)).toEqual([]);
  17. });
  18. });