Skip to content

Commit

Permalink
chore: remove feedback records which are beyond retention policy (#2766)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike-Heneghan authored Feb 9, 2024
1 parent 6fb80d6 commit 15af1b0
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 5 deletions.
2 changes: 1 addition & 1 deletion api.planx.uk/helpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe("getEnvironment function", () => {

test("Development env", () => {
process.env.NODE_ENV = "development";
expect(getFormattedEnvironment()).toBe("Development");
expect(getFormattedEnvironment()).toBe("Local");
});
});

Expand Down
4 changes: 4 additions & 0 deletions api.planx.uk/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,10 @@ const getFormattedEnvironment = (): string => {
const pizzaNumber = new URL(process.env.API_URL_EXT!).href.split(".")[1];
environment += ` ${pizzaNumber}`;
}
// For readability redefine development as local for slack warnings
if (environment === "development") {
environment = "local";
}
return capitalize(environment);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,13 @@ export const mockGetExpiredSessionIdsQuery = {
lowcal_sessions: [{ id: "id1" }, { id: "id2" }, { id: "id3" }],
},
};

export const mockDeleteFeedbackMutation = {
name: "DeleteFeedback",
matchOnVariables: false,
data: {
feedback: {
returning: mockIds,
},
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
mockSanitiseUniformApplicationsMutation,
mockGetExpiredSessionIdsQuery,
mockDeletePaymentRequests,
mockDeleteFeedbackMutation,
} from "./mocks/queries";
import {
deleteHasuraEventLogs,
Expand All @@ -23,6 +24,7 @@ import {
deleteApplicationFiles,
deletePaymentRequests,
deleteHasuraScheduledEventsForSubmittedSessions,
deleteFeedback,
} from "./operations";

jest.mock("../../../../lib/hasura/schema");
Expand Down Expand Up @@ -142,6 +144,10 @@ describe("Data sanitation operations", () => {
operation: deletePaymentRequests,
query: mockDeletePaymentRequests,
},
{
operation: deleteFeedback,
query: mockDeleteFeedbackMutation,
},
];

for (const { operation, query } of testCases) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ export const getOperations = (): Operation[] => [

// Queued up scheduled events (backup method to PG function/trigger)
deleteHasuraScheduledEventsForSubmittedSessions,

// Feedback records
deleteFeedback,
];

export const operationHandler = async (
Expand Down Expand Up @@ -292,3 +295,23 @@ export const deleteHasuraScheduledEventsForSubmittedSessions: Operation =
const [_column_name, ...ids] = response?.result?.flat() || [];
return ids;
};

export const deleteFeedback: Operation = async () => {
const mutation = gql`
mutation DeleteFeedback($retentionPeriod: timestamptz) {
feedback: delete_feedback(
where: { created_at: { _lt: $retentionPeriod } }
) {
returning {
id
}
}
}
`;
const {
feedback: { returning: result },
} = await $api.client.request<{ feedback: Result }>(mutation, {
retentionPeriod: getRetentionPeriod(),
});
return result;
};
13 changes: 13 additions & 0 deletions hasura.planx.uk/metadata/tables.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,19 @@
- user_context
- user_data
comment: Allow users who want to leave feedback on their experience to write to the table
select_permissions:
- role: api
permission:
columns:
- created_at
- id
filter: {}
comment: ""
delete_permissions:
- role: api
permission:
filter: {}
comment: ""
- table:
name: feedback_status_enum
schema: public
Expand Down
17 changes: 13 additions & 4 deletions hasura.planx.uk/tests/feedback.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,21 @@ describe("feedback", () => {
i = await introspectAs("api");
});

test("cannot query feedback", () => {
expect(i.queries).not.toContain("feedback");
test("can query feedback", () => {
expect(i.queries).toContain("feedback");
});

test("cannot create, update, or delete teams", () => {
expect(i).toHaveNoMutationsFor("feedback");
test("cannot update feedback", () => {
expect(i.mutations).not.toContain("update_feedback");
expect(i.mutations).not.toContain("update_feedback_by_pk");
});

test("can delete feedback", async () => {
expect(i.mutations).toContain("delete_feedback");
});

test("cannot insert feedback", async () => {
expect(i.mutations).not.toContain("insert_feedback");
});
});
});

0 comments on commit 15af1b0

Please sign in to comment.