Skip to content

Commit

Permalink
feat(app-headless-cms): advanced search filters (#3604)
Browse files Browse the repository at this point in the history
  • Loading branch information
leopuleo authored Oct 25, 2023
1 parent 486ce22 commit 6d1492b
Show file tree
Hide file tree
Showing 102 changed files with 6,388 additions and 13 deletions.
2 changes: 1 addition & 1 deletion jest.config.base.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module.exports = function ({ path }, presets = []) {
const merged = merge.recursive(true, { setupFilesAfterEnv: [] }, tsPreset, {
displayName: name,
modulePaths: [`${path}/src`],
testMatch: [`${path}/**/__tests__/**/*${type}.test.[jt]s?(x)`],
testMatch: [`${path}/**/*${type}.test.[jt]s?(x)`],
transform: {
"^.+\\.[jt]sx?$": [
"ts-jest",
Expand Down
143 changes: 143 additions & 0 deletions packages/api-aco/__tests__/filter.hooks.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
import { useGraphQlHandler } from "./utils/useGraphQlHandler";

import { assignFilterLifecycleEvents, tracker } from "./mocks/lifecycle.mock";
import { Operation } from "~/filter/filter.types";

const id = "filter-id";
const name = "Filter Lifecycle Events";
const namespace = "demo-lifecycle-events";
const operation = Operation.AND;
const groups = [
{
operation: Operation.OR,
filters: [
{
field: "any-field",
condition: "any-condition",
value: "any-value"
}
]
}
];

describe("Filter Lifecycle Events", () => {
const { aco } = useGraphQlHandler({
plugins: [assignFilterLifecycleEvents()]
});

beforeEach(async () => {
tracker.reset();
});

it("should trigger create lifecycle events", async () => {
const [response] = await aco.createFilter({
data: {
id,
name,
namespace,
operation,
groups
}
});

expect(response).toMatchObject({
data: {
aco: {
createFilter: {
data: {
id: expect.stringContaining(id),
name,
namespace,
operation,
groups
},
error: null
}
}
}
});

expect(tracker.isExecutedOnce("filter:beforeCreate")).toEqual(true);
expect(tracker.isExecutedOnce("filter:afterCreate")).toEqual(true);
expect(tracker.isExecutedOnce("filter:beforeUpdate")).toEqual(false);
expect(tracker.isExecutedOnce("filter:afterUpdate")).toEqual(false);
expect(tracker.isExecutedOnce("filter:beforeDelete")).toEqual(false);
expect(tracker.isExecutedOnce("filter:afterDelete")).toEqual(false);
});

it("should trigger update lifecycle events", async () => {
const [createResponse] = await aco.createFilter({
data: {
id,
name,
namespace,
operation,
groups
}
});

tracker.reset();

const [updateResponse] = await aco.updateFilter({
id: createResponse.data.aco.createFilter.data.id,
data: {
name: `${name} updated`
}
});

expect(updateResponse).toMatchObject({
data: {
aco: {
updateFilter: {
data: {
name: `${name} updated`
},
error: null
}
}
}
});

expect(tracker.isExecutedOnce("filter:beforeCreate")).toEqual(false);
expect(tracker.isExecutedOnce("filter:afterCreate")).toEqual(false);
expect(tracker.isExecutedOnce("filter:beforeUpdate")).toEqual(true);
expect(tracker.isExecutedOnce("filter:afterUpdate")).toEqual(true);
expect(tracker.isExecutedOnce("filter:beforeDelete")).toEqual(false);
expect(tracker.isExecutedOnce("filter:afterDelete")).toEqual(false);
});

it("should trigger delete lifecycle events", async () => {
const [createResponse] = await aco.createFilter({
data: {
id,
name,
namespace,
operation,
groups
}
});

tracker.reset();

const [deleteResponse] = await aco.deleteFilter({
id: createResponse.data.aco.createFilter.data.id
});
expect(deleteResponse).toMatchObject({
data: {
aco: {
deleteFilter: {
data: true,
error: null
}
}
}
});

expect(tracker.isExecutedOnce("filter:beforeCreate")).toEqual(false);
expect(tracker.isExecutedOnce("filter:afterCreate")).toEqual(false);
expect(tracker.isExecutedOnce("filter:beforeUpdate")).toEqual(false);
expect(tracker.isExecutedOnce("filter:afterUpdate")).toEqual(false);
expect(tracker.isExecutedOnce("filter:beforeDelete")).toEqual(true);
expect(tracker.isExecutedOnce("filter:afterDelete")).toEqual(true);
});
});
Loading

0 comments on commit 6d1492b

Please sign in to comment.