diff --git a/src/cloudevents.ts b/src/cloudevents.ts index fa5ca2fe..c3da6940 100644 --- a/src/cloudevents.ts +++ b/src/cloudevents.ts @@ -19,7 +19,7 @@ import { CloudEventsContext } from './functions'; * Checks whether the incoming request is a CloudEvents event in binary content * mode. This is verified by checking the presence of required headers. * - * @link https://github.com/cloudevents/spec/blob/master/http-transport-binding.md#31-binary-content-mode + * @link https://github.com/cloudevents/spec/blob/master/http-protocol-binding.md#3-http-message-mapping * * @param req Express request object. * @return True if the request is a CloudEvents event in binary content mode, diff --git a/src/functions.ts b/src/functions.ts index 2494f019..854e0573 100644 --- a/src/functions.ts +++ b/src/functions.ts @@ -57,9 +57,9 @@ export interface CloudFunctionsContext { } /** - * The CloudEvents v0.2 context object for the event. + * The CloudEvents v1.0 context object for the event. * - * @link https://github.com/cloudevents/spec/blob/v0.2/spec.md#context-attributes + * @link https://github.com/cloudevents/spec/blob/master/spec.md#context-attributes */ export interface CloudEventsContext { /** diff --git a/test/invoker.ts b/test/invoker.ts index e9546e80..c31beb30 100644 --- a/test/invoker.ts +++ b/test/invoker.ts @@ -156,38 +156,47 @@ describe('CloudEvents request to event function', () => { headers: { [key: string]: string }; body: {}; } + + const specversion = '1.0'; + const type = 'com.google.cloud.storage'; + const source = + 'https://github.com/GoogleCloudPlatform/functions-framework-nodejs'; + const subject = 'test-subject'; + const id = 'test-1234-1234'; + const time = '2020-05-13T01:23:45Z'; + const datacontenttype = 'application/json'; + const data = { + some: 'payload', + }; + const testData: TestData[] = [ { - name: 'CloudEvents v0.2 structured content mode', + name: 'CloudEvents v1.0 structured content mode', headers: { 'Content-Type': 'application/cloudevents+json' }, body: { - type: 'testType', - specversion: 'testSpecversion', - source: 'testSource', - id: 'testId', - time: 'testTime', - schemaurl: 'testSchemaurl', - contenttype: 'testContenttype', - data: { - some: 'payload', - }, + specversion, + type, + source, + subject, + id, + time, + datacontenttype, + data, }, }, { - name: 'CloudEvents v0.2 binary content mode', + name: 'CloudEvents v1.0 binary content mode', headers: { 'Content-Type': 'application/json', - 'ce-type': 'testType', - 'ce-specversion': 'testSpecversion', - 'ce-source': 'testSource', - 'ce-id': 'testId', - 'ce-time': 'testTime', - 'ce-schemaurl': 'testSchemaurl', - 'ce-contenttype': 'testContenttype', - }, - body: { - some: 'payload', + 'ce-specversion': specversion, + 'ce-type': type, + 'ce-source': source, + 'ce-subject': subject, + 'ce-id': id, + 'ce-time': time, + 'ce-datacontenttype': datacontenttype, }, + body: data, }, ]; testData.forEach(test => { @@ -206,15 +215,15 @@ describe('CloudEvents request to event function', () => { .set(test.headers) .send(test.body) .expect(204); - assert.deepStrictEqual(receivedData, { some: 'payload' }); + assert.deepStrictEqual(receivedData, data); assert.notStrictEqual(receivedContext, null); - assert.strictEqual(receivedContext!.type, 'testType'); - assert.strictEqual(receivedContext!.specversion, 'testSpecversion'); - assert.strictEqual(receivedContext!.source, 'testSource'); - assert.strictEqual(receivedContext!.id, 'testId'); - assert.strictEqual(receivedContext!.time, 'testTime'); - assert.strictEqual(receivedContext!.schemaurl, 'testSchemaurl'); - assert.strictEqual(receivedContext!.contenttype, 'testContenttype'); + assert.strictEqual(receivedContext!.specversion, specversion); + assert.strictEqual(receivedContext!.type, type); + assert.strictEqual(receivedContext!.source, source); + assert.strictEqual(receivedContext!.subject, subject); + assert.strictEqual(receivedContext!.id, id); + assert.strictEqual(receivedContext!.time, time); + assert.strictEqual(receivedContext!.datacontenttype, datacontenttype); }); }); });