From 413d430025935057c416026fe6ac3fa6f97ee3ef Mon Sep 17 00:00:00 2001 From: Aishwarya-U-R <91450662+Aishwarya-U-R@users.noreply.github.com> Date: Fri, 24 Mar 2023 21:36:48 +0530 Subject: [PATCH] test: Cypress - Segment calls intercepted (#21726) ## Description - This PR adds the host for segment calls as localhost as opposed to sending it to Segment itself - Diverting segment calls to Localhost for Cypress CI runs & intercepting the response - Updated to Analytics spec to validate the enableTelemtry false state - Bug 21191, validation included - Welcome screen - not toggling off the Usage Details anymore ## Type of change - Yml file update - Script updates ## Checklist: ### QA activity: - [X] Added Test Plan Approved label after reviewing all changes --- .github/workflows/ci-test.yml | 2 +- .../OtherUIFeatures/Analytics_spec.js | 47 +++++++++++++------ app/client/cypress/support/commands.js | 12 +++++ 3 files changed, 45 insertions(+), 16 deletions(-) diff --git a/.github/workflows/ci-test.yml b/.github/workflows/ci-test.yml index 5c0e712401..763fb28f89 100644 --- a/.github/workflows/ci-test.yml +++ b/.github/workflows/ci-test.yml @@ -161,7 +161,7 @@ jobs: -v "$PWD/stacks:/appsmith-stacks" -e APPSMITH_LICENSE_KEY=$APPSMITH_LICENSE_KEY \ -e APPSMITH_DISABLE_TELEMETRY=true \ -e APPSMITH_CLOUD_SERVICES_BASE_URL=http://host.docker.internal:5001 \ - --add-host=host.docker.internal:host-gateway \ + --add-host=host.docker.internal:host-gateway --add-host=api.segment.io:host-gateway --add-host=t.appsmith.com:host-gateway \ cicontainer - name: Setup MSSQL docker container diff --git a/app/client/cypress/integration/Regression_TestSuite/ClientSideTests/OtherUIFeatures/Analytics_spec.js b/app/client/cypress/integration/Regression_TestSuite/ClientSideTests/OtherUIFeatures/Analytics_spec.js index e9750379c5..c266fc4251 100644 --- a/app/client/cypress/integration/Regression_TestSuite/ClientSideTests/OtherUIFeatures/Analytics_spec.js +++ b/app/client/cypress/integration/Regression_TestSuite/ClientSideTests/OtherUIFeatures/Analytics_spec.js @@ -1,27 +1,44 @@ -import User from "../../../../fixtures/user.json"; - let appId; -describe("Checks for analytics initialization", function () { +describe("1. Checks for analytics initialization", function () { + before(() => { + cy.visit("/applications"); + cy.get(".admin-settings-menu-option").click(); + cy.get("[data-cy='APPSMITH_DISABLE_TELEMETRY'] > input").should( + "be.checked", + ); //Bug 21191 + cy.get("[data-cy='APPSMITH_DISABLE_TELEMETRY']") + .find("span") + .last() + .click(); //disabling sharing of anonymous data + cy.get(".t--admin-settings-save-button").click(); + cy.wait(2000); + cy.get(".t--admin-settings-restart-notice", { timeout: 120000 }).should( + "not.exist", + ); + cy.wait("@getGeneral").its("response.statusCode").should("eq", 200); + }); + it("Should check analytics is not initialised when enableTelemtry is false", function () { cy.visit("/applications"); - cy.reload(); - cy.wait(3000); - cy.wait("@getMe") - .wait("@getMe") - .should( - "have.nested.property", - "response.body.data.enableTelemetry", - false, - ); + // cy.reload(); + // cy.wait(3000); + // cy.wait("@getMe") + // //.wait("@getMe") + // .should( + // "have.nested.property", + // "response.body.data.enableTelemetry", + // false, + // ); cy.window().then((window) => { - expect(window.analytics).to.be.equal(undefined); + expect(window.analytics).to.equal(undefined); }); let interceptFlag = false; cy.intercept("POST", "https://api.segment.io/**", (req) => { interceptFlag = true; req.continue(); }); + cy.get(".t--new-button").should("be.visible"); cy.generateUUID().then((id) => { appId = id; cy.CreateAppInFirstListedWorkspace(id); @@ -33,7 +50,7 @@ describe("Checks for analytics initialization", function () { }); }); - it("Should check smartlook is not initialised when enableTelemtry is false", function () { + it("2. Should check smartlook is not initialised when enableTelemtry is false", function () { cy.visit("/applications"); cy.reload(); cy.wait(3000); @@ -57,7 +74,7 @@ describe("Checks for analytics initialization", function () { }); }); - it("Should check Sentry is not initialised when enableTelemtry is false", function () { + it("3. Should check Sentry is not initialised when enableTelemtry is false", function () { cy.visit("/applications"); cy.reload(); cy.wait(3000); diff --git a/app/client/cypress/support/commands.js b/app/client/cypress/support/commands.js index a44cdf5e4b..2d2a9fa037 100644 --- a/app/client/cypress/support/commands.js +++ b/app/client/cypress/support/commands.js @@ -1017,6 +1017,18 @@ Cypress.Commands.add("startServerAndRoutes", () => { cy.intercept({ method: "PUT", }).as("sucessSave"); + + cy.intercept("POST", "https://api.segment.io/v1/b", (req) => { + req.reply((res) => { + res.send({ + //status: 200, + body: { + success: false, //since anything can be faked! + }, + }); + }); + }); + cy.intercept("GET", "/settings/general").as("getGeneral"); }); Cypress.Commands.add("startErrorRoutes", () => {