From 688a77d1e1c45be15cf2a693b4c2cf49c89a28cb Mon Sep 17 00:00:00 2001 From: Dominik Seeger <dominik.seeger@gmx.net> Date: Fri, 4 Jan 2019 12:21:11 +0100 Subject: [PATCH] added tests for AutoLogout component --- .../tests/unit/components/AutoLogout.spec.ts | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/frontend/tests/unit/components/AutoLogout.spec.ts b/frontend/tests/unit/components/AutoLogout.spec.ts index e33bdabf..5a5730f6 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) + }) }) -- GitLab