Skip to content

test: implement pending tests leftover from TS rewrite #315

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 12, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 40 additions & 6 deletions test/integration/cloud_event_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,26 @@ describe("A 1.0 CloudEvent", () => {
expect(ce["extensionkey"]).to.equal(extensions["extensionkey"]);
});

it("throws ValidationError if the CloudEvent does not conform to the schema");
it("returns a JSON string even if format is invalid");
it("correctly formats a CloudEvent as JSON");
it("throws TypeError if the CloudEvent does not conform to the schema", () => {
try {
new CloudEvent({
...fixture,
source: (null as unknown) as string,
});
} catch (err) {
expect(err).to.be.instanceOf(TypeError);
expect(err.message).to.equal("invalid payload");
}
});

it("correctly formats a CloudEvent as JSON", () => {
const ce = new CloudEvent({ ...fixture });
const json = ce.toString();
const obj = JSON.parse((json as unknown) as string);
expect(obj.type).to.equal(type);
expect(obj.source).to.equal(source);
expect(obj.specversion).to.equal(Version.V1);
});
});

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

it("throws ValidationError if the CloudEvent does not conform to the schema");
it("returns a JSON string even if format is invalid");
it("correctly formats a CloudEvent as JSON");
it("throws TypeError if the CloudEvent does not conform to the schema", () => {
try {
new CloudEvent({
...v03fixture,
source: (null as unknown) as string,
});
} catch (err) {
expect(err).to.be.instanceOf(TypeError);
expect(err.message).to.equal("invalid payload");
}
});

it("correctly formats a CloudEvent as JSON", () => {
const ce = new CloudEvent({ ...v03fixture });
const json = ce.toString();
const obj = JSON.parse((json as unknown) as string);
expect(obj.type).to.equal(type);
expect(obj.source).to.equal(source);
expect(obj.specversion).to.equal(Version.V03);
});
});