@@ -9,6 +9,7 @@ import {OpenFunctionContext} from '../../src/openfunction/function_context';
99
1010import { OpenFunctionRuntime } from '../../src/functions' ;
1111import { getServer } from '../../src/server' ;
12+ import { FUNCTION_STATUS_HEADER_FIELD } from '../../src/types' ;
1213
1314const TEST_CONTEXT : OpenFunctionContext = {
1415 name : 'test-context' ,
@@ -72,6 +73,7 @@ describe('OpenFunction - HTTP Binding', () => {
7273 { name : 'Save data' , operation : 'create' , listable : true } ,
7374 { name : 'Get data' , operation : 'get' , listable : true } ,
7475 { name : 'Delete data' , operation : 'delete' , listable : false } ,
76+ { name : 'Error data' , operation : '' , listable : false } ,
7577 ] ;
7678
7779 testData . forEach ( test => {
@@ -83,6 +85,8 @@ describe('OpenFunction - HTTP Binding', () => {
8385
8486 const server = getServer (
8587 async ( ctx : OpenFunctionRuntime , data : { } ) => {
88+ if ( ! test . operation ) throw new Error ( 'I crashed' ) ;
89+
8690 await ctx . send ( data ) ;
8791 ctx . res ?. send ( data ) ;
8892 } ,
@@ -93,9 +97,14 @@ describe('OpenFunction - HTTP Binding', () => {
9397 await supertest ( server )
9498 . post ( '/' )
9599 . send ( TEST_PAYLOAD )
96- . expect ( 200 )
100+ . expect ( test . operation ? 200 : 500 )
97101 . expect ( res => {
98- deepStrictEqual ( res . body , TEST_PAYLOAD ) ;
102+ ! test . operation
103+ ? deepStrictEqual (
104+ res . headers [ FUNCTION_STATUS_HEADER_FIELD . toLowerCase ( ) ] ,
105+ 'error'
106+ )
107+ : deepStrictEqual ( res . body , TEST_PAYLOAD ) ;
99108 } ) ;
100109
101110 forEach ( context . outputs , output => {
0 commit comments