Skip to content

Commit

Permalink
fixup! refactor: remove unnecessary new Promise wrappers
Browse files Browse the repository at this point in the history
  • Loading branch information
JKRhb committed Oct 9, 2023
1 parent 8ad5948 commit a04622e
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 31 deletions.
12 changes: 3 additions & 9 deletions packages/binding-http/test/http-client-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,10 @@ class TestHttpServer implements ProtocolServer {
}
}

public expose(thing: unknown): Promise<void> {
return new Promise<void>((resolve, reject) => {
resolve();
});
}
public async expose(thing: unknown): Promise<void> {}

public destroy(thingId: string): Promise<boolean> {
return new Promise<boolean>((resolve, reject) => {
resolve(false);
});
public async destroy(thingId: string): Promise<boolean> {
return false;
}

public setTestVector(vector: TestVector) {
Expand Down
26 changes: 9 additions & 17 deletions packages/binding-http/test/http-server-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,8 @@ class HttpServerTest {
test = await value.value();
});

testThing.setActionHandler("try", (input: WoT.InteractionOutput) => {
return new Promise<string>((resolve, reject) => {
resolve("TEST");
});
testThing.setActionHandler("try", async (input: WoT.InteractionOutput) => {
return "TEST";
});

await httpServer.expose(testThing);
Expand Down Expand Up @@ -276,11 +274,9 @@ class HttpServerTest {
},
});
let test: DataSchemaValue;
testThing.setPropertyReadHandler("test", (options) => {
testThing.setPropertyReadHandler("test", async (options) => {
expect(options?.uriVariables).to.deep.equal({ id: "testId" });
return new Promise<InteractionInput>((resolve, reject) => {
resolve(test);
});
return test;
});
testThing.setPropertyWriteHandler("test", async (value, options) => {
expect(options?.uriVariables).to.deep.equal({ id: "testId" });
Expand All @@ -289,11 +285,9 @@ class HttpServerTest {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
testThing.properties.test.forms = [];
testThing.setActionHandler("try", (input: WoT.InteractionOutput, params?: InteractionOptions) => {
return new Promise<string>((resolve, reject) => {
expect(params?.uriVariables).to.deep.equal({ step: 5 });
resolve("TEST");
});
testThing.setActionHandler("try", async (input: WoT.InteractionOutput, params?: InteractionOptions) => {
expect(params?.uriVariables).to.deep.equal({ step: 5 });
return "TEST";
});
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
Expand Down Expand Up @@ -339,10 +333,8 @@ class HttpServerTest {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
testThing.properties.test.forms = [];
testThing.setActionHandler("try", (input: WoT.InteractionOutput) => {
return new Promise<string>((resolve, reject) => {
resolve("TEST");
});
testThing.setActionHandler("try", async (input: WoT.InteractionOutput) => {
return "TEST";
});
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
Expand Down
2 changes: 1 addition & 1 deletion packages/core/test/ClientTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ class WoTClientTest {
expect(value).to.equal(12);
resolve(true);
});
})
});
}

@test async "observe property with formIndex"() {
Expand Down
6 changes: 2 additions & 4 deletions packages/core/test/ServerTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,13 @@ chaiUse(spies);
class TestProtocolServer implements ProtocolServer {
public readonly scheme: string = "test";

async expose(thing: ExposedThing): Promise<void> {
}
async expose(thing: ExposedThing): Promise<void> {}

async destroy(thingId: string): Promise<boolean> {
return true;
}

async start(): Promise<void> {
}
async start(): Promise<void> {}

async stop(): Promise<void> {}

Expand Down

0 comments on commit a04622e

Please sign in to comment.