Skip to content
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

fix(api-log): handle error on log insert #4488

Merged
merged 6 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
fix: tests
  • Loading branch information
brunozoric committed Jan 14, 2025
commit 20e30ed951f794f6a2ba7b0f7182410753c3888c
9 changes: 9 additions & 0 deletions packages/api-log/__tests__/mocks/getIdentity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { SecurityIdentity } from "@webiny/api-security/types";

export const getIdentity = (): Pick<SecurityIdentity, "id" | "displayName" | "type"> => {
return {
id: "mocked-identity-id",
displayName: "mocked-identity-display-name",
type: "mocked-identity-type"
};
};
27 changes: 27 additions & 0 deletions packages/api-log/__tests__/tasks/pruneLogs/PruneLogs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import {
import { Entity } from "@webiny/db-dynamodb/toolbox";
import { create } from "~/db";
import { createMockLogger } from "~tests/mocks/logger";
import { GetValueResult, IStore, RemoveValueResult, StorageKey } from "@webiny/db";
import { getIdentity } from "~tests/mocks/getIdentity";

describe("PruneLogs", () => {
let prune: PruneLogs;
Expand All @@ -23,6 +25,27 @@ describe("PruneLogs", () => {

let logger: ILogger;

const store: Pick<IStore, "getValue" | "removeValue"> = {
async getValue(key: StorageKey): Promise<GetValueResult<any>> {
return {
key,
data: {
identity: getIdentity(),
taskId: "1234"
}
};
},
async removeValue(key: StorageKey): Promise<RemoveValueResult<any>> {
return {
key,
data: {
identity: getIdentity(),
taskId: "1234"
}
};
}
};

beforeEach(async () => {
prune = new PruneLogs({
documentClient,
Expand Down Expand Up @@ -64,6 +87,7 @@ describe("PruneLogs", () => {
};
};
const result = await prune.execute({
store,
list,
response,
input: {},
Expand Down Expand Up @@ -186,6 +210,7 @@ describe("PruneLogs", () => {
* Should not prune anything because the default date is too far into the past.
*/
const pruneNothingResult = await prune.execute({
store,
list,
response,
input: {},
Expand All @@ -209,6 +234,7 @@ describe("PruneLogs", () => {
* Only prune from anotherTenant.
*/
const pruneResult = await prune.execute({
store,
list,
response,
input: {
Expand Down Expand Up @@ -256,6 +282,7 @@ describe("PruneLogs", () => {
* And then prune everything.
*/
const pruneAllResult = await prune.execute({
store,
list,
response,
input: {
Expand Down
2 changes: 1 addition & 1 deletion packages/api-log/src/tasks/pruneLogs/PruneLogs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export interface IPruneLogsExecuteParams<
I extends IPruneLogsInput = IPruneLogsInput,
O extends IPruneLogsOutput = IPruneLogsOutput
> {
store: IStore;
store: Pick<IStore, "getValue" | "removeValue">;
list: ILoggerCrudListLogsCallable;
input: I;
response: ITaskResponse<I, O>;
Expand Down
Loading