@@ -640,6 +640,67 @@ final class ProductsRemoteTests: XCTestCase {
640640 }
641641 }
642642
643+ /// Verifies that updateProduct sends only subscription details in metadata and does not send custom fields.
644+ ///
645+ func test_updateProduct_sends_only_subscription_in_metadata_not_custom_fields( ) throws {
646+ // Given
647+ let remote = ProductsRemote ( network: network)
648+ network. simulateResponse ( requestUrlSuffix: " products/ \( sampleProductID) " , filename: " product-update " )
649+
650+ // Create a product with both custom fields and a subscription
651+ let customFields = [
652+ MetaData ( metadataID: 1 , key: " custom_field_1 " , value: " value_1 " ) ,
653+ MetaData ( metadataID: 2 , key: " custom_field_2 " , value: " value_2 " )
654+ ]
655+ let subscription = ProductSubscription (
656+ length: " 12 " ,
657+ period: . month,
658+ periodInterval: " 1 " ,
659+ price: " 9.99 " ,
660+ signUpFee: " 0 " ,
661+ trialLength: " 7 " ,
662+ trialPeriod: . day,
663+ oneTimeShipping: false ,
664+ paymentSyncDate: " 0 " ,
665+ paymentSyncMonth: " "
666+ )
667+ let product = sampleProduct ( ) . copy ( subscription: subscription, customFields: customFields)
668+
669+ // When
670+ waitForExpectation { expectation in
671+ remote. updateProduct ( product: product) { _ in
672+ expectation. fulfill ( )
673+ }
674+ }
675+
676+ // Then
677+ let parametersDictionary = try XCTUnwrap ( network. queryParametersDictionary)
678+
679+ // Verify that metadata contains only subscription details, not custom fields
680+ if let metadata = parametersDictionary [ " meta_data " ] as? [ [ String : Any ] ] {
681+ let metadataKeys = metadata. compactMap { $0 [ " key " ] as? String }
682+
683+ // Verify subscription metadata is present
684+ XCTAssertTrue ( metadataKeys. contains ( " _subscription_length " ) , " Subscription length should be in metadata " )
685+ XCTAssertTrue ( metadataKeys. contains ( " _subscription_period " ) , " Subscription period should be in metadata " )
686+ XCTAssertTrue ( metadataKeys. contains ( " _subscription_period_interval " ) , " Subscription period interval should be in metadata " )
687+ XCTAssertTrue ( metadataKeys. contains ( " _subscription_price " ) , " Subscription price should be in metadata " )
688+ XCTAssertTrue ( metadataKeys. contains ( " _subscription_sign_up_fee " ) , " Subscription sign up fee should be in metadata " )
689+ XCTAssertTrue ( metadataKeys. contains ( " _subscription_trial_length " ) , " Subscription trial length should be in metadata " )
690+ XCTAssertTrue ( metadataKeys. contains ( " _subscription_trial_period " ) , " Subscription trial period should be in metadata " )
691+ XCTAssertTrue ( metadataKeys. contains ( " _subscription_one_time_shipping " ) , " Subscription one time shipping should be in metadata " )
692+
693+ // Verify custom fields are NOT in metadata
694+ XCTAssertFalse ( metadataKeys. contains ( " custom_field_1 " ) , " Custom field 1 should not be sent in metadata " )
695+ XCTAssertFalse ( metadataKeys. contains ( " custom_field_2 " ) , " Custom field 2 should not be sent in metadata " )
696+
697+ // Verify metadata contains exactly 8 subscription fields and no custom fields
698+ XCTAssertEqual ( metadata. count, 8 , " Metadata should contain exactly 8 subscription fields " )
699+ } else {
700+ XCTFail ( " Metadata should be present when product has subscription " )
701+ }
702+ }
703+
643704 // MARK: - Update Product Images
644705
645706 /// Verifies that updateProductImages properly parses the `product-update` sample response.
0 commit comments