Skip to content

Commit

Permalink
test: implement pending tests leftover from TS rewrite (#315)
Browse files Browse the repository at this point in the history
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 <lball@redhat.com>
  • Loading branch information
lance authored Aug 12, 2020
1 parent 8ac3eb0 commit b5cf886
Showing 1 changed file with 40 additions and 6 deletions.
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);
});
});

0 comments on commit b5cf886

Please sign in to comment.