Skip to content

Commit 351ca21

Browse files
🧪 test(roles): update roles case tests
1 parent 98ba984 commit 351ca21

File tree

8 files changed

+29
-17
lines changed

8 files changed

+29
-17
lines changed

src/__tests__/actions/constants.spec.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ describe("pages/actions/constants", () => {
3131

3232
expect(
3333
await screen.findByRole("row", {
34-
name: "Key Sort By Key Value Sort By Value Action",
34+
name: "Key Sort By Key Filter By Search Value Sort By Value Action",
3535
})
3636
).toBeInTheDocument();
3737
expect(

src/__tests__/api/account/index.spec.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ describe("/api/account/index", () => {
2222
[
2323
{
2424
"name": "Root User",
25-
"role": "creator",
25+
"role": "Creator",
2626
"username": "root",
2727
},
2828
]
@@ -55,7 +55,7 @@ describe("/api/account/index", () => {
5555
expect(getRequest.res._getJSONData()[1]).toMatchInlineSnapshot(`
5656
{
5757
"name": "New user",
58-
"role": "viewer",
58+
"role": "Viewer",
5959
"username": "newuser",
6060
}
6161
`);
@@ -97,7 +97,7 @@ describe("/api/account/index", () => {
9797
expect(getRequest.res._getJSONData()[1]).toMatchInlineSnapshot(`
9898
{
9999
"name": "New user",
100-
"role": "viewer",
100+
"role": "Viewer",
101101
"username": "newuser",
102102
}
103103
`);

src/__tests__/roles/index.spec.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ describe("pages/roles", () => {
2424
);
2525

2626
expect(
27-
await screen.findByRole("row", { name: "Role Sort By Role Action" })
27+
await screen.findByRole("row", {
28+
name: "Role Sort By Role Filter By Search Action",
29+
})
2830
).toBeInTheDocument();
2931
expect(screen.getByRole("row", { name: "Creator" })).toBeInTheDocument();
3032
expect(screen.getByRole("row", { name: "Viewer" })).toBeInTheDocument();

src/__tests__/users/index.spec.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,17 @@ describe("pages/users", () => {
2525

2626
expect(
2727
await screen.findByRole("row", {
28-
name: "Username Sort By Username Name Sort By Name Role Sort By Role Action",
28+
name: "Username Sort By Username Filter By Search Name Sort By Name Filter By Search Role Sort By Role Filter By Search Action",
2929
})
3030
).toBeInTheDocument();
3131
expect(
32-
screen.getByRole("row", { name: "user-1 User 1 Role 1 Edit" })
32+
screen.getByRole("row", { name: "user-1 User 1 role-1 Edit" })
3333
).toBeInTheDocument();
3434
expect(
35-
screen.getByRole("row", { name: "user-2 User 2 Role 2 Edit" })
35+
screen.getByRole("row", { name: "user-2 User 2 role-2 Edit" })
3636
).toBeInTheDocument();
3737
expect(
38-
screen.getByRole("row", { name: "user-3 User 3 Role 3 Edit" })
38+
screen.getByRole("row", { name: "user-3 User 3 role-3 Edit" })
3939
).toBeInTheDocument();
4040
});
4141

src/backend/users/users.controller.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { ForbiddenError } from "backend/lib/errors";
22
import { RolesService, rolesService } from "backend/roles/roles.service";
3+
import { userFriendlyCase } from "frontend/lib/strings";
34
import { REQUEST_ERROR_CODES } from "shared/constants/auth";
45
import { ISignInForm } from "shared/form-schemas/auth/signin";
56
import { IChangePasswordForm } from "shared/form-schemas/profile/password";
@@ -23,7 +24,10 @@ export class UsersController {
2324
}
2425

2526
async listUsers() {
26-
return await this._usersService.listUsers();
27+
return (await this._usersService.listUsers()).map((user) => ({
28+
...user,
29+
role: userFriendlyCase(user.role),
30+
}));
2731
}
2832

2933
async createUser(user: IAccountUser) {

src/backend/users/users.service.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import { HashService } from "backend/lib/hash/hash.service";
1111
import { IApplicationService } from "backend/types";
1212
import { IAccountUser, IAccountProfile } from "shared/types/user";
1313
import { ISuccessfullAuthenticationResponse } from "shared/types/auth";
14-
import { userFriendlyCase } from "frontend/lib/strings";
1514

1615
const INVALID_LOGIN_MESSAGE = "Invalid Login";
1716

@@ -64,7 +63,7 @@ export class UsersService implements IApplicationService {
6463
delete userCopy.systemProfile;
6564
delete userCopy.preferences;
6665

67-
return { ...userCopy, role: userFriendlyCase(user.role) };
66+
return userCopy;
6867
});
6968
}
7069

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { noop } from "lodash";
2+
import { useFEPaginatedData } from "./useFEPagination";
3+
4+
describe("Foo", () => {
5+
it("Bar", () => {
6+
noop(useFEPaginatedData);
7+
expect(1).toBe(1);
8+
});
9+
});

src/frontend/components/FEPaginationTable/useFEPagination.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,15 @@ export function useFEPaginatedData<T>(
2424
return useQuery<PaginatedData<T>>(
2525
getQueryCachekey(endPoint),
2626
async () => {
27-
if (options?.wipData) {
28-
return options.wipData;
29-
}
3027
return await makeGetRequest(endPoint, "Data could not be retrieved");
3128
},
3229
{
3330
enabled: options.enabled,
3431
select: (data: any) => {
3532
let returnData: T[] = data as unknown as T[];
36-
const pageSize = dataState.pageSize || DEFAULT_PAGE_SIZE;
3733
if (dataState.filters) {
3834
returnData = returnData.filter((datum) => {
39-
return Object.values(dataState.filters || {}).every(($filter) => {
35+
return (dataState.filters || []).every(($filter) => {
4036
const filter = $filter as unknown as QueryFilter;
4137
const filterValue = filter.value.value;
4238
const currentValue = get(datum, filter.id);
@@ -74,6 +70,8 @@ export function useFEPaginatedData<T>(
7470
});
7571
}
7672
const totalReturnData = returnData.length;
73+
const pageSize = dataState.pageSize || DEFAULT_PAGE_SIZE;
74+
7775
return {
7876
pageIndex: dataState.pageIndex,
7977
pageSize,

0 commit comments

Comments
 (0)