Skip to content

Commit

Permalink
test: update
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed May 24, 2021
1 parent 688dc46 commit 8342654
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions test/server.test.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
import { listen } from 'listhen'
import { $fetch } from 'ohmyfetch/node'
import { createStorage } from '../src'
import { createStorageServer } from '../src/server'

describe('server', () => {
it('basic', async () => {
const storage = createStorage()
const storageServer = createStorageServer(storage)
const { $fetch, close } = await listen(storageServer.handle)
const { close, url: serverURL } = await listen(storageServer.handle)

expect(await $fetch('foo', {})).toMatchObject([])
const fetchStorage = (url: string, opts?: any) => $fetch(url, { baseURL: serverURL, ...opts })

expect(await fetchStorage('foo', {})).toMatchObject([])

await storage.setItem('foo/bar', 'bar')
expect(await $fetch('foo/bar')).toBe('bar')
expect(await fetchStorage('foo/bar')).toBe('bar')

expect(await $fetch('foo/bar', { method: 'PUT', body: 'updated' })).toBe('OK')
expect(await $fetch('foo/bar')).toBe('updated')
expect(await $fetch('/')).toMatchObject(['foo/bar'])
expect(await fetchStorage('foo/bar', { method: 'PUT', body: 'updated' })).toBe('OK')
expect(await fetchStorage('foo/bar')).toBe('updated')
expect(await fetchStorage('/')).toMatchObject(['foo/bar'])

expect(await $fetch('foo/bar', { method: 'DELETE' })).toBe('OK')
expect(await $fetch('foo/bar', {})).toMatchObject([])
expect(await fetchStorage('foo/bar', { method: 'DELETE' })).toBe('OK')
expect(await fetchStorage('foo/bar', {})).toMatchObject([])

await close()
})
Expand Down

0 comments on commit 8342654

Please sign in to comment.