-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathintegration.ts
52 lines (46 loc) · 1.18 KB
/
integration.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
'use strict';
import { CloudEvent, HTTP } from 'cloudevents';
import { start, InvokerOptions } from 'faas-js-runtime';
import request from 'supertest';
import * as func from '../build';
import test, { Test } from 'tape';
// Test typed CloudEvent data
interface Customer {
name: string;
customerId: string;
}
const data: Customer = {
name: 'tiger',
customerId: '01234'
};
const message = HTTP.binary(
new CloudEvent({
source: '/test/integration',
type: 'test',
data
})
);
const errHandler = (t: Test) => (err: Error) => {
t.error(err);
t.end();
};
test('Integration: handles a valid event', (t) => {
start(func.handle, {} as InvokerOptions).then((server) => {
t.plan(5);
request(server)
.post('/')
.send(message.body)
.set(message.headers)
.expect(200)
.expect('Content-Type', /json/)
.end((err, result) => {
t.error(err, 'No error');
t.ok(result);
t.deepEqual(result.body, JSON.parse(message.body as string));
t.equal(result.headers['ce-type'], 'echo');
t.equal(result.headers['ce-source'], 'function.eventViewer');
t.end();
server.close();
});
}, errHandler(t));
});