Skip to content

Commit 3750258

Browse files
committed
Support prediction cancelation
1 parent 42416a6 commit 3750258

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

lib/Prediction.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ export default class Prediction extends ReplicateObject {
2626
return `GET /v1/predictions/${this.id}`;
2727
}
2828

29+
async cancel() {
30+
await this.client.request(`POST /v1/predictions/${this.id}/cancel`);
31+
}
32+
2933
hasTerminalStatus() {
3034
return [
3135
PredictionStatus.CANCELED,

lib/Prediction.test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,18 @@ describe("load()", () => {
5555
expect(returnedPrediction).toBe(prediction);
5656
});
5757
});
58+
59+
describe("cancel()", () => {
60+
it("makes request to cancel prediction", async () => {
61+
jest.spyOn(client, "request").mockResolvedValue({
62+
id: "testprediction",
63+
status: PredictionStatus.PROCESSING,
64+
});
65+
66+
await prediction.cancel();
67+
68+
expect(client.request).toHaveBeenCalledWith(
69+
"POST /v1/predictions/testprediction/cancel"
70+
);
71+
});
72+
});

0 commit comments

Comments
 (0)