view models
This commit is contained in:
46
apps/website/lib/view-models/SponsorViewModel.test.ts
Normal file
46
apps/website/lib/view-models/SponsorViewModel.test.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { SponsorViewModel } from './SponsorViewModel';
|
||||
|
||||
describe('SponsorViewModel', () => {
|
||||
it('maps basic sponsor fields from DTO', () => {
|
||||
const dto = {
|
||||
id: 'sp-1',
|
||||
name: 'Acme Corp',
|
||||
logoUrl: '/logo.png',
|
||||
websiteUrl: 'https://acme.example',
|
||||
};
|
||||
|
||||
const vm = new SponsorViewModel(dto as any);
|
||||
|
||||
expect(vm.id).toBe(dto.id);
|
||||
expect(vm.name).toBe(dto.name);
|
||||
expect(vm.logoUrl).toBe(dto.logoUrl);
|
||||
expect(vm.websiteUrl).toBe(dto.websiteUrl);
|
||||
});
|
||||
|
||||
it('does not assign optional fields when they are undefined', () => {
|
||||
const dto = {
|
||||
id: 'sp-2',
|
||||
name: 'Minimal Sponsor',
|
||||
logoUrl: undefined,
|
||||
websiteUrl: undefined,
|
||||
};
|
||||
|
||||
const vm = new SponsorViewModel(dto as any);
|
||||
|
||||
expect(vm.id).toBe(dto.id);
|
||||
expect(vm.name).toBe(dto.name);
|
||||
expect('logoUrl' in vm).toBe(false);
|
||||
expect('websiteUrl' in vm).toBe(false);
|
||||
});
|
||||
|
||||
it('exposes simple UI helpers', () => {
|
||||
const withWebsite = new SponsorViewModel({ id: 'sp-3', name: 'With Site', websiteUrl: 'https://example.com' } as any);
|
||||
const withoutWebsite = new SponsorViewModel({ id: 'sp-4', name: 'No Site' } as any);
|
||||
|
||||
expect(withWebsite.displayName).toBe(withWebsite.name);
|
||||
expect(withWebsite.hasWebsite).toBe(true);
|
||||
expect(withoutWebsite.hasWebsite).toBe(false);
|
||||
expect(withWebsite.websiteLinkText).toBe('Visit Website');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user