Skip to content

Commit

Permalink
tests: Add tests for storageInit()
Browse files Browse the repository at this point in the history
Ensures that default settings are being merged with the existing
extension settings found in the browser as appropriate.
  • Loading branch information
donovanglover committed May 8, 2024
1 parent 0c00766 commit d24bdcf
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions tests/lib/storageInit.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { describe, expect, it, vi } from 'vitest'
import { storageInit } from '@/lib/storageInit'
import type { StorageAll } from '@/types/StorageAll'

const browserMock = {
storage: {
sync: {
get: vi.fn(async (_: string | string[] | Record<string, any> | null | undefined): Promise<Record<string, any>> => ({ blockDefault: true })),
set: vi.fn(async (_: Record<string, any>): Promise<void> => {})
},

local: {
get: vi.fn(async (_: string | string[] | Record<string, any> | null | undefined): Promise<Record<string, any>> => ({})),
set: vi.fn(async (_: Record<string, any>): Promise<void> => {})
}
}
}

vi.stubGlobal('browser', browserMock)

const defaultStorage: StorageAll = {
sync: {
provider: 'mullvad',
blockDefault: false
},

local: {
servers: [],
lastUpdated: 0
}
}

describe('storageInit()', () => {
it('should initialize with default values with existing browser storage values taking priority', async () => {
expect(await storageInit(defaultStorage)).toEqual({
sync: {
provider: 'mullvad',
blockDefault: true
},

local: {
servers: [],
lastUpdated: 0
}
})
})
})

0 comments on commit d24bdcf

Please sign in to comment.