Skip to content

Commit 8cc84ba

Browse files
committed
Add test coverage for deployment endpoints
1 parent 6c5b418 commit 8cc84ba

File tree

1 file changed

+129
-0
lines changed

1 file changed

+129
-0
lines changed

index.test.ts

+129
Original file line numberDiff line numberDiff line change
@@ -811,6 +811,135 @@ describe("Replicate client", () => {
811811
// Add more tests for error handling, edge cases, etc.
812812
});
813813

814+
describe("deployments.create", () => {
815+
test("Calls the correct API route with the correct payload", async () => {
816+
nock(BASE_URL)
817+
.post("/deployments")
818+
.reply(200, {
819+
owner: "acme",
820+
name: "my-app-image-generator",
821+
current_release: {
822+
number: 1,
823+
model: "stability-ai/sdxl",
824+
version:
825+
"da77bc59ee60423279fd632efb4795ab731d9e3ca9705ef3341091fb989b7eaf",
826+
created_at: "2024-02-15T16:32:57.018467Z",
827+
created_by: {
828+
type: "organization",
829+
username: "acme",
830+
name: "Acme Corp, Inc.",
831+
github_url: "https://github.com/acme",
832+
},
833+
configuration: {
834+
hardware: "gpu-t4",
835+
scaling: {
836+
min_instances: 1,
837+
max_instances: 5,
838+
},
839+
},
840+
},
841+
});
842+
843+
const deployment = await client.deployments.create({
844+
name: "my-app-image-generator",
845+
model: "stability-ai/sdxl",
846+
version:
847+
"da77bc59ee60423279fd632efb4795ab731d9e3ca9705ef3341091fb989b7eaf",
848+
hardware: "gpu-t4",
849+
min_instances: 1,
850+
max_instances: 5,
851+
});
852+
853+
expect(deployment.owner).toBe("acme");
854+
expect(deployment.name).toBe("my-app-image-generator");
855+
expect(deployment.current_release.model).toBe("stability-ai/sdxl");
856+
});
857+
// Add more tests for error handling, edge cases, etc.
858+
});
859+
860+
describe("deployments.update", () => {
861+
test("Calls the correct API route with the correct payload", async () => {
862+
nock(BASE_URL)
863+
.patch("/deployments/acme/my-app-image-generator")
864+
.reply(200, {
865+
owner: "acme",
866+
name: "my-app-image-generator",
867+
current_release: {
868+
number: 2,
869+
model: "stability-ai/sdxl",
870+
version:
871+
"632231d0d49d34d5c4633bd838aee3d81d936e59a886fbf28524702003b4c532",
872+
created_at: "2024-02-16T08:14:22.345678Z",
873+
created_by: {
874+
type: "organization",
875+
username: "acme",
876+
name: "Acme Corp, Inc.",
877+
github_url: "https://github.com/acme",
878+
},
879+
configuration: {
880+
hardware: "gpu-a40-large",
881+
scaling: {
882+
min_instances: 3,
883+
max_instances: 10,
884+
},
885+
},
886+
},
887+
});
888+
889+
const deployment = await client.deployments.update(
890+
"acme",
891+
"my-app-image-generator",
892+
{
893+
version:
894+
"632231d0d49d34d5c4633bd838aee3d81d936e59a886fbf28524702003b4c532",
895+
hardware: "gpu-a40-large",
896+
min_instances: 3,
897+
max_instances: 10,
898+
}
899+
);
900+
901+
expect(deployment.current_release.number).toBe(2);
902+
expect(deployment.current_release.version).toBe(
903+
"632231d0d49d34d5c4633bd838aee3d81d936e59a886fbf28524702003b4c532"
904+
);
905+
expect(deployment.current_release.configuration.hardware).toBe(
906+
"gpu-a40-large"
907+
);
908+
expect(
909+
deployment.current_release.configuration.scaling?.min_instances
910+
).toBe(3);
911+
expect(
912+
deployment.current_release.configuration.scaling?.max_instances
913+
).toBe(10);
914+
});
915+
// Add more tests for error handling, edge cases, etc.
916+
});
917+
918+
describe("deployments.list", () => {
919+
test("Calls the correct API route", async () => {
920+
nock(BASE_URL)
921+
.get("/deployments")
922+
.reply(200, {
923+
next: null,
924+
previous: null,
925+
results: [
926+
{
927+
owner: "acme",
928+
name: "my-app-image-generator",
929+
current_release: {
930+
// ...
931+
},
932+
},
933+
// ...
934+
],
935+
});
936+
937+
const deployments = await client.deployments.list();
938+
expect(deployments.results.length).toBe(1)
939+
});
940+
// Add more tests for pagination, error handling, edge cases, etc.
941+
});
942+
814943
describe("predictions.create with model", () => {
815944
test("Calls the correct API route with the correct payload", async () => {
816945
nock(BASE_URL)

0 commit comments

Comments
 (0)