Skip to content

Commit 9271802

Browse files
authored
chore(integration-test): add get/list membership integration-test (#1324)
Because - add get/list membership integration-test This commit - add get/list membership integration-test
1 parent 895c163 commit 9271802

File tree

4 files changed

+96
-23
lines changed

4 files changed

+96
-23
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import { expect, test } from "vitest";
2+
3+
import { InstillAPIClient } from "../../main";
4+
import {
5+
getUserMembershipResponseValidator,
6+
listOrganizationMembershipsResponseValidator,
7+
listUserMembershipsResponseValidator,
8+
} from "./types";
9+
10+
test("listUserMemberships", async () => {
11+
const client = new InstillAPIClient({
12+
baseURL: `http://localhost:8080/${process.env.INSTILL_API_VERSION}`,
13+
apiToken: "test",
14+
debug: true,
15+
});
16+
17+
const memberships = await client.core.membership.listUserMemberships({
18+
userName: "users/uid",
19+
});
20+
21+
const parsedData =
22+
listUserMembershipsResponseValidator.safeParse(memberships);
23+
24+
expect(parsedData.success).toBe(true);
25+
});
26+
27+
test("getUserMembership", async () => {
28+
const client = new InstillAPIClient({
29+
baseURL: `http://localhost:8080/${process.env.INSTILL_API_VERSION}`,
30+
apiToken: "test",
31+
debug: true,
32+
});
33+
34+
const membership = await client.core.membership.getUserMembership({
35+
userMembershipName: "users/uid/memberships/mid",
36+
view: "FULL",
37+
});
38+
39+
const parsedData = getUserMembershipResponseValidator.safeParse(membership);
40+
41+
expect(parsedData.success).toBe(true);
42+
});
43+
44+
test("listOrganizationMemberships", async () => {
45+
const client = new InstillAPIClient({
46+
baseURL: `http://localhost:8080/${process.env.INSTILL_API_VERSION}`,
47+
apiToken: "test",
48+
debug: true,
49+
});
50+
51+
const memberships = await client.core.membership.listOrganizationMemberships({
52+
organizationName: "organizations/oid",
53+
});
54+
55+
const parsedData =
56+
listOrganizationMembershipsResponseValidator.safeParse(memberships);
57+
58+
expect(parsedData.success).toBe(true);
59+
});
60+
61+
test("getOrganizationMembership", async () => {
62+
const client = new InstillAPIClient({
63+
baseURL: `http://localhost:8080/${process.env.INSTILL_API_VERSION}`,
64+
apiToken: "test",
65+
debug: true,
66+
});
67+
68+
const membership = await client.core.membership.getOrganizationMembership({
69+
organizationMembershipName: "organizations/oid/memberships/mid",
70+
view: "FULL",
71+
});
72+
73+
const parsedData = getUserMembershipResponseValidator.safeParse(membership);
74+
75+
expect(parsedData.success).toBe(true);
76+
});

packages/sdk/src/core/membership/MembershipClient.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export class MembershipClient extends APIResource {
2424
async listUserMemberships({ userName }: ListUserMembershipsRequest) {
2525
try {
2626
const data = await this._client.get<ListUserMembershipsResponse>(
27-
`/${userName}`,
27+
`/${userName}/memberships`,
2828
);
2929

3030
return Promise.resolve(data.memberships);
@@ -57,7 +57,7 @@ export class MembershipClient extends APIResource {
5757
}: ListOrganizationMembershipsRequest) {
5858
try {
5959
const data = await this._client.get<ListOrganizationMembershipsResponse>(
60-
`/${organizationName}`,
60+
`/${organizationName}/memberships`,
6161
);
6262

6363
return Promise.resolve(data.memberships);

packages/sdk/src/core/membership/types.ts

+9-17
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,6 @@ import { User, UserSchema } from "../user/types";
66

77
export type MembershipRole = "admin" | "member" | "pending_member" | "owner";
88

9-
export const MembershipRoleSchema = z.enum([
10-
"admin",
11-
"member",
12-
"pending_member",
13-
"owner",
14-
]);
15-
169
export type MembershipState =
1710
| "MEMBERSHIP_STATE_ACTIVE"
1811
| "MEMBERSHIP_STATE_PENDING";
@@ -34,7 +27,7 @@ export const UserMembershipSchema = z.object({
3427
user: UserSchema,
3528
organization: OrganizationSchema,
3629
name: z.string().nullable(),
37-
role: MembershipRoleSchema,
30+
role: z.string(),
3831
state: MembershipStateSchema,
3932
});
4033

@@ -50,7 +43,7 @@ export const OrganizationMembershipSchema = z.object({
5043
user: UserSchema,
5144
organization: OrganizationSchema,
5245
name: z.string().nullable(),
53-
role: MembershipRoleSchema,
46+
role: z.string(),
5447
state: MembershipStateSchema,
5548
});
5649

@@ -62,9 +55,8 @@ export type ListUserMembershipsResponse = {
6255
memberships: UserMembership[];
6356
};
6457

65-
export const ListUserMembershipsResponseValidator = z.object({
66-
memberships: z.array(UserMembershipSchema),
67-
});
58+
export const listUserMembershipsResponseValidator =
59+
z.array(UserMembershipSchema);
6860

6961
export type GetUserMembershipRequest = {
7062
userMembershipName: string;
@@ -75,7 +67,7 @@ export type GetUserMembershipResponse = {
7567
membership: UserMembership;
7668
};
7769

78-
export const GetUserMembershipResponseValidator = UserMembershipSchema;
70+
export const getUserMembershipResponseValidator = UserMembershipSchema;
7971

8072
export type ListOrganizationMembershipsRequest = {
8173
organizationName: string;
@@ -85,9 +77,9 @@ export type ListOrganizationMembershipsResponse = {
8577
memberships: OrganizationMembership[];
8678
};
8779

88-
export const ListOrganizationMembershipsResponseValidator = z.object({
89-
memberships: z.array(OrganizationMembershipSchema),
90-
});
80+
export const listOrganizationMembershipsResponseValidator = z.array(
81+
OrganizationMembershipSchema,
82+
);
9183

9284
export type GetOrganizationMembershipRequest = {
9385
organizationMembershipName: string;
@@ -98,7 +90,7 @@ export type GetOrganizationMembershipResponse = {
9890
membership: OrganizationMembership;
9991
};
10092

101-
export const GetOrganizationMembershipResponseValidator =
93+
export const getOrganizationMembershipResponseValidator =
10294
OrganizationMembershipSchema;
10395

10496
export type DeleteUserMembershipRequest = {

packages/sdk/src/main/index.ts

+9-4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import "whatwg-fetch";
22

33
import {
44
CreditClient,
5+
MembershipClient,
56
MetricClient,
67
OrganizationClient,
78
SubscriptionClient,
@@ -11,10 +12,13 @@ import {
1112
} from "../core";
1213
import { ModelClient } from "../model";
1314
import { GeneralRecord, HttpMethod } from "../types";
14-
import { ComponentClient, PipelineClient } from "../vdp";
15-
import { ReleaseClient } from "../vdp/release";
16-
import { SecretClient } from "../vdp/secret";
17-
import { TriggerClient } from "../vdp/trigger";
15+
import {
16+
ComponentClient,
17+
PipelineClient,
18+
ReleaseClient,
19+
SecretClient,
20+
TriggerClient,
21+
} from "../vdp";
1822

1923
export type RequestOption = {
2024
body?: string;
@@ -115,6 +119,7 @@ export class InstillAPIClient {
115119
subscription: new SubscriptionClient(this),
116120
credit: new CreditClient(this),
117121
utils: new UtilsClient(this),
122+
membership: new MembershipClient(this),
118123
};
119124

120125
model = new ModelClient(this);

0 commit comments

Comments
 (0)