-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrequest_test.ts
28 lines (27 loc) · 1.11 KB
/
request_test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import { parseRequest } from './request.ts'
import { assertEquals } from 'https://deno.land/[email protected]/testing/asserts.ts'
Deno.test('parseRequest', async (t) => {
await t.step('Returns an error if not object', () => {
assertEquals(parseRequest('i am text'), 'parse-error')
})
await t.step('Marks as invalid if empty array', () => {
assertEquals(parseRequest('[]'), ['invalid'])
})
await t.step('Marks as invalid if not array of objects', () => {
assertEquals(parseRequest('["i am text"]'), ['invalid'])
})
await t.step('Marks as invalid if version is not 2.0', () => {
assertEquals(parseRequest(JSON.stringify({ method: 'hello' })), ['invalid'])
assertEquals(
parseRequest(JSON.stringify({ method: 'hello', jsonrpc: '1.0' })),
['invalid'],
)
})
await t.step('Marks as invalid if method is missing', () => {
assertEquals(parseRequest(JSON.stringify({ jsonrpc: '2.0' })), ['invalid'])
})
await t.step('Properly parses valid request', () => {
const response = { jsonrpc: '2.0', method: 'hello' }
assertEquals(parseRequest(JSON.stringify(response)), [response])
})
})