diff --git a/frontend/tests/unit/components/AutoLogout.spec.ts b/frontend/tests/unit/components/AutoLogout.spec.ts index e33bdabf95928c2c241cfdc798d2b81351aae7a2..5a5730f68f8b1ca55742d89365a85c028793c863 100644 --- a/frontend/tests/unit/components/AutoLogout.spec.ts +++ b/frontend/tests/unit/components/AutoLogout.spec.ts @@ -3,6 +3,8 @@ import { mount, createLocalVue } from '@vue/test-utils' import AutoLogout from '@/components/AutoLogout.vue' import sinon from 'sinon' import { Authentication } from '@/store/modules/authentication' +import { SET_LAST_INTERACTION } from '@/store/mutations' +import { lastInteraction } from '@/store/plugins/lastInteractionPlugin' import chai from 'chai' chai.should() @@ -28,7 +30,7 @@ describe('Auto Logout Unit Tests', () => { beforeEach(() => { store = new Vuex.Store({ - state: {} + plugins: [lastInteraction] }) }) @@ -43,7 +45,7 @@ describe('Auto Logout Unit Tests', () => { }) it('should be visible when logoutDialog is set to true', () => { let store = new Vuex.Store({}) - let wrapper = mount(AutoLogout, { localVue, store }) + let wrapper = mount(AutoLogout, { localVue: localVue, store }) wrapper.vm.$data.logoutDialog = true wrapper.html().should.contain('<div class="v-dialog v-dialog--active v-dialog--persistent" style="max-width: 30%;">') }) @@ -51,8 +53,16 @@ describe('Auto Logout Unit Tests', () => { let spy = sinon.spy() sinon.replace(Authentication, 'refreshJWT', spy) let store = new Vuex.Store({}) - let wrapper = mount(AutoLogout, { localVue, store }) + let wrapper = mount(AutoLogout, { localVue: localVue, store }) wrapper.find('#continue-btn').trigger('click') spy.called.should.equal(true) }) + it('should automatically update jwt when it is older than 20% of its lifetime', () => { + // replace lastTokenRefreshTry and jwtTimeDelta from the store to emulate wanted behaviour + let wrapper = mount(AutoLogout, { localVue: localVue, store }) + let spy = sinon.spy() + sinon.replaceGetter(Authentication.state, 'jwtTimeDelta', () => 10 * 1e3) + sinon.replaceGetter(Authentication.state, 'lastTokenRefreshTry', () => Date.now() - 2.1 * 1e3) + sinon.replace(Authentication, 'refreshJWT', spy) + }) })