Skip to content

Commit

Permalink
chore(integration-test): add get/list membership integration-test (#1324
Browse files Browse the repository at this point in the history
)

Because

- add get/list membership integration-test

This commit

- add get/list membership integration-test
  • Loading branch information
EiffelFly authored Jul 26, 2024
1 parent 895c163 commit 9271802
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 23 deletions.
76 changes: 76 additions & 0 deletions packages/sdk/src/core/membership/MembershipClient.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import { expect, test } from "vitest";

import { InstillAPIClient } from "../../main";
import {
getUserMembershipResponseValidator,
listOrganizationMembershipsResponseValidator,
listUserMembershipsResponseValidator,
} from "./types";

test("listUserMemberships", async () => {
const client = new InstillAPIClient({
baseURL: `http://localhost:8080/${process.env.INSTILL_API_VERSION}`,
apiToken: "test",
debug: true,
});

const memberships = await client.core.membership.listUserMemberships({
userName: "users/uid",
});

const parsedData =
listUserMembershipsResponseValidator.safeParse(memberships);

expect(parsedData.success).toBe(true);
});

test("getUserMembership", async () => {
const client = new InstillAPIClient({
baseURL: `http://localhost:8080/${process.env.INSTILL_API_VERSION}`,
apiToken: "test",
debug: true,
});

const membership = await client.core.membership.getUserMembership({
userMembershipName: "users/uid/memberships/mid",
view: "FULL",
});

const parsedData = getUserMembershipResponseValidator.safeParse(membership);

expect(parsedData.success).toBe(true);
});

test("listOrganizationMemberships", async () => {
const client = new InstillAPIClient({
baseURL: `http://localhost:8080/${process.env.INSTILL_API_VERSION}`,
apiToken: "test",
debug: true,
});

const memberships = await client.core.membership.listOrganizationMemberships({
organizationName: "organizations/oid",
});

const parsedData =
listOrganizationMembershipsResponseValidator.safeParse(memberships);

expect(parsedData.success).toBe(true);
});

test("getOrganizationMembership", async () => {
const client = new InstillAPIClient({
baseURL: `http://localhost:8080/${process.env.INSTILL_API_VERSION}`,
apiToken: "test",
debug: true,
});

const membership = await client.core.membership.getOrganizationMembership({
organizationMembershipName: "organizations/oid/memberships/mid",
view: "FULL",
});

const parsedData = getUserMembershipResponseValidator.safeParse(membership);

expect(parsedData.success).toBe(true);
});
4 changes: 2 additions & 2 deletions packages/sdk/src/core/membership/MembershipClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class MembershipClient extends APIResource {
async listUserMemberships({ userName }: ListUserMembershipsRequest) {
try {
const data = await this._client.get<ListUserMembershipsResponse>(
`/${userName}`,
`/${userName}/memberships`,
);

return Promise.resolve(data.memberships);
Expand Down Expand Up @@ -57,7 +57,7 @@ export class MembershipClient extends APIResource {
}: ListOrganizationMembershipsRequest) {
try {
const data = await this._client.get<ListOrganizationMembershipsResponse>(
`/${organizationName}`,
`/${organizationName}/memberships`,
);

return Promise.resolve(data.memberships);
Expand Down
26 changes: 9 additions & 17 deletions packages/sdk/src/core/membership/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,6 @@ import { User, UserSchema } from "../user/types";

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

export const MembershipRoleSchema = z.enum([
"admin",
"member",
"pending_member",
"owner",
]);

export type MembershipState =
| "MEMBERSHIP_STATE_ACTIVE"
| "MEMBERSHIP_STATE_PENDING";
Expand All @@ -34,7 +27,7 @@ export const UserMembershipSchema = z.object({
user: UserSchema,
organization: OrganizationSchema,
name: z.string().nullable(),
role: MembershipRoleSchema,
role: z.string(),
state: MembershipStateSchema,
});

Expand All @@ -50,7 +43,7 @@ export const OrganizationMembershipSchema = z.object({
user: UserSchema,
organization: OrganizationSchema,
name: z.string().nullable(),
role: MembershipRoleSchema,
role: z.string(),
state: MembershipStateSchema,
});

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

export const ListUserMembershipsResponseValidator = z.object({
memberships: z.array(UserMembershipSchema),
});
export const listUserMembershipsResponseValidator =
z.array(UserMembershipSchema);

export type GetUserMembershipRequest = {
userMembershipName: string;
Expand All @@ -75,7 +67,7 @@ export type GetUserMembershipResponse = {
membership: UserMembership;
};

export const GetUserMembershipResponseValidator = UserMembershipSchema;
export const getUserMembershipResponseValidator = UserMembershipSchema;

export type ListOrganizationMembershipsRequest = {
organizationName: string;
Expand All @@ -85,9 +77,9 @@ export type ListOrganizationMembershipsResponse = {
memberships: OrganizationMembership[];
};

export const ListOrganizationMembershipsResponseValidator = z.object({
memberships: z.array(OrganizationMembershipSchema),
});
export const listOrganizationMembershipsResponseValidator = z.array(
OrganizationMembershipSchema,
);

export type GetOrganizationMembershipRequest = {
organizationMembershipName: string;
Expand All @@ -98,7 +90,7 @@ export type GetOrganizationMembershipResponse = {
membership: OrganizationMembership;
};

export const GetOrganizationMembershipResponseValidator =
export const getOrganizationMembershipResponseValidator =
OrganizationMembershipSchema;

export type DeleteUserMembershipRequest = {
Expand Down
13 changes: 9 additions & 4 deletions packages/sdk/src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import "whatwg-fetch";

import {
CreditClient,
MembershipClient,
MetricClient,
OrganizationClient,
SubscriptionClient,
Expand All @@ -11,10 +12,13 @@ import {
} from "../core";
import { ModelClient } from "../model";
import { GeneralRecord, HttpMethod } from "../types";
import { ComponentClient, PipelineClient } from "../vdp";
import { ReleaseClient } from "../vdp/release";
import { SecretClient } from "../vdp/secret";
import { TriggerClient } from "../vdp/trigger";
import {
ComponentClient,
PipelineClient,
ReleaseClient,
SecretClient,
TriggerClient,
} from "../vdp";

export type RequestOption = {
body?: string;
Expand Down Expand Up @@ -115,6 +119,7 @@ export class InstillAPIClient {
subscription: new SubscriptionClient(this),
credit: new CreditClient(this),
utils: new UtilsClient(this),
membership: new MembershipClient(this),
};

model = new ModelClient(this);
Expand Down

0 comments on commit 9271802

Please sign in to comment.