You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

88 lines
3.1 KiB

import { describe, it, expect, vi, beforeEach } from 'vitest';
import { getSubmitPath } from './get-submit-path';
import * as firstEntryHelper from './first-entry-helper';
import * as matchStartGrace from './match-start-grace';
import type { MarriageProfileResponse } from '@/hooks/marriage/types';
vi.mock('./first-entry-helper', () => ({
isFirstEntryCompleted: vi.fn(),
}));
vi.mock('./match-start-grace', () => ({
clearLegacyMatchSubmittedFlag: vi.fn(),
isWithinMatchStartGrace: vi.fn(),
}));
describe('getSubmitPath', () => {
beforeEach(() => {
vi.clearAllMocks();
vi.mocked(firstEntryHelper.isFirstEntryCompleted).mockReturnValue(true);
vi.mocked(matchStartGrace.isWithinMatchStartGrace).mockReturnValue(false);
});
const baseProfile: MarriageProfileResponse = {
status: 'pending_onboarding',
id: 1,
gender: 'male',
is_registering_for_self: true,
};
it('pending_onboarding returns /terms', () => {
expect(getSubmitPath({ ...baseProfile, status: 'pending_onboarding' })).toBe('/terms');
});
it('waiting returns /finding-match', () => {
expect(getSubmitPath({ ...baseProfile, status: 'waiting' })).toBe('/finding-match');
});
it('pending_info returns questions path', () => {
expect(getSubmitPath({ ...baseProfile, status: 'pending_info' })).toBe('/questions-list');
vi.mocked(firstEntryHelper.isFirstEntryCompleted).mockReturnValue(false);
expect(getSubmitPath({ ...baseProfile, status: 'pending_info' })).toBe('/questions-list/personal_info');
});
it('matched returns /request-accepted', () => {
expect(getSubmitPath({ ...baseProfile, status: 'matched' })).toBe('/request-accepted');
});
describe('active_case priority', () => {
it('returns /new-match when status="pending_info" but active_case is introduced and action pending', () => {
const profileWithCase = {
...baseProfile,
status: 'pending_info' as const,
active_case: {
status: 'introduced' as const,
my_action: 'pending' as const,
},
};
// Type assertion added because the mock profile object is lacking many properties of the full MarriageProfileResponse,
// but it contains everything needed for the logic being tested.
expect(getSubmitPath(profileWithCase as any)).toBe('/new-match');
});
it('returns /request-accepted when status="pending_info" but active_case is payment_done', () => {
const profileWithCase = {
...baseProfile,
status: 'pending_info' as const,
active_case: {
status: 'payment_done' as const,
my_action: 'pending' as const,
},
};
expect(getSubmitPath(profileWithCase as any)).toBe('/request-accepted');
});
it('returns /request-sent when status="waiting" but active_case is male_accepted and action done', () => {
const profileWithCase = {
...baseProfile,
status: 'waiting' as const,
active_case: {
status: 'male_accepted' as const,
my_action: 'done' as const,
},
};
expect(getSubmitPath(profileWithCase as any)).toBe('/request-sent');
});
});
});