Skip to content

Commit

Permalink
fix(mis-server): 增加removeUserFromAccount测试用例 (#1108)
Browse files Browse the repository at this point in the history
  • Loading branch information
OYX-1 authored Feb 2, 2024
1 parent 48844dc commit 5ec0c34
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
49 changes: 49 additions & 0 deletions apps/mis-server/tests/admin/user.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ import { asyncClientCall } from "@ddadaal/tsgrpc-client";
import { Server } from "@ddadaal/tsgrpc-server";
import { ChannelCredentials } from "@grpc/grpc-js";
import { Status } from "@grpc/grpc-js/build/src/constants";
import { Loaded } from "@mikro-orm/core";
import { createUser } from "@scow/lib-auth";
import { GetAllUsersRequest_UsersSortField, PlatformRole, platformRoleFromJSON,
SortDirection, TenantRole, UserServiceClient } from "@scow/protos/build/server/user";
import dayjs from "dayjs";
import { createServer } from "src/app";
import { authUrl } from "src/config";
import { Account } from "src/entities/Account";
import { Tenant } from "src/entities/Tenant";
import { PlatformRole as pRole, TenantRole as tRole, User } from "src/entities/User";
import { UserAccount, UserRole, UserStatus } from "src/entities/UserAccount";
Expand Down Expand Up @@ -127,6 +129,53 @@ it("cannot remove owner from account", async () => {
expect(reply.code).toBe(Status.OUT_OF_RANGE);
});

it("cannot remove a user from account,when user has jobs running or pending", async () => {
const data = await insertInitialData(server.ext.orm.em.fork());

const reply = await asyncClientCall(client, "removeUserFromAccount", {
tenantName: data.tenant.name,
accountName: data.accountA.accountName,
userId: data.userB.userId,
}).catch((e) => e);

expect(reply.code).toBe(Status.FAILED_PRECONDITION);
});

it("when removing a user from an account, the account and user cannot be deleted", async () => {
const data = await insertInitialData(server.ext.orm.em.fork());
const em = server.ext.orm.em.fork();

const account = new Account({
accountName: "account_remove", comment: "", blocked: false, tenant:data.tenant,
}) as Loaded<Account, "tenant">;

const uaA = new UserAccount({
account,
user: data.userA,
role: UserRole.OWNER, status: UserStatus.UNBLOCKED,
}) as Loaded<UserAccount, "account" | "user">;

const uaB = new UserAccount({
account,
user: data.userB,
role: UserRole.USER, status: UserStatus.UNBLOCKED,
}) as Loaded<UserAccount, "account" | "user">;

await em.persistAndFlush([account, uaA, uaB]);

await asyncClientCall(client, "removeUserFromAccount", {
tenantName: data.tenant.name,
accountName: account.accountName,
userId: data.userB.userId,
});

const accountA = await em.findOneOrFail(Account, { id:account.id });
const userB = await em.findOneOrFail(User, { id:data.userB.id });

expect(accountA).toBeTruthy();
expect(userB).toBeTruthy();
});

it("deletes user", async () => {
const em = server.ext.orm.em.fork();
const data = await insertInitialData(em);
Expand Down
7 changes: 7 additions & 0 deletions dev/test-adapter/src/services/job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ export const jobServiceServer = plugin((server) => {
server.addService<JobServiceServer>(JobServiceService, {
getJobs: async ({ request }) => {
const endTimeRange = request.filter?.endTime;
const accountNames = request.filter?.accounts;

// 用于测试removeUserFromAccount接口
if (accountNames && accountNames[0] === "account_remove") {
return [{ jobs:[], totalCount:0 }];
}

return [{
jobs: testData.filter((x) =>
x.cluster === clusterId &&
Expand Down

0 comments on commit 5ec0c34

Please sign in to comment.