From d0c207d06f5deada52337340c6df8f61eb66644d Mon Sep 17 00:00:00 2001 From: Andre Christoga Pramaditya Date: Wed, 20 Apr 2022 19:56:51 +0700 Subject: [PATCH] feat(jest): 100% coverage for store/settings/actions (#2937) --- store/settings/actions.test.ts | 36 ++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/store/settings/actions.test.ts b/store/settings/actions.test.ts index 49771b410b..86fdec8627 100644 --- a/store/settings/actions.test.ts +++ b/store/settings/actions.test.ts @@ -1,6 +1,9 @@ +import Vue from 'vue' +import { TextileError } from '../textile/types' import * as actions from './actions' import { SettingsError } from './types' import { db } from '~/libraries/SatelliteDB/SatelliteDB' +import TextileManager from '~/libraries/Textile/TextileManager' describe('actions.default', () => { const original = window.location @@ -20,6 +23,7 @@ describe('actions.default', () => { }) test('actions.default.clearLocalStorage successful', async () => { + Vue.prototype.$TextileManager = new TextileManager() db.delete = jest.fn().mockReturnValue(true) const commit = jest.fn() await actions.default.clearLocalStorage({ commit }) @@ -28,6 +32,7 @@ describe('actions.default', () => { }) test('actions.default.clearLocalStorage error', async () => { + Vue.prototype.$TextileManager = new TextileManager() try { db.delete = jest.fn().mockImplementation(() => { throw new Error('mock error') @@ -42,6 +47,37 @@ describe('actions.default', () => { ) } }) + + test('setConsentScan with consentScan but error occured', async () => { + const commit = jest.fn() + + try { + await actions.default.setConsentScan({ commit }, true) + } catch (error) { + console.log(2) + expect(commit).toHaveBeenCalledWith('setConsentScan', true) + expect(error).toBeInstanceOf(Error) + expect(error).toHaveProperty( + 'message', + TextileError.USERINFO_MANAGER_NOT_FOUND, + ) + } + }) + + test('setConsentScan with consentScan', async () => { + Vue.prototype.$TextileManager = new TextileManager() + const TMConstructor = Vue.prototype.$TextileManager + TMConstructor.userInfoManager = jest.fn() + TMConstructor.userInfoManager.setConsent = jest + .fn() + .mockReturnValueOnce(Promise.resolve()) + + const commit = jest.fn() + + await actions.default.setConsentScan({ commit }, true) + expect(commit).toHaveBeenCalledWith('setConsentScan', true) + expect(TMConstructor.userInfoManager.setConsent).toHaveBeenCalled() + }) }) describe('actions.default.setConsentScan', () => {