This commit is contained in:
@@ -1,33 +1,38 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { readCachedPaymentLink, writeCachedPaymentLink } from './paymentLinkCache'
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import {
|
||||
readCachedPaymentLink,
|
||||
writeCachedPaymentLink,
|
||||
} from './paymentLinkCache';
|
||||
|
||||
function createMockStorage(): Storage {
|
||||
const store = new Map<string, string>()
|
||||
const store = new Map<string, string>();
|
||||
return {
|
||||
getItem: (key: string) => store.get(key) ?? null,
|
||||
setItem: (key: string, value: string) => void store.set(key, value),
|
||||
removeItem: (key: string) => void store.delete(key),
|
||||
clear: () => store.clear(),
|
||||
key: () => null,
|
||||
get length() { return store.size },
|
||||
}
|
||||
get length() {
|
||||
return store.size;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
describe('payment link cache', () => {
|
||||
it('returns null when nothing is cached', () => {
|
||||
expect(readCachedPaymentLink(createMockStorage())).toBeNull()
|
||||
})
|
||||
expect(readCachedPaymentLink(createMockStorage())).toBeNull();
|
||||
});
|
||||
|
||||
it('round-trips a cached link', () => {
|
||||
const storage = createMockStorage()
|
||||
writeCachedPaymentLink(storage, 'https://paypal.me/alice')
|
||||
expect(readCachedPaymentLink(storage)).toBe('https://paypal.me/alice')
|
||||
})
|
||||
const storage = createMockStorage();
|
||||
writeCachedPaymentLink(storage, 'https://paypal.me/alice');
|
||||
expect(readCachedPaymentLink(storage)).toBe('https://paypal.me/alice');
|
||||
});
|
||||
|
||||
it('overwrites a previously cached link', () => {
|
||||
const storage = createMockStorage()
|
||||
writeCachedPaymentLink(storage, 'https://paypal.me/alice')
|
||||
writeCachedPaymentLink(storage, 'https://paypal.me/bob')
|
||||
expect(readCachedPaymentLink(storage)).toBe('https://paypal.me/bob')
|
||||
})
|
||||
})
|
||||
const storage = createMockStorage();
|
||||
writeCachedPaymentLink(storage, 'https://paypal.me/alice');
|
||||
writeCachedPaymentLink(storage, 'https://paypal.me/bob');
|
||||
expect(readCachedPaymentLink(storage)).toBe('https://paypal.me/bob');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user