47 lines
1.4 KiB
TypeScript
47 lines
1.4 KiB
TypeScript
import { describe, it, expect } from 'vitest';
|
|
import { CountryCode } from './CountryCode';
|
|
|
|
describe('CountryCode', () => {
|
|
it('should create a country code', () => {
|
|
const code = CountryCode.create('US');
|
|
expect(code.toString()).toBe('US');
|
|
});
|
|
|
|
it('should uppercase the code', () => {
|
|
const code = CountryCode.create('us');
|
|
expect(code.toString()).toBe('US');
|
|
});
|
|
|
|
it('should accept 3 letter code', () => {
|
|
const code = CountryCode.create('USA');
|
|
expect(code.toString()).toBe('USA');
|
|
});
|
|
|
|
it('should throw on empty code', () => {
|
|
expect(() => CountryCode.create('')).toThrow('Country code is required');
|
|
});
|
|
|
|
it('should throw on invalid length', () => {
|
|
expect(() => CountryCode.create('U')).toThrow('Country must be a valid ISO code (2-3 letters)');
|
|
});
|
|
|
|
it('should throw on 4 letters', () => {
|
|
expect(() => CountryCode.create('USAA')).toThrow('Country must be a valid ISO code (2-3 letters)');
|
|
});
|
|
|
|
it('should throw on non-letters', () => {
|
|
expect(() => CountryCode.create('U1')).toThrow('Country must be a valid ISO code (2-3 letters)');
|
|
});
|
|
|
|
it('should equal same code', () => {
|
|
const c1 = CountryCode.create('US');
|
|
const c2 = CountryCode.create('US');
|
|
expect(c1.equals(c2)).toBe(true);
|
|
});
|
|
|
|
it('should not equal different code', () => {
|
|
const c1 = CountryCode.create('US');
|
|
const c2 = CountryCode.create('CA');
|
|
expect(c1.equals(c2)).toBe(false);
|
|
});
|
|
}); |