From ed3fd5e852acd2ac72ffde41af79c8ee53df11db Mon Sep 17 00:00:00 2001 From: Richard Foster Date: Tue, 14 Nov 2023 18:58:07 +0000 Subject: [PATCH 1/4] Include feedback source when submitting --- src/main.ts | 5 +++++ src/types.ts | 5 +++++ test/e2e/acceptance.node.test.ts | 1 + test/e2e/feedback-widget.browser.spec.ts | 3 +++ test/usage.test.ts | 2 ++ 5 files changed, 16 insertions(+) diff --git a/src/main.ts b/src/main.ts index de009ac3..883902d4 100644 --- a/src/main.ts +++ b/src/main.ts @@ -231,6 +231,7 @@ export default function main() { comment, promptId, promptedQuestion, + source, }: Feedback) { checkKey(); if (!featureId) err("No featureId provided"); @@ -247,6 +248,7 @@ export default function main() { promptId, question, promptedQuestion, + source: source ?? "SDK", }; const res = await request(`${getUrl()}/feedback`, payload); @@ -383,6 +385,7 @@ export default function main() { promptId: message.promptId, question: reply.question, promptedQuestion: message.question, + source: "PROMPT", }); completionHandler(); @@ -470,6 +473,7 @@ export default function main() { featureId: options.featureId, userId: options.userId, companyId: options.companyId, + source: "WIDGET", ...data, }); @@ -482,6 +486,7 @@ export default function main() { featureId: options.featureId, userId: options.userId, companyId: options.companyId, + source: "WIDGET", ...data, }); diff --git a/src/types.ts b/src/types.ts index 0f09b065..3b373740 100644 --- a/src/types.ts +++ b/src/types.ts @@ -138,6 +138,11 @@ export type Feedback = { * feedback. */ promptId?: FeedbackPrompt["promptId"]; + + /** + * Source, depending on how the user was asked + */ + source?: "API" | "MANUAL" | "PROMPT" | "SDK" | "WIDGET"; }; export type FeedbackPrompt = { diff --git a/test/e2e/acceptance.node.test.ts b/test/e2e/acceptance.node.test.ts index 23cd6cba..76c34860 100644 --- a/test/e2e/acceptance.node.test.ts +++ b/test/e2e/acceptance.node.test.ts @@ -44,6 +44,7 @@ test("Acceptance", async () => { featureId: "featureId1", score: 5, comment: "test!", + source: "SDK", }) .reply(200); diff --git a/test/e2e/feedback-widget.browser.spec.ts b/test/e2e/feedback-widget.browser.spec.ts index 64c583d2..05aa4bd3 100644 --- a/test/e2e/feedback-widget.browser.spec.ts +++ b/test/e2e/feedback-widget.browser.spec.ts @@ -193,6 +193,7 @@ test("Sends a request when choosing a score immediately", async ({ page }) => { score: expectedScore, question: "baz", userId: "foo", + source: "WIDGET", }); }); @@ -251,6 +252,7 @@ test("Updates the score on every change", async ({ page }) => { question: "baz", score: 3, userId: "foo", + source: "WIDGET", }); }); @@ -309,6 +311,7 @@ test("Sends a request with both the score and comment when submitting", async ({ featureId: "featureId1", feedbackId: "123", userId: "foo", + source: "WIDGET", }); }); diff --git a/test/usage.test.ts b/test/usage.test.ts index 674d94cb..c62cf9ad 100644 --- a/test/usage.test.ts +++ b/test/usage.test.ts @@ -76,6 +76,7 @@ describe("usage", () => { comment: "Sunt bine!", question: "Cum esti?", promptedQuestion: "How are you?", + source: "SDK", }) .reply(200); @@ -683,6 +684,7 @@ describe("feedback state management", () => { score: 5, question: "Cum esti?", promptedQuestion: "How are you?", + source: "PROMPT", }) .reply(200, { feedbackId: "feedback123", From afa2442bbb663c356622ae2ebc0ab94029787272 Mon Sep 17 00:00:00 2001 From: Richard Foster Date: Wed, 15 Nov 2023 17:23:22 +0000 Subject: [PATCH 2/4] Lowercase source names --- src/main.ts | 8 ++++---- src/types.ts | 2 +- test/e2e/acceptance.node.test.ts | 2 +- test/e2e/feedback-widget.browser.spec.ts | 6 +++--- test/usage.test.ts | 4 ++-- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/main.ts b/src/main.ts index 883902d4..b3423fbc 100644 --- a/src/main.ts +++ b/src/main.ts @@ -248,7 +248,7 @@ export default function main() { promptId, question, promptedQuestion, - source: source ?? "SDK", + source: source ?? "sdk", }; const res = await request(`${getUrl()}/feedback`, payload); @@ -385,7 +385,7 @@ export default function main() { promptId: message.promptId, question: reply.question, promptedQuestion: message.question, - source: "PROMPT", + source: "prompt", }); completionHandler(); @@ -473,7 +473,7 @@ export default function main() { featureId: options.featureId, userId: options.userId, companyId: options.companyId, - source: "WIDGET", + source: "widget", ...data, }); @@ -486,7 +486,7 @@ export default function main() { featureId: options.featureId, userId: options.userId, companyId: options.companyId, - source: "WIDGET", + source: "widget", ...data, }); diff --git a/src/types.ts b/src/types.ts index 3b373740..403e15b0 100644 --- a/src/types.ts +++ b/src/types.ts @@ -142,7 +142,7 @@ export type Feedback = { /** * Source, depending on how the user was asked */ - source?: "API" | "MANUAL" | "PROMPT" | "SDK" | "WIDGET"; + source?: "api" | "manual" | "prompt" | "sdk" | "widget"; }; export type FeedbackPrompt = { diff --git a/test/e2e/acceptance.node.test.ts b/test/e2e/acceptance.node.test.ts index 76c34860..f52ed9bf 100644 --- a/test/e2e/acceptance.node.test.ts +++ b/test/e2e/acceptance.node.test.ts @@ -44,7 +44,7 @@ test("Acceptance", async () => { featureId: "featureId1", score: 5, comment: "test!", - source: "SDK", + source: "sdk", }) .reply(200); diff --git a/test/e2e/feedback-widget.browser.spec.ts b/test/e2e/feedback-widget.browser.spec.ts index 05aa4bd3..08ec9398 100644 --- a/test/e2e/feedback-widget.browser.spec.ts +++ b/test/e2e/feedback-widget.browser.spec.ts @@ -193,7 +193,7 @@ test("Sends a request when choosing a score immediately", async ({ page }) => { score: expectedScore, question: "baz", userId: "foo", - source: "WIDGET", + source: "widget", }); }); @@ -252,7 +252,7 @@ test("Updates the score on every change", async ({ page }) => { question: "baz", score: 3, userId: "foo", - source: "WIDGET", + source: "widget", }); }); @@ -311,7 +311,7 @@ test("Sends a request with both the score and comment when submitting", async ({ featureId: "featureId1", feedbackId: "123", userId: "foo", - source: "WIDGET", + source: "widget", }); }); diff --git a/test/usage.test.ts b/test/usage.test.ts index c62cf9ad..04a9c911 100644 --- a/test/usage.test.ts +++ b/test/usage.test.ts @@ -76,7 +76,7 @@ describe("usage", () => { comment: "Sunt bine!", question: "Cum esti?", promptedQuestion: "How are you?", - source: "SDK", + source: "sdk", }) .reply(200); @@ -684,7 +684,7 @@ describe("feedback state management", () => { score: 5, question: "Cum esti?", promptedQuestion: "How are you?", - source: "PROMPT", + source: "prompt", }) .reply(200, { feedbackId: "feedback123", From 76d41bf2708b00ff16bb9501e8842852df3bc040 Mon Sep 17 00:00:00 2001 From: Richard Foster Date: Fri, 17 Nov 2023 15:10:11 +0000 Subject: [PATCH 3/4] Remove irrelevant source options from types --- src/types.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/types.ts b/src/types.ts index 403e15b0..a8b28b3e 100644 --- a/src/types.ts +++ b/src/types.ts @@ -142,7 +142,7 @@ export type Feedback = { /** * Source, depending on how the user was asked */ - source?: "api" | "manual" | "prompt" | "sdk" | "widget"; + source?: "prompt" | "sdk" | "widget"; }; export type FeedbackPrompt = { From e3138ce701818ebf7d2991e43f54adff7124784e Mon Sep 17 00:00:00 2001 From: Richard Foster Date: Fri, 17 Nov 2023 15:11:52 +0000 Subject: [PATCH 4/4] Improve documentation of source --- src/types.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/types.ts b/src/types.ts index a8b28b3e..bb34e04b 100644 --- a/src/types.ts +++ b/src/types.ts @@ -140,7 +140,10 @@ export type Feedback = { promptId?: FeedbackPrompt["promptId"]; /** - * Source, depending on how the user was asked + * Source of the feedback, depending on how the user was asked + * - `prompt` - Feedback submitted by a Live Satisfaction prompt + * - `widget` - Feedback submitted via `requestFeedback` + * - `sdk` - Feedback submitted via `feedback` */ source?: "prompt" | "sdk" | "widget"; };