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

Cannot Mock PaywallModel #36

Closed
GutteApps opened this issue May 3, 2022 · 2 comments
Closed

Cannot Mock PaywallModel #36

GutteApps opened this issue May 3, 2022 · 2 comments

Comments

@GutteApps
Copy link

Hi,

I'm trying to mock PaywallModel so I can test the creation of Paywalls before submitting my IAP for review.

I looked at ModelsTest in the example project and created this similiar function:

    func getMockPaywall() -> PaywallModel?{
        
        guard let url = Bundle.main.url(forResource: "Paywall", withExtension: "json") else {
            print("Missing file: Paywall.json")
            return nil
        }
        do{
            let data = try Data(contentsOf: url)
            let json = try JSONSerialization.jsonObject(with: data, options: []) as! [String: Any]
            let paywall = try PaywallModel(json: attributes(from: json))

            return paywall
        }
        catch{
            return nil
        }
        
        return nil
     
    }
     private func attributes(from params: Parameters) -> Parameters {
        return ["attributes": params]
    }

For some reason, the compiler seems to think I'm using the wrong initializer.
I thought this was a conflict specific to my project but the same error appears when I create a clean project with only Adapty.
Screen Shot 2022-05-03 at 6 28 30 PM

I'm using version 1.17.0, Installed with SPM, on SwiftUI if that makes a difference.

Please help 🙏

@rudrankriyam
Copy link
Contributor

From what I understand, if you look at the declaration of PaywallModel, you will see the required init?(json: Parameters) is not public; hence the compiler cannot access it.

I forked the repository and made the init public:

public required init?(json: Parameters) throws {
}

And it works fine. Although, the library authors can tell better if they want to expose the initializer of PaywallModel or not.

@GutteApps
Copy link
Author

mmm.. the class itself is public. I didn't realize the initializer needs to be explicitly public as well. thanks

@x401om x401om closed this as completed Jul 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants