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

Unit tests #27

Merged
merged 20 commits into from
Dec 3, 2024
Merged

Unit tests #27

merged 20 commits into from
Dec 3, 2024

Conversation

BenCookie95
Copy link
Contributor

@BenCookie95 BenCookie95 commented Nov 1, 2024

Summary

I had to use mocks for the unit tests due to the use of the Google api package. I apologize but the tests are hard to read due to the amount of mocking 😅

  • Added unit tests for most of the api endpoints
  • Unit test for the token replenishment job
  • Moved some code around so I can mock it: oauth2 library and mutex logic
  • Fixed a few bugs I found while writing the unit tests

Test cases

  1. Notification refresh. We don’t have a test case for this in the spreadsheet but we need to add this. We have a job that runs every 12 hours and it will check if there are any notification channels that are due to expire in 24 hours or less, it will create a new notification channel with Google if that is the case
  • /google-drive notifications start
  • In your database, find the PluginKeyValueStore table find the entry for your user with the pkey drive_change_channels-<userid>. The PValue will looks something like this:
    { "channel_id": "3376dacc-fc44-456c-83da-e89fb46ebff6", "resource_id": "<resource>", "mm_user_id": "jrhwa8mch38hjymsr7kuy7smnh", "expiration": 1731962203000, "token": "<token>", "page_token": "1053" }
  • Change the expiration value so that it’s due to expire in the next 24 hours. You will need to do this in the database.
  • Restart the plugin or remove it/re-upload, on startup it will run the notification refresh job
  • Expected Result: You have a new expiration. You will also have a new token
  1. Quick regression test of:
  • connecting your account
  • disconnecting your account
  • A few notification test cases of creating comments

@BenCookie95 BenCookie95 changed the base branch from fix-unbounded-calls to master November 5, 2024 18:02
@BenCookie95 BenCookie95 changed the title WIP: Unit tests Unit tests Nov 6, 2024
Copy link
Contributor

@fmartingr fmartingr left a comment

Choose a reason for hiding this comment

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

LGTM, I tried to check that tests should be doing what they are supposed to, Im not really fan of mocks but we have to work with what we have :)

Good work!

Copy link
Collaborator

@wiggin77 wiggin77 left a comment

Choose a reason for hiding this comment

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

LGTM 👍 I'm wondering if we could have a CI step that checks whether the mocks need to be regenerated. Something along the lines of running the generator and checking that nothing changed.

@BenCookie95
Copy link
Contributor Author

LGTM 👍 I'm wondering if we could have a CI step that checks whether the mocks need to be regenerated. Something along the lines of running the generator and checking that nothing changed.

I've added a ticket for this #37. I'll catch that with other bug fixes

Copy link
Contributor

Choose a reason for hiding this comment

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

How come this file is not in a mocks/ folder and has a slightly different naming? i.e. something_mock.go instead of mock_something.go

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can change the name of it to match the others. It wasn't auto-generated so it didn't seem right to include it next to all the other auto-generated mocks. It could get lost in there?

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh that makes sense

server/plugin/test_utils.go Outdated Show resolved Hide resolved
Copy link

@arush-vashishtha arush-vashishtha left a comment

Choose a reason for hiding this comment

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

I have tested this PR and the expiration date and token is updated upon re-uploading the plugin also the basic functionality of the plugin is working fine. LGTM.

@BenCookie95 BenCookie95 merged commit 3140bf9 into master Dec 3, 2024
4 checks passed
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.

5 participants