fix: improve test infrastructure and add ID validation

- Add TestMain to set test env vars and testdb.TruncateTables for test
  isolation
- Add chi routing context to test helpers for path parameter extraction
- Fix SQL error handling to use errors.Is() instead of ==
- Add validators package with ID validation
- Fix admin test middleware chain (RequireAdmin wrapper)
- Update test user inserts to include phone and date_of_birth fields
- Update service delete test to check soft-delete (is_active=false)
- Update holiday hours test to use new schema (weekday, is_open)
- Add phone number validation tests for UK mobile numbers
This commit is contained in:
2026-02-23 00:59:32 +00:00
parent 355e8a26c1
commit df3439bd70
30 changed files with 1081 additions and 360 deletions
+7 -8
View File
@@ -16,7 +16,7 @@ CREATE TYPE account_type AS ENUM ('email', 'google', 'microsoft', 'facebook', 'g
CREATE TYPE payment_type AS ENUM ('deposit', 'full', 'tip', 'balance', 'partial');
CREATE TYPE payment_method AS ENUM ('online_square', 'in_person_card', 'cash', 'giftcard', 'discount');
CREATE TYPE payment_status AS ENUM ('pending', 'completed', 'failed', 'refunded');
CREATE TYPE booking_status AS ENUM ('pending', 'confirmed', 'in_progress', 'completed', 'client_cancelled', 'we_cancelled', 're-schedule', 'no_show');
CREATE TYPE booking_status AS ENUM ('pending', 'confirmed', 'in_progress', 'completed', 'client_cancelled', 'we_cancelled', 're-schedule', 'no_show', 'no_deposit');
-- =======================================
-- SHORT ID GENERATION
@@ -89,8 +89,8 @@ CREATE TABLE users (
n_last_name VARCHAR(50) NOT NULL, -- vCard N.family
fn VARCHAR(120) GENERATED ALWAYS AS (n_first_name || ' ' || n_last_name) STORED, -- vCard FN
email VARCHAR(255) UNIQUE, -- vCard EMAIL (nullable for social-only/guest)
phone VARCHAR(20), -- vCard TEL
date_of_birth DATE, -- vCard BDAY
phone VARCHAR(20) NOT NULL, -- vCard TEL
date_of_birth DATE NOT NULL, -- vCard BDAY
profile_pic_url TEXT, -- vCard PHOTO
-- Account fields
account_role account_role NOT NULL DEFAULT 'unverified_email', -- initial signup role
@@ -412,7 +412,7 @@ create table tags (
-- Indexes
create index idx_images_tag_names on images using gin(tag_names);
create index idx_images_tag_names_trgm on images using gin ((tag_names::text[]) gin_trgm_ops);
-- create index idx_images_tag_names_trgm on images using gin ((tag_names::text[]) gin_trgm_ops);
create index idx_images_created_at on images(created_at desc);
create index idx_tags_name_trgm on tags using gin (name gin_trgm_ops);
@@ -614,8 +614,7 @@ BEGIN
WHEN p.vat_amount IS NOT NULL THEN p.vat_amount
-- If business is VAT registered but no VAT breakdown, calculate it
WHEN (SELECT is_vat_registered FROM business_settings WHERE id = 1) THEN
ROUND(p.amount - (p.amount / (1 + COALESCE(p.vat_rate,
(SELECT default_vat_rate FROM business_settings WHERE id = 1))/100), 2)
ROUND(p.amount - (p.amount / (1 + COALESCE(p.vat_rate, (SELECT default_vat_rate FROM business_settings WHERE id = 1)) / 100)), 2)
-- Business not VAT registered = no VAT charged
ELSE 0
END
@@ -973,7 +972,7 @@ VAT RECEIPT REQUIREMENTS (if VAT registered):
-- WHEN: After each completed payment/booking
-- OUTPUT: All data needed for receipt printing/email
-- USE: Call from Go API to generate customer receipts
CREATE OR REPLACE FUNCTION get_receipt_data(payment_id CHAR(12))
CREATE OR REPLACE FUNCTION get_receipt_data(p_payment_id CHAR(12))
RETURNS TABLE (
-- Business Information
business_name TEXT,
@@ -1107,7 +1106,7 @@ BEGIN
FROM payments p
JOIN bookings b ON p.booking_id = b.id
LEFT JOIN users u ON b.user_id = u.id
WHERE p.id = payment_id;
WHERE p.id = p_payment_id;
END;
$$ LANGUAGE plpgsql;