Skip to content

Commit

Permalink
feat: create feedback tables (#2679)
Browse files Browse the repository at this point in the history
* feat: add enum for feedback_type

* feat: add table for feedback_status enum

* feat: add table for storing user feedback

* feat: add public insert permission to feedback table

* chore: setup feedback_status_enum db tests

* chore: setup feedback_type_enum db tests

* chore: setup feedback db tests
  • Loading branch information
Mike-Heneghan authored Jan 22, 2024
1 parent 61b9781 commit 0a94567
Show file tree
Hide file tree
Showing 10 changed files with 414 additions and 0 deletions.
40 changes: 40 additions & 0 deletions hasura.planx.uk/metadata/tables.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,46 @@
template_engine: Kriti
url: '{{$base_url}}/webhooks/hasura/send-slack-notification'
version: 2
- table:
name: feedback
schema: public
object_relationships:
- name: flow
using:
foreign_key_constraint_on: flow_id
- name: team
using:
foreign_key_constraint_on: team_id
insert_permissions:
- role: public
permission:
check: {}
columns:
- address
- breadcrumbs
- component_metadata
- created_at
- device
- feedback_type
- flow_id
- help_text
- id
- node_id
- node_text
- project_type
- status
- team_id
- user_comment
- user_context
comment: Allow users who want to leave feedback on their experience to write to the table
- table:
name: feedback_status_enum
schema: public
is_enum: true
- table:
name: feedback_type_enum
schema: public
is_enum: true
- table:
name: flow_document_templates
schema: public
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

DELETE FROM "public"."feedback_type_enum" WHERE "value" = 'helpful';

DELETE FROM "public"."feedback_type_enum" WHERE "value" = 'unhelpful';

DELETE FROM "public"."feedback_type_enum" WHERE "value" = 'comment';

DELETE FROM "public"."feedback_type_enum" WHERE "value" = 'idea';

DELETE FROM "public"."feedback_type_enum" WHERE "value" = 'issue';

DROP TABLE "public"."feedback_type_enum";
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

CREATE TABLE "public"."feedback_type_enum" ("value" text NOT NULL, "comment" text NOT NULL, PRIMARY KEY ("value") );COMMENT ON TABLE "public"."feedback_type_enum" IS E'Store the different types of feedback we gather from user';

INSERT INTO "public"."feedback_type_enum"("value", "comment") VALUES (E'issue', E' A user reporting an issue with a service');

INSERT INTO "public"."feedback_type_enum"("value", "comment") VALUES (E'idea', E'A user has shared an idea');

INSERT INTO "public"."feedback_type_enum"("value", "comment") VALUES (E'comment', E'A user has shared a comment on a service');

INSERT INTO "public"."feedback_type_enum"("value", "comment") VALUES (E'unhelpful', E'A user has fed back that help text was unhelpful');

INSERT INTO "public"."feedback_type_enum"("value", "comment") VALUES (E'helpful', E'A user has fed back that help text was helpful');
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
DELETE FROM "public"."feedback_status" WHERE "value" = 'urgent';

DELETE FROM "public"."feedback_status" WHERE "value" = 'watch';

DELETE FROM "public"."feedback_status" WHERE "value" = 'maybe_in_future';

DELETE FROM "public"."feedback_status" WHERE "value" = 'no_action';

DELETE FROM "public"."feedback_status" WHERE "value" = 'doing';

DELETE FROM "public"."feedback_status" WHERE "value" = 'planned';

DELETE FROM "public"."feedback_status" WHERE "value" = 'done';

DROP TABLE "public"."feedback_status_enum";
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

CREATE TABLE "public"."feedback_status_enum" ("value" text NOT NULL, "comment" text NOT NULL, PRIMARY KEY ("value") , UNIQUE ("value"));COMMENT ON TABLE "public"."feedback_status_enum" IS E'An enum for tracking the status of received feedback';

INSERT INTO "public"."feedback_status_enum"("value", "comment") VALUES (E'done', E'Any related actions have been completed');

INSERT INTO "public"."feedback_status_enum"("value", "comment") VALUES (E'planned', E'Related actions have been planned');

INSERT INTO "public"."feedback_status_enum"("value", "comment") VALUES (E'doing', E'Related actions are in progress');

INSERT INTO "public"."feedback_status_enum"("value", "comment") VALUES (E'no_action', E'It has been deemed there are no related actions');

INSERT INTO "public"."feedback_status_enum"("value", "comment") VALUES (E'maybe_in_future', E'Related actions might be considered in the future');

INSERT INTO "public"."feedback_status_enum"("value", "comment") VALUES (E'watch', E'Feedback of this time should be monitored');

INSERT INTO "public"."feedback_status_enum"("value", "comment") VALUES (E'urgent', E'This issue has been deemed urgent and related actions should be completed asap');

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ALTER TABLE feedback DROP CONSTRAINT feedback_feedback_type_fkey;

ALTER TABLE feedback DROP CONSTRAINT feedback_status_fkey;

DROP TABLE public.feedback;
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
CREATE TABLE "public"."feedback" (
"id" serial not null unique,
PRIMARY KEY ("id"),
"team_id" integer,
"flow_id" uuid,
"created_at" timestamptz NOT NULL DEFAULT now(),
"node_id" text,
"node_text" text,
"help_text" text,
"project_type" text,
"address" text,
"device" jsonb NOT NULL,
"breadcrumbs" jsonb NOT NULL,
"component_metadata" jsonb NOT NULL,
"user_context" text,
"user_comment" text NOT NULL,
"feedback_type" text NOT NULL,
"status" text,
FOREIGN KEY ("team_id") REFERENCES "public"."teams"("id") ON UPDATE restrict ON DELETE restrict,
FOREIGN KEY ("flow_id") REFERENCES "public"."flows"("id") ON UPDATE restrict ON DELETE restrict,
UNIQUE ("id")
);

COMMENT ON TABLE "public"."feedback" IS E'A table for storing user feedback on services';
COMMENT ON COLUMN "public"."feedback"."user_context" is E'User explanation of the context in which they\'re sharing comment';
COMMENT ON COLUMN "public"."feedback"."user_comment" is E'The user\'s comment on the service';
COMMENT ON COLUMN "public"."feedback"."status" is E'The status of our processing of the feedback';

ALTER TABLE
feedback
ADD
CONSTRAINT feedback_feedback_type_fkey FOREIGN KEY (feedback_type) REFERENCES feedback_type_enum;

ALTER TABLE
feedback
ADD
CONSTRAINT feedback_status_fkey FOREIGN KEY (status) REFERENCES feedback_status_enum;

91 changes: 91 additions & 0 deletions hasura.planx.uk/tests/feedback.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
const { introspectAs } = require("./utils");

describe("feedback", () => {
describe("public", () => {
let i;
beforeAll(async () => {
i = await introspectAs("public");
});

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

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

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

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

describe("admin", () => {
let i;
beforeAll(async () => {
i = await introspectAs("admin");
});

test("has full access to query and mutate feedback", () => {
expect(i.mutations).toContain("insert_feedback");
expect(i.mutations).toContain("insert_feedback_one");
expect(i.mutations).toContain("update_feedback");
expect(i.mutations).toContain("update_feedback_by_pk");
expect(i.mutations).toContain("update_feedback_many");
expect(i.mutations).toContain("delete_feedback");
expect(i.mutations).toContain("delete_feedback_by_pk");
});
});

describe("platformAdmin", () => {
let i;
beforeAll(async () => {
i = await introspectAs("platformAdmin");
});

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

});

test("cannot mutate feedback", async () => {
expect(i).toHaveNoMutationsFor("feedback")
});
});

describe("teamEditor", () => {
let i;
beforeAll(async () => {
i = await introspectAs("teamEditor");
});

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

});

test("cannot mutate feedback", async () => {
expect(i).toHaveNoMutationsFor("feedback")
});
});

describe("api", () => {
let i;
beforeAll(async () => {
i = await introspectAs("api");
});

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

test("cannot create, update, or delete teams", () => {
expect(i).toHaveNoMutationsFor("feedback");
});
});
});
92 changes: 92 additions & 0 deletions hasura.planx.uk/tests/feedback_status.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
const { introspectAs } = require("./utils");

describe("feedback_status_enum", () => {
describe("public", () => {
let i;
beforeAll(async () => {
i = await introspectAs("public");
});

test("cannot INSERT records", () => {
expect(i.mutations).not.toContain("insert_feedback_status_enum");
});

test("cannot QUERY records", () => {
expect(i.queries).not.toContain("feedback_status_enum");
});

test("cannot DELETE records", () => {
expect(i.mutations).not.toContain("delete_feedback_status_enum");
});

test("cannot UPDATE records", () => {
expect(i.mutations).not.toContain("update_feedback_status_enum");
});
});

describe("admin", () => {
let i;
beforeAll(async () => {
i = await introspectAs("admin");
});

test("has full access to query and mutate feedback_status_enum", async () => {
expect(i.queries).toContain("feedback_status_enum");
expect(i.mutations).toContain("insert_feedback_status_enum");
expect(i.mutations).toContain("delete_feedback_status_enum");
});
});

describe("platformAdmin", () => {
let i;
beforeAll(async () => {
i = await introspectAs("platformAdmin");
});

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

test("cannot create, update, or delete feedback_status_enum", () => {
expect(i).toHaveNoMutationsFor("feedback_status_enum");
});
});

describe("teamEditor", () => {
let i;
beforeAll(async () => {
i = await introspectAs("teamEditor");
});

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

test("cannot create, update, or delete feedback_status_enum", () => {
expect(i).toHaveNoMutationsFor("feedback_status_enum");
});
});

describe("api", () => {
let i;
beforeAll(async () => {
i = await introspectAs("api");
});

test("cannot INSERT records", () => {
expect(i.mutations).not.toContain("insert_feedback_status_enum");
});

test("cannot QUERY records", () => {
expect(i.queries).not.toContain("feedback_status_enum");
});

test("cannot DELETE records", () => {
expect(i.mutations).not.toContain("delete_feedback_status_enum");
});

test("cannot UPDATE records", () => {
expect(i.mutations).not.toContain("update_feedback_status_enum");
});
});
});
Loading

0 comments on commit 0a94567

Please sign in to comment.