🐛Do not show anonymous user is the user list everywhere on UI (#182)
* 🐛Do not show anonymous user is the user list everywhere on UI
This commit is contained in:
@@ -30,6 +30,7 @@ export default class TestHelpers {
|
||||
platform: TestPlatform;
|
||||
dbService: TestDbService;
|
||||
user: User;
|
||||
anonymous: User;
|
||||
workspace: Workspace;
|
||||
jwt: string;
|
||||
|
||||
@@ -45,6 +46,11 @@ export default class TestHelpers {
|
||||
this.workspace = this.platform.workspace;
|
||||
const workspacePK = {id: this.workspace.workspace_id, company_id: this.workspace.company_id};
|
||||
this.user = await this.dbService.createUser([workspacePK], options, uuidv1());
|
||||
this.anonymous = await this.dbService.createUser([workspacePK],
|
||||
{ ...options,
|
||||
identity_provider: "anonymous",
|
||||
},
|
||||
uuidv1());
|
||||
} else {
|
||||
this.user = this.platform.currentUser;
|
||||
this.workspace = this.platform.workspace;
|
||||
|
||||
@@ -3,6 +3,7 @@ import { init, TestPlatform } from "../setup";
|
||||
import { TestDbService } from "../utils.prepare.db";
|
||||
import { v1 as uuidv1 } from "uuid";
|
||||
import { CompanyLimitsEnum } from "../../../src/services/user/web/types";
|
||||
import TestHelpers from "../common/common_test_helpers";
|
||||
|
||||
describe("The /users API", () => {
|
||||
const url = "/internal/services/users/v1";
|
||||
@@ -209,8 +210,32 @@ describe("The /users API", () => {
|
||||
expect(response.statusCode).toBe(200);
|
||||
const json = response.json();
|
||||
expect(json).toMatchObject({ resources: expect.any(Array) });
|
||||
const resources = json.resources;
|
||||
});
|
||||
|
||||
it("shouldn't return anonymous accounts ", async () => {
|
||||
const oneUser = await TestHelpers.getInstance(platform, true);
|
||||
|
||||
const response = await platform.app.inject({
|
||||
method: "GET",
|
||||
url: `${url}/users`,
|
||||
headers: {
|
||||
authorization: `Bearer ${oneUser.jwt}`,
|
||||
},
|
||||
query: {
|
||||
search: "anon",
|
||||
company_ids: oneUser.workspace.company_id
|
||||
},
|
||||
});
|
||||
|
||||
expect(response.statusCode).toBe(200);
|
||||
const json = response.json();
|
||||
expect(json).toMatchObject({ resources: expect.any(Array) });
|
||||
const resources = json.resources;
|
||||
console.log(resources);
|
||||
expect(resources.length).toBe(0);
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe("The GET /users/:user_id/companies route", () => {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { TestPlatform } from "./setup";
|
||||
import User from "./../../src/services/user/entities/user";
|
||||
import User, { UserType } from "./../../src/services/user/entities/user";
|
||||
import Company, {
|
||||
getInstance as getCompanyInstance,
|
||||
} from "./../../src/services/user/entities/company";
|
||||
@@ -128,6 +128,8 @@ export class TestDbService {
|
||||
username?: string;
|
||||
password?: string;
|
||||
cache?: User["cache"];
|
||||
identity_provider?: string;
|
||||
type?: UserType;
|
||||
} = {},
|
||||
id: string = uuidv1(),
|
||||
): Promise<User> {
|
||||
@@ -140,6 +142,8 @@ export class TestDbService {
|
||||
user.email_canonical = options.email || `test${random}@tdrive.app`;
|
||||
user.identity_provider_id = user.id;
|
||||
user.cache = options.cache || user.cache || { companies: [] };
|
||||
user.identity_provider = options.identity_provider || "console";
|
||||
user.type = options.type || "regular";
|
||||
|
||||
//Fixme this is cheating, we should correctly set the cache in internal mode in the code
|
||||
user.cache.companies = [
|
||||
|
||||
Reference in New Issue
Block a user