Skip to content

Commit

Permalink
feat(jest): 100% coverage for store/settings/actions
Browse files Browse the repository at this point in the history
  • Loading branch information
drepram committed Apr 20, 2022
1 parent 4e3948f commit 1195555
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions store/settings/actions.test.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 })
Expand All @@ -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')
Expand All @@ -42,4 +47,35 @@ 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()
})
})

0 comments on commit 1195555

Please sign in to comment.