Skip to content

Commit 016a827

Browse files
committed
chore: fix tests
1 parent d8aec15 commit 016a827

1 file changed

Lines changed: 48 additions & 32 deletions

File tree

packages/admin/tests/client.spec.ts

Lines changed: 48 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ describe("ReplaneAdmin - Initialization", () => {
4141
});
4242

4343
expect(admin).toBeInstanceOf(ReplaneAdmin);
44+
expect(admin.workspaces).toBeDefined();
4445
expect(admin.projects).toBeDefined();
4546
expect(admin.configs).toBeDefined();
4647
expect(admin.environments).toBeDefined();
@@ -244,7 +245,7 @@ describe("ReplaneAdmin - Error Handling", () => {
244245
});
245246

246247
try {
247-
await admin.projects.get("non-existent-id");
248+
await admin.projects.get({ projectId: "non-existent-id" });
248249
expect.fail("Expected ReplaneAdminError to be thrown");
249250
} catch (error) {
250251
expect(error).toBeInstanceOf(ReplaneAdminError);
@@ -363,7 +364,7 @@ describe("Workspaces API", () => {
363364

364365
mockFetch.mockResolvedValueOnce(jsonResponse(workspace));
365366

366-
const result = await admin.workspaces.get("ws-1");
367+
const result = await admin.workspaces.get({ workspaceId: "ws-1" });
367368

368369
expect(result).toMatchObject({
369370
id: "ws-1",
@@ -381,7 +382,7 @@ describe("Workspaces API", () => {
381382
})
382383
);
383384

384-
await admin.workspaces.get("ws-123");
385+
await admin.workspaces.get({ workspaceId: "ws-123" });
385386

386387
expect(mockFetch).toHaveBeenCalledWith(
387388
expect.stringContaining("/workspaces/ws-123"),
@@ -427,7 +428,7 @@ describe("Workspaces API", () => {
427428
it("deletes a workspace", async () => {
428429
mockFetch.mockResolvedValueOnce(noContentResponse());
429430

430-
await admin.workspaces.delete("ws-1");
431+
await admin.workspaces.delete({ workspaceId: "ws-1" });
431432

432433
expect(mockFetch).toHaveBeenCalledWith(
433434
expect.stringContaining("/workspaces/ws-1"),
@@ -438,7 +439,7 @@ describe("Workspaces API", () => {
438439
it("handles 204 No Content response", async () => {
439440
mockFetch.mockResolvedValueOnce(noContentResponse());
440441

441-
const result = await admin.workspaces.delete("ws-1");
442+
const result = await admin.workspaces.delete({ workspaceId: "ws-1" });
442443

443444
expect(result).toBeUndefined();
444445
});
@@ -515,7 +516,7 @@ describe("Projects API", () => {
515516

516517
mockFetch.mockResolvedValueOnce(jsonResponse(project));
517518

518-
const result = await admin.projects.get("proj-1");
519+
const result = await admin.projects.get({ projectId: "proj-1" });
519520

520521
expect(result).toMatchObject({
521522
id: "proj-1",
@@ -535,7 +536,7 @@ describe("Projects API", () => {
535536
})
536537
);
537538

538-
await admin.projects.get("proj-123");
539+
await admin.projects.get({ projectId: "proj-123" });
539540

540541
expect(mockFetch).toHaveBeenCalledWith(
541542
expect.stringContaining("/projects/proj-123"),
@@ -548,7 +549,8 @@ describe("Projects API", () => {
548549
it("creates a new project", async () => {
549550
mockFetch.mockResolvedValueOnce(jsonResponse({ id: "new-proj-id" }, 201));
550551

551-
const result = await admin.projects.create("ws-123", {
552+
const result = await admin.projects.create({
553+
workspaceId: "ws-123",
552554
name: "New Project",
553555
description: "New project description",
554556
});
@@ -559,7 +561,8 @@ describe("Projects API", () => {
559561
it("makes POST request to /workspaces/{workspaceId}/projects with JSON body", async () => {
560562
mockFetch.mockResolvedValueOnce(jsonResponse({ id: "new-proj-id" }, 201));
561563

562-
await admin.projects.create("ws-123", {
564+
await admin.projects.create({
565+
workspaceId: "ws-123",
563566
name: "New Project",
564567
description: "Description",
565568
});
@@ -584,7 +587,8 @@ describe("Projects API", () => {
584587
it("updates an existing project", async () => {
585588
mockFetch.mockResolvedValueOnce(jsonResponse({ id: "proj-1" }));
586589

587-
const result = await admin.projects.update("proj-1", {
590+
const result = await admin.projects.update({
591+
projectId: "proj-1",
588592
name: "Updated Name",
589593
});
590594

@@ -594,7 +598,8 @@ describe("Projects API", () => {
594598
it("makes PATCH request with JSON body", async () => {
595599
mockFetch.mockResolvedValueOnce(jsonResponse({ id: "proj-1" }));
596600

597-
await admin.projects.update("proj-1", {
601+
await admin.projects.update({
602+
projectId: "proj-1",
598603
name: "Updated Name",
599604
description: "Updated description",
600605
});
@@ -616,7 +621,7 @@ describe("Projects API", () => {
616621
it("deletes a project", async () => {
617622
mockFetch.mockResolvedValueOnce(noContentResponse());
618623

619-
await admin.projects.delete("proj-1");
624+
await admin.projects.delete({ projectId: "proj-1" });
620625

621626
expect(mockFetch).toHaveBeenCalledWith(
622627
expect.stringContaining("/projects/proj-1"),
@@ -627,7 +632,7 @@ describe("Projects API", () => {
627632
it("handles 204 No Content response", async () => {
628633
mockFetch.mockResolvedValueOnce(noContentResponse());
629634

630-
const result = await admin.projects.delete("proj-1");
635+
const result = await admin.projects.delete({ projectId: "proj-1" });
631636

632637
expect(result).toBeUndefined();
633638
});
@@ -667,7 +672,7 @@ describe("Configs API", () => {
667672

668673
mockFetch.mockResolvedValueOnce(jsonResponse({ configs }));
669674

670-
const result = await admin.configs.list("proj-1");
675+
const result = await admin.configs.list({ projectId: "proj-1" });
671676

672677
expect(result.configs).toHaveLength(1);
673678
expect(result.configs[0]).toMatchObject({
@@ -679,7 +684,7 @@ describe("Configs API", () => {
679684
it("makes GET request to /projects/{projectId}/configs", async () => {
680685
mockFetch.mockResolvedValueOnce(jsonResponse({ configs: [] }));
681686

682-
await admin.configs.list("proj-123");
687+
await admin.configs.list({ projectId: "proj-123" });
683688

684689
expect(mockFetch).toHaveBeenCalledWith(
685690
expect.stringContaining("/projects/proj-123/configs"),
@@ -708,7 +713,7 @@ describe("Configs API", () => {
708713

709714
mockFetch.mockResolvedValueOnce(jsonResponse(config));
710715

711-
const result = await admin.configs.get("proj-1", "my-config");
716+
const result = await admin.configs.get({ projectId: "proj-1", configName: "my-config" });
712717

713718
expect(result).toMatchObject({
714719
id: "config-1",
@@ -731,7 +736,7 @@ describe("Configs API", () => {
731736
})
732737
);
733738

734-
await admin.configs.get("proj-1", "config with spaces");
739+
await admin.configs.get({ projectId: "proj-1", configName: "config with spaces" });
735740

736741
expect(mockFetch).toHaveBeenCalledWith(
737742
expect.stringContaining("/configs/config%20with%20spaces"),
@@ -744,7 +749,8 @@ describe("Configs API", () => {
744749
it("creates a new config", async () => {
745750
mockFetch.mockResolvedValueOnce(jsonResponse({ id: "new-config-id" }, 201));
746751

747-
const result = await admin.configs.create("proj-1", {
752+
const result = await admin.configs.create({
753+
projectId: "proj-1",
748754
name: "new-config",
749755
description: "New config",
750756
editors: ["user@example.com"],
@@ -764,6 +770,7 @@ describe("Configs API", () => {
764770
mockFetch.mockResolvedValueOnce(jsonResponse({ id: "new-config-id" }, 201));
765771

766772
const createData = {
773+
projectId: "proj-1",
767774
name: "new-config",
768775
description: "New config",
769776
editors: ["user@example.com"],
@@ -784,13 +791,16 @@ describe("Configs API", () => {
784791
],
785792
};
786793

787-
await admin.configs.create("proj-1", createData);
794+
await admin.configs.create(createData);
795+
796+
// The body should not include projectId
797+
const { projectId, ...bodyWithoutProjectId } = createData;
788798

789799
expect(mockFetch).toHaveBeenCalledWith(
790800
expect.stringContaining("/projects/proj-1/configs"),
791801
expect.objectContaining({
792802
method: "POST",
793-
body: JSON.stringify(createData),
803+
body: JSON.stringify(bodyWithoutProjectId),
794804
})
795805
);
796806
});
@@ -800,7 +810,9 @@ describe("Configs API", () => {
800810
it("updates an existing config", async () => {
801811
mockFetch.mockResolvedValueOnce(jsonResponse({ id: "config-1", version: 4 }));
802812

803-
const result = await admin.configs.update("proj-1", "my-config", {
813+
const result = await admin.configs.update({
814+
projectId: "proj-1",
815+
configName: "my-config",
804816
description: "Updated description",
805817
editors: [],
806818
base: { value: true, schema: null, overrides: [] },
@@ -813,7 +825,9 @@ describe("Configs API", () => {
813825
it("makes PUT request to /projects/{projectId}/configs/{configName}", async () => {
814826
mockFetch.mockResolvedValueOnce(jsonResponse({ id: "config-1", version: 2 }));
815827

816-
await admin.configs.update("proj-1", "my-config", {
828+
await admin.configs.update({
829+
projectId: "proj-1",
830+
configName: "my-config",
817831
description: "Updated",
818832
editors: [],
819833
base: { value: false, schema: null, overrides: [] },
@@ -831,7 +845,7 @@ describe("Configs API", () => {
831845
it("deletes a config", async () => {
832846
mockFetch.mockResolvedValueOnce(noContentResponse());
833847

834-
await admin.configs.delete("proj-1", "my-config");
848+
await admin.configs.delete({ projectId: "proj-1", configName: "my-config" });
835849

836850
expect(mockFetch).toHaveBeenCalledWith(
837851
expect.stringContaining("/projects/proj-1/configs/my-config"),
@@ -869,7 +883,7 @@ describe("Environments API", () => {
869883

870884
mockFetch.mockResolvedValueOnce(jsonResponse({ environments }));
871885

872-
const result = await admin.environments.list("proj-1");
886+
const result = await admin.environments.list({ projectId: "proj-1" });
873887

874888
expect(result.environments).toHaveLength(3);
875889
expect(result.environments[0]).toMatchObject({
@@ -881,7 +895,7 @@ describe("Environments API", () => {
881895
it("makes GET request to /projects/{projectId}/environments", async () => {
882896
mockFetch.mockResolvedValueOnce(jsonResponse({ environments: [] }));
883897

884-
await admin.environments.list("proj-123");
898+
await admin.environments.list({ projectId: "proj-123" });
885899

886900
expect(mockFetch).toHaveBeenCalledWith(
887901
expect.stringContaining("/projects/proj-123/environments"),
@@ -930,7 +944,7 @@ describe("SDK Keys API", () => {
930944

931945
mockFetch.mockResolvedValueOnce(jsonResponse({ sdkKeys }));
932946

933-
const result = await admin.sdkKeys.list("proj-1");
947+
const result = await admin.sdkKeys.list({ projectId: "proj-1" });
934948

935949
expect(result.sdkKeys).toHaveLength(2);
936950
expect(result.sdkKeys[0]).toMatchObject({
@@ -942,7 +956,7 @@ describe("SDK Keys API", () => {
942956
it("makes GET request to /projects/{projectId}/sdk-keys", async () => {
943957
mockFetch.mockResolvedValueOnce(jsonResponse({ sdkKeys: [] }));
944958

945-
await admin.sdkKeys.list("proj-123");
959+
await admin.sdkKeys.list({ projectId: "proj-123" });
946960

947961
expect(mockFetch).toHaveBeenCalledWith(
948962
expect.stringContaining("/projects/proj-123/sdk-keys"),
@@ -964,7 +978,8 @@ describe("SDK Keys API", () => {
964978

965979
mockFetch.mockResolvedValueOnce(jsonResponse(newKey, 201));
966980

967-
const result = await admin.sdkKeys.create("proj-1", {
981+
const result = await admin.sdkKeys.create({
982+
projectId: "proj-1",
968983
name: "New SDK Key",
969984
description: "A new key",
970985
environmentId: "env-1",
@@ -992,7 +1007,8 @@ describe("SDK Keys API", () => {
9921007
)
9931008
);
9941009

995-
await admin.sdkKeys.create("proj-1", {
1010+
await admin.sdkKeys.create({
1011+
projectId: "proj-1",
9961012
name: "Test Key",
9971013
description: "Test description",
9981014
environmentId: "env-1",
@@ -1016,7 +1032,7 @@ describe("SDK Keys API", () => {
10161032
it("deletes an SDK key", async () => {
10171033
mockFetch.mockResolvedValueOnce(noContentResponse());
10181034

1019-
await admin.sdkKeys.delete("proj-1", "key-1");
1035+
await admin.sdkKeys.delete({ projectId: "proj-1", sdkKeyId: "key-1" });
10201036

10211037
expect(mockFetch).toHaveBeenCalledWith(
10221038
expect.stringContaining("/projects/proj-1/sdk-keys/key-1"),
@@ -1054,7 +1070,7 @@ describe("Members API", () => {
10541070

10551071
mockFetch.mockResolvedValueOnce(jsonResponse({ members }));
10561072

1057-
const result = await admin.members.list("proj-1");
1073+
const result = await admin.members.list({ projectId: "proj-1" });
10581074

10591075
expect(result.members).toHaveLength(3);
10601076
expect(result.members[0]).toMatchObject({
@@ -1066,7 +1082,7 @@ describe("Members API", () => {
10661082
it("makes GET request to /projects/{projectId}/members", async () => {
10671083
mockFetch.mockResolvedValueOnce(jsonResponse({ members: [] }));
10681084

1069-
await admin.members.list("proj-123");
1085+
await admin.members.list({ projectId: "proj-123" });
10701086

10711087
expect(mockFetch).toHaveBeenCalledWith(
10721088
expect.stringContaining("/projects/proj-123/members"),

0 commit comments

Comments
 (0)