diff --git a/api.planx.uk/helpers.test.ts b/api.planx.uk/helpers.test.ts index 953bfdb4f1..5c275e1437 100644 --- a/api.planx.uk/helpers.test.ts +++ b/api.planx.uk/helpers.test.ts @@ -38,7 +38,7 @@ describe("getEnvironment function", () => { test("Development env", () => { process.env.NODE_ENV = "development"; - expect(getFormattedEnvironment()).toBe("Development"); + expect(getFormattedEnvironment()).toBe("Local"); }); }); diff --git a/api.planx.uk/helpers.ts b/api.planx.uk/helpers.ts index 7e09603aa4..624fa5169b 100644 --- a/api.planx.uk/helpers.ts +++ b/api.planx.uk/helpers.ts @@ -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); }; diff --git a/api.planx.uk/modules/webhooks/service/sanitiseApplicationData/mocks/queries.ts b/api.planx.uk/modules/webhooks/service/sanitiseApplicationData/mocks/queries.ts index 73be6c851a..a78ae11377 100644 --- a/api.planx.uk/modules/webhooks/service/sanitiseApplicationData/mocks/queries.ts +++ b/api.planx.uk/modules/webhooks/service/sanitiseApplicationData/mocks/queries.ts @@ -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, + }, + }, +}; diff --git a/api.planx.uk/modules/webhooks/service/sanitiseApplicationData/operations.test.ts b/api.planx.uk/modules/webhooks/service/sanitiseApplicationData/operations.test.ts index bf406d3a3a..cec0532097 100644 --- a/api.planx.uk/modules/webhooks/service/sanitiseApplicationData/operations.test.ts +++ b/api.planx.uk/modules/webhooks/service/sanitiseApplicationData/operations.test.ts @@ -9,6 +9,7 @@ import { mockSanitiseUniformApplicationsMutation, mockGetExpiredSessionIdsQuery, mockDeletePaymentRequests, + mockDeleteFeedbackMutation, } from "./mocks/queries"; import { deleteHasuraEventLogs, @@ -23,6 +24,7 @@ import { deleteApplicationFiles, deletePaymentRequests, deleteHasuraScheduledEventsForSubmittedSessions, + deleteFeedback, } from "./operations"; jest.mock("../../../../lib/hasura/schema"); @@ -142,6 +144,10 @@ describe("Data sanitation operations", () => { operation: deletePaymentRequests, query: mockDeletePaymentRequests, }, + { + operation: deleteFeedback, + query: mockDeleteFeedbackMutation, + }, ]; for (const { operation, query } of testCases) { diff --git a/api.planx.uk/modules/webhooks/service/sanitiseApplicationData/operations.ts b/api.planx.uk/modules/webhooks/service/sanitiseApplicationData/operations.ts index 9bd6b8b7ab..189f8956cc 100644 --- a/api.planx.uk/modules/webhooks/service/sanitiseApplicationData/operations.ts +++ b/api.planx.uk/modules/webhooks/service/sanitiseApplicationData/operations.ts @@ -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 ( @@ -291,3 +294,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; +}; diff --git a/hasura.planx.uk/metadata/tables.yaml b/hasura.planx.uk/metadata/tables.yaml index b4cd51a1bf..557eefa0e7 100644 --- a/hasura.planx.uk/metadata/tables.yaml +++ b/hasura.planx.uk/metadata/tables.yaml @@ -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 diff --git a/hasura.planx.uk/tests/feedback.test.js b/hasura.planx.uk/tests/feedback.test.js index e83df7537d..07d5e4b4da 100644 --- a/hasura.planx.uk/tests/feedback.test.js +++ b/hasura.planx.uk/tests/feedback.test.js @@ -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"); }); }); });