@@ -2,20 +2,151 @@ CREATE EXTENSION IF NOT EXISTS pgtap;
22
33BEGIN ;
44
5- SELECT plan(9 );
5+ SELECT plan(86 );
66
7- -- Verify that the schema has the expected tables
7+ -- =============================================================================
8+ -- TABLE EXISTENCE TESTS
9+ -- =============================================================================
810
9- SELECT has_table(' languages' , ' Table exists' );
10- SELECT has_table(' products' , ' Table exists' );
11- SELECT has_table(' product_categories' , ' Table exists' );
12- SELECT has_table(' product_variants' , ' Table exists' );
13- SELECT has_table(' product_images' , ' Table exists' );
14- SELECT has_table(' translations' , ' Table exists' );
15- SELECT has_table(' product_translations' , ' Table exists' );
16- SELECT has_table(' category_translations' , ' Table exists' );
17- SELECT has_table(' contact_messages' , ' Table exists' );
11+ SELECT has_table(' languages' , ' Languages table exists' );
12+ SELECT has_table(' products' , ' Products table exists' );
13+ SELECT has_table(' product_categories' , ' Product categories table exists' );
14+ SELECT has_table(' product_variants' , ' Product variants table exists' );
15+ SELECT has_table(' product_images' , ' Product images table exists' );
16+ SELECT has_table(' translations' , ' Translations table exists' );
17+ SELECT has_table(' product_translations' , ' Product translations table exists' );
18+ SELECT has_table(' category_translations' , ' Category translations table exists' );
19+ SELECT has_table(' contact_messages' , ' Contact messages table exists' );
1820
19- SELECT finish(TRUE);
21+ -- =============================================================================
22+ -- ENUM AND TYPE TESTS
23+ -- =============================================================================
24+
25+ SELECT has_type(' delivery_type' , ' delivery_type enum exists' );
26+
27+ -- =============================================================================
28+ -- COLUMN EXISTENCE AND TYPE TESTS
29+ -- =============================================================================
30+
31+ -- Languages table columns
32+ SELECT has_column(' languages' , ' language_id' , ' languages.language_id exists' );
33+ SELECT has_column(' languages' , ' iso_code' , ' languages.iso_code exists' );
34+ SELECT has_column(' languages' , ' english_name' , ' languages.english_name exists' );
35+ SELECT has_column(' languages' , ' native_name' , ' languages.native_name exists' );
36+
37+ SELECT col_type_is(' languages' , ' language_id' , ' integer' , ' languages.language_id is integer' );
38+ SELECT col_type_is(' languages' , ' iso_code' , ' character(2)' , ' languages.iso_code is char(2)' );
39+ SELECT col_type_is(' languages' , ' english_name' , ' text' , ' languages.english_name is text' );
40+ SELECT col_type_is(' languages' , ' native_name' , ' text' , ' languages.native_name is text' );
41+
42+ -- Products table columns
43+ SELECT has_column(' products' , ' product_id' , ' products.product_id exists' );
44+ SELECT has_column(' products' , ' product_name' , ' products.product_name exists' );
45+ SELECT has_column(' products' , ' product_description' , ' products.product_description exists' );
46+ SELECT has_column(' products' , ' price' , ' products.price exists' );
47+ SELECT has_column(' products' , ' image_url' , ' products.image_url exists' );
48+ SELECT has_column(' products' , ' is_enabled' , ' products.is_enabled exists' );
49+ SELECT has_column(' products' , ' created_at' , ' products.created_at exists' );
50+ SELECT has_column(' products' , ' updated_at' , ' products.updated_at exists' );
51+
52+ SELECT col_type_is(' products' , ' product_id' , ' integer' , ' products.product_id is integer' );
53+ SELECT col_type_is(' products' , ' product_name' , ' text' , ' products.product_name is text' );
54+ SELECT col_type_is(' products' , ' price' , ' numeric(10,2)' , ' products.price is numeric(10,2)' );
55+ SELECT col_type_is(' products' , ' is_enabled' , ' boolean' , ' products.is_enabled is boolean' );
56+ SELECT col_type_is(' products' , ' created_at' , ' timestamp with time zone' , ' products.created_at is timestamptz' );
57+
58+ -- Product categories table columns
59+ SELECT has_column(' product_categories' , ' product_category_id' , ' product_categories.product_category_id exists' );
60+ SELECT has_column(' product_categories' , ' product_category_name' , ' product_categories.product_category_name exists' );
61+ SELECT has_column(' product_categories' , ' product_category_description' , ' product_categories.product_category_description exists' );
62+ SELECT has_column(' product_categories' , ' created_at' , ' product_categories.created_at exists' );
63+ SELECT has_column(' product_categories' , ' updated_at' , ' product_categories.updated_at exists' );
64+
65+ -- Product variants table columns
66+ SELECT has_column(' product_variants' , ' product_variant_id' , ' product_variants.product_variant_id exists' );
67+ SELECT has_column(' product_variants' , ' product_id' , ' product_variants.product_id exists' );
68+ SELECT has_column(' product_variants' , ' size' , ' product_variants.size exists' );
69+ SELECT has_column(' product_variants' , ' is_test' , ' product_variants.is_test exists' );
70+ SELECT has_column(' product_variants' , ' price_override' , ' product_variants.price_override exists' );
71+
72+ SELECT col_type_is(' product_variants' , ' is_test' , ' boolean' , ' product_variants.is_test is boolean' );
73+ SELECT col_type_is(' product_variants' , ' price_override' , ' numeric(10,2)' , ' product_variants.price_override is numeric(10,2)' );
74+
75+ -- =============================================================================
76+ -- PRIMARY KEY TESTS
77+ -- =============================================================================
78+
79+ SELECT has_pk(' languages' , ' languages has primary key' );
80+ SELECT has_pk(' products' , ' products has primary key' );
81+ SELECT has_pk(' product_categories' , ' product_categories has primary key' );
82+ SELECT has_pk(' product_variants' , ' product_variants has primary key' );
83+ SELECT has_pk(' product_images' , ' product_images has primary key' );
84+ SELECT has_pk(' translations' , ' translations has primary key' );
85+ SELECT has_pk(' product_translations' , ' product_translations has primary key' );
86+ SELECT has_pk(' category_translations' , ' category_translations has primary key' );
87+ SELECT has_pk(' contact_messages' , ' contact_messages has primary key' );
88+
89+ SELECT col_is_pk(' languages' , ' language_id' , ' languages.language_id is primary key' );
90+ SELECT col_is_pk(' products' , ' product_id' , ' products.product_id is primary key' );
91+ SELECT col_is_pk(' product_categories' , ' product_category_id' , ' product_categories.product_category_id is primary key' );
92+
93+ -- =============================================================================
94+ -- FOREIGN KEY TESTS
95+ -- =============================================================================
96+
97+ SELECT has_fk(' product_variants' , ' product_variants has foreign key' );
98+ SELECT has_fk(' product_images' , ' product_images has foreign key' );
99+ SELECT has_fk(' translations' , ' translations has foreign key' );
100+ SELECT has_fk(' product_translations' , ' product_translations has foreign key' );
101+ SELECT has_fk(' category_translations' , ' category_translations has foreign key' );
102+
103+ -- Specific foreign key relationships
104+ SELECT col_is_fk(' product_variants' , ' product_id' , ' product_variants.product_id is foreign key' );
105+ SELECT col_is_fk(' product_images' , ' product_id' , ' product_images.product_id is foreign key' );
106+ SELECT col_is_fk(' translations' , ' language_id' , ' translations.language_id is foreign key' );
107+ SELECT col_is_fk(' product_translations' , ' product_id' , ' product_translations.product_id is foreign key' );
108+ SELECT col_is_fk(' product_translations' , ' language_id' , ' product_translations.language_id is foreign key' );
109+
110+ -- =============================================================================
111+ -- UNIQUE CONSTRAINT TESTS
112+ -- =============================================================================
113+
114+ SELECT col_is_unique(' languages' , ARRAY[' iso_code' ], ' languages.iso_code is unique' );
115+ SELECT col_is_unique(' languages' , ARRAY[' english_name' ], ' languages.english_name is unique' );
116+ SELECT col_is_unique(' languages' , ARRAY[' native_name' ], ' languages.native_name is unique' );
117+ SELECT col_is_unique(' product_categories' , ARRAY[' product_category_name' ], ' product_categories.product_category_name is unique' );
118+ SELECT col_is_unique(' translations' , ARRAY[' translation_key' ], ' translations.translation_key is unique' );
119+ SELECT col_is_unique(' translations' , ARRAY[' translation_key' , ' language_id' ], ' translations (translation_key, language_id) is unique' );
120+ SELECT col_is_unique(' product_translations' , ARRAY[' product_id' , ' language_id' ], ' product_translations (product_id, language_id) is unique' );
121+ SELECT col_is_unique(' category_translations' , ARRAY[' category_id' , ' language_id' ], ' category_translations (category_id, language_id) is unique' );
122+
123+ -- =============================================================================
124+ -- NOT NULL CONSTRAINT TESTS
125+ -- =============================================================================
126+
127+ SELECT col_not_null(' products' , ' product_name' , ' products.product_name is not null' );
128+ SELECT col_not_null(' products' , ' price' , ' products.price is not null' );
129+ SELECT col_not_null(' product_categories' , ' product_category_name' , ' product_categories.product_category_name is not null' );
130+ SELECT col_not_null(' product_variants' , ' product_id' , ' product_variants.product_id is not null' );
131+ SELECT col_not_null(' product_images' , ' product_id' , ' product_images.product_id is not null' );
132+ SELECT col_not_null(' product_images' , ' image_url' , ' product_images.image_url is not null' );
133+ SELECT col_not_null(' translations' , ' translation_key' , ' translations.translation_key is not null' );
134+ SELECT col_not_null(' translations' , ' language_id' , ' translations.language_id is not null' );
135+ SELECT col_not_null(' translations' , ' translation_value' , ' translations.translation_value is not null' );
136+
137+ -- =============================================================================
138+ -- DEFAULT VALUE TESTS
139+ -- =============================================================================
140+
141+ SELECT col_has_default(' products' , ' is_enabled' , ' products.is_enabled has default' );
142+ SELECT col_has_default(' products' , ' created_at' , ' products.created_at has default' );
143+ SELECT col_has_default(' product_variants' , ' is_test' , ' product_variants.is_test has default' );
144+ SELECT col_has_default(' product_images' , ' is_primary' , ' product_images.is_primary has default' );
145+
146+ -- =============================================================================
147+ -- TODO: INDEX TESTS
148+ -- =============================================================================
149+
150+ SELECT finish();
20151
21152ROLLBACK ;
0 commit comments