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: Avoid trigger last execution "unknown" while the connector is still running #1515

Merged
merged 3 commits into from
Apr 8, 2022

Conversation

doubleface
Copy link
Contributor

This is a problem especially visible with client side connectors but you can also reproduce it with node connecteur :

When you display the harvest dialog for a trigger which is still running and which runs for the first time, the trigger is marked as not running and the last execution date is "unknown"

For node connecteur, when the LOGIN_SUCCESS event is triggered, we display a popup which explains that authentication is a success and that the user can do someting else, then this bug is not too much pain

But for client side connectors, on LOGIN_SUCCESS, the harvest is displayed and the connector is displayed as not running, which is wrong and suggests an error :

image

Now, when a still running trigger is displayed, harvest will mark it a running and watch the corresponding job to get the result of the job and display it

  • feat: Do not mark a job as succeeded on login success
  • feat: Watch job changes when the trigger is already running

@doubleface doubleface requested a review from Crash-- April 5, 2022 08:50
@doubleface doubleface force-pushed the feat/watchJobAfterAccountCreate branch from 18a1d99 to 7fcdac1 Compare April 5, 2022 10:09
@@ -66,6 +66,11 @@ export class KonnectorJobWatcher {
this.emit('error', new KonnectorJobError(error))
}

handleLoginSuccess() {
Copy link
Contributor

@trollepierre trollepierre Apr 5, 2022

Choose a reason for hiding this comment

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

nit: don't we test that part?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This would need to be an integration test. I think there is no point to add a unit test here.

})

afterAll(() => {
jest.restoreAllMocks()
Copy link
Contributor

Choose a reason for hiding this comment

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

what is the point to use a clearAllMocks before restoreAllMocks:

https://jestjs.io/docs/mock-function-api#mockfnmockrestore

I read here that mockRestore does everything that mockReset does
And mockReset does everything that mockClear deos

Copy link
Contributor

Choose a reason for hiding this comment

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

nit: i recommend to remove clearAllMocks

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 prefer to remove restoreAllMocks in this case. ClearAllMocks will erase the history of calls between test which is what I want in the first place.

And removing clearAllMocks makes the tests fail

Copy link
Contributor

Choose a reason for hiding this comment

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

ok, then.

ps: I need to understand one day why mocks are not reset by default. 🤯

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed

})

afterAll(() => {
jest.restoreAllMocks()
Copy link
Contributor

Choose a reason for hiding this comment

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

what is the point to use a clearAllMocks before restoreAllMocks:

https://jestjs.io/docs/mock-function-api#mockfnmockrestore

I read here that mockRestore does everything that mockReset does
And mockReset does everything that mockClear deos

Copy link
Contributor

Choose a reason for hiding this comment

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

nit: i recommend to remove clearAllMocks

@doubleface doubleface merged commit 6dd376a into master Apr 8, 2022
@doubleface doubleface deleted the feat/watchJobAfterAccountCreate branch April 8, 2022 10:24
doubleface pushed a commit to cozy/cozy-harvest-app that referenced this pull request Apr 8, 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

Successfully merging this pull request may close these issues.

2 participants