diff --git a/test/spec_0_3_tests.js b/test/spec_0_3_tests.js index 442e7f1..8db95ff 100644 --- a/test/spec_0_3_tests.js +++ b/test/spec_0_3_tests.js @@ -1,14 +1,17 @@ const expect = require("chai").expect; const Spec03 = require("../lib/specs/spec_0_3.js"); const { CloudEvent } = require("../index.js"); +const { + MIME_JSON, + ENCODING_BASE64, + SPEC_V03 +} = require("../lib/bindings/http/constants.js"); const id = "97699ec2-a8d9-47c1-bfa0-ff7aa526f838"; const type = "com.github.pull.create"; const source = "urn:event:from:myapi/resourse/123"; const time = new Date(); const schemaurl = "http://example.com/registry/myschema.json"; -const dataContentEncoding = "base64"; -const dataContentType = "application/json"; const data = { much: "wow" }; @@ -19,7 +22,7 @@ const cloudevent = .id(id) .source(source) .type(type) - .dataContentType(dataContentType) + .dataContentType(MIME_JSON) .schemaurl(schemaurl) .subject(subject) .time(time) @@ -36,7 +39,7 @@ describe("CloudEvents Spec v0.3", () => { }); it("Should have 'specversion'", () => { - expect(cloudevent.getSpecversion()).to.equal("0.3"); + expect(cloudevent.getSpecversion()).to.equal(SPEC_V03); }); it("Should have 'type'", () => { @@ -46,14 +49,14 @@ describe("CloudEvents Spec v0.3", () => { describe("OPTIONAL Attributes", () => { it("Should have 'datacontentencoding'", () => { - cloudevent.dataContentEncoding(dataContentEncoding); + cloudevent.dataContentEncoding(ENCODING_BASE64); expect(cloudevent.spec.payload.datacontentencoding) - .to.equal(dataContentEncoding); + .to.equal(ENCODING_BASE64); delete cloudevent.spec.payload.datacontentencoding; }); it("Should have 'datacontenttype'", () => { - expect(cloudevent.getDataContentType()).to.equal(dataContentType); + expect(cloudevent.getDataContentType()).to.equal(MIME_JSON); }); it("Should have 'schemaurl'", () => { @@ -119,7 +122,7 @@ describe("CloudEvents Spec v0.3", () => { expect(cloudevent.format.bind(cloudevent)) .to .throw("invalid payload"); - cloudevent.spec.payload.specversion = "0.3"; + cloudevent.spec.payload.specversion = SPEC_V03; }); it("should throw an error when is empty", () => { @@ -127,7 +130,7 @@ describe("CloudEvents Spec v0.3", () => { expect(cloudevent.format.bind(cloudevent)) .to .throw("invalid payload"); - cloudevent.spec.payload.specversion = "0.3"; + cloudevent.spec.payload.specversion = SPEC_V03; }); }); @@ -170,7 +173,7 @@ describe("CloudEvents Spec v0.3", () => { () => { cloudevent .data("no base 64 value") - .dataContentEncoding("base64") + .dataContentEncoding(ENCODING_BASE64) .dataContentType("text/plain"); expect(cloudevent.format.bind(cloudevent)) @@ -184,7 +187,7 @@ describe("CloudEvents Spec v0.3", () => { it("should accept when 'data' is a string", () => { cloudevent .data("Y2xvdWRldmVudHMK") - .dataContentEncoding("base64"); + .dataContentEncoding(ENCODING_BASE64); expect(cloudevent.format()).to.have.property("datacontentencoding"); delete cloudevent.spec.payload.datacontentencoding; cloudevent.data(data); @@ -198,12 +201,12 @@ describe("CloudEvents Spec v0.3", () => { .data(JSON.stringify(data)); expect(typeof cloudevent.getData()).to.equal("string"); - cloudevent.dataContentType(dataContentType); + cloudevent.dataContentType(MIME_JSON); }); it("should convert data with stringified json to a json object", () => { cloudevent - .dataContentType(dataContentType) + .dataContentType(MIME_JSON) .data(JSON.stringify(data)); expect(cloudevent.getData()).to.deep.equal(data); });