|
| 1 | +import {validateThemePassword} from './flags-validation.js' |
| 2 | +import {describe, expect, test} from 'vitest' |
| 3 | +import {AbortError} from '@shopify/cli-kit/node/error' |
| 4 | + |
| 5 | +describe('validateThemePassword', () => { |
| 6 | + describe('valid cases', () => { |
| 7 | + test('should not throw when password is undefined or empty string', () => { |
| 8 | + expect(() => validateThemePassword(undefined)).not.toThrow() |
| 9 | + expect(() => validateThemePassword('')).not.toThrow() |
| 10 | + }) |
| 11 | + |
| 12 | + test('should not throw when password starts with shptka_', () => { |
| 13 | + expect(() => validateThemePassword('shptka_valid_token')).not.toThrow() |
| 14 | + expect(() => validateThemePassword('shptka_')).not.toThrow() |
| 15 | + expect(() => validateThemePassword('shptka_abc123')).not.toThrow() |
| 16 | + }) |
| 17 | + }) |
| 18 | + |
| 19 | + describe('invalid cases', () => { |
| 20 | + test('should throw AbortError when password does not start with shptka_', () => { |
| 21 | + expect(() => validateThemePassword('valid-password')).toThrow(AbortError) |
| 22 | + expect(() => validateThemePassword('theme_token_123')).toThrow(AbortError) |
| 23 | + expect(() => validateThemePassword('shpat_abc123def456')).toThrow(AbortError) |
| 24 | + }) |
| 25 | + |
| 26 | + test('should throw when shptka_ appears but not at the start', () => { |
| 27 | + expect(() => validateThemePassword('prefix_shptka_suffix')).toThrow(AbortError) |
| 28 | + expect(() => validateThemePassword('some_shptka_token')).toThrow(AbortError) |
| 29 | + }) |
| 30 | + |
| 31 | + test('should throw correct error message for non-shptka_ passwords', () => { |
| 32 | + expect(() => validateThemePassword('invalid_token')).toThrow( |
| 33 | + 'Invalid password. Please generate a new password from the Theme Access app.', |
| 34 | + ) |
| 35 | + }) |
| 36 | + }) |
| 37 | +}) |
0 commit comments