From 60ff848b1355b6cdbead84fc6a4d7f0de6abbd67 Mon Sep 17 00:00:00 2001 From: Ash Date: Tue, 12 Dec 2023 09:46:50 +0000 Subject: [PATCH] test(cli): add tests for denying telemetry consent --- packages/@sanity/cli/test/telemetry.test.ts | 62 +++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/packages/@sanity/cli/test/telemetry.test.ts b/packages/@sanity/cli/test/telemetry.test.ts index e01d3604dd88..ef8e5978a22a 100644 --- a/packages/@sanity/cli/test/telemetry.test.ts +++ b/packages/@sanity/cli/test/telemetry.test.ts @@ -133,3 +133,65 @@ https://sanity.io/telemetry `) }) }) + +describeCliTest('CLI: `sanity telemetry disable`', () => { + testConcurrent('sanity telemetry disable: success', async () => { + const result = await runSanityCmdCommand('v3', ['telemetry', 'disable'], { + env: { + MOCK_TELEMETRY_CONSENT_MODE: 'success', + }, + }) + + expect(result.stdout).toMatchInlineSnapshot(` +"Status: Disabled + +You've opted out of telemetry data collection. +No data will be collected from your Sanity account. + +Learn more here: +https://sanity.io/telemetry +" +`) + }) + + testConcurrent('sanity telemetry disable: success (already denied)', async () => { + const result = await runSanityCmdCommand('v3', ['telemetry', 'disable'], { + env: { + MOCK_CONSENT: 'denied', + }, + }) + + expect(result.stdout).toMatchInlineSnapshot(` +"Status: Disabled + +You've already opted out of telemetry data collection. +No data is collected from your Sanity account. + +Learn more here: +https://sanity.io/telemetry +" +`) + }) + + testConcurrent( + 'sanity telemetry disable: success (already denied using DO_NOT_TRACK)', + async () => { + const result = await runSanityCmdCommand('v3', ['telemetry', 'disable'], { + env: { + DO_NOT_TRACK: '1', + }, + }) + + expect(result.stdout).toMatchInlineSnapshot(` +"Status: Disabled + +You've already opted out of telemetry data collection. +No data is collected from your Sanity account. + +Learn more here: +https://sanity.io/telemetry +" +`) + }, + ) +})