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

Moved login/logout logic into the useUser composable and updated references #12915

Open
wants to merge 207 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
207 commits
Select commit Hold shift + click to select a range
75a3901
Turn off gcloudignore parsing as we do not have one, to suppress warn…
rtibbles Nov 6, 2024
fcb8c36
Update h5p build for newer webpack version.
rtibbles Nov 7, 2024
5bc3d41
Add manual/scheduled job to create h5p update PRs when needed.
rtibbles Nov 7, 2024
eceb954
Format as warning
MisRob Nov 15, 2024
4355069
Consistent heading levels
MisRob Nov 15, 2024
3ba70a6
Link how to import with token
MisRob Nov 15, 2024
b3e7706
Add mobile device guide
MisRob Nov 15, 2024
ed99415
Merge branch 'develop' into docs-new-howtos
MisRob Nov 15, 2024
a381dde
moved login/logout logic into useUser composable
iamshobhraj Nov 19, 2024
b5f51b4
Ensure the specific node is returned, not just any with the matching …
rtibbles Nov 6, 2024
adea365
Use kolibri-image-pi repo for building raspberry pi image.
rtibbles Nov 20, 2024
0b70dad
avoid type error in initClassInfo; use KExternalLink to redirect in a…
nucleogenesis Oct 25, 2024
d2acd3c
update authmessage test suite
nucleogenesis Oct 25, 2024
37c2cc5
AuthMessage updates fix post-rebase
nucleogenesis Nov 27, 2024
3eaa320
Revise CoachToolsModule's promise handling to keep things moving alon…
nucleogenesis Nov 27, 2024
e32b103
Conditionalize hideContinue on whether we are displaying an error or not
rtibbles Nov 28, 2024
49caa38
Bump version to 0.17.4
rtibbles Dec 3, 2024
2869ee5
Merge pull request #12893 from rtibbles/multiple_facility_continue
rtibbles Dec 3, 2024
c7ddfdb
Update changelog for 0.17.4
marcellamaki Dec 3, 2024
44c8236
Merge pull request #12904 from marcellamaki/update-changelog-0.17.4
rtibbles Dec 3, 2024
626cce5
Merge branch 'learningequality:develop' into useUser-comp
iamshobhraj Dec 4, 2024
7055012
lessons can be filter by recipents
AllanOXDi Dec 5, 2024
cf41082
[pre-commit.ci lite] apply automatic fixes
pre-commit-ci-lite[bot] Dec 5, 2024
2dfa765
Merge branch 'release-v0.17.x' into develop
rtibbles Dec 5, 2024
894389e
Merge branch 'learningequality:develop' into useUser-comp
iamshobhraj Dec 5, 2024
edf5aee
updated references to CORE_SET_SESSION and changed it to the new comp…
iamshobhraj Dec 5, 2024
8f5d63d
updated useUser mock file as per the new compostion api
iamshobhraj Dec 5, 2024
e0bebb4
Merge branch 'useUser-comp' of github.com:iamshobhraj/kolibri into us…
iamshobhraj Dec 5, 2024
b5647ba
[pre-commit.ci lite] apply automatic fixes
pre-commit-ci-lite[bot] Dec 6, 2024
3936349
Merge pull request #12913 from rtibbles/0.17intodevelop
marcellamaki Dec 6, 2024
ade4e39
added 'mock.setup' in 'beforeEach'
iamshobhraj Dec 9, 2024
818c19e
Merge remote-tracking branch 'origin/useUser-comp' into useUser-comp
iamshobhraj Dec 9, 2024
cd6091d
Fix colors of list items
MisRob Jul 8, 2024
0355e8f
removed existing vuex methods
iamshobhraj Dec 10, 2024
f78ae8d
refactored store.dispatch with setSession mutation
iamshobhraj Dec 10, 2024
ec7851a
removed existing vuex methods
iamshobhraj Dec 10, 2024
d5d8c42
Merge pull request #12911 from AllanOXDi/reciepient-fix
LianaHarris360 Dec 10, 2024
a7402a3
Merge pull request #12920 from nucleogenesis/12425-eqm-preview-quiz-t…
rtibbles Dec 11, 2024
f7e6454
Bump katex from 0.16.11 to 0.16.15
dependabot[bot] Dec 11, 2024
ae747d0
Bump express from 4.21.1 to 4.21.2
dependabot[bot] Dec 11, 2024
4aa277c
avoid console errors by including meta in exam route
nucleogenesis Dec 5, 2024
fce634d
QuizSummaryPage - remove unnecessary quiz property, fix errors due to it
nucleogenesis Dec 5, 2024
27c5596
Bump sass-loader from 16.0.3 to 16.0.4
dependabot[bot] Dec 11, 2024
fa3ef9d
fixes uncategorized filtering in learn
AllanOXDi Dec 11, 2024
4ae719c
AppBar: Use appBarText for text/icon colors
nucleogenesis Dec 11, 2024
5f1840c
Upgrade to vue2.7 and remove @vue/composition-api.
rtibbles Dec 11, 2024
2d704b1
wrap <h2> in <div>
AllanOXDi Dec 12, 2024
f408a44
Merge pull request #12933 from rtibbles/vue2.7
AlexVelezLl Dec 12, 2024
0f850d8
Bump nanoid from 3.3.7 to 3.3.8
dependabot[bot] Dec 12, 2024
3a42d9b
Bump axios from 1.7.8 to 1.7.9
dependabot[bot] Dec 12, 2024
8756395
Bump webpack from 5.97.0 to 5.97.1
dependabot[bot] Dec 12, 2024
40ec617
Bump prettier from 3.4.1 to 3.4.2
dependabot[bot] Dec 12, 2024
ea79b66
Fix coach quizzes blank page
AlexVelezLl Dec 12, 2024
de63959
Merge pull request #12940 from AlexVelezLl/fix-coach-blank-page
AlexVelezLl Dec 12, 2024
317769c
Merge pull request #12926 from learningequality/dependabot/npm_and_ya…
rtibbles Dec 12, 2024
7ade044
Merge pull request #12927 from learningequality/dependabot/npm_and_ya…
rtibbles Dec 12, 2024
71f556d
Merge pull request #12929 from learningequality/dependabot/npm_and_ya…
rtibbles Dec 12, 2024
1300d46
Merge pull request #12931 from learningequality/dependabot/npm_and_ya…
rtibbles Dec 12, 2024
38dd591
Merge pull request #12932 from learningequality/dependabot/npm_and_ya…
rtibbles Dec 12, 2024
de03a66
Merge pull request #12938 from learningequality/dependabot/npm_and_ya…
rtibbles Dec 12, 2024
7b129f3
Merge pull request #12928 from learningequality/dependabot/npm_and_ya…
rtibbles Dec 12, 2024
c9f4bcd
<div> in <div>
AllanOXDi Dec 12, 2024
53267c9
[pre-commit.ci lite] apply automatic fixes
pre-commit-ci-lite[bot] Dec 12, 2024
c94d25c
Ensure properties assignment and learner_ids in assignment obj are al…
LianaHarris360 Dec 12, 2024
d397ff7
Merge pull request #12935 from AllanOXDi/filters-are-not-filtering
rtibbles Dec 12, 2024
0997020
Merge pull request #12869 from rtibbles/blowing_raspberries
jredrejo Dec 12, 2024
025d085
Merge pull request #12941 from LianaHarris360/fix-quiz-copy
LianaHarris360 Dec 12, 2024
3feeb9e
Don't use 'auto' public paths to resolve resources.
rtibbles Dec 12, 2024
4c0bee9
Include appBar in themeconfig; validate in themeSpec for appBar image…
nucleogenesis Dec 12, 2024
1851e10
use themeTokens in themeSpec for appbar
nucleogenesis Dec 12, 2024
ec00222
Update appbar & sidenav to use appbar themeConfig values
nucleogenesis Dec 12, 2024
f994e5c
Merge pull request #12942 from rtibbles/no_auto_kolibri
rtibbles Dec 13, 2024
572ff10
Remove non-extant TODO
rtibbles Dec 13, 2024
1f00801
eliminates new quiz button at printing
AllanOXDi Oct 18, 2024
1383218
eliminates the buttons in the print preview
AllanOXDi Dec 13, 2024
74dcc1a
Use the composable in module scope, as can't define setup on a mixin …
rtibbles Dec 13, 2024
9f0dec1
Add pre-commit hook to prevent references to kolibri-common package i…
rtibbles Dec 2, 2024
ad78b7d
fix incorrect uses of themeConfig and themeTokens utilities
nucleogenesis Dec 13, 2024
9e7134e
Remove prop-drilling, just use theemConfig
nucleogenesis Dec 13, 2024
504fc58
Merge pull request #12891 from rtibbles/none_of_your_common_ilk_here_…
rtibbles Dec 13, 2024
a645782
Use stricted no-unused-properties linting.
rtibbles Dec 4, 2024
a7a26e7
Fix all unused properties linting errors.
rtibbles Dec 12, 2024
c8af4c1
missed default text updated
nucleogenesis Dec 13, 2024
d06c2b4
Merge pull request #12943 from learningequality/rtibbles-patch-2
marcellamaki Dec 13, 2024
deecb99
Merge pull request #12910 from rtibbles/no_unused_all
rtibbles Dec 13, 2024
46ad24d
refelect filtering in csv export
ozer550 Dec 16, 2024
8e6cbab
Fix and simplify spreadsheet action
MisRob Dec 16, 2024
7c83079
Merge branch 'develop' into docs-new-howtos
MisRob Dec 16, 2024
e047e1b
Improve guidance on getting the correct URL
MisRob Dec 16, 2024
c9ccaba
Merge pull request #12803 from rtibbles/gcloud_storage_ignore_ignore_…
LianaHarris360 Dec 16, 2024
9501abb
Merge pull request #12950 from MisRob/fix-spreadsheet-action
rtibbles Dec 16, 2024
0379629
Add v-if to KPageContainer in CoachClassListPage to avoid displaying …
LianaHarris360 Dec 16, 2024
763df69
Created ChannelMetadata model modifications to add ordered fields
jredrejo Dec 13, 2024
a1bf8b8
Change calculate_included_languages to include them in order
jredrejo Dec 13, 2024
24e6296
Add methods to calculate ordered categories and grade_levels
jredrejo Dec 13, 2024
0d8415e
added tests
jredrejo Dec 13, 2024
3881193
Added upgrade procedure
jredrejo Dec 13, 2024
6b614f1
Generated schema and fixed generate_schema procedure to make it compa…
jredrejo Dec 16, 2024
d33c457
bump patch version to 0.17.5
nucleogenesis Dec 16, 2024
c466ef2
Avoid problems with CheckConstraint using DEFERRABLE INITIALLY DEFERRED
jredrejo Dec 16, 2024
3b9dfdd
Merge pull request #12937 from nucleogenesis/themeTokens-appBarText-f…
rtibbles Dec 16, 2024
22391ff
ensure question_sources are converted when copying
nucleogenesis Dec 17, 2024
b9667a7
uses media query to hide buttons from print preview
AllanOXDi Dec 17, 2024
95d5985
basic layout added
AllanOXDi Nov 13, 2024
7291c44
fixes routes
AllanOXDi Nov 14, 2024
4e571ab
fixes the routing issue
AllanOXDi Nov 18, 2024
0b1e4a0
clean up routing business
AllanOXDi Nov 21, 2024
c5a0cce
clean ups importations
AllanOXDi Nov 22, 2024
257bd3f
clean timout
AllanOXDi Nov 25, 2024
5264a6c
rebase
AllanOXDi Nov 27, 2024
76a4fd7
fix review comments
AllanOXDi Nov 27, 2024
adaf345
adds a draggable
AllanOXDi Nov 28, 2024
620e709
removed unused variables
AllanOXDi Nov 28, 2024
9bd9be7
removes unused data prop
AllanOXDi Nov 28, 2024
a3cb994
[pre-commit.ci lite] apply automatic fixes
pre-commit-ci-lite[bot] Nov 28, 2024
25cafe4
handles navigation
AllanOXDi Dec 5, 2024
2cb92ed
fixes failing test
AllanOXDi Dec 5, 2024
e925502
fixes failing test
AllanOXDi Dec 5, 2024
5ff97a3
fixes failing test
AllanOXDi Dec 5, 2024
6fef976
updates the test
AllanOXDi Dec 5, 2024
8bc13de
restores test
AllanOXDi Dec 12, 2024
179cf20
Avoid loading the CoachClassList page if there is only one class
LianaHarris360 Dec 17, 2024
8421cf0
Merge pull request #12849 from MisRob/docs-new-howtos
rtibbles Dec 17, 2024
597ec1a
Merge pull request #12944 from jredrejo/annotate_ordered_channels
rtibbles Dec 17, 2024
2f05ca7
Drop and recreate M2M field to avoid constraint errors.
rtibbles Dec 18, 2024
dd9b9cb
Merge pull request #12957 from rtibbles/fix_migration
rtibbles Dec 18, 2024
790b678
Bump terser-webpack-plugin from 5.3.10 to 5.3.11
dependabot[bot] Dec 18, 2024
8890ed5
Bump webpack-dev-server from 5.1.0 to 5.2.0
dependabot[bot] Dec 18, 2024
c728caf
Bump eslint-plugin-compat from 6.0.1 to 6.0.2
dependabot[bot] Dec 18, 2024
c6c81cd
Bump katex from 0.16.15 to 0.16.17
dependabot[bot] Dec 18, 2024
eadce27
Bump react-window from 1.8.10 to 1.8.11
dependabot[bot] Dec 18, 2024
01d182e
fixes comments
AllanOXDi Dec 18, 2024
a9eb601
fixes comments
AllanOXDi Dec 18, 2024
c837aa8
Merge pull request #12959 from learningequality/dependabot/npm_and_ya…
rtibbles Dec 18, 2024
0b9f233
Merge pull request #12960 from learningequality/dependabot/npm_and_ya…
rtibbles Dec 18, 2024
ae69f93
Merge pull request #12961 from learningequality/dependabot/npm_and_ya…
rtibbles Dec 18, 2024
3fed76d
Merge pull request #12962 from learningequality/dependabot/npm_and_ya…
rtibbles Dec 18, 2024
26142c6
more comment fix
AllanOXDi Dec 18, 2024
2293e22
Merge pull request #12963 from learningequality/dependabot/npm_and_ya…
rtibbles Dec 18, 2024
d4fe9f5
fix failing check
AllanOXDi Dec 18, 2024
12e2a32
themetoken
AllanOXDi Dec 18, 2024
a1e0333
Merge pull request #12945 from AllanOXDi/print-fix
marcellamaki Dec 18, 2024
2ae2257
Merge pull request #12949 from ozer550/reflect-filters-in-csv-export
marcellamaki Dec 19, 2024
25e3650
Merge pull request #12804 from rtibbles/captains_log
rtibbles Dec 19, 2024
a780aa6
Merge branch 'release-v0.17.x' into develop
rtibbles Dec 19, 2024
2218fbb
clean up code
AllanOXDi Dec 19, 2024
018ae11
Merge pull request #12951 from LianaHarris360/class-page-flash
LianaHarris360 Dec 19, 2024
8d398a9
Unset loading after trying to setError
nucleogenesis Dec 19, 2024
49555de
Merge pull request #12964 from rtibbles/017intodevelop
rtibbles Dec 19, 2024
af1eedb
Merge pull request #12845 from AllanOXDi/basic-layout-for-lesson-reso…
marcellamaki Dec 19, 2024
f0b7591
Refactor views lessons side panel view handling
AlexVelezLl Nov 27, 2024
26c5735
Add basic implementation of UpdateResourceSelection
AlexVelezLl Nov 27, 2024
09d1798
Add selection and deselection of resources
AlexVelezLl Nov 27, 2024
eab5200
Fix styles and details to select from bookmarks
AlexVelezLl Nov 27, 2024
181209e
Fix fetch more resources in quizzes
AlexVelezLl Nov 28, 2024
6dee068
Add fetch and fetch more management
AlexVelezLl Nov 28, 2024
7f8c585
Implement tree fetch and display
AlexVelezLl Nov 28, 2024
1f4a695
Add restrictions to select all
AlexVelezLl Nov 29, 2024
9fa1b28
Show selected resources with its size
AlexVelezLl Nov 29, 2024
a0bd796
Remove unused code
AlexVelezLl Dec 3, 2024
2f56d93
use vue router to manage side panels sub pages
AlexVelezLl Dec 3, 2024
e442f8f
Move composables
AlexVelezLl Dec 3, 2024
cd317b8
Replace provide/inject
AlexVelezLl Dec 4, 2024
4f4da5f
Add documentation and remove unused code
AlexVelezLl Dec 12, 2024
41f4898
Update vue composition api package
AlexVelezLl Dec 12, 2024
8bc179d
WIP Commit
AlexVelezLl Dec 12, 2024
798f90d
Refactor side panel positioning
AlexVelezLl Dec 12, 2024
451df01
Refactor useFetch to return hasMore, loadingMore and count
AlexVelezLl Dec 16, 2024
fa380fe
Remove moreKey, dataKey and countKey
AlexVelezLl Dec 17, 2024
a091ad8
Update jsdoc docs
AlexVelezLl Dec 17, 2024
28177ee
Lint files
AlexVelezLl Dec 17, 2024
6901443
Update more to be called moreParams and update channels route name
AlexVelezLl Dec 17, 2024
196bcb6
Manage fetch concurrency
AlexVelezLl Dec 17, 2024
6b0170c
Add unit tests to useFetch
AlexVelezLl Dec 18, 2024
6cfdb65
Link to updated shopping cart
AlexVelezLl Dec 19, 2024
f27d1ac
Merge pull request #12755 from nucleogenesis/0.17--quiz-routing-auth-…
rtibbles Dec 19, 2024
46c8911
Merge pull request #12895 from AlexVelezLl/new-UpdatedResourceSelection
AlexVelezLl Dec 19, 2024
9966f00
Merge pull request #12554 from nucleogenesis/fix--delete-quiz-missing…
rtibbles Dec 19, 2024
763726b
Make setting django settings and pythonpath idempotent and reusable.
rtibbles Nov 21, 2024
4a905a3
Update all subcommands to be KolibriCommands if they don't have a com…
rtibbles Dec 20, 2024
03d0c50
Merge pull request #12874 from rtibbles/snake_like_path
rtibbles Dec 20, 2024
e99a9bb
Merge pull request #12946 from rtibbles/dont_cross_the_streams
nucleogenesis Dec 20, 2024
ae03bdb
Bump webpack-cli from 5.1.4 to 6.0.1
dependabot[bot] Dec 25, 2024
7ad1399
Bump ua-parser-js from 1.0.39 to 1.0.40
dependabot[bot] Dec 25, 2024
392cf11
Bump eslint-plugin-jest from 28.9.0 to 28.10.0
dependabot[bot] Dec 25, 2024
f170990
Bump katex from 0.16.17 to 0.16.18
dependabot[bot] Dec 25, 2024
930f4ae
Merge pull request #12968 from learningequality/dependabot/npm_and_ya…
rtibbles Dec 27, 2024
10baf29
Merge pull request #12969 from learningequality/dependabot/npm_and_ya…
rtibbles Dec 27, 2024
da5a82c
Merge pull request #12970 from learningequality/dependabot/npm_and_ya…
rtibbles Dec 27, 2024
81023f1
Merge pull request #12971 from learningequality/dependabot/npm_and_ya…
rtibbles Dec 27, 2024
ec86cf5
Merge pull request #12806 from rtibbles/auto_update_h5p
rtibbles Dec 27, 2024
33048c7
moved login/logout logic into useUser composable
iamshobhraj Nov 19, 2024
f154cff
updated references to CORE_SET_SESSION and changed it to the new comp…
iamshobhraj Dec 5, 2024
e6c7fa7
updated useUser mock file as per the new compostion api
iamshobhraj Dec 5, 2024
615cbbb
added 'mock.setup' in 'beforeEach'
iamshobhraj Dec 9, 2024
363a9b6
[pre-commit.ci lite] apply automatic fixes
pre-commit-ci-lite[bot] Dec 6, 2024
22c25e1
removed existing vuex methods
iamshobhraj Dec 10, 2024
87c1546
refactored store.dispatch with setSession mutation
iamshobhraj Dec 10, 2024
39e9db7
removed existing vuex methods
iamshobhraj Dec 10, 2024
402d1d8
resolved merge conflict
iamshobhraj Jan 1, 2025
b28c250
fixed imports for ref and computed from vue
iamshobhraj Jan 1, 2025
4b938b8
fix useUser mock to handle clientNow in setSession
iamshobhraj Jan 1, 2025
27bd2d6
Merge branch 'useUser-comp' of github.com:iamshobhraj/kolibri into us…
iamshobhraj Jan 1, 2025
d703749
resolved merge conflict
iamshobhraj Jan 1, 2025
8c01d47
[pre-commit.ci lite] apply automatic fixes
pre-commit-ci-lite[bot] Jan 1, 2025
a86c358
fixed linting errors
iamshobhraj Jan 1, 2025
68f29f5
Merge branch 'useUser-comp' of github.com:iamshobhraj/kolibri into us…
iamshobhraj Jan 1, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions packages/kolibri/__tests__/heartbeat.spec.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
import mock from 'xhr-mock';
import coreStore from 'kolibri/store';
import redirectBrowser from 'kolibri/utils/redirectBrowser';
import * as serverClock from 'kolibri/utils/serverClock';
import { get, set } from '@vueuse/core';
import useSnackbar, { useSnackbarMock } from 'kolibri/composables/useSnackbar'; // eslint-disable-line
import { ref } from '@vue/composition-api';
import { DisconnectionErrorCodes } from 'kolibri/constants';
import useUser, { useUserMock } from 'kolibri/composables/useUser'; // eslint-disable-line
import { HeartBeat } from '../heartbeat.js';
import { trs } from '../internal/disconnection';
import coreModule from '../../../kolibri/core/assets/src/state/modules/core';
import { stubWindowLocation } from 'testUtils'; // eslint-disable-line

jest.mock('kolibri/utils/redirectBrowser');
jest.mock('kolibri/urls');
jest.mock('lockr');
jest.mock('kolibri/composables/useSnackbar');

coreStore.registerModule('core', coreModule);
jest.mock('kolibri/composables/useUser');

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()));
Copy link
Member

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

Copy link
Contributor Author

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.


// put the real XHR object back and clear the mocks after each test
afterEach(() => mock.teardown());
Expand Down Expand Up @@ -206,7 +204,8 @@ describe('HeartBeat', function () {
jest.spyOn(heartBeat, '_sessionUrl').mockReturnValue('url');
});
it('should sign out if an auto logout is detected', function () {
coreStore.commit('CORE_SET_SESSION', { user_id: 'test', id: 'current' });
const { setSession } = useUser();
setSession({ session: { user_id: 'test', id: 'current' } });
mock.put(/.*/, {
status: 200,
body: JSON.stringify({ user_id: null, id: 'current' }),
Expand All @@ -218,7 +217,8 @@ describe('HeartBeat', function () {
});
});
it('should redirect if a change in user is detected', function () {
coreStore.commit('CORE_SET_SESSION', { user_id: 'test', id: 'current' });
const { setSession } = useUser();
setSession({ session: { user_id: 'test', id: 'current' } });
redirectBrowser.mockReset();
mock.put(/.*/, {
status: 200,
Expand All @@ -230,7 +230,8 @@ describe('HeartBeat', function () {
});
});
it('should not sign out if user_id changes but session is being set for first time', function () {
coreStore.commit('CORE_SET_SESSION', { user_id: undefined, id: undefined });
const { setSession } = useUser();
setSession({ session: { user_id: undefined, id: undefined } });
mock.put(/.*/, {
status: 200,
body: JSON.stringify({ user_id: null, id: 'current' }),
Expand All @@ -242,7 +243,8 @@ describe('HeartBeat', function () {
});
});
it('should call setServerTime with a clientNow value that is between the start and finish of the poll', function () {
coreStore.commit('CORE_SET_SESSION', { user_id: 'test', id: 'current' });
const { setSession } = useUser();
setSession({ session: { user_id: 'test', id: 'current' } });
const serverTime = new Date().toJSON();
mock.put(/.*/, {
status: 200,
Expand Down
35 changes: 29 additions & 6 deletions packages/kolibri/composables/__mocks__/useUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@
* useUser.mockImplementation(() => useUserMock())
* ```
*/
import { computed } from '@vue/composition-api';
import { ref, computed } from '@vue/composition-api';
import { UserKinds } from 'kolibri/constants';
import { jest } from '@jest/globals'; // Ensure jest is imported for mocking functions

const session = {
const MOCK_DEFAULT_SESSION = {
app_context: false,
can_manage_content: false,
facility_id: undefined,
Expand Down Expand Up @@ -63,9 +64,9 @@ const MOCK_DEFAULTS = {
userFacilityId: undefined,
getUserKind: UserKinds.ANONYMOUS,
userHasPermissions: false,
session,
//state
...session,
session: { ...MOCK_DEFAULT_SESSION },
// Mock state
...MOCK_DEFAULT_SESSION,
};

export function useUserMock(overrides = {}) {
Expand All @@ -77,7 +78,29 @@ export function useUserMock(overrides = {}) {
for (const key in mocks) {
computedMocks[key] = computed(() => mocks[key]);
}
return computedMocks;

// Module-level state reference for actions
const session = ref({ ...mocks.session });

// Mock implementation of `useUser` methods
return {
...computedMocks,
session, // Make session mutable for test scenarios

// Actions
setSession: jest.fn(({ session: newSession, clientNow }) => {
Copy link
Member

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.

session.value = {
...MOCK_DEFAULT_SESSION,
...newSession,
};
}),

kolibriLogin: jest.fn(async () => Promise.resolve()),

kolibriLogout: jest.fn(() => {}),

kolibrisetUnspecifiedPassword: jest.fn(async () => Promise.resolve()),
};
}

export default jest.fn(() => useUserMock());
171 changes: 130 additions & 41 deletions packages/kolibri/composables/useUser.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,132 @@
import { computed } from '@vue/composition-api';
import store from 'kolibri/store';
import { ref, computed } from '@vue/composition-api';
import client from 'kolibri/client';
import urls from 'kolibri/urls';
import redirectBrowser from 'kolibri/utils/redirectBrowser';
import CatchErrors from 'kolibri/utils/CatchErrors';
import Lockr from 'lockr';
import some from 'lodash/some';
import pick from 'lodash/pick';
import { setServerTime } from 'kolibri/utils/serverClock';
import { UserKinds, ERROR_CONSTANTS, LoginErrors, UPDATE_MODAL_DISMISSED } from 'kolibri/constants';
import { browser, os } from 'kolibri/utils/browserInfo';

// Module level state
const session = ref({
app_context: false,
can_manage_content: false,
facility_id: undefined,
full_name: '',
id: undefined,
kind: [UserKinds.ANONYMOUS],
user_id: undefined,
username: '',
full_facility_import: true,
});

export default function useUser() {
//getters
const isUserLoggedIn = computed(() => store.getters.isUserLoggedIn);
const currentUserId = computed(() => store.getters.currentUserId);
const isLearnerOnlyImport = computed(() => store.getters.isLearnerOnlyImport);
const isCoach = computed(() => store.getters.isCoach);
const isAdmin = computed(() => store.getters.isAdmin);
const isSuperuser = computed(() => store.getters.isSuperuser);
const canManageContent = computed(() => store.getters.canManageContent);
const isAppContext = computed(() => store.getters.isAppContext);
const isClassCoach = computed(() => store.getters.isClassCoach);
const isFacilityCoach = computed(() => store.getters.isFacilityCoach);
const isLearner = computed(() => store.getters.isLearner);
const isFacilityAdmin = computed(() => store.getters.isFacilityAdmin);
const userIsMultiFacilityAdmin = computed(() => store.getters.userIsMultiFacilityAdmin);
const getUserPermissions = computed(() => store.getters.getUserPermissions);
const userFacilityId = computed(() => store.getters.userFacilityId);
const getUserKind = computed(() => store.getters.getUserKind);
const userHasPermissions = computed(() => store.getters.userHasPermissions);
const session = computed(() => store.getters.session);
// Computed properties (former Vuex getters)
const isUserLoggedIn = computed(() => session.value.id !== undefined);
const currentUserId = computed(() => session.value.user_id);
const isLearnerOnlyImport = computed(() => !session.value.full_facility_import);
const isCoach = computed(() =>
session.value.kind.some(kind => [UserKinds.COACH, UserKinds.ASSIGNABLE_COACH].includes(kind)),
);
const isAdmin = computed(() =>
session.value.kind.some(kind => [UserKinds.ADMIN, UserKinds.SUPERUSER].includes(kind)),
);
const isSuperuser = computed(() => session.value.kind.includes(UserKinds.SUPERUSER));
const canManageContent = computed(() =>
session.value.kind.includes(UserKinds.CAN_MANAGE_CONTENT),
);
const isAppContext = computed(() => session.value.app_context);
const isClassCoach = computed(() => session.value.kind.includes(UserKinds.ASSIGNABLE_COACH));
const isFacilityCoach = computed(() => session.value.kind.includes(UserKinds.COACH));
const isFacilityAdmin = computed(() => session.value.kind.includes(UserKinds.ADMIN));
const userIsMultiFacilityAdmin = computed(
rootState => isSuperuser.value && rootState.core.facilities.length > 1,
);
const getUserPermissions = computed(() => {
const permissions = {};
permissions.can_manage_content = canManageContent.value;
return permissions;
});
const isLearner = computed(() => session.value.kind.includes(UserKinds.LEARNER));
const userFacilityId = computed(() => session.value.facility_id);
const getUserKind = computed(() => session.value.kind[0]);
const userHasPermissions = computed(() => some(getUserPermissions.value));

// Actions
async function kolibriLogin(sessionPayload) {
Lockr.set(UPDATE_MODAL_DISMISSED, false);

try {
await client({
data: {
...sessionPayload,
active: true,
browser,
os,
},
url: urls['kolibri:core:session-list'](),
method: 'post',
});

if (!sessionPayload.disableRedirect) {
if (sessionPayload.next) {
redirectBrowser(sessionPayload.next);
} else {
redirectBrowser();
}
}
} catch (error) {
const errorsCaught = CatchErrors(error, [
ERROR_CONSTANTS.INVALID_CREDENTIALS,
ERROR_CONSTANTS.MISSING_PASSWORD,
ERROR_CONSTANTS.PASSWORD_NOT_SPECIFIED,
ERROR_CONSTANTS.NOT_FOUND,
]);

//state
const app_context = computed(() => store.getters.session.app_context);
const can_manage_content = computed(() => store.getters.session.can_manage_content);
const facility_id = computed(() => store.getters.session.facility_id);
const full_name = computed(() => store.getters.session.full_name);
const id = computed(() => store.getters.session.id);
const kind = computed(() => store.getters.session.kind);
const user_id = computed(() => store.getters.session.user_id);
const full_facility_import = computed(() => store.getters.session.full_facility_import);
const username = computed(() => store.getters.session.username);
if (errorsCaught) {
if (errorsCaught.includes(ERROR_CONSTANTS.INVALID_CREDENTIALS)) {
return LoginErrors.INVALID_CREDENTIALS;
} else if (errorsCaught.includes(ERROR_CONSTANTS.MISSING_PASSWORD)) {
return LoginErrors.PASSWORD_MISSING;
} else if (errorsCaught.includes(ERROR_CONSTANTS.PASSWORD_NOT_SPECIFIED)) {
return LoginErrors.PASSWORD_NOT_SPECIFIED;
} else if (errorsCaught.includes(ERROR_CONSTANTS.NOT_FOUND)) {
return LoginErrors.USER_NOT_FOUND;
}
}
throw error;
}
}

function kolibriLogout() {
redirectBrowser(urls['kolibri:core:logout']());
}

function setSession({ session: newSession, clientNow }) {
const serverTime = newSession.server_time;
if (clientNow) {
setServerTime(serverTime, clientNow);
}
const filteredSession = pick(newSession, Object.keys(session));
session.value = {
...session.value,
...filteredSession,
};
}

async function kolibrisetUnspecifiedPassword({ username, password, facility }) {
return client({
url: urls['kolibri:core:setnonspecifiedpassword'](),
data: { username, password, facility },
method: 'post',
});
}

return {
// Computed
isLearnerOnlyImport,
isUserLoggedIn,
currentUserId,
Expand All @@ -52,15 +145,11 @@ export default function useUser() {
getUserKind,
userHasPermissions,
session,
//state
app_context,
can_manage_content,
facility_id,
full_name,
id,
kind,
user_id,
username,
full_facility_import,

// Actions
kolibriLogin,
kolibriLogout,
setSession,
kolibrisetUnspecifiedPassword,
};
}
Loading