-
Notifications
You must be signed in to change notification settings - Fork 736
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
Moved login/logout logic into the useUser composable and updated references #12915
base: develop
Are you sure you want to change the base?
Conversation
Build Artifacts
|
|
||
describe('HeartBeat', function () { | ||
stubWindowLocation(beforeAll, afterAll); | ||
// replace the real XHR object with the mock XHR object before each test | ||
beforeEach(() => mock.setup()); | ||
beforeEach(() => useUser.mockImplementation(() => useUserMock())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a particular reason for mock.setup()
not to be called anymore? I'm wondering if this is related to the failing tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the oversight. I’ve fixed this now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the description you mentioned that the logic was moved from an actions.js file but there are no changes to any Vuex files included.
I also see that heartbeat.js
may need to be updated to use the useUser
module as it is still calling dispatch('setSession', ...)
here.
I had a comment in the heartbeat.spec.js file re: the tests but I think that updating heartbeat.js
might be the key
@nucleogenesis Thanks for pointing that out. I had initially planned on removing the Vuex logic after successfully migrating the login and session logic to the new Composition API. However, I got stuck with the heartbeat.spec.js tests. I’ve now removed the login/logout and session logic from the Vuex files.
Regarding the heartbeat.js, I refactored the store.dispatch to use the setSession method, but the failing tests persist. I suspect the issue might be related to xhr-mock, but I’m unable to pinpoint the exact cause. Please let me know if you have any suggestions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added one comment to the mock function for setSession
and after some thinking and looking at the code locally I'm not sure precisely what the fix is, but I'm feeling it is very likely to do with that function altogether and it's differences to the real setSession
.
Another thing I saw was that the kolibriLogin
action is being dispatched a few places - such as the store.spec.js
file
Thank you for your effort on this. I hope anything I've said can be helpful. I'll keep thinking about this and come back to it again tomorrow if I can
session, // Make session mutable for test scenarios | ||
|
||
// Actions | ||
setSession: jest.fn(({ session: newSession, clientNow }) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One of the failing tests re: not calling serverTime
w/ clientNow
may be fixed by calling it here.
When I did a rebase locally on develop here, it threw up some weird conflicts, but resolving them during the rebase did reduce it down to only about 10 commits, so I think this can be cleaned up! Let me know if it would be helpful for me to force push updates for this. |
Thank you for your help! If you think force pushing the updates would clean up the commit history and make it easier to manage, I would appreciate it. Please go ahead and do so if it's not too much trouble. |
Sure thing, @iamshobhraj - I will make the update for you! |
…osition API useUser
…osition API useUser
68f29f5
to
f330911
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are still a few failing tests after the rebase, but the commit history seems a bit more coherent now.
@@ -52,15 +145,11 @@ export default function useUser() { | |||
getUserKind, | |||
userHasPermissions, | |||
session, | |||
//state |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you cross check that these are not used anywhere before deleting them?
}; | ||
} | ||
|
||
async function kolibrisetUnspecifiedPassword({ username, password, facility }) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't need to be in here, we can leave it in the actions.js instead.
@@ -196,17 +196,8 @@ export class HeartBeat { | |||
redirectBrowser(); | |||
} | |||
} | |||
store.dispatch('setSession', { | |||
session, | |||
// Calculate an approximation of the client 'now' that was simultaneous to the server |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This explanatory comment should not be deleted.
Summary
Login/logout and session logic is moved into
useUser
composable fromaction.js
. Refactored vuex state into module level state. References toCORE_SET_SESSION
is updated to use the setSession method from useUser composable.References
fixes #12204
Reviewer guidance
after updating references to
CORE_SET_SESSION
inheartbeat.spec.js
file, some tests still failed. I am unable to figure out why these tests are failing. I updated the mock file and implementated it as written in documentation.