50 lines
1.3 KiB
TypeScript
50 lines
1.3 KiB
TypeScript
/**
|
|
* pending-address (src/lib/pending-address.ts).
|
|
*
|
|
* A delivery address a signed-out user filled in is kept in casual storage and
|
|
* posted after authentication (see PendingAddressSync).
|
|
*/
|
|
|
|
import {
|
|
clearPendingAddress,
|
|
getPendingAddress,
|
|
savePendingAddress,
|
|
} from '@/src/lib/pending-address'
|
|
|
|
const ADDRESS = {
|
|
regionId: 1,
|
|
name: 'Home',
|
|
phone: '9876543210',
|
|
addressLine1: '12 Main Road',
|
|
city: 'Mahabubnagar',
|
|
state: 'Telangana',
|
|
latitude: 16.7488,
|
|
longitude: 77.9851,
|
|
}
|
|
|
|
describe('pending address', () => {
|
|
beforeEach(async () => {
|
|
await clearPendingAddress()
|
|
})
|
|
|
|
it('round-trips a signed-out draft', async () => {
|
|
await savePendingAddress(ADDRESS)
|
|
expect(await getPendingAddress()).toEqual(ADDRESS)
|
|
})
|
|
|
|
it('returns null when there is no draft', async () => {
|
|
expect(await getPendingAddress()).toBeNull()
|
|
})
|
|
|
|
it('clears the draft', async () => {
|
|
await savePendingAddress(ADDRESS)
|
|
await clearPendingAddress()
|
|
expect(await getPendingAddress()).toBeNull()
|
|
})
|
|
|
|
it('returns null for corrupt stored JSON', async () => {
|
|
const { StorageServiceCasual } = require('common-ui/src/services/StorageServiceCasual')
|
|
await StorageServiceCasual.setItem('freshyo_pending_address', '{not json')
|
|
expect(await getPendingAddress()).toBeNull()
|
|
})
|
|
})
|