33 lines
732 B
JavaScript
33 lines
732 B
JavaScript
import Cookies from 'js-cookie'
|
|
import { getToken, removeToken, setToken } from '@/utils/auth'
|
|
|
|
jest.mock('js-cookie', () => ({
|
|
get: jest.fn(),
|
|
set: jest.fn(),
|
|
remove: jest.fn()
|
|
}))
|
|
|
|
describe('Sense login token cookie', () => {
|
|
beforeEach(() => {
|
|
jest.clearAllMocks()
|
|
})
|
|
|
|
it('persists the token for 30 days', () => {
|
|
setToken('test-token')
|
|
|
|
expect(Cookies.set).toHaveBeenCalledWith(
|
|
'Sense-Admin-Token',
|
|
'test-token',
|
|
{ expires: 30 }
|
|
)
|
|
})
|
|
|
|
it('reads and removes the same product-specific cookie', () => {
|
|
getToken()
|
|
removeToken()
|
|
|
|
expect(Cookies.get).toHaveBeenCalledWith('Sense-Admin-Token')
|
|
expect(Cookies.remove).toHaveBeenCalledWith('Sense-Admin-Token')
|
|
})
|
|
})
|