42 lines
1.1 KiB
TypeScript
42 lines
1.1 KiB
TypeScript
import { afterEach, describe, expect, it, vi } from 'vitest'
|
|
import { clearCachedEmployeeProfile, hasCachedEmployeeProfile } from './MarketplaceShell'
|
|
|
|
afterEach(() => {
|
|
vi.unstubAllGlobals()
|
|
})
|
|
|
|
describe('MarketplaceShell auth helpers', () => {
|
|
it('does not report an employee profile when the browser cache is empty', () => {
|
|
vi.stubGlobal('window', {
|
|
localStorage: {
|
|
getItem: vi.fn(() => null),
|
|
},
|
|
})
|
|
|
|
expect(hasCachedEmployeeProfile()).toBe(false)
|
|
})
|
|
|
|
it('detects the cached employee profile marker written by dashboard sign-in', () => {
|
|
vi.stubGlobal('window', {
|
|
localStorage: {
|
|
getItem: vi.fn((key: string) => (key === 'employee_profile' ? '{"id":"emp_1"}' : null)),
|
|
},
|
|
})
|
|
|
|
expect(hasCachedEmployeeProfile()).toBe(true)
|
|
})
|
|
|
|
it('clears the cached employee profile marker', () => {
|
|
const removeItem = vi.fn()
|
|
vi.stubGlobal('window', {
|
|
localStorage: {
|
|
removeItem,
|
|
},
|
|
})
|
|
|
|
clearCachedEmployeeProfile()
|
|
|
|
expect(removeItem).toHaveBeenCalledWith('employee_profile')
|
|
})
|
|
})
|