Skip to content
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

refactor: report undefined for no expected value() #1230

Merged
merged 8 commits into from
Feb 22, 2024
11 changes: 9 additions & 2 deletions packages/core/src/interaction-output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@
}

async arrayBuffer(): Promise<ArrayBuffer> {
// TODO check for this.schema == null also and return empty array?
danielpeintner marked this conversation as resolved.
Show resolved Hide resolved

if (this.#buffer) {
return this.#buffer;
}
Expand All @@ -78,6 +80,11 @@
}

async value<T extends WoT.DataSchemaValue>(): Promise<T> {
// is there any value expected at all?
if (this.schema == null) {
return undefined as unknown as T;
}

Check warning on line 86 in packages/core/src/interaction-output.ts

View check run for this annotation

Codecov / codecov/patch

packages/core/src/interaction-output.ts#L85-L86

Added lines #L85 - L86 were not covered by tests

// the value has been already read?
if (this.#value !== undefined) {
return this.#value as T;
Expand All @@ -91,8 +98,8 @@
throw new NotReadableError("No form defined");
}

if (this.schema == null || this.schema.type == null) {
throw new NotReadableError("No schema defined");
if (this.schema.type == null) {
throw new NotReadableError("No schema type defined");

Check warning on line 102 in packages/core/src/interaction-output.ts

View check run for this annotation

Codecov / codecov/patch

packages/core/src/interaction-output.ts#L102

Added line #L102 was not covered by tests
}

// is content type valid?
Expand Down
2 changes: 1 addition & 1 deletion packages/core/test/InteractionOutputTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class InteractionOutputTests {
const stream = Readable.from([1, 2, 3]);
const content = new Content("application/json", stream);

const out = new InteractionOutput(content, {});
const out = new InteractionOutput(content, {}, { type: "string" });
const result = [];
const reader = out.data.getReader();
expect(reader).not.to.be.undefined;
Expand Down
Loading