Skip to content

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
brunozoric committed Jan 14, 2025
1 parent 4e1e6d7 commit 20e30ed
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
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

0 comments on commit 20e30ed

Please sign in to comment.