trustedshops-public / etrusted-ios-trustbadge-library

Show TrustBadge on your iOS app
MIT License
2 stars 2 forks source link

Feature/buyer protection #17

Closed prempratapsingh closed 1 year ago

prempratapsingh commented 1 year ago

Description

Buyer protection widget is now added to the library with,

  1. Figma based UI/UX specs
  2. Integration to backend API for fetching and displaying shop specific buyer protection details
  3. Unit tests

Also refactored Trustbadge view and widget views for improved unit test coverage. Sonar cloud reports now show 91% code coverage πŸš€

Xcode unit test coverage reports however shows 92.3% code coverage. I will see why there is a difference b/w XCode code coverage and Sonar cloud code coverage.

codecov[bot] commented 1 year ago

Codecov Report

Patch coverage: 85.07% and project coverage change: +9.42 :tada:

Comparison is base (17ede39) 74.17% compared to head (f35889c) 83.60%.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## develop #17 +/- ## =========================================== + Coverage 74.17% 83.60% +9.42% =========================================== Files 43 56 +13 Lines 1642 2177 +535 Branches 609 784 +175 =========================================== + Hits 1218 1820 +602 + Misses 330 212 -118 - Partials 94 145 +51 ``` | [Impacted Files](https://codecov.io/gh/trustedshops-public/etrusted-ios-trustbadge-library/pull/17?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=trustedshops-public) | Coverage Ξ” | | |---|---|---| | [Sources/Trustylib/Models/TrustbadgeContext.swift](https://codecov.io/gh/trustedshops-public/etrusted-ios-trustbadge-library/pull/17?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=trustedshops-public#diff-U291cmNlcy9UcnVzdHlsaWIvTW9kZWxzL1RydXN0YmFkZ2VDb250ZXh0LnN3aWZ0) | `71.42% <0.00%> (-11.91%)` | :arrow_down: | | [...ources/Trustylib/Views/Common/StarRatingView.swift](https://codecov.io/gh/trustedshops-public/etrusted-ios-trustbadge-library/pull/17?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=trustedshops-public#diff-U291cmNlcy9UcnVzdHlsaWIvVmlld3MvQ29tbW9uL1N0YXJSYXRpbmdWaWV3LnN3aWZ0) | `83.01% <ΓΈ> (+6.23%)` | :arrow_up: | | [...ests/TrustylibTests/TestUtils/FileDataLoader.swift](https://codecov.io/gh/trustedshops-public/etrusted-ios-trustbadge-library/pull/17?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=trustedshops-public#diff-VGVzdHMvVHJ1c3R5bGliVGVzdHMvVGVzdFV0aWxzL0ZpbGVEYXRhTG9hZGVyLnN3aWZ0) | `64.28% <ΓΈ> (ΓΈ)` | | | [...ts/TrustylibTests/TrustbadgeViewWrapperTests.swift](https://codecov.io/gh/trustedshops-public/etrusted-ios-trustbadge-library/pull/17?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=trustedshops-public#diff-VGVzdHMvVHJ1c3R5bGliVGVzdHMvVHJ1c3RiYWRnZVZpZXdXcmFwcGVyVGVzdHMuc3dpZnQ=) | `91.66% <ΓΈ> (-0.65%)` | :arrow_down: | | [Tests/TrustylibTests/GradeCalculatorTests.swift](https://codecov.io/gh/trustedshops-public/etrusted-ios-trustbadge-library/pull/17?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=trustedshops-public#diff-VGVzdHMvVHJ1c3R5bGliVGVzdHMvR3JhZGVDYWxjdWxhdG9yVGVzdHMuc3dpZnQ=) | `44.44% <44.44%> (ΓΈ)` | | | [...ests/TrustylibTests/TrustbadgeViewModelTests.swift](https://codecov.io/gh/trustedshops-public/etrusted-ios-trustbadge-library/pull/17?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=trustedshops-public#diff-VGVzdHMvVHJ1c3R5bGliVGVzdHMvVHJ1c3RiYWRnZVZpZXdNb2RlbFRlc3RzLnN3aWZ0) | `89.13% <66.66%> (-0.87%)` | :arrow_down: | | [...stylibTests/BuyerProtectionDetailsModelTests.swift](https://codecov.io/gh/trustedshops-public/etrusted-ios-trustbadge-library/pull/17?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=trustedshops-public#diff-VGVzdHMvVHJ1c3R5bGliVGVzdHMvQnV5ZXJQcm90ZWN0aW9uRGV0YWlsc01vZGVsVGVzdHMuc3dpZnQ=) | `69.81% <69.81%> (ΓΈ)` | | | [Tests/TrustylibTests/ShopGradeViewModelTests.swift](https://codecov.io/gh/trustedshops-public/etrusted-ios-trustbadge-library/pull/17?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=trustedshops-public#diff-VGVzdHMvVHJ1c3R5bGliVGVzdHMvU2hvcEdyYWRlVmlld01vZGVsVGVzdHMuc3dpZnQ=) | `85.14% <75.60%> (-0.97%)` | :arrow_down: | | [Sources/Trustylib/Views/TrustbadgeView.swift](https://codecov.io/gh/trustedshops-public/etrusted-ios-trustbadge-library/pull/17?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=trustedshops-public#diff-U291cmNlcy9UcnVzdHlsaWIvVmlld3MvVHJ1c3RiYWRnZVZpZXcuc3dpZnQ=) | `74.80% <76.59%> (+52.28%)` | :arrow_up: | | [Sources/Trustylib/Models/CurrencyCode.swift](https://codecov.io/gh/trustedshops-public/etrusted-ios-trustbadge-library/pull/17?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=trustedshops-public#diff-U291cmNlcy9UcnVzdHlsaWIvTW9kZWxzL0N1cnJlbmN5Q29kZS5zd2lmdA==) | `83.33% <83.33%> (ΓΈ)` | | | ... and [15 more](https://codecov.io/gh/trustedshops-public/etrusted-ios-trustbadge-library/pull/17?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=trustedshops-public) | | ... and [2 files with indirect coverage changes](https://codecov.io/gh/trustedshops-public/etrusted-ios-trustbadge-library/pull/17/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=trustedshops-public) Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=trustedshops-public). Have a feature suggestion? [Share it here.](https://app.codecov.io/gh/feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=trustedshops-public)

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.

sonarcloud[bot] commented 1 year ago

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 5 Code Smells

91.0% 91.0% Coverage
0.0% 0.0% Duplication

prempratapsingh commented 1 year ago

The code itself looks good πŸ™‚ there is only one thing: It seems like there is code coverage reported for the "Test files".

chore: Please exclude the test files from calculated coverage report.

Everything else looks good, added some suggestions in the comments. πŸ™‚

hey @superus8r what do you mean by Test Files?

XCTest test results and code coverage are based on the actual Swift/Objective-C code which are executed unit tests. It doesn't consider artifect files like mock JSON/Text, etc.

The increase in code coverage % report is because I have refactored the SwiftUI views, Models and ViewModels in a way that more code blocks could be covered during tests runs. I also added good amount of new tests πŸ™‚

superus8r commented 1 year ago

Hey @prempratapsingh thank you for your answer.

what do you mean by Test Files?

Test Files are files under Tests group.

XCTest test results and code coverage are based on the actual Swift/Objective-C code which are executed unit tests.

Could you please tell which groups (e.g. Sources, Tests, Example, etc) have active test coverage? πŸ™‚

prempratapsingh commented 1 year ago

Hey @prempratapsingh thank you for your answer.

what do you mean by Test Files?

Test Files are files under Tests group.

XCTest test results and code coverage are based on the actual Swift/Objective-C code which are executed unit tests.

Could you please tell which groups (e.g. Sources, Tests, Example, etc) have active test coverage? πŸ™‚

@superus8r XCTest doesn't work on the concept of covering a group Sources, Tests, Example, etc. Rather it uses a TestTarget named TrustylibTests where unit test classes (BuyerProtectionDetailsModelTests, BuyerProtectionViewModelTests, etc) are added as pure Swift code.

So in essence TrustylibTests has only Swift test cases (shown in screenshot below) added to it and thus the test reports, code coverage reports are based on these test cases only.

Screenshot 2023-04-03 at 2 15 32 PM
prempratapsingh commented 1 year ago

@superus8r I am not sure about what I need to change for this PR. If you have something specific concern or points for change, please let me know.

superus8r commented 1 year ago

@prempratapsingh

XCTest doesn't work on the concept of covering a group Sources, Tests, Example, etc. Rather it uses a TestTarget named TrustylibTests where unit test classes (BuyerProtectionDetailsModelTests, BuyerProtectionViewModelTests, etc) are added as pure Swift code.

Thank you for clarifying that the XCTest uses TrustylibTests as TestTarget where unit test classes are added as pure Swift code, I understand that. πŸ™‚βœ…

So in essence TrustylibTests has only Swift test cases (shown in screenshot below) added to it and thus the test reports, code coverage reports are based on these test cases only.

I also understand that the TrustylibTests only has Swift test cases and you agree that coverage reports must be based on the test cases. βœ… It's great to know you also agree with that, πŸ™‚ however, along with that, the tests are also reporting coverage on themselves. This is extra and needs to be excluded.

In a nutshell: tests should not report coverage on themselves and this should be excluded πŸ™‚ @irockel could we please get a third opinion on this? I also added a screenshot:

Screenshot 2023-04-03 at 11 01 48
superus8r commented 1 year ago

@prempratapsingh I approved this for now. If it's okay, I can fix it myself later. πŸ™‚

prempratapsingh commented 1 year ago

@prempratapsingh

XCTest doesn't work on the concept of covering a group Sources, Tests, Example, etc. Rather it uses a TestTarget named TrustylibTests where unit test classes (BuyerProtectionDetailsModelTests, BuyerProtectionViewModelTests, etc) are added as pure Swift code.

Thank you for clarifying that the XCTest uses TrustylibTests as TestTarget where unit test classes are added as pure Swift code, I understand that. πŸ™‚βœ…

So in essence TrustylibTests has only Swift test cases (shown in screenshot below) added to it and thus the test reports, code coverage reports are based on these test cases only.

I also understand that the TrustylibTests only has Swift test cases and you agree that coverage reports must be based on the test cases. βœ… It's great to know you also agree with that, πŸ™‚ however, along with that, the tests are also reporting coverage on themselves. This is extra and needs to be excluded.

In a nutshell: tests should not report coverage on themselves and this should be excluded πŸ™‚ @irockel could we please get a third opinion on this? I also added a screenshot: Screenshot 2023-04-03 at 11 01 48

@superus8r the CircleCI configuration for groups to be covered (that you showed in attached screenshot) hasn't been changed. It is the same as when the iOS trustylib code coverage was 72%

The increase in code coverage reports is primarily due to the refactoring I did last week for Views, Models, ViewModel and other related layers. Please see this code commit for reference - https://github.com/trustedshops-public/etrusted-ios-trustbadge-library/commit/3b04f6dcbd6db35ca580913cd815cd15a9d0cd96

prempratapsingh commented 1 year ago

@prempratapsingh I approved this for now. If it's okay, I can fix it myself later. πŸ™‚

@superus8r what fix your are referring to? Could you elaborate please.

superus8r commented 1 year ago

@prempratapsingh

The increase in code coverage reports is primarily due to the refactoring I did last week for Views, Models, ViewModel and other related layers. Please see this code commit for reference

I understand and respect that πŸ™‚

This discussion is:

Mixing these two would not help

prempratapsingh commented 1 year ago

@prempratapsingh

The increase in code coverage reports is primarily due to the refactoring I did last week for Views, Models, ViewModel and other related layers. Please see this code commit for reference

I understand and respect that πŸ™‚

This discussion is:

  • about: tests covering themselves
  • not about: increase in code coverage ❌

Please do not mix these.

@superus8r I am confused about why there is point/concern about tests covering themselves now?

Please see Xcode generated code coverage report (for feature/buyer-protection branch) in the screenshot below. This coverage report is purely by Xcode, there is no CodeCov or CircleCI envolved, still the coverage shows 93.6% :)

Screenshot 2023-04-03 at 3 22 45 PM

I don't understand why tests covering themselves could be a concern as the CircleCI and XCode generated coverage reports are very similar.

Anyways, if you feel like some CircleCI end of change is required for better test coverage, please go for it.

superus8r commented 1 year ago

@prempratapsingh Thanks I will do that

hrayatnia commented 1 year ago

In spirits of open source and contribution, two of the tests get failed with XCode 14.2 by just running tests and also by using Fastlane. Iphone 11 simulator, Iphone 14 Pro simulator.

Test names:

testBuyerProtectionDetailsReturnsCorrectFormattedStringForProtectionAmount on both devices, regardless of the approach

testNetworkDataServiceAddsCorrectURLParameters acted randomly but failed a couple of times.

Screenshot 2023-04-03 at 12 01 38 PNG image PNG image

Also, to contribute to the discussion, the XCode test coverage will also be 91.8% if you turn on the coverage target.

Screenshot 2023-04-03 at 12 24 31 Screenshot 2023-04-03 at 12 24 42

@superus8r @prempratapsingh

superus8r commented 1 year ago

@prempratapsingh fyi