Skip to content

chore(integration-test): add get/list membership integration-test #1324

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading