Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unused code in Zendesk utils #22651

Merged
merged 1 commit into from
Feb 21, 2024
Merged

Remove unused code in Zendesk utils #22651

merged 1 commit into from
Feb 21, 2024

Conversation

guarani
Copy link
Contributor

@guarani guarani commented Feb 20, 2024

This code includes specific WP.com plan names, which we should avoid hard-coding since they can change.

This came up because when WP.com plan names changed, this unused code was found in a search for hard-coded plan names: pcNC1U-WN-p2#comment-1198

To test: Verify the code builds.

Regression Notes

  1. Potential unintended areas of impact: None
  2. What I did to test those areas of impact (or what existing automated tests I relied on): None
  3. What automated tests I added (or what prevented me from doing so): None

PR submission checklist:

  • I have completed the Regression Notes.
  • I have considered adding unit tests for my changes.
  • I have considered adding accessibility improvements for my changes.
  • I have considered if this change warrants user-facing release notes and have added them to RELEASE-NOTES.txt if necessary.

Testing checklist: Not applicable

This code includes specific WP.com plan names, which we should avoid hard-coding since they can change.
@guarani guarani added this to the 24.4 milestone Feb 20, 2024
@guarani guarani requested a review from staskus February 20, 2024 21:49
@guarani guarani enabled auto-merge February 20, 2024 21:50
@wpmobilebot
Copy link
Contributor

WordPress Alpha📲 You can test the changes from this Pull Request in WordPress Alpha by scanning the QR code below to install the corresponding build.
App NameWordPress Alpha WordPress Alpha
ConfigurationRelease-Alpha
Build Numberpr22651-8621500
Version24.3
Bundle IDorg.wordpress.alpha
Commit8621500
App Center BuildWPiOS - One-Offs #8881
Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.

@wpmobilebot
Copy link
Contributor

Jetpack Alpha📲 You can test the changes from this Pull Request in Jetpack Alpha by scanning the QR code below to install the corresponding build.
App NameJetpack Alpha Jetpack Alpha
ConfigurationRelease-Alpha
Build Numberpr22651-8621500
Version24.3
Bundle IDcom.jetpack.alpha
Commit8621500
App Center Buildjetpack-installable-builds #7911
Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.

Copy link
Contributor

@staskus staskus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Thanks. Yes, method such as getHighestPriorityPlan are no longer used sinceZendeskUtils now uses getZendeskMetadata to fetch plan data dynamically.

There's still ZendeskUtilsPlans (ZendeskUtlsTests+Plans.swift) file that use hardcoded plan names for testing, although I think one generic test would be enough instead of having a test for each hardcoded plan name. Tests simply validate that hardcoded plan names in MockPlanServiceRemote get set in customFields.

@guarani guarani merged commit a2aacfc into trunk Feb 21, 2024
21 of 25 checks passed
@guarani guarani deleted the task/remove-unused-code branch February 21, 2024 08:03
@guarani
Copy link
Contributor Author

guarani commented Feb 21, 2024

Good catch, I forgot about the tests. I'd enabled auto-merge, so this PR got merged already. I have this change ready to clean up the tests file:

class ZendeskUtilsPlans: XCTestCase {

    static let examplePlan = "a_plan"
    static let addOnPlan = "add_on_plan"
    static let addOn = "jetpack_addon_scan_daily"

    class MockPlanServiceRemote: PlanServiceRemote {
        override func getZendeskMetadata(siteID: Int, completion: @escaping (Result<ZendeskMetadata, Error>) -> Void) {
            let metadata = ZendeskMetadata(plan: examplePlan, jetpackAddons: [])
            completion(.success(metadata))
        }
    }

    class MockAddOnServiceRemote: PlanServiceRemote {
        override func getZendeskMetadata(siteID: Int, completion: @escaping (Result<ZendeskMetadata, Error>) -> Void) {
            let metadata = ZendeskMetadata(plan: addOnPlan, jetpackAddons: [addOn])
            completion(.success(metadata))
        }
    }

    func testAPlanSelected() {
        // Given
        let planServiceRemote = MockPlanServiceRemote(wordPressComRestApi: MockWordPressComRestApi())

        // When
        ZendeskUtils.sharedInstance.createRequest(planServiceRemote: planServiceRemote, siteID: 0) { requestConfiguration in
            let requestFields = requestConfiguration.customFields
            // Then
            XCTAssert(requestFields.contains(where: {
                return $0.fieldId == ZendeskUtils.TicketFieldIDs.plan && $0.value as! String == ZendeskUtilsPlans.examplePlan
            }))

            XCTAssert(requestFields.contains(where: {
                return $0.fieldId == ZendeskUtils.TicketFieldIDs.addOns && $0.value as! [String] == []
            }))
        }
    }

    func testAddOnSelected() {

        // Given
        let addOnServiceRemote = MockAddOnServiceRemote(wordPressComRestApi: MockWordPressComRestApi())

        // When
        ZendeskUtils.sharedInstance.createRequest(planServiceRemote: addOnServiceRemote, siteID: 0) { requestConfiguration in
            let requestFields = requestConfiguration.customFields

            // Then
            XCTAssert(requestFields.contains(where: {
                return $0.fieldId == ZendeskUtils.TicketFieldIDs.plan && $0.value as! String == ZendeskUtilsPlans.addOnPlan
            }))

            XCTAssert(requestFields.contains(where: {
                return $0.fieldId == ZendeskUtils.TicketFieldIDs.addOns && $0.value as! [String] == [ZendeskUtilsPlans.addOn]
            }))
        }
    }
}

I could put it in a separate PR, but will wait to do some more clean-up later of plan names later on. For example, there's a "business" plan name in an error message during the AT process when installing a plugin. As noted in the link above, this could be renamed to be future-proof against plan name changes, such as "plugin-enabled plan".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants