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

Fix: issue 629 #714

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

aaryankotharii
Copy link

This PR migrates regions storage from UserDefaults to FileManager. Same file structure followed as mentioned in issue description.

fixes issue: #629

Code Changes

  • Created FileManagerProtocol to abstract FileManager operations for testability.
  • Updated RegionService to store and fetch defaultRegion and custom Regions in File system.
  • Created FileManagerMock and updated RegionsServiceTests.

@CLAassistant
Copy link

CLAassistant commented Feb 23, 2024

CLA assistant check
All committers have signed the CLA.

@aaronbrethorst
Copy link
Member

Thank you @aaryankotharii! I'll review and get back to you soon!

@ualch9 ualch9 self-requested a review March 8, 2024 18:46
@ualch9 ualch9 self-assigned this Mar 13, 2024
Copy link
Member

@ualch9 ualch9 left a comment

Choose a reason for hiding this comment

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

Thanks for this PR, @aaryankotharii, we really appreciate it! Great job with updating the tests to ensure quality! I have a few concerns with the layering and the addition of more state.

Also, please test that users who update are able to continue using the app with no interruptions. For example, regions are currently stored in UserDefaults and this PR changes it to storing on disk. Please run the app in a current App Store version, then run a version of the app with this PR and validate that the user can continuing the app without it being confused on the currently selected region.

Please ask questions if you have any, or are unclear about my comments!

OBAKitCore/Location/Regions/FileManagerProtocol.swift Outdated Show resolved Hide resolved
OBAKitTests/Helpers/Mocks/FileManagerMock.swift Outdated Show resolved Hide resolved
OBAKitCore/Location/Regions/RegionsService.swift Outdated Show resolved Hide resolved
OBAKitCore/Location/Regions/FileManagerProtocol.swift Outdated Show resolved Hide resolved
OBAKitCore/Location/Regions/FileManagerProtocol.swift Outdated Show resolved Hide resolved
OBAKitCore/Location/Regions/FileManagerProtocol.swift Outdated Show resolved Hide resolved
OBAKitTests/Helpers/Mocks/FileManagerMock.swift Outdated Show resolved Hide resolved
OBAKitTests/Helpers/Mocks/FileManagerMock.swift Outdated Show resolved Hide resolved
@aaryankotharii
Copy link
Author

Hello @ualch9, I have made the following changes as requested above.

  1. replaced PropertyListEncoder / Decoder with JSONEncoder / Decoder.
  2. replaced enum FileDestination logic with simple static constants in RegionsService.
  3. renamed FileManagerProtocol to RegionsServiceFileManagerProtocol.

@aaryankotharii aaryankotharii requested a review from ualch9 March 17, 2024 00:19
@ualch9
Copy link
Member

ualch9 commented Mar 17, 2024

Thank you @aaryankotharii! Apologies for the delayed turnaround in reviewing, I'll get to this ASAP.

@aaryankotharii
Copy link
Author

no worries @ualch9, but there are a few migration issues I'm not sure how to address. for example, how to approach fetching custom regions, of existing users, which are stored in userdefaults ?

@ualch9
Copy link
Member

ualch9 commented Mar 17, 2024

no worries @ualch9, but there are a few migration issues I'm not sure how to address. for example, how to approach fetching custom regions, of existing users, which are stored in userdefaults ?

Excellent question... @aaronbrethorst, do you have any insight on if custom regions are used enough for us to support a migration path?

@aaronbrethorst
Copy link
Member

I would not worry about custom regions at this time. Thanks for checking!

Copy link
Member

@ualch9 ualch9 left a comment

Choose a reason for hiding this comment

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

Just a documentation nit and a question for you to answer. Thanks!

@@ -204,17 +207,10 @@ public class RegionsService: NSObject, LocationServiceDelegate {

// MARK: - Custom Regions
/// Adds the provided custom region to the RegionsService.
/// If an existing custom region with the same `regionIdentifier` exists, the new region replaces the existing region.
Copy link
Member

Choose a reason for hiding this comment

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

With this new file manager service, what happens if an existing custom region with the same regionIdentifier exists?

static let currentRegionUserDefaultsKey = "OBACurrentRegionUserDefaultsKey"
static let regionsUpdatedAtUserDefaultsKey = "OBARegionsUpdatedAtUserDefaultsKey"
static let defaultRegionsPath = URL.applicationSupportDirectory.appendingPathComponent("default-regions.json")
static let customRegionsPath = URL.documentsDirectory.appendingPathComponent("Regions/custom-regions")
Copy link
Member

Choose a reason for hiding this comment

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

👍

@@ -68,10 +70,9 @@ class RegionsServiceTests: OBATestCase {
stubRegions(dataLoader: dataLoader)
Copy link
Member

Choose a reason for hiding this comment

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

Please update the function signature comment to saved to disk instead of user defaults.

@@ -83,26 +84,25 @@ class RegionsServiceTests: OBATestCase {
stubRegions(dataLoader: dataLoader)
Copy link
Member

Choose a reason for hiding this comment

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

Please update the function signature comment to saved to disk instead of user defaults.

@aaronbrethorst
Copy link
Member

@aaryankotharii - need anything from me in order to get this wrapped up?

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

Successfully merging this pull request may close these issues.

4 participants