45 lines
1.3 KiB
TypeScript
45 lines
1.3 KiB
TypeScript
/** Lot N2: the purge of local recovery copies by account (contract C43, ruling R24). */
|
|
import { afterEach, describe, expect, it } from 'vitest'
|
|
import {
|
|
copyKey,
|
|
hasUserCopies,
|
|
removeOtherUsersCopies,
|
|
removeUserCopies,
|
|
} from '@/editor/state/recovery'
|
|
|
|
const A = 'aaaaaaaa-0000-0000-0000-000000000001'
|
|
const B = 'bbbbbbbb-0000-0000-0000-000000000002'
|
|
|
|
function seed() {
|
|
sessionStorage.setItem(copyKey(A, 'v1'), '{}')
|
|
sessionStorage.setItem(copyKey(A, 'v2'), '{}')
|
|
sessionStorage.setItem(copyKey(B, 'v1'), '{}')
|
|
sessionStorage.setItem('osteo:draft', '{}')
|
|
}
|
|
const keys = () => Object.keys(sessionStorage).sort()
|
|
|
|
afterEach(() => sessionStorage.clear())
|
|
|
|
describe('copy purge', () => {
|
|
it('sees whether an account holds a copy', () => {
|
|
expect(hasUserCopies(A)).toBe(false)
|
|
seed()
|
|
expect(hasUserCopies(A)).toBe(true)
|
|
expect(hasUserCopies('cccccccc')).toBe(false)
|
|
})
|
|
|
|
it('removes every copy of one account and nothing else', () => {
|
|
seed()
|
|
removeUserCopies(A)
|
|
expect(keys()).toEqual([copyKey(B, 'v1'), 'osteo:draft'].sort())
|
|
})
|
|
|
|
it('keeps the signed-in account copies and removes the others', () => {
|
|
seed()
|
|
removeOtherUsersCopies(A)
|
|
expect(keys()).toEqual(
|
|
[copyKey(A, 'v1'), copyKey(A, 'v2'), 'osteo:draft'].sort(),
|
|
)
|
|
})
|
|
})
|