feat: integration tests

This commit is contained in:
Nathnael
2026-08-03 10:51:43 +00:00
parent 6f137a11c3
commit f103b51de5
38 changed files with 7306 additions and 228 deletions

View File

@@ -0,0 +1,34 @@
-- Second tenant for the integration suite: user2@gmail.com gets its own ACTIVE
-- company + approved importer profile, mirroring seed-company.sql (which only
-- sets up user@gmail.com). Two real tenants are what make the cross-tenant
-- isolation and the "two companies race for the same train" scenarios honest.
-- Idempotent; TIN is the key.
INSERT INTO freight.companies
(id, name, type, status, tin, fan_number, country, address, phone, email,
nationality, kind, attributes)
SELECT gen_random_uuid(), 'IT Freight Partners PLC', 'customer', 'active',
'0102030406', '1234567890123457', 'Ethiopia', 'Adama, Ethiopia',
'+251911000011', 'ops@it-partners.test', 'ethiopian', 'commercial',
'{"contactPersonName":"IT Contact","contactPersonPhone":"+251911000012","generalManagerName":"IT GM","generalManagerEmail":"gm@it-partners.test","generalManagerPhone":"+251911000013"}'::jsonb
WHERE NOT EXISTS (SELECT 1 FROM freight.companies WHERE tin = '0102030406');
INSERT INTO freight.company_profiles (id, company_id, type, status, reference)
SELECT gen_random_uuid(), c.id, 'importer', 'active', 'IMP-IT-0002'
FROM freight.companies c
WHERE c.tin = '0102030406'
AND NOT EXISTS (
SELECT 1 FROM freight.company_profiles p
WHERE p.company_id = c.id AND p.type = 'importer'
);
INSERT INTO freight.external_profiles
(id, user_id, company_id, first_name, last_name, is_primary_contact,
onboarding_step, onboarding_completed)
SELECT gen_random_uuid(), u.id, c.id, 'Demo', 'User2', true, 'done', true
FROM iam.users u
JOIN freight.companies c ON c.tin = '0102030406'
WHERE u.email = 'user2@gmail.com'
AND NOT EXISTS (
SELECT 1 FROM freight.external_profiles ep WHERE ep.user_id = u.id
);

View File

@@ -0,0 +1,17 @@
-- A service type whose bundle INCLUDES customs, for the priority-tier scenario
-- (g1-s6-s8, S8). Idempotent.
--
-- The rule engine's CUSTOMS priority band only applies when the booking's
-- service type has `includes_customs = true` (rule-engine.service.ts:251), and
-- the corridor fixture ships exactly one service type — RAIL, which does not.
-- Without this row the customs tier can never fire and "customs outranks plain"
-- is untestable: both bookings score the same.
--
-- Contracts opt in with seedContract({ serviceTypeCode: 'RAIL_CUSTOMS' }).
INSERT INTO freight.service_types
(code, service_name, description, includes_customs, is_active, display_order)
SELECT 'RAIL_CUSTOMS', 'Rail Transport + Customs Clearance',
'IT fixture: the customs-bundled service tier', true, true, 2
WHERE NOT EXISTS (
SELECT 1 FROM freight.service_types WHERE code = 'RAIL_CUSTOMS'
);