Skip to content

Commit fcd869e

Browse files
committed
test: implement pending tests leftover from TS rewrite (#315)
This commit implements 4 of the 6 pending tests that were not completed during the TypeScript rewrite. The two tests that were not implemented were (one for each of v1 and v03): ``` it("returns a JSON string even if format is invalid"); ``` I don't really know what that's supposed to be/mean, so I removed them. Fixes: #232 Signed-off-by: Lance Ball <[email protected]>
1 parent 3d2f01a commit fcd869e

File tree

1 file changed

+40
-6
lines changed

1 file changed

+40
-6
lines changed

test/integration/cloud_event_test.ts

+40-6
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,26 @@ describe("A 1.0 CloudEvent", () => {
144144
expect(ce["extensionkey"]).to.equal(extensions["extensionkey"]);
145145
});
146146

147-
it("throws ValidationError if the CloudEvent does not conform to the schema");
148-
it("returns a JSON string even if format is invalid");
149-
it("correctly formats a CloudEvent as JSON");
147+
it("throws TypeError if the CloudEvent does not conform to the schema", () => {
148+
try {
149+
new CloudEvent({
150+
...fixture,
151+
source: (null as unknown) as string,
152+
});
153+
} catch (err) {
154+
expect(err).to.be.instanceOf(TypeError);
155+
expect(err.message).to.equal("invalid payload");
156+
}
157+
});
158+
159+
it("correctly formats a CloudEvent as JSON", () => {
160+
const ce = new CloudEvent({ ...fixture });
161+
const json = ce.toString();
162+
const obj = JSON.parse((json as unknown) as string);
163+
expect(obj.type).to.equal(type);
164+
expect(obj.source).to.equal(source);
165+
expect(obj.specversion).to.equal(Version.V1);
166+
});
150167
});
151168

152169
describe("A 0.3 CloudEvent", () => {
@@ -211,7 +228,24 @@ describe("A 0.3 CloudEvent", () => {
211228
expect(ce.data).to.deep.equal({ lunch: "tacos" });
212229
});
213230

214-
it("throws ValidationError if the CloudEvent does not conform to the schema");
215-
it("returns a JSON string even if format is invalid");
216-
it("correctly formats a CloudEvent as JSON");
231+
it("throws TypeError if the CloudEvent does not conform to the schema", () => {
232+
try {
233+
new CloudEvent({
234+
...v03fixture,
235+
source: (null as unknown) as string,
236+
});
237+
} catch (err) {
238+
expect(err).to.be.instanceOf(TypeError);
239+
expect(err.message).to.equal("invalid payload");
240+
}
241+
});
242+
243+
it("correctly formats a CloudEvent as JSON", () => {
244+
const ce = new CloudEvent({ ...v03fixture });
245+
const json = ce.toString();
246+
const obj = JSON.parse((json as unknown) as string);
247+
expect(obj.type).to.equal(type);
248+
expect(obj.source).to.equal(source);
249+
expect(obj.specversion).to.equal(Version.V03);
250+
});
217251
});

0 commit comments

Comments
 (0)