core tests
Some checks failed
Contract Testing / contract-tests (pull_request) Failing after 5m51s
Contract Testing / contract-snapshot (pull_request) Has been skipped

This commit is contained in:
2026-01-22 18:44:01 +01:00
parent 093eece3d7
commit 280d6fc199
7 changed files with 96 additions and 7 deletions

View File

@@ -0,0 +1,78 @@
import { describe, expect, it } from 'vitest';
import { SocialDomainError } from './SocialDomainError';
describe('SocialDomainError', () => {
it('creates an error with default kind (validation)', () => {
const error = new SocialDomainError('Invalid social data');
expect(error.name).toBe('SocialDomainError');
expect(error.type).toBe('domain');
expect(error.context).toBe('social');
expect(error.kind).toBe('validation');
expect(error.message).toBe('Invalid social data');
});
it('creates an error with custom kind', () => {
const error = new SocialDomainError('Social graph error', 'repository');
expect(error.name).toBe('SocialDomainError');
expect(error.type).toBe('domain');
expect(error.context).toBe('social');
expect(error.kind).toBe('repository');
expect(error.message).toBe('Social graph error');
});
it('creates an error with business kind', () => {
const error = new SocialDomainError('Friend limit exceeded', 'business');
expect(error.kind).toBe('business');
expect(error.message).toBe('Friend limit exceeded');
});
it('creates an error with infrastructure kind', () => {
const error = new SocialDomainError('Database connection failed', 'infrastructure');
expect(error.kind).toBe('infrastructure');
expect(error.message).toBe('Database connection failed');
});
it('creates an error with technical kind', () => {
const error = new SocialDomainError('Serialization error', 'technical');
expect(error.kind).toBe('technical');
expect(error.message).toBe('Serialization error');
});
it('creates an error with empty message', () => {
const error = new SocialDomainError('');
expect(error.message).toBe('');
expect(error.kind).toBe('validation');
});
it('creates an error with multiline message', () => {
const error = new SocialDomainError('Error\nwith\nmultiple\nlines');
expect(error.message).toBe('Error\nwith\nmultiple\nlines');
});
it('creates an error with special characters in message', () => {
const error = new SocialDomainError('Error with special chars: @#$%^&*()');
expect(error.message).toBe('Error with special chars: @#$%^&*()');
});
it('error is instance of Error', () => {
const error = new SocialDomainError('Test error');
expect(error).toBeInstanceOf(Error);
expect(error).toBeInstanceOf(SocialDomainError);
});
it('error has correct prototype chain', () => {
const error = new SocialDomainError('Test error');
expect(Object.getPrototypeOf(error)).toBe(SocialDomainError.prototype);
expect(Object.getPrototypeOf(Object.getPrototypeOf(error))).toBe(Error.prototype);
});
});