123 lines
3.1 KiB
TypeScript
123 lines
3.1 KiB
TypeScript
import { describe, it, expect } from 'vitest';
|
|
import { OnboardingPageViewDataBuilder } from './OnboardingPageViewDataBuilder';
|
|
|
|
describe('OnboardingPageViewDataBuilder', () => {
|
|
describe('happy paths', () => {
|
|
it('should transform driver data to ViewData correctly when driver exists', () => {
|
|
const apiDto = { id: 'driver-123', name: 'Test Driver' };
|
|
|
|
const result = OnboardingPageViewDataBuilder.build(apiDto);
|
|
|
|
expect(result).toEqual({
|
|
isAlreadyOnboarded: true,
|
|
});
|
|
});
|
|
|
|
it('should handle empty object as driver data', () => {
|
|
const apiDto = {};
|
|
|
|
const result = OnboardingPageViewDataBuilder.build(apiDto);
|
|
|
|
expect(result).toEqual({
|
|
isAlreadyOnboarded: true,
|
|
});
|
|
});
|
|
|
|
it('should handle null driver data', () => {
|
|
const apiDto = null;
|
|
|
|
const result = OnboardingPageViewDataBuilder.build(apiDto);
|
|
|
|
expect(result).toEqual({
|
|
isAlreadyOnboarded: false,
|
|
});
|
|
});
|
|
|
|
it('should handle undefined driver data', () => {
|
|
const apiDto = undefined;
|
|
|
|
const result = OnboardingPageViewDataBuilder.build(apiDto);
|
|
|
|
expect(result).toEqual({
|
|
isAlreadyOnboarded: false,
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('data transformation', () => {
|
|
it('should preserve all driver data fields in the output', () => {
|
|
const apiDto = {
|
|
id: 'driver-123',
|
|
name: 'Test Driver',
|
|
email: 'test@example.com',
|
|
createdAt: '2024-01-01T00:00:00.000Z',
|
|
};
|
|
|
|
const result = OnboardingPageViewDataBuilder.build(apiDto);
|
|
|
|
expect(result.isAlreadyOnboarded).toBe(true);
|
|
});
|
|
|
|
it('should not modify the input driver data', () => {
|
|
const apiDto = { id: 'driver-123', name: 'Test Driver' };
|
|
const originalDto = { ...apiDto };
|
|
|
|
OnboardingPageViewDataBuilder.build(apiDto);
|
|
|
|
expect(apiDto).toEqual(originalDto);
|
|
});
|
|
});
|
|
|
|
describe('edge cases', () => {
|
|
it('should handle empty string as driver data', () => {
|
|
const apiDto = '';
|
|
|
|
const result = OnboardingPageViewDataBuilder.build(apiDto);
|
|
|
|
expect(result).toEqual({
|
|
isAlreadyOnboarded: false,
|
|
});
|
|
});
|
|
|
|
it('should handle zero as driver data', () => {
|
|
const apiDto = 0;
|
|
|
|
const result = OnboardingPageViewDataBuilder.build(apiDto);
|
|
|
|
expect(result).toEqual({
|
|
isAlreadyOnboarded: false,
|
|
});
|
|
});
|
|
|
|
it('should handle false as driver data', () => {
|
|
const apiDto = false;
|
|
|
|
const result = OnboardingPageViewDataBuilder.build(apiDto);
|
|
|
|
expect(result).toEqual({
|
|
isAlreadyOnboarded: false,
|
|
});
|
|
});
|
|
|
|
it('should handle array as driver data', () => {
|
|
const apiDto = ['driver-123'];
|
|
|
|
const result = OnboardingPageViewDataBuilder.build(apiDto);
|
|
|
|
expect(result).toEqual({
|
|
isAlreadyOnboarded: true,
|
|
});
|
|
});
|
|
|
|
it('should handle function as driver data', () => {
|
|
const apiDto = () => {};
|
|
|
|
const result = OnboardingPageViewDataBuilder.build(apiDto);
|
|
|
|
expect(result).toEqual({
|
|
isAlreadyOnboarded: true,
|
|
});
|
|
});
|
|
});
|
|
});
|