@@ -122,6 +122,7 @@ struct PersistedProductTests {
122122
123123 @Test ( " A Product's images and attributes are fetched automatically " )
124124 func product_with_associations_fetches_related_records( ) throws {
125+ // Given
125126 let grdbManager = try GRDBManager ( )
126127 let db = grdbManager. databaseConnection
127128
@@ -136,15 +137,15 @@ struct PersistedProductTests {
136137 siteID: 1 ,
137138 name: " Test Product " ,
138139 productTypeKey: " simple " ,
139- fullDescription: " Full description " ,
140- shortDescription: " Short description " ,
141- sku: " TEST-SKU " ,
142- globalUniqueID: " GID-100 " ,
140+ fullDescription: nil ,
141+ shortDescription: nil ,
142+ sku: nil ,
143+ globalUniqueID: nil ,
143144 price: " 29.99 " ,
144145 downloadable: false ,
145146 parentID: 0 ,
146- manageStock: true ,
147- stockQuantity: 10 ,
147+ manageStock: false ,
148+ stockQuantity: nil ,
148149 stockStatusKey: " instock "
149150 )
150151 try product. insert ( db)
@@ -190,23 +191,17 @@ struct PersistedProductTests {
190191 try attribute2. insert ( db)
191192 }
192193
193- // Test automatic fetching via associations
194+ // When the product is fetched and converted to a POSProduct
194195 let fetchedProduct = try db. read { db in
195196 try PersistedProduct . filter ( PersistedProduct . Columns. id == 100 ) . fetchOne ( db)
196197 }
197198
198199 let product = try #require( fetchedProduct)
199200 let posProduct = try product. toPOSProduct ( db: db)
200201
201- // Verify product fields
202+ // Then during conversion, images and attributes are populated via associations
203+ // Verify product
202204 #expect( posProduct. productID == 100 )
203- #expect( posProduct. siteID == 1 )
204- #expect( posProduct. name == " Test Product " )
205- #expect( posProduct. fullDescription == " Full description " )
206- #expect( posProduct. shortDescription == " Short description " )
207- #expect( posProduct. sku == " TEST-SKU " )
208- #expect( posProduct. price == " 29.99 " )
209- #expect( posProduct. stockQuantity == 10 )
210205
211206 // Verify images were fetched
212207 #expect( posProduct. images. count == 2 )
@@ -235,6 +230,7 @@ struct PersistedProductTests {
235230
236231 @Test ( " Product without related records has empty arrays " )
237232 func product_without_related_records_creates_empty_arrays( ) throws {
233+ // Given a product without any images or attributes
238234 let grdbManager = try GRDBManager ( )
239235 let db = grdbManager. databaseConnection
240236
@@ -243,7 +239,6 @@ struct PersistedProductTests {
243239 let site = PersistedSite ( id: 3 )
244240 try site. insert ( db)
245241
246- // Insert product without any images or attributes
247242 let product = PersistedProduct (
248243 id: 300 ,
249244 siteID: 3 ,
@@ -263,20 +258,19 @@ struct PersistedProductTests {
263258 try product. insert ( db)
264259 }
265260
266- // Test that product with no related records returns empty arrays
261+ // When we retrieve and convert the product to a POSProduct
267262 let fetchedProduct = try db. read { db in
268263 try PersistedProduct . filter ( PersistedProduct . Columns. id == 300 ) . fetchOne ( db)
269264 }
270265
271266 let product = try #require( fetchedProduct)
272267 let posProduct = try product. toPOSProduct ( db: db)
273268
269+ // Then the POSProduct has empty arrays for images and attributes
274270 #expect( posProduct. productID == 300 )
275271 #expect( posProduct. name == " Lonely Product " )
276272 #expect( posProduct. images. isEmpty)
277273 #expect( posProduct. attributes. isEmpty)
278- #expect( posProduct. fullDescription == nil )
279- #expect( posProduct. shortDescription == nil )
280274 }
281275
282276 @Test ( " PersistedProductAttribute init(from:) and toProductAttribute round-trip " )
0 commit comments