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

‼️📅 Rewrite - notifScheduler.ts #1092

Merged

Commits on Oct 31, 2023

  1. Add notifScheduler.ts

    Translated notifScheduler.js from Angular to React Typescript
    
    commHelper.ts
    - Added a temporary "any" return type for getUser because the TS needed it
    
    ProfileSettings.jsx
    - Imported the new useSchedulerHelper function (name in progress - need to find a good name for this hook)
    - Replaced any instances of the old Angular NotificationScheduler module with the new schedulerHelper hook
    
    notifScheduler.ts
    - Translated the file from Angular to React TS
    - This file exports a single function which initializes the appConfig and then returns an object containing the functions that the Notification Scheduler functions need (only ProfileSettings.jsx is using this file currently)
    - Replaced any instances of moment with Luxon equivalent
    sebastianbarry committed Oct 31, 2023
    Configuration menu
    Copy the full SHA
    4abe86d View commit details
    Browse the repository at this point in the history

Commits on Nov 2, 2023

  1. Configuration menu
    Copy the full SHA
    da87f47 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    1bfb113 View commit details
    Browse the repository at this point in the history
  3. Format notifScheduler.ts

    Following the Prettier changes in @jiji14 commit bb73676
    sebastianbarry committed Nov 2, 2023
    Configuration menu
    Copy the full SHA
    131eca5 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    cc7664f View commit details
    Browse the repository at this point in the history
  5. Temporary any type, handled purely in notifScheduler getReminderPrefs

    In order to not mess with commHelper.ts as it is outside of the scope of this issue - related to e-mission#1092 (comment)
    sebastianbarry committed Nov 2, 2023
    Configuration menu
    Copy the full SHA
    39986a3 View commit details
    Browse the repository at this point in the history
  6. Undoing imports getting duplicated during prettier changes

    During the prettier changes, a bunch of the imports got merged. Undoing in this commit: e-mission@1bfb113
    sebastianbarry committed Nov 2, 2023
    Configuration menu
    Copy the full SHA
    58539ca View commit details
    Browse the repository at this point in the history
  7. Configuration menu
    Copy the full SHA
    384ffe8 View commit details
    Browse the repository at this point in the history

Commits on Nov 3, 2023

  1. Configuration menu
    Copy the full SHA
    9d3c718 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    a1e035f View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    8b09cb3 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    96d1d50 View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    a6d99e7 View commit details
    Browse the repository at this point in the history

Commits on Nov 7, 2023

  1. Configuration menu
    Copy the full SHA
    b0da6e9 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    6b9d222 View commit details
    Browse the repository at this point in the history
  3. Added typing for User object in getReminderPrefs

    notifScheduler.ts
    - Added a User interface that acts as a structure instead of using any for the type
    sebastianbarry committed Nov 7, 2023
    Configuration menu
    Copy the full SHA
    97571ee View commit details
    Browse the repository at this point in the history
  4. Restructure promise format and replaced moment with Luxon

    ProfileSettings.tsx
    - 2 locations that used moment I replaced with Luxon because the notifScheduler is returning DateTime objects which don't mesh with moment
    - Restructured the if(uiConfig?.reminderSchemes) in refreshNotificationSettings to execute the promises at first, and then set the data
    - Some Prettier formatting took over here automatically too
    sebastianbarry committed Nov 7, 2023
    Configuration menu
    Copy the full SHA
    a29705d View commit details
    Browse the repository at this point in the history

Commits on Nov 9, 2023

  1. Configuration menu
    Copy the full SHA
    9b4b1d0 View commit details
    Browse the repository at this point in the history
  2. Resolve the app crashing errors

    From e-mission#1092 (comment)
    
    notifScheduler.ts
    - Replaced toISO for the date object with toJSDate, per @JGreenlee suggestion: e-mission#1092 (comment)
    sebastianbarry committed Nov 9, 2023
    Configuration menu
    Copy the full SHA
    ba239e6 View commit details
    Browse the repository at this point in the history

Commits on Nov 10, 2023

  1. Remove unnecessary imports

    notifScheduler.ts
    - Removed angular (no longer used),
    - React useState and useEffect (no hooks used),
    - and useAppConfig (pulled in as arguments in the exported functions)
    sebastianbarry committed Nov 10, 2023
    Configuration menu
    Copy the full SHA
    2f75de9 View commit details
    Browse the repository at this point in the history

Commits on Nov 14, 2023

  1. notif-scheduling-state variables kept in ProfileSettings.jsx and hand…

    …ed as parameters
    
    ProfileSettings.jsx
    - Created scheduledPromise and isScheduling
    - Hand these variables as arguments to notifScheduler functions that require it
    
    notifScheduler
    - Removed scheduledPromise and isScheduling as they aren't doing anything
    - Added isScheduling and scheduledPromise as parameters to functions that require it
    - Some prettier formatting came in
    sebastianbarry committed Nov 14, 2023
    Configuration menu
    Copy the full SHA
    5e572d4 View commit details
    Browse the repository at this point in the history
  2. Remove empty objects from notifs, fixing the "n.trigger.at does not e…

    …xist" error
    
    notifScheduler.ts
    - Added some typing
    - Created removeEmptyObjects to remove any empty objects from notifs coming from the cordova plugin
    sebastianbarry committed Nov 14, 2023
    Configuration menu
    Copy the full SHA
    db91c8c View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    e4817da View commit details
    Browse the repository at this point in the history

Commits on Nov 16, 2023

  1. Added sorting to list of notifications right before they get scheduled

    notifScheduler.ts
    - Added a sort function to the list of notifications before they get scheduled
    - I chose to go with id since it's an convenient way to sort, since the id is the number of epoch seconds. the alternative is .trigger.at, but that is a full on JSDate in Luxon which is a string ("Date Thu Nov 16 2023 09:36:17 GMT-0700 (Mountain Standard Time)") and harder to sort
    sebastianbarry committed Nov 16, 2023
    Configuration menu
    Copy the full SHA
    0ee468a View commit details
    Browse the repository at this point in the history
  2. Change static variable isScheduling to a useState

    I was not confident that isScheduling would be set properly if it were set as a static variable being passed as an arg, so I used useState and passed the value and set function
    sebastianbarry committed Nov 16, 2023
    Configuration menu
    Copy the full SHA
    e209f10 View commit details
    Browse the repository at this point in the history
  3. Replace console.logs with logDebugs

    We want to standardize on using logDebug, so I replaced all important console.logs with logDebugs that use JSON.stringify for object printouts
    sebastianbarry committed Nov 16, 2023
    Configuration menu
    Copy the full SHA
    b8bf1cf View commit details
    Browse the repository at this point in the history
  4. Add in more type declarations

    notifScheduler.ts
    - notifs uses any[], because n.trigger.at is not recognized if we use object[]
    - TODO: We may want to create a typing file for these types, such as User, which is currently declared as an interface within this file
    - TODO: We will want to add a type for notifs coming from cordova, and for ReminderScheme from the config, but I'm not sure how since ReminderScheme is an object with a variety of inner objects whose keys may or may not be named the same (weekly, week-quarterly, passive, etc.)
    sebastianbarry committed Nov 16, 2023
    Configuration menu
    Copy the full SHA
    b27ae9a View commit details
    Browse the repository at this point in the history
  5. Add Jest Testing - getScheduledNotifs

    cordovaMocks.ts
    - Added a reminder mock for the cordova plugin for reminders
    
    notifScheduler.test.ts
    - Mock the cordova plugin to return the active reminders
    - Test the getScheduledNotifs function
    sebastianbarry committed Nov 16, 2023
    Configuration menu
    Copy the full SHA
    abbe618 View commit details
    Browse the repository at this point in the history

Commits on Nov 17, 2023

  1. Add first updateScheduledNotifs test

    A lot of mocking was required to do this:
    
    globalMocks.ts
    - Added log mock for console.alert
    - Added log mock for console.error
    - Both of these are called in displayErrorMsg, which is why we have to mock them
    
    notifScheduler.ts
    - Added a resolve in the if statement for the case of "reminders are already scheduled", so that we don't keep running the test and possibly time-out
    
    notifScheduler.test.ts
    - added new mocks for clientStats, logger, commHelper, and notifScheduler
    - Added comments for clarity in tests
    - Renamed any instances of mockNotifications to mockNotifs for more clarity and to mirror the variable name notifs in the actual file
    - Created the new test for updateScheduledNotifs that currently only tests to see if it sees that notifications have already been scheduled and then ends
    sebastianbarry committed Nov 17, 2023
    Configuration menu
    Copy the full SHA
    fbd1b62 View commit details
    Browse the repository at this point in the history

Commits on Nov 21, 2023

  1. Add reminder scheme missing test for updateScheduledNotifs

    I also had to adjust the error coming from notifScheduler because it wasn't helping much with the way it was defined before
    sebastianbarry committed Nov 21, 2023
    Configuration menu
    Copy the full SHA
    87fdae5 View commit details
    Browse the repository at this point in the history

Commits on Nov 22, 2023

  1. Configuration menu
    Copy the full SHA
    214081e View commit details
    Browse the repository at this point in the history
  2. Fixing comments

    sebastianbarry committed Nov 22, 2023
    Configuration menu
    Copy the full SHA
    f5ebb1e View commit details
    Browse the repository at this point in the history

Commits on Nov 24, 2023

  1. Final overall test for updateScheduledNotifs

    This tests the final functionality and longest path through this function
    sebastianbarry committed Nov 24, 2023
    Configuration menu
    Copy the full SHA
    6892580 View commit details
    Browse the repository at this point in the history

Commits on Nov 30, 2023

  1. Configuration menu
    Copy the full SHA
    e8b449f View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    85f0519 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    0528fb0 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    2c0ec40 View commit details
    Browse the repository at this point in the history

Commits on Dec 6, 2023

  1. Configuration menu
    Copy the full SHA
    35ffc41 View commit details
    Browse the repository at this point in the history
  2. fix error on configs without reminderSchemes

    If there are no reminderSchemes in the appConfig, notifScheduler doesn't need to do anything so let's not invoke it.
    
    Also, let's create the type definition for reminderSchemes and use it here in notifScheduler.
    JGreenlee committed Dec 6, 2023
    Configuration menu
    Copy the full SHA
    4e44dba View commit details
    Browse the repository at this point in the history

Commits on Dec 12, 2023

  1. Add getReminderPrefs test for when user does not exist

    notifScheduler.test.ts
    - Imported getUser and updateUser so that we can mock them in the tests
    - Imported addStatReading so we can mock it to do nothing
    - Removed the old way of mocking the implementation of getUser, and the new way allows us to change them per-test
    - Added automatic mock for clientStats
    - added beforeEach statements to mock getUser inside the describe blocks
    -
    sebastianbarry committed Dec 12, 2023
    Configuration menu
    Copy the full SHA
    5ee4d64 View commit details
    Browse the repository at this point in the history
  2. Add simple setReminderPrefs test

    - Tests to see if setReminderPrefs works when called in the way that ProfileSettings.jsx calls it
    sebastianbarry committed Dec 12, 2023
    Configuration menu
    Copy the full SHA
    d3750c3 View commit details
    Browse the repository at this point in the history

Commits on Dec 15, 2023

  1. Add test for updateScheduledNotifs to test if notifs successfully get…

    … scheduled
    
    - There were many places where I used to/fromMillis instead of to/fromJSDate, causing a type difference that was causing errors
    - Added a i18n mock because not having a language code return was messing with the debugScheduledNotifs log outputs
    - Added a funcitonality for mockNotifs in the test, so that it can be adjusted, cleared, added to, etc. so that we can test with getScheduledNotifs if it successfully scheduled the notifs
    sebastianbarry committed Dec 15, 2023
    Configuration menu
    Copy the full SHA
    ec9729d View commit details
    Browse the repository at this point in the history