@@ -598,85 +598,10 @@ final class ProductMapperTests: XCTestCase {
598598 ///
599599 func test_metadata_flexible_decoding_array_format( ) throws {
600600 // Given - JSON with metadata as array (current format)
601- let jsonString = """
602- {
603- " id " : 282,
604- " name " : " Test Product " ,
605- " slug " : " test-product " ,
606- " permalink " : " https://example.com/product/test-product/ " ,
607- " date_created_gmt " : " 2019-02-19T17:33:31 " ,
608- " date_modified_gmt " : " 2019-02-19T17:48:01 " ,
609- " type " : " simple " ,
610- " status " : " publish " ,
611- " featured " : false,
612- " catalog_visibility " : " visible " ,
613- " description " : " " ,
614- " short_description " : " " ,
615- " sku " : " " ,
616- " price " : " 10.00 " ,
617- " regular_price " : " 10.00 " ,
618- " sale_price " : " " ,
619- " on_sale " : false,
620- " purchasable " : true,
621- " total_sales " : 0,
622- " virtual " : false,
623- " downloadable " : false,
624- " downloads " : [],
625- " download_limit " : -1,
626- " download_expiry " : -1,
627- " button_text " : " " ,
628- " external_url " : " " ,
629- " tax_status " : " taxable " ,
630- " tax_class " : " " ,
631- " manage_stock " : false,
632- " stock_quantity " : null,
633- " stock_status " : " instock " ,
634- " backorders " : " no " ,
635- " backorders_allowed " : false,
636- " backordered " : false,
637- " sold_individually " : false,
638- " weight " : " " ,
639- " dimensions " : {
640- " length " : " " ,
641- " width " : " " ,
642- " height " : " "
643- },
644- " shipping_required " : false,
645- " shipping_taxable " : false,
646- " shipping_class " : " " ,
647- " shipping_class_id " : 0,
648- " reviews_allowed " : true,
649- " average_rating " : " 0.00 " ,
650- " rating_count " : 0,
651- " related_ids " : [],
652- " upsell_ids " : [],
653- " cross_sell_ids " : [],
654- " parent_id " : 0,
655- " purchase_note " : " " ,
656- " categories " : [],
657- " tags " : [],
658- " images " : [],
659- " attributes " : [],
660- " default_attributes " : [],
661- " variations " : [],
662- " grouped_products " : [],
663- " menu_order " : 0,
664- " meta_data " : [
665- {
666- " id " : 1001,
667- " key " : " custom_field_1 " ,
668- " value " : " value1 "
669- },
670- {
671- " id " : 1002,
672- " key " : " custom_field_2 " ,
673- " value " : " value2 "
674- }
675- ]
601+ guard let data = Loader . contentsOf ( " minimal-product-array-metadata " ) else {
602+ XCTFail ( " Unable to load test data " )
603+ return
676604 }
677- """
678-
679- let data = jsonString. data ( using: . utf8) !
680605 let decoder = JSONDecoder ( )
681606 decoder. dateDecodingStrategy = . formatted( DateFormatter . Defaults. dateTimeFormatter)
682607 decoder. userInfo [ . siteID] = dummySiteID
@@ -698,85 +623,10 @@ final class ProductMapperTests: XCTestCase {
698623 ///
699624 func test_metadata_flexible_decoding_dictionary_format( ) throws {
700625 // Given - JSON with metadata as object keyed by index strings (new format)
701- let jsonString = """
702- {
703- " id " : 282,
704- " name " : " Test Product " ,
705- " slug " : " test-product " ,
706- " permalink " : " https://example.com/product/test-product/ " ,
707- " date_created_gmt " : " 2019-02-19T17:33:31 " ,
708- " date_modified_gmt " : " 2019-02-19T17:48:01 " ,
709- " type " : " simple " ,
710- " status " : " publish " ,
711- " featured " : false,
712- " catalog_visibility " : " visible " ,
713- " description " : " " ,
714- " short_description " : " " ,
715- " sku " : " " ,
716- " price " : " 10.00 " ,
717- " regular_price " : " 10.00 " ,
718- " sale_price " : " " ,
719- " on_sale " : false,
720- " purchasable " : true,
721- " total_sales " : 0,
722- " virtual " : false,
723- " downloadable " : false,
724- " downloads " : [],
725- " download_limit " : -1,
726- " download_expiry " : -1,
727- " button_text " : " " ,
728- " external_url " : " " ,
729- " tax_status " : " taxable " ,
730- " tax_class " : " " ,
731- " manage_stock " : false,
732- " stock_quantity " : null,
733- " stock_status " : " instock " ,
734- " backorders " : " no " ,
735- " backorders_allowed " : false,
736- " backordered " : false,
737- " sold_individually " : false,
738- " weight " : " " ,
739- " dimensions " : {
740- " length " : " " ,
741- " width " : " " ,
742- " height " : " "
743- },
744- " shipping_required " : false,
745- " shipping_taxable " : false,
746- " shipping_class " : " " ,
747- " shipping_class_id " : 0,
748- " reviews_allowed " : true,
749- " average_rating " : " 0.00 " ,
750- " rating_count " : 0,
751- " related_ids " : [],
752- " upsell_ids " : [],
753- " cross_sell_ids " : [],
754- " parent_id " : 0,
755- " purchase_note " : " " ,
756- " categories " : [],
757- " tags " : [],
758- " images " : [],
759- " attributes " : [],
760- " default_attributes " : [],
761- " variations " : [],
762- " grouped_products " : [],
763- " menu_order " : 0,
764- " meta_data " : {
765- " 0 " : {
766- " id " : 2001,
767- " key " : " custom_field_a " ,
768- " value " : " valueA "
769- },
770- " 1 " : {
771- " id " : 2002,
772- " key " : " custom_field_b " ,
773- " value " : " valueB "
774- }
775- }
626+ guard let data = Loader . contentsOf ( " minimal-product-dictionary-metadata " ) else {
627+ XCTFail ( " Unable to load test data " )
628+ return
776629 }
777- """
778-
779- let data = jsonString. data ( using: . utf8) !
780630 let decoder = JSONDecoder ( )
781631 decoder. dateDecodingStrategy = . formatted( DateFormatter . Defaults. dateTimeFormatter)
782632 decoder. userInfo [ . siteID] = dummySiteID
@@ -787,15 +637,15 @@ final class ProductMapperTests: XCTestCase {
787637 // Then
788638 XCTAssertEqual ( product. customFields. count, 2 )
789639 // Since dictionary values don't have a guaranteed order, we need to check by key
790- let fieldA = product. customFields. first { $0. key == " custom_field_a " }
791- let fieldB = product. customFields. first { $0. key == " custom_field_b " }
792-
793- XCTAssertNotNil ( fieldA )
794- XCTAssertNotNil ( fieldB )
795- XCTAssertEqual ( fieldA ? . metadataID, 2001 )
796- XCTAssertEqual ( fieldA ? . value. stringValue, " valueA " )
797- XCTAssertEqual ( fieldB ? . metadataID, 2002 )
798- XCTAssertEqual ( fieldB ? . value. stringValue, " valueB " )
640+ let field1 = product. customFields. first { $0. key == " custom_field_1 " }
641+ let field2 = product. customFields. first { $0. key == " custom_field_2 " }
642+
643+ XCTAssertNotNil ( field1 )
644+ XCTAssertNotNil ( field2 )
645+ XCTAssertEqual ( field1 ? . metadataID, 1001 )
646+ XCTAssertEqual ( field1 ? . value. stringValue, " value1 " )
647+ XCTAssertEqual ( field2 ? . metadataID, 1002 )
648+ XCTAssertEqual ( field2 ? . value. stringValue, " value2 " )
799649 }
800650}
801651
0 commit comments