fix: Add Correct Headers to emitted Binary Event (#302)
* fix: Binary emitter should add a basic application/json header. fixes #301 Signed-off-by: Lucas Holmquist <lholmqui@redhat.com>
This commit is contained in:
parent
a7e0aa07ac
commit
ad0c4340b2
|
@ -20,7 +20,7 @@ export async function emitBinary(event: CloudEvent, options: TransportOptions):
|
||||||
}
|
}
|
||||||
|
|
||||||
async function emit(event: CloudEvent, options: TransportOptions, headers: Headers): Promise<AxiosResponse> {
|
async function emit(event: CloudEvent, options: TransportOptions, headers: Headers): Promise<AxiosResponse> {
|
||||||
const contentType: Headers = { [CONSTANTS.HEADER_CONTENT_TYPE]: CONSTANTS.DEFAULT_CE_CONTENT_TYPE };
|
const contentType: Headers = { [CONSTANTS.HEADER_CONTENT_TYPE]: CONSTANTS.DEFAULT_CONTENT_TYPE };
|
||||||
const config = {
|
const config = {
|
||||||
...options,
|
...options,
|
||||||
method: "POST",
|
method: "POST",
|
||||||
|
|
|
@ -4,6 +4,7 @@ import nock from "nock";
|
||||||
import CONSTANTS from "../../src/constants";
|
import CONSTANTS from "../../src/constants";
|
||||||
|
|
||||||
const DEFAULT_CE_CONTENT_TYPE = CONSTANTS.DEFAULT_CE_CONTENT_TYPE;
|
const DEFAULT_CE_CONTENT_TYPE = CONSTANTS.DEFAULT_CE_CONTENT_TYPE;
|
||||||
|
const DEFAULT_CONTENT_TYPE = CONSTANTS.DEFAULT_CONTENT_TYPE;
|
||||||
|
|
||||||
import { CloudEvent, Version, Emitter, Protocol, headersFor } from "../../src";
|
import { CloudEvent, Version, Emitter, Protocol, headersFor } from "../../src";
|
||||||
import { AxiosResponse } from "axios";
|
import { AxiosResponse } from "axios";
|
||||||
|
@ -55,6 +56,7 @@ describe("HTTP Transport Binding Emitter for CloudEvents", () => {
|
||||||
.send(event)
|
.send(event)
|
||||||
.then((response: AxiosResponse) => {
|
.then((response: AxiosResponse) => {
|
||||||
// A binary message will have a ce-id header
|
// A binary message will have a ce-id header
|
||||||
|
expect(response.data["content-type"]).to.equal(DEFAULT_CONTENT_TYPE);
|
||||||
expect(response.data[CONSTANTS.CE_HEADERS.ID]).to.equal(event.id);
|
expect(response.data[CONSTANTS.CE_HEADERS.ID]).to.equal(event.id);
|
||||||
expect(response.data[CONSTANTS.CE_HEADERS.SPEC_VERSION]).to.equal(Version.V1);
|
expect(response.data[CONSTANTS.CE_HEADERS.SPEC_VERSION]).to.equal(Version.V1);
|
||||||
// A binary message will have a request body for the data
|
// A binary message will have a request body for the data
|
||||||
|
@ -82,6 +84,7 @@ describe("HTTP Transport Binding Emitter for CloudEvents", () => {
|
||||||
.then((response: { data: { [k: string]: string } }) => {
|
.then((response: { data: { [k: string]: string } }) => {
|
||||||
// A binary message will have a ce-id header
|
// A binary message will have a ce-id header
|
||||||
expect(response.data.customheader).to.equal("value");
|
expect(response.data.customheader).to.equal("value");
|
||||||
|
expect(response.data["content-type"]).to.equal(DEFAULT_CONTENT_TYPE);
|
||||||
expect(response.data[CONSTANTS.CE_HEADERS.ID]).to.equal(event.id);
|
expect(response.data[CONSTANTS.CE_HEADERS.ID]).to.equal(event.id);
|
||||||
expect(response.data[CONSTANTS.CE_HEADERS.SPEC_VERSION]).to.equal(Version.V1);
|
expect(response.data[CONSTANTS.CE_HEADERS.SPEC_VERSION]).to.equal(Version.V1);
|
||||||
// A binary message will have a request body for the data
|
// A binary message will have a request body for the data
|
||||||
|
|
Loading…
Reference in New Issue