-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathunit.ts
35 lines (30 loc) · 1.04 KB
/
unit.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
29
30
31
32
33
34
35
'use strict';
import test from 'tape';
import { expectType } from 'tsd';
import { CloudEvent } from 'cloudevents';
import { CloudEventFunction, Context } from 'faas-js-runtime';
import { handle, Customer } from '../src';
// Ensure that the function completes cleanly when passed a valid event.
test('Unit: handles a valid event', async (t) => {
t.plan(4);
const data: Customer = {
name: 'tiger',
customerId: '01234'
};
// A valid event includes id, type and source at a minimum.
const cloudevent: CloudEvent<Customer> = new CloudEvent({
id: '01234',
type: 'com.example.cloudevents.test',
source: '/test',
data
});
// Invoke the function with the valid event, which should complete without error.
const result = await handle({ log: { info: (_) => _ } } as Context, cloudevent);
t.ok(result);
t.deepEqual(result.data, data);
t.equal(result.type, 'echo');
t.equal(result.source, 'function.eventViewer');
t.end();
});
// Ensure that the handle function is typed correctly.
expectType<CloudEventFunction>(handle);