Skip to content

Commit 215bc34

Browse files
committed
Test for data 'Binary'
Signed-off-by: Fabio José <[email protected]>
1 parent 8959798 commit 215bc34

File tree

1 file changed

+38
-24
lines changed

1 file changed

+38
-24
lines changed

test/spec_1_tests.js

Lines changed: 38 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,6 @@ describe("CloudEvents Spec v1.0", () => {
6161
it("Should have 'time'", () => {
6262
expect(cloudevent.getTime()).to.equal(time.toISOString());
6363
});
64-
65-
it("Should have 'data'", () => {
66-
expect(cloudevent.getData()).to.deep.equal(data);
67-
});
6864
});
6965

7066
describe("Extenstions Constraints", () => {
@@ -86,8 +82,8 @@ describe("CloudEvents Spec v1.0", () => {
8682
.to.equal("an-string");
8783
});
8884

89-
it("should be ok when type is 'ArrayBuffer' for 'Binary'", () => {
90-
let myBinary = new ArrayBuffer(2019);
85+
it("should be ok when type is 'Uint32Array' for 'Binary'", () => {
86+
let myBinary = new Uint32Array(2019);
9187
cloudevent.addExtension("ext-binary", myBinary);
9288
expect(cloudevent.spec.payload["ext-binary"])
9389
.to.equal(myBinary);
@@ -189,24 +185,6 @@ describe("CloudEvents Spec v1.0", () => {
189185
});
190186
});
191187

192-
describe("'data'", () => {
193-
it("should maintain the type of data when no data content type", () =>{
194-
delete cloudevent.spec.payload.datacontenttype;
195-
cloudevent
196-
.data(JSON.stringify(data));
197-
198-
expect(typeof cloudevent.getData()).to.equal("string");
199-
cloudevent.dataContentType(dataContentType);
200-
});
201-
202-
it("should convert data with stringified json to a json object", () => {
203-
cloudevent
204-
.dataContentType(dataContentType)
205-
.data(JSON.stringify(data));
206-
expect(cloudevent.getData()).to.deep.equal(data);
207-
});
208-
});
209-
210188
describe("'subject'", () => {
211189
it("should throw an error when is an empty string", () => {
212190
cloudevent.subject("");
@@ -224,4 +202,40 @@ describe("CloudEvents Spec v1.0", () => {
224202
});
225203
});
226204
});
205+
206+
describe("Event data constraints", () => {
207+
it("Should have 'data'", () => {
208+
expect(cloudevent.getData()).to.deep.equal(data);
209+
});
210+
211+
it("should maintain the type of data when no data content type", () =>{
212+
delete cloudevent.spec.payload.datacontenttype;
213+
cloudevent
214+
.data(JSON.stringify(data));
215+
216+
expect(typeof cloudevent.getData()).to.equal("string");
217+
cloudevent.dataContentType(dataContentType);
218+
});
219+
220+
it("should convert data with stringified json to a json object", () => {
221+
cloudevent
222+
.dataContentType(dataContentType)
223+
.data(JSON.stringify(data));
224+
expect(cloudevent.getData()).to.deep.equal(data);
225+
});
226+
227+
it("should be ok when type is 'Uint32Array' for 'Binary'", () => {
228+
let dataString = ")(*~^my data for ce#@#$%"
229+
230+
let expected = Uint32Array.from(dataString, (c) => c.codePointAt(0));;
231+
let olddct = cloudevent.getDataContentType();
232+
233+
cloudevent
234+
.dataContentType("text/plain")
235+
.data(expected);
236+
expect(cloudevent.getData()).to.deep.equal(expected);
237+
238+
cloudevent.dataContentType(olddct);
239+
});
240+
});
227241
});

0 commit comments

Comments
 (0)