diff --git a/.eslintignore b/.eslintignore index 91f5433596..54824be5c7 100644 --- a/.eslintignore +++ b/.eslintignore @@ -6,4 +6,5 @@ packages/server/coverage packages/server/client packages/builder/.routify packages/builder/cypress/support/queryLevelTransformerFunction.js -packages/builder/cypress/support/queryLevelTransformerFunctionWithData.js \ No newline at end of file +packages/builder/cypress/support/queryLevelTransformerFunctionWithData.js +packages/builder/cypress/reports \ No newline at end of file diff --git a/.github/workflows/smoke_test.yaml b/.github/workflows/smoke_test.yaml index d5a5f0b02a..09da7ec44e 100644 --- a/.github/workflows/smoke_test.yaml +++ b/.github/workflows/smoke_test.yaml @@ -33,23 +33,20 @@ jobs: with: record: true install: false + tag: nightly command: yarn test:e2e:ci:record env: CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }} - # TODO: upload recordings to s3 - # - name: Configure AWS Credentials - # uses: aws-actions/configure-aws-credentials@v1 - # with: - # aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} - # aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} - # aws-region: eu-west-1 - - - name: Discord Webhook Action - uses: tsickert/discord-webhook@v4.0.0 + - uses: actions/upload-artifact@v3 with: - webhook-url: ${{ secrets.BUDI_QA_WEBHOOK }} - content: "Smoke test run completed with ${{ steps.cypress.outcome }}. See results at ${{ steps.cypress.outputs.dashboardUrl }}" - embed-title: ${{ steps.cypress.outcome }} - embed-color: ${{ steps.cypress.outcome == 'success' && '3066993' || '15548997' }} + name: Test Reports + path: packages/builder/cypress/reports/mocha + - name: Cypress Discord Notify + run: yarn test:e2e:ci:report + env: + CYPRESS_WEBHOOK_URL: ${{ secrets.BUDI_QA_WEBHOOK }} + CYPRESS_OUTCOME: ${{ steps.cypress.outcome }} + CYPRESS_DASHBOARD_URL: ${{ steps.cypress.outputs.dashboardUrl }} + GITHUB_RUN_URL: ${{ env.GITHUB_SERVER_URL }}/${{ env.GITHUB_REPOSITORY }}/actions/runs/${{ env.GITHUB_RUN_ID }} diff --git a/.gitignore b/.gitignore index 7d09f0a2ba..03d77c5477 100644 --- a/.gitignore +++ b/.gitignore @@ -97,5 +97,7 @@ hosting/proxy/.generated-nginx.prod.conf bin/ hosting/.generated* -packages/builder/cypress.env.json -stats.html +packages/builder/cypress.env.json +packages/builder/cypress/reports +stats.html + diff --git a/lerna.json b/lerna.json index cacd810e12..d065df1b12 100644 --- a/lerna.json +++ b/lerna.json @@ -1,5 +1,5 @@ { - "version": "1.0.164-alpha.0", + "version": "1.0.167-alpha.7", "npmClient": "yarn", "packages": [ "packages/*" diff --git a/package.json b/package.json index 84f1999ead..28d234ee89 100644 --- a/package.json +++ b/package.json @@ -49,6 +49,7 @@ "test:e2e": "lerna run cy:test --stream", "test:e2e:ci": "lerna run cy:ci --stream", "test:e2e:ci:record": "lerna run cy:ci:record --stream", + "test:e2e:ci:report": "lerna run cy:ci:report", "build:specs": "lerna run specs", "build:docker": "lerna run build:docker && npm run build:docker:proxy:compose && cd hosting/scripts/linux/ && ./release-to-docker-hub.sh $BUDIBASE_RELEASE_VERSION && cd -", "build:docker:proxy": "docker build hosting/proxy -t proxy-service", diff --git a/packages/backend-core/package.json b/packages/backend-core/package.json index aa65f90141..94acb23298 100644 --- a/packages/backend-core/package.json +++ b/packages/backend-core/package.json @@ -1,6 +1,6 @@ { "name": "@budibase/backend-core", - "version": "1.0.164-alpha.0", + "version": "1.0.167-alpha.7", "description": "Budibase backend core libraries used in server and worker", "main": "src/index.js", "author": "Budibase", @@ -13,6 +13,7 @@ "@techpass/passport-openidconnect": "^0.3.0", "aws-sdk": "^2.901.0", "bcryptjs": "^2.4.3", + "dotenv": "^16.0.1", "emitter-listener": "^1.1.2", "ioredis": "^4.27.1", "jsonwebtoken": "^8.5.1", diff --git a/packages/backend-core/src/db/tests/utils.spec.js b/packages/backend-core/src/db/tests/utils.spec.js index ebef670a81..f8b9549d46 100644 --- a/packages/backend-core/src/db/tests/utils.spec.js +++ b/packages/backend-core/src/db/tests/utils.spec.js @@ -1,61 +1,194 @@ +require("../../tests/utilities/dbConfig"); const { generateAppID, getDevelopmentAppID, getProdAppID, isDevAppID, isProdAppID, + getPlatformUrl, + getScopedConfig } = require("../utils") +const tenancy = require("../../tenancy"); +const { Configs, DEFAULT_TENANT_ID } = require("../../constants"); +const env = require("../../environment") -function getID() { - const appId = generateAppID() - const split = appId.split("_") - const uuid = split[split.length - 1] - const devAppId = `app_dev_${uuid}` - return { appId, devAppId, split, uuid } +describe("utils", () => { + describe("app ID manipulation", () => { + + function getID() { + const appId = generateAppID() + const split = appId.split("_") + const uuid = split[split.length - 1] + const devAppId = `app_dev_${uuid}` + return { appId, devAppId, split, uuid } + } + + it("should be able to generate a new app ID", () => { + expect(generateAppID().startsWith("app_")).toEqual(true) + }) + + it("should be able to convert a production app ID to development", () => { + const { appId, uuid } = getID() + expect(getDevelopmentAppID(appId)).toEqual(`app_dev_${uuid}`) + }) + + it("should be able to convert a development app ID to development", () => { + const { devAppId, uuid } = getID() + expect(getDevelopmentAppID(devAppId)).toEqual(`app_dev_${uuid}`) + }) + + it("should be able to convert a development ID to a production", () => { + const { devAppId, uuid } = getID() + expect(getProdAppID(devAppId)).toEqual(`app_${uuid}`) + }) + + it("should be able to convert a production ID to production", () => { + const { appId, uuid } = getID() + expect(getProdAppID(appId)).toEqual(`app_${uuid}`) + }) + + it("should be able to confirm dev app ID is development", () => { + const { devAppId } = getID() + expect(isDevAppID(devAppId)).toEqual(true) + }) + + it("should be able to confirm prod app ID is not development", () => { + const { appId } = getID() + expect(isDevAppID(appId)).toEqual(false) + }) + + it("should be able to confirm prod app ID is prod", () => { + const { appId } = getID() + expect(isProdAppID(appId)).toEqual(true) + }) + + it("should be able to confirm dev app ID is not prod", () => { + const { devAppId } = getID() + expect(isProdAppID(devAppId)).toEqual(false) + }) + }) +}) + +const DB_URL = "http://dburl.com" +const DEFAULT_URL = "http://localhost:10000" +const ENV_URL = "http://env.com" + +const setDbPlatformUrl = async () => { + const db = tenancy.getGlobalDB() + db.put({ + _id: "config_settings", + type: Configs.SETTINGS, + config: { + platformUrl: DB_URL + } + }) } -describe("app ID manipulation", () => { - it("should be able to generate a new app ID", () => { - expect(generateAppID().startsWith("app_")).toEqual(true) +const clearSettingsConfig = async () => { + await tenancy.doInTenant(DEFAULT_TENANT_ID, async () => { + const db = tenancy.getGlobalDB() + try { + const config = await db.get("config_settings") + await db.remove("config_settings", config._rev) + } catch (e) { + if (e.status !== 404) { + throw e + } + } + }) +} + +describe("getPlatformUrl", () => { + describe("self host", () => { + + beforeEach(async () => { + env._set("SELF_HOST", 1) + await clearSettingsConfig() + }) + + it("gets the default url", async () => { + await tenancy.doInTenant(null, async () => { + const url = await getPlatformUrl() + expect(url).toBe(DEFAULT_URL) + }) + }) + + it("gets the platform url from the environment", async () => { + await tenancy.doInTenant(null, async () => { + env._set("PLATFORM_URL", ENV_URL) + const url = await getPlatformUrl() + expect(url).toBe(ENV_URL) + }) + }) + + it("gets the platform url from the database", async () => { + await tenancy.doInTenant(null, async () => { + await setDbPlatformUrl() + const url = await getPlatformUrl() + expect(url).toBe(DB_URL) + }) + }) }) - it("should be able to convert a production app ID to development", () => { - const { appId, uuid } = getID() - expect(getDevelopmentAppID(appId)).toEqual(`app_dev_${uuid}`) - }) - it("should be able to convert a development app ID to development", () => { - const { devAppId, uuid } = getID() - expect(getDevelopmentAppID(devAppId)).toEqual(`app_dev_${uuid}`) - }) + describe("cloud", () => { + const TENANT_AWARE_URL = "http://default.env.com" - it("should be able to convert a development ID to a production", () => { - const { devAppId, uuid } = getID() - expect(getProdAppID(devAppId)).toEqual(`app_${uuid}`) - }) + beforeEach(async () => { + env._set("SELF_HOSTED", 0) + env._set("MULTI_TENANCY", 1) + env._set("PLATFORM_URL", ENV_URL) + await clearSettingsConfig() + }) - it("should be able to convert a production ID to production", () => { - const { appId, uuid } = getID() - expect(getProdAppID(appId)).toEqual(`app_${uuid}`) - }) + it("gets the platform url from the environment without tenancy", async () => { + await tenancy.doInTenant(DEFAULT_TENANT_ID, async () => { + const url = await getPlatformUrl({ tenantAware: false }) + expect(url).toBe(ENV_URL) + }) + }) - it("should be able to confirm dev app ID is development", () => { - const { devAppId } = getID() - expect(isDevAppID(devAppId)).toEqual(true) - }) + it("gets the platform url from the environment with tenancy", async () => { + await tenancy.doInTenant(DEFAULT_TENANT_ID, async () => { + const url = await getPlatformUrl() + expect(url).toBe(TENANT_AWARE_URL) + }) + }) - it("should be able to confirm prod app ID is not development", () => { - const { appId } = getID() - expect(isDevAppID(appId)).toEqual(false) + it("never gets the platform url from the database", async () => { + await tenancy.doInTenant(DEFAULT_TENANT_ID, async () => { + await setDbPlatformUrl() + const url = await getPlatformUrl() + expect(url).toBe(TENANT_AWARE_URL) + }) + }) }) +}) - it("should be able to confirm prod app ID is prod", () => { - const { appId } = getID() - expect(isProdAppID(appId)).toEqual(true) - }) +describe("getScopedConfig", () => { + describe("settings config", () => { - it("should be able to confirm dev app ID is not prod", () => { - const { devAppId } = getID() - expect(isProdAppID(devAppId)).toEqual(false) + beforeEach(async () => { + env._set("SELF_HOSTED", 1) + env._set("PLATFORM_URL", "") + await clearSettingsConfig() + }) + + it("returns the platform url with an existing config", async () => { + await tenancy.doInTenant(DEFAULT_TENANT_ID, async () => { + await setDbPlatformUrl() + const db = tenancy.getGlobalDB() + const config = await getScopedConfig(db, { type: Configs.SETTINGS }) + expect(config.platformUrl).toBe(DB_URL) + }) + }) + + it("returns the platform url without an existing config", async () => { + await tenancy.doInTenant(DEFAULT_TENANT_ID, async () => { + const db = tenancy.getGlobalDB() + const config = await getScopedConfig(db, { type: Configs.SETTINGS }) + expect(config.platformUrl).toBe(DEFAULT_URL) + }) + }) }) -}) \ No newline at end of file +}) diff --git a/packages/backend-core/src/db/utils.js b/packages/backend-core/src/db/utils.js index 5f7bf794c2..d6eb0aa89e 100644 --- a/packages/backend-core/src/db/utils.js +++ b/packages/backend-core/src/db/utils.js @@ -9,7 +9,7 @@ const { APP_PREFIX, APP_DEV, } = require("./constants") -const { getTenantId, getGlobalDBName } = require("../tenancy") +const { getTenantId, getGlobalDBName, getGlobalDB } = require("../tenancy") const fetch = require("node-fetch") const { doWithDB, allDbs } = require("./index") const { getCouchInfo } = require("./pouch") @@ -392,9 +392,7 @@ const getScopedFullConfig = async function (db, { type, user, workspace }) { // always provide the platform URL if (type === Configs.SETTINGS) { if (scopedConfig && scopedConfig.doc) { - scopedConfig.doc.config.platformUrl = await getPlatformUrl( - scopedConfig.doc.config - ) + scopedConfig.doc.config.platformUrl = await getPlatformUrl() } else { scopedConfig = { doc: { @@ -409,19 +407,30 @@ const getScopedFullConfig = async function (db, { type, user, workspace }) { return scopedConfig && scopedConfig.doc } -const getPlatformUrl = async settings => { +const getPlatformUrl = async (opts = { tenantAware: true }) => { let platformUrl = env.PLATFORM_URL || "http://localhost:10000" - if (!env.SELF_HOSTED && env.MULTI_TENANCY) { + if (!env.SELF_HOSTED && env.MULTI_TENANCY && opts.tenantAware) { // cloud and multi tenant - add the tenant to the default platform url const tenantId = getTenantId() if (!platformUrl.includes("localhost:")) { platformUrl = platformUrl.replace("://", `://${tenantId}.`) } - } else { + } else if (env.SELF_HOSTED) { + const db = getGlobalDB() + // get the doc directly instead of with getScopedConfig to prevent loop + let settings + try { + settings = await db.get(generateConfigID({ type: Configs.SETTINGS })) + } catch (e) { + if (e.status !== 404) { + throw e + } + } + // self hosted - check for platform url override - if (settings && settings.platformUrl) { - platformUrl = settings.platformUrl + if (settings && settings.config && settings.config.platformUrl) { + platformUrl = settings.config.platformUrl } } diff --git a/packages/backend-core/src/environment.js b/packages/backend-core/src/environment.js index f628e899ad..e0b70d4007 100644 --- a/packages/backend-core/src/environment.js +++ b/packages/backend-core/src/environment.js @@ -10,7 +10,15 @@ function isDev() { return process.env.NODE_ENV !== "production" } +let LOADED = false +if (!LOADED && isDev() && !isTest()) { + require("dotenv").config() + LOADED = true +} + module.exports = { + isTest, + isDev, JWT_SECRET: process.env.JWT_SECRET, COUCH_DB_URL: process.env.COUCH_DB_URL || "http://localhost:4005", COUCH_DB_USERNAME: process.env.COUCH_DB_USER, @@ -41,8 +49,7 @@ module.exports = { GLOBAL_CLOUD_BUCKET_NAME: process.env.GLOBAL_CLOUD_BUCKET_NAME || "prod-budi-tenant-uploads", USE_COUCH: process.env.USE_COUCH || true, - isTest, - isDev, + DISABLE_DEVELOPER_LICENSE: process.env.DISABLE_DEVELOPER_LICENSE, _set(key, value) { process.env[key] = value module.exports[key] = value diff --git a/packages/backend-core/src/index.js b/packages/backend-core/src/index.js index 3868d9bffa..572b61fbeb 100644 --- a/packages/backend-core/src/index.js +++ b/packages/backend-core/src/index.js @@ -19,5 +19,6 @@ module.exports = { env: require("./environment"), accounts: require("./cloud/accounts"), tenancy: require("./tenancy"), + context: require("../context"), featureFlags: require("./featureFlags"), } diff --git a/packages/backend-core/src/middleware/passport/datasource/google.js b/packages/backend-core/src/middleware/passport/datasource/google.js index 9b8019575c..53719b8350 100644 --- a/packages/backend-core/src/middleware/passport/datasource/google.js +++ b/packages/backend-core/src/middleware/passport/datasource/google.js @@ -1,7 +1,7 @@ const google = require("../google") const { Cookies, Configs } = require("../../../constants") const { clearCookie, getCookie } = require("../../../utils") -const { getScopedConfig } = require("../../../db/utils") +const { getScopedConfig, getPlatformUrl } = require("../../../db/utils") const { doWithDB } = require("../../../db") const environment = require("../../../environment") const { getGlobalDB } = require("../../../tenancy") @@ -21,26 +21,10 @@ async function fetchGoogleCreds() { ) } -async function getPlatformUrl() { - let platformUrl = environment.PLATFORM_URL || "http://localhost:10000" - - const db = getGlobalDB() - const settings = await getScopedConfig(db, { - type: Configs.SETTINGS, - }) - - // self hosted - check for platform url override - if (settings && settings.platformUrl) { - platformUrl = settings.platformUrl - } - - return platformUrl -} - async function preAuth(passport, ctx, next) { // get the relevant config const googleConfig = await fetchGoogleCreds() - const platformUrl = await getPlatformUrl() + const platformUrl = await getPlatformUrl({ tenantAware: false }) let callbackUrl = `${platformUrl}/api/global/auth/datasource/google/callback` const strategy = await google.strategyFactory(googleConfig, callbackUrl) @@ -59,7 +43,7 @@ async function preAuth(passport, ctx, next) { async function postAuth(passport, ctx, next) { // get the relevant config const config = await fetchGoogleCreds() - const platformUrl = await getPlatformUrl() + const platformUrl = await getPlatformUrl({ tenantAware: false }) let callbackUrl = `${platformUrl}/api/global/auth/datasource/google/callback` const strategy = await google.strategyFactory( diff --git a/packages/backend-core/yarn.lock b/packages/backend-core/yarn.lock index 7dfa64810e..80f292140d 100644 --- a/packages/backend-core/yarn.lock +++ b/packages/backend-core/yarn.lock @@ -1485,6 +1485,11 @@ domexception@^2.0.1: dependencies: webidl-conversions "^5.0.0" +dotenv@^16.0.1: + version "16.0.1" + resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-16.0.1.tgz#8f8f9d94876c35dac989876a5d3a82a267fdce1d" + integrity sha512-1K6hR6wtk2FviQ4kEiSjFiH5rpzEVi8WW0x96aztHVMhEspNpc4DVOUTEHtEva5VThQ8IaBX1Pe4gSzpVVUsKQ== + double-ended-queue@2.1.0-0: version "2.1.0-0" resolved "https://registry.yarnpkg.com/double-ended-queue/-/double-ended-queue-2.1.0-0.tgz#103d3527fd31528f40188130c841efdd78264e5c" diff --git a/packages/bbui/package.json b/packages/bbui/package.json index 34d2aa1817..98852ef0ea 100644 --- a/packages/bbui/package.json +++ b/packages/bbui/package.json @@ -1,7 +1,7 @@ { "name": "@budibase/bbui", "description": "A UI solution used in the different Budibase projects.", - "version": "1.0.164-alpha.0", + "version": "1.0.167-alpha.7", "license": "MPL-2.0", "svelte": "src/index.js", "module": "dist/bbui.es.js", @@ -38,7 +38,7 @@ ], "dependencies": { "@adobe/spectrum-css-workflow-icons": "^1.2.1", - "@budibase/string-templates": "^1.0.164-alpha.0", + "@budibase/string-templates": "^1.0.167-alpha.7", "@spectrum-css/actionbutton": "^1.0.1", "@spectrum-css/actiongroup": "^1.0.1", "@spectrum-css/avatar": "^3.0.2", diff --git a/packages/builder/cypress.json b/packages/builder/cypress.json index 0828c9987b..06bf558946 100644 --- a/packages/builder/cypress.json +++ b/packages/builder/cypress.json @@ -2,6 +2,10 @@ "baseUrl": "http://localhost:4100", "video": true, "projectId": "bmbemn", + "reporter": "cypress-multi-reporters", + "reporterOptions": { + "configFile": "reporterConfig.json" + }, "env": { "PORT": "4100", "WORKER_PORT": "4200", diff --git a/packages/builder/cypress/integration/addMultiOptionDatatype.spec.js b/packages/builder/cypress/integration/addMultiOptionDatatype.spec.js index e67f1eb2a2..3e0ba92ba4 100644 --- a/packages/builder/cypress/integration/addMultiOptionDatatype.spec.js +++ b/packages/builder/cypress/integration/addMultiOptionDatatype.spec.js @@ -1,4 +1,5 @@ import filterTests from "../support/filterTests" +const interact = require('../support/interact') filterTests(['all'], () => { context("Add Multi-Option Datatype", () => { @@ -17,19 +18,19 @@ filterTests(['all'], () => { cy.navigateToFrontend() cy.wait(500) // Add data provider - cy.get(`[data-cy="category-Data"]`).click() - cy.get(`[data-cy="component-Data Provider"]`).click() - cy.get('[data-cy="dataSource-prop-control"]').click() - cy.get(".dropdown").contains("Multi Data").click() + cy.get(interact.CATEGORY_DATA).click() + cy.get(interact.COMPONENT_DATA_PROVIDER).click() + cy.get(interact.DATASOURCE_PROP_CONTROL).click() + cy.get(interact.DROPDOWN).contains("Multi Data").click() cy.wait(500) // Add Form with schema to match table cy.addComponent("Form", "Form") - cy.get('[data-cy="dataSource-prop-control"').click() - cy.get(".dropdown").contains("Multi Data").click() + cy.get(interact.DATASOURCE_PROP_CONTROL).click() + cy.get(interact.DROPDOWN).contains("Multi Data").click() cy.wait(500) // Add multi-select picker to form cy.addComponent("Form", "Multi-select Picker").then(componentId => { - cy.get('[data-cy="field-prop-control"]').type("Test Data").type("{enter}") + cy.get(interact.DATASOURCE_FIELD_CONTROL).type("Test Data").type("{enter}") cy.wait(1000) cy.getComponent(componentId).contains("Choose some options").click() // Check picker has 5 items @@ -40,7 +41,7 @@ filterTests(['all'], () => { } // Check items have been selected cy.getComponent(componentId) - .find(".spectrum-Picker-label") + .find(interact.SPECTRUM_Picker_LABEL) .contains("(5)") }) }) diff --git a/packages/builder/cypress/integration/addRadioButtons.spec.js b/packages/builder/cypress/integration/addRadioButtons.spec.js index 9888b56086..8f5b1a527b 100644 --- a/packages/builder/cypress/integration/addRadioButtons.spec.js +++ b/packages/builder/cypress/integration/addRadioButtons.spec.js @@ -1,4 +1,5 @@ import filterTests from "../support/filterTests" +const interact = require('../support/interact') filterTests(['all'], () => { context("Add Radio Buttons", () => { @@ -12,10 +13,10 @@ filterTests(['all'], () => { cy.addComponent("Form", "Form") cy.addComponent("Form", "Options Picker").then((componentId) => { // Provide field setting - cy.get(`[data-cy="field-prop-control"]`).type("1") + cy.get(interact.DATASOURCE_FIELD_CONTROL).type("1") // Open dropdown and select Radio buttons - cy.get(`[data-cy="optionsType-prop-control"]`).click().then(() => { - cy.get('.spectrum-Popover').contains('Radio buttons') + cy.get(interact.OPTION_TYPE_PROP_CONTROL).click().then(() => { + cy.get(interact.SPECTRUM_POPOVER).contains('Radio buttons') .wait(500) .click() }) @@ -28,8 +29,8 @@ filterTests(['all'], () => { }) const addRadioButtonData = (totalRadioButtons) => { - cy.get(`[data-cy="optionsSource-prop-control"]`).click().then(() => { - cy.get('.spectrum-Popover').contains('Custom') + cy.get(interact.OPTION_SOURCE_PROP_CONROL).click().then(() => { + cy.get(interact.SPECTRUM_POPOVER).contains('Custom') .wait(500) .click() }) diff --git a/packages/builder/cypress/integration/createApp.spec.js b/packages/builder/cypress/integration/createApp.spec.js index 73f8e645c9..ce5e2bd0c2 100644 --- a/packages/builder/cypress/integration/createApp.spec.js +++ b/packages/builder/cypress/integration/createApp.spec.js @@ -123,6 +123,7 @@ filterTests(['smoke', 'all'], () => { cy.applicationInAppTable("Teds app") cy.deleteApp("Teds app") + cy.wait(2000) //Accomodate names that end in 'S' cy.updateUserInformation("Chris", "Userman") @@ -134,6 +135,7 @@ filterTests(['smoke', 'all'], () => { cy.applicationInAppTable("Chris app") cy.deleteApp("Chris app") + cy.wait(2000) cy.updateUserInformation("", "") }) diff --git a/packages/builder/cypress/integration/createUserAndRoles.spec.js b/packages/builder/cypress/integration/createUserAndRoles.spec.js index 2dbe91ce19..ac7ec1b5fd 100644 --- a/packages/builder/cypress/integration/createUserAndRoles.spec.js +++ b/packages/builder/cypress/integration/createUserAndRoles.spec.js @@ -4,6 +4,8 @@ filterTests(["smoke", "all"], () => { context("Create a User and Assign Roles", () => { before(() => { cy.login() + cy.deleteApp("Cypress Tests") + cy.createApp("Cypress Tests") }) it("should create a user", () => { @@ -52,7 +54,7 @@ filterTests(["smoke", "all"], () => { cy.get(".spectrum-Table").contains("bbuser").click() cy.wait(1000) for (let i = 0; i < 3; i++) { - cy.get(".spectrum-Table") + cy.get(".spectrum-Table", { timeout: 3000}) .eq(1) .find(".spectrum-Table-row") .eq(0) @@ -79,6 +81,7 @@ filterTests(["smoke", "all"], () => { .contains("Update role") .click({ force: true }) }) + cy.reload() } // Confirm roles exist within Configure roles table cy.wait(2000) diff --git a/packages/builder/cypress/integration/templates/HR/jobApplicationTracker.spec.js b/packages/builder/cypress/integration/templates/HR/jobApplicationTracker.spec.js index efb9e58c75..ff6cb91bad 100644 --- a/packages/builder/cypress/integration/templates/HR/jobApplicationTracker.spec.js +++ b/packages/builder/cypress/integration/templates/HR/jobApplicationTracker.spec.js @@ -1,7 +1,7 @@ import filterTests from "../../../support/filterTests" filterTests(["all"], () => { - context("Job Application Functionality", () => { + context("Job Application Tracker Template Functionality", () => { const templateName = "Job Application Tracker" const templateNameParsed = templateName.toLowerCase().replace(/\s+/g, '-') @@ -14,15 +14,7 @@ filterTests(["all"], () => { } }) cy.wait(2000) - - // Template navigation - cy.request(`${Cypress.config().baseUrl}/api/applications?status=all`) - .its("body") - .then(val => { - if (val.length > 0) { - cy.get(".spectrum-Button").contains("Templates").click({force: true}) - } - }) + cy.templateNavigation() }) it("should create and publish app with Job Application Tracker template", () => { diff --git a/packages/builder/cypress/integration/templates/IT/ITTicketingSystem.spec.js b/packages/builder/cypress/integration/templates/IT/ITTicketingSystem.spec.js new file mode 100644 index 0000000000..118625ac65 --- /dev/null +++ b/packages/builder/cypress/integration/templates/IT/ITTicketingSystem.spec.js @@ -0,0 +1,81 @@ +import filterTests from "../../../support/filterTests" + +filterTests(["all"], () => { + context("IT Ticketing System Template Functionality", () => { + const templateName = "IT Ticketing System" + const templateNameParsed = templateName.toLowerCase().replace(/\s+/g, '-') + + before(() => { + cy.login() + cy.deleteApp(templateName) + cy.visit(`${Cypress.config().baseUrl}/builder`, { + onBeforeLoad(win) { + cy.stub(win, 'open') + } + }) + cy.wait(2000) + cy.templateNavigation() + }) + + it("should create and publish app with IT Ticketing System template", () => { + // Select IT Ticketing System template + cy.get(".template-thumbnail-text") + .contains(templateName).parentsUntil(".template-grid").within(() => { + cy.get(".spectrum-Button").contains("Use template").click({ force: true }) + }) + + // Confirm URL matches template name + const appUrl = cy.get(".app-server") + appUrl.invoke('text').then(appUrlText => { + expect(appUrlText).to.equal(`${Cypress.config().baseUrl}/app/` + templateNameParsed) + }) + + // Create App + cy.get(".spectrum-Dialog-grid").within(() => { + cy.get(".spectrum-Button").contains("Create app").click({ force: true }) + }) + + // Publish App + cy.wait(2000) // Wait for app to generate + cy.get(".toprightnav").contains("Publish").click({ force: true }) + cy.get(".spectrum-Dialog-grid").within(() => { + cy.get(".spectrum-Button").contains("Publish").click({ force: true }) + }) + + // Verify Published app + cy.wait(2000) // Wait for App to publish and modal to appear + cy.get(".spectrum-Dialog-grid").within(() => { + cy.get(".spectrum-Button").contains("View App").click({ force: true }) + cy.window().its('open').should('be.calledOnce') + }) + }) + + xit("should filter tickets by status", () => { + // Visit published app + cy.visit(`${Cypress.config().baseUrl}/app/` + templateNameParsed) + cy.wait(1000) + + // Tickets section + cy.get(".links").contains("Tickets").click({ force: true }) + cy.wait(1000) + + // Filter by stage - Confirm table updates + cy.get(".spectrum-Picker").contains("Filter by status").click({ force: true }) + cy.get(".spectrum-Menu").find('li').its('length').then(len => { + for (let i = 1; i < len; i++) { + cy.get(".spectrum-Menu-item").eq(i).click() + const stage = cy.get(".spectrum-Picker-label") + stage.invoke('text').then(stageText => { + if (stageText == "In progress" || stageText == "On hold" || stageText == "Triaged") { + cy.get(".placeholder").should('contain', 'No rows found') + } + else { + cy.get(".spectrum-Table-row").should('contain', stageText) + } + cy.get(".spectrum-Picker").contains(stageText).click({ force: true }) + }) + } + }) + }) + }) +}) diff --git a/packages/builder/cypress/setup.js b/packages/builder/cypress/setup.js index e19c931ed9..d10990573a 100644 --- a/packages/builder/cypress/setup.js +++ b/packages/builder/cypress/setup.js @@ -7,7 +7,6 @@ const tmpdir = path.join(require("os").tmpdir(), ".budibase") const SERVER_PORT = cypressConfig.env.PORT const WORKER_PORT = cypressConfig.env.WORKER_PORT -process.env.BUDIBASE_API_KEY = "6BE826CB-6B30-4AEC-8777-2E90464633DE" process.env.NODE_ENV = "cypress" process.env.ENABLE_ANALYTICS = "false" process.env.JWT_SECRET = cypressConfig.env.JWT_SECRET diff --git a/packages/builder/cypress/support/commands.js b/packages/builder/cypress/support/commands.js index 3baa148ae8..7d40d5d478 100644 --- a/packages/builder/cypress/support/commands.js +++ b/packages/builder/cypress/support/commands.js @@ -524,7 +524,12 @@ Cypress.Commands.add("createAppFromScratch", appName => { .contains("Start from scratch") .click({ force: true }) cy.get(".spectrum-Modal").within(() => { - cy.get("input").eq(0).type(appName).should("have.value", appName).blur() + cy.get("input") + .eq(0) + .clear() + .type(appName) + .should("have.value", appName) + .blur() cy.get(".spectrum-ButtonGroup").contains("Create app").click() cy.wait(10000) }) @@ -638,12 +643,14 @@ Cypress.Commands.add("addDatasourceConfig", (datasource, skipFetch) => { .click({ force: true }) }) } else { + cy.intercept("**/tables").as("datasourceTables") cy.get(".spectrum-Dialog-grid").within(() => { cy.get(".spectrum-Button") .contains("Save and fetch tables") .click({ force: true }) - cy.wait(3000) }) + // Wait for tables to be fetched + cy.wait("@datasourceTables", { timeout: 60000 }) } }) @@ -664,3 +671,15 @@ Cypress.Commands.add("createRestQuery", (method, restUrl, queryPrettyName) => { .should("contain", method) .and("contain", queryPrettyName) }) + +Cypress.Commands.add("templateNavigation", () => { + // Navigates to templates section + cy.request(`${Cypress.config().baseUrl}/api/applications?status=all`) + .its("body") + .then(val => { + // Templates button needs clicked if apps already exist + if (val.length > 0) { + cy.get(".spectrum-Button").contains("Templates").click({ force: true }) + } + }) +}) diff --git a/packages/builder/cypress/support/interact.js b/packages/builder/cypress/support/interact.js index 46954227de..11794d940d 100644 --- a/packages/builder/cypress/support/interact.js +++ b/packages/builder/cypress/support/interact.js @@ -8,6 +8,19 @@ export const TEMPLATE_CATEGORY_ACTIONGROUP = ".template-category" export const TEMPLATE_CATEGORY_FILTER_ACTIONBUTTON = ".template-category-filters .spectrum-ActionButton" export const SPECTRUM_MODAL = ".spectrum-Modal" -export const APP_NAME_INPUT = "input" // we need to update this with atribute cy-data +export const APP_NAME_INPUT = "input" // we need to update this with atribute cy-data; export const SPECTRUM_BUTTON_GROUP = ".spectrum-ButtonGroup" export const SPECTRUM_MODAL_INPUT = ".spectrum-Modal input" + +//AddMultiOptionDatatype test +export const CATEGORY_DATA = '[data-cy="category-Data"]' +export const COMPONENT_DATA_PROVIDER = '[data-cy="component-Data Provider"]' +export const DATASOURCE_PROP_CONTROL = '[data-cy="dataSource-prop-control"]' +export const DROPDOWN = ".dropdown" +export const SPECTRUM_Picker_LABEL = ".spectrum-Picker-label" +export const DATASOURCE_FIELD_CONTROL = '[data-cy="field-prop-control"]' +export const OPTION_TYPE_PROP_CONTROL = '[data-cy="optionsType-prop-control' + +//AddRadioButtons +export const SPECTRUM_POPOVER = ".spectrum-Popover" +export const OPTION_SOURCE_PROP_CONROL = '[data-cy="optionsSource-prop-control' diff --git a/packages/builder/package.json b/packages/builder/package.json index 39f3429103..e13ed5d4e0 100644 --- a/packages/builder/package.json +++ b/packages/builder/package.json @@ -1,6 +1,6 @@ { "name": "@budibase/builder", - "version": "1.0.164-alpha.0", + "version": "1.0.167-alpha.7", "license": "GPL-3.0", "private": true, "scripts": { @@ -13,11 +13,12 @@ "cy:setup:ci": "node ./cypress/setup.js", "cy:open": "cypress open", "cy:run": "cypress run", - "cy:run:ci": "xvfb-run cypress run --headed --browser chrome", + "cy:run:ci": "cypress run --headed --browser chrome --spec cypress/integration/createApp.spec.js", "cy:run:ci:record": "xvfb-run cypress run --headed --browser chrome --record", "cy:test": "start-server-and-test cy:setup http://localhost:4100/builder cy:run", "cy:ci": "start-server-and-test cy:setup:ci http://localhost:4100/builder cy:run:ci", "cy:ci:record": "start-server-and-test cy:setup:ci http://localhost:4100/builder cy:run:ci:record", + "cy:ci:report": "node scripts/cypressResultsWebhook", "cy:debug": "start-server-and-test cy:setup http://localhost:4100/builder cy:open", "cy:debug:ci": "start-server-and-test cy:setup:ci http://localhost:4100/builder cy:open" }, @@ -67,10 +68,10 @@ } }, "dependencies": { - "@budibase/bbui": "^1.0.164-alpha.0", - "@budibase/client": "^1.0.164-alpha.0", - "@budibase/frontend-core": "^1.0.164-alpha.0", - "@budibase/string-templates": "^1.0.164-alpha.0", + "@budibase/bbui": "^1.0.167-alpha.7", + "@budibase/client": "^1.0.167-alpha.7", + "@budibase/frontend-core": "^1.0.167-alpha.7", + "@budibase/string-templates": "^1.0.167-alpha.7", "@sentry/browser": "5.19.1", "@spectrum-css/page": "^3.0.1", "@spectrum-css/vars": "^3.0.1", @@ -98,9 +99,13 @@ "@testing-library/svelte": "^3.0.0", "babel-jest": "^26.6.3", "cypress": "^9.3.1", + "cypress-multi-reporters": "^1.6.0", "cypress-terminal-report": "^1.4.1", "identity-obj-proxy": "^3.0.0", "jest": "^26.6.3", + "mochawesome": "^7.1.3", + "mochawesome-merge": "^4.2.1", + "mochawesome-report-generator": "^6.2.0", "ncp": "^2.0.0", "rimraf": "^3.0.2", "rollup": "^2.44.0", diff --git a/packages/builder/reporterConfig.json b/packages/builder/reporterConfig.json new file mode 100644 index 0000000000..a3b713a3cd --- /dev/null +++ b/packages/builder/reporterConfig.json @@ -0,0 +1,10 @@ +{ + "reporterEnabled": "mochawesome", + "mochawesomeReporterOptions": { + "reportDir": "cypress/reports/mocha", + "quiet": true, + "overwrite": false, + "html": true, + "json": true + } +} \ No newline at end of file diff --git a/packages/builder/scripts/cypressResultsWebhook.js b/packages/builder/scripts/cypressResultsWebhook.js new file mode 100644 index 0000000000..f224664120 --- /dev/null +++ b/packages/builder/scripts/cypressResultsWebhook.js @@ -0,0 +1,131 @@ +#!/usr/bin/env node + +const fetch = require("node-fetch") +const path = require("path") +const { merge } = require("mochawesome-merge") + +const WEBHOOK_URL = process.env.CYPRESS_WEBHOOK_URL +const OUTCOME = process.env.CYPRESS_OUTCOME +const DASHBOARD_URL = process.env.CYPRESS_DASHBOARD_URL +const GIT_SHA = process.env.GITHUB_SHA +const GITHUB_ACTIONS_RUN_URL = process.env.GITHUB_ACTIONS_RUN_URL + +async function generateReport() { + // read the report file + const REPORT_PATH = path.resolve( + __dirname, + "..", + "cypress", + "reports", + "mocha", + "*.json" + ) + const testReport = await merge({ files: [REPORT_PATH] }) + return testReport +} + +async function discordCypressResultsNotification(report) { + const { + suites, + tests, + passes, + pending, + failures, + duration, + passPercent, + skipped, + } = report.stats + + const options = { + method: "POST", + headers: { + "Content-Type": "application/json", + Accept: "application/json", + }, + body: JSON.stringify({ + content: `**Nightly Tests Status**: ${OUTCOME}`, + embeds: [ + { + title: "Budi QA Bot", + description: `Nightly Tests`, + url: GITHUB_ACTIONS_RUN_URL, + color: OUTCOME === "success" ? 3066993 : 15548997, + timestamp: new Date(), + footer: { + icon_url: "http://bbui.budibase.com/budibase-logo.png", + text: "Budibase QA Bot", + }, + thumbnail: { + url: "http://bbui.budibase.com/budibase-logo.png", + }, + author: { + name: "Budibase QA Bot", + url: "https://discordapp.com", + icon_url: "http://bbui.budibase.com/budibase-logo.png", + }, + fields: [ + { + name: "Commit", + value: GIT_SHA || "None Supplied", + }, + { + name: "Cypress Dashboard URL", + value: DASHBOARD_URL || "None Supplied", + }, + { + name: "Github Actions Run URL", + value: GITHUB_ACTIONS_RUN_URL, + }, + { + name: "Test Suites", + value: suites, + }, + { + name: "Tests", + value: tests, + }, + { + name: "Passed", + value: passes, + }, + { + name: "Pending", + value: pending, + }, + { + name: "Skipped", + value: skipped, + }, + { + name: "Failures", + value: failures, + }, + { + name: "Duration", + value: `${duration / 1000} Seconds`, + }, + { + name: "Pass Percentage", + value: passPercent, + }, + ], + }, + ], + }), + } + const response = await fetch(WEBHOOK_URL, options) + + if (response.status >= 400) { + const text = await response.text() + console.error( + `Error sending discord webhook. \nStatus: ${response.status}. \nResponse Body: ${text}. \nRequest Body: ${options.body}` + ) + } +} + +async function run() { + const report = await generateReport() + await discordCypressResultsNotification(report) +} + +run() diff --git a/packages/builder/src/components/usage/Usage.svelte b/packages/builder/src/components/usage/Usage.svelte new file mode 100644 index 0000000000..cd9071785d --- /dev/null +++ b/packages/builder/src/components/usage/Usage.svelte @@ -0,0 +1,56 @@ + + +