Skip to content

Commit

Permalink
WD-7354 - fix: Fix Audit Logs filter (canonical#1654)
Browse files Browse the repository at this point in the history
  • Loading branch information
vladimir-cucu authored Nov 16, 2023
1 parent 4b92fe1 commit 3c77523
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 18 deletions.
9 changes: 9 additions & 0 deletions src/components/AuditLogsTable/AuditLogsTable.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,15 @@ describe("AuditLogsTable", () => {
});

it("should display audit logs", async () => {
state.juju.auditEvents.items = [
auditEventFactory.build({
model: "microk8s",
time: add(new Date(), { days: -1 }).toISOString(),
"facade-name": "ModelManager",
"facade-method": "AddModel",
"facade-version": 3,
}),
];
renderComponent(<AuditLogsTable />, { state });
expect(await screen.findByRole("table")).toBeInTheDocument();
expect(screen.queryByTestId(TestId.LOADING)).not.toBeInTheDocument();
Expand Down
14 changes: 7 additions & 7 deletions src/juju/jimm/JIMMV3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ export type ControllerInfo = {
// https://github.com/canonical/jimm/blob/1da76ed2d8dba741f5880f32c073f85f7d518904/api/params/params.go#L92
export type AuditEvent<P = unknown, E = unknown> = {
"conversation-id": string;
errors: Record<string, E> | null;
"facade-method": string;
"facade-name": string;
"facade-version": number;
errors?: Record<string, E> | null;
"facade-method"?: string;
"facade-name"?: string;
"facade-version"?: number;
"is-response": boolean;
"message-id": number;
model: string;
"object-id": string;
params: Record<string, P> | null;
model?: string;
"object-id"?: string;
params?: Record<string, P> | null;
time: string;
"user-tag": string;
};
Expand Down
3 changes: 3 additions & 0 deletions src/store/juju/selectors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ describe("selectors", () => {
auditEventFactory.build({ model: "model1" }),
auditEventFactory.build({ model: "model2" }),
auditEventFactory.build({ model: "model2" }),
auditEventFactory.build(),
];
expect(
getAuditEventsModels(
Expand All @@ -180,6 +181,7 @@ describe("selectors", () => {
auditEventFactory.build({ "facade-name": "Client" }),
auditEventFactory.build({ "facade-name": "Client" }),
auditEventFactory.build({ "facade-name": "Admin" }),
auditEventFactory.build(),
];
expect(
getAuditEventsFacades(
Expand All @@ -197,6 +199,7 @@ describe("selectors", () => {
auditEventFactory.build({ "facade-method": "Login" }),
auditEventFactory.build({ "facade-method": "Logout" }),
auditEventFactory.build({ "facade-method": "Login" }),
auditEventFactory.build(),
];
expect(
getAuditEventsMethods(
Expand Down
10 changes: 6 additions & 4 deletions src/store/juju/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,12 @@ const getUniqueAuditEventValues = <K extends keyof AuditEvent>(
modifier?: (value: AuditEvent[K]) => string
) => {
// Use a set to get unique values.
const values = new Set();
auditEvents?.forEach(({ [key]: value }) =>
values.add(modifier ? modifier(value) : value)
);
const values = new Set<string | AuditEvent[K]>();
auditEvents
?.filter(({ [key]: value }) => typeof value !== "undefined")
.forEach(({ [key]: value }) =>
values.add(modifier ? modifier(value) : value)
);
return Array.from(values);
};

Expand Down
7 changes: 0 additions & 7 deletions src/testing/factories/juju/jimm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,8 @@ export const auditEventFactory = Factory.define<AuditEvent>(() => ({
time: "2023-07-01T09:04:04.279Z",
"conversation-id": "fakeabc123",
"message-id": 2,
"facade-name": "ModelManager",
"facade-method": "AddModel",
"facade-version": 3,
"object-id": "4",
"user-tag": "user-eggman",
model: "microk8s",
"is-response": false,
params: null,
errors: null,
}));

class CrossModelQueryFactory extends Factory<CrossModelQuery> {
Expand Down

0 comments on commit 3c77523

Please sign in to comment.