From 27b3369fa16aba39e7ae0bc62c9ad8732704adfe Mon Sep 17 00:00:00 2001 From: Diana Barsan <35681649+dianabarsan@users.noreply.github.com> Date: Mon, 17 Jun 2024 12:07:24 +0300 Subject: [PATCH] fix(#9166): backwards compatible couchdb views (#9183) #9166 --- .github/workflows/build.yml | 12 +++++++-- ddocs/.eslintrc | 2 +- .../users-meta/views/device_by_user/map.js | 7 +++-- .../users-meta/views/device_by_user/reduce.js | 4 +-- package-lock.json | 4 +-- package.json | 2 +- tests/e2e/upgrade/upgrade.wdio-spec.js | 26 ++++++++++++++----- tests/e2e/upgrade/wdio.conf.js | 12 ++++++--- tests/factories/cht/reports/pregnancy.js | 2 +- .../integration/couchdb/couch_chttpd.spec.js | 11 +++++++- .../couch_httpd_script/docker-compose.yml | 3 +-- 11 files changed, 61 insertions(+), 24 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index cf9a46538c5..a4acceaf71e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -330,10 +330,17 @@ jobs: upgrade: needs: [publish] - name: Upgrade from latest release + name: Upgrade from ${{ matrix.version }} runs-on: ubuntu-22.04 + timeout-minutes: 60 + if: ${{ github.event_name != 'pull_request' }} + strategy: + fail-fast: false + matrix: + version: [ '4.2.4', 'latest' ] + steps: - name: Configure AWS credentials Public if: ${{ env.INTERNAL_CONTRIBUTOR }} @@ -353,6 +360,7 @@ jobs: - name: Set ENV run: | echo "BUILDS_SERVER=$STAGING_SERVER" >> $GITHUB_ENV + echo "BASE_VERSION=${{ matrix.version }}" >> $GITHUB_ENV - run: npm ci - name: Create logs directory run: mkdir tests/logs @@ -362,7 +370,7 @@ jobs: - name: Archive Results uses: actions/upload-artifact@v4 with: - name: Upgrade + name: upgrade-${{ matrix.version }} path: | allure-results allure-report diff --git a/ddocs/.eslintrc b/ddocs/.eslintrc index fcdea031c61..c4d5c126164 100644 --- a/ddocs/.eslintrc +++ b/ddocs/.eslintrc @@ -7,6 +7,6 @@ "no-var": "off" }, "parserOptions": { - "ecmaVersion": 6, + "ecmaVersion": 5 } } diff --git a/ddocs/users-meta-db/users-meta/views/device_by_user/map.js b/ddocs/users-meta-db/users-meta/views/device_by_user/map.js index 425d19ebc7d..3edc3071c69 100644 --- a/ddocs/users-meta-db/users-meta/views/device_by_user/map.js +++ b/ddocs/users-meta-db/users-meta/views/device_by_user/map.js @@ -8,9 +8,12 @@ function(doc) { doc.metadata.month && doc.metadata.day ) { - const pad = number => number.toString().padStart(2, '0'); + var pad = function (number) { + return number.toString().padStart(2, '0'); + }; + emit([doc.metadata.user, doc.metadata.deviceId], { - date: `${doc.metadata.year}-${pad(doc.metadata.month)}-${pad(doc.metadata.day)}`, + date: doc.metadata.year + '-' + pad(doc.metadata.month) + '-' + pad(doc.metadata.day), id: doc._id, device: { userAgent: doc.device && doc.device.userAgent, diff --git a/ddocs/users-meta-db/users-meta/views/device_by_user/reduce.js b/ddocs/users-meta-db/users-meta/views/device_by_user/reduce.js index b84a11d566e..944557e9601 100644 --- a/ddocs/users-meta-db/users-meta/views/device_by_user/reduce.js +++ b/ddocs/users-meta-db/users-meta/views/device_by_user/reduce.js @@ -1,6 +1,6 @@ function (keys, values) { - let latest = { date: '1970-01-01' }; - values.forEach(function (value) { + var latest = { date: '1970-01-01' }; + values.forEach(function(value) { if (value.date > latest.date) { latest = value; } diff --git a/package-lock.json b/package-lock.json index eb695818cea..29d090bbe1b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "medic", - "version": "4.7.1", + "version": "4.7.2", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "medic", - "version": "4.7.1", + "version": "4.7.2", "hasInstallScript": true, "license": "AGPL-3.0-only", "workspaces": [ diff --git a/package.json b/package.json index ed667abdd5c..db40eff8bf8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "medic", - "version": "4.7.1", + "version": "4.7.2", "private": true, "license": "AGPL-3.0-only", "repository": { diff --git a/tests/e2e/upgrade/upgrade.wdio-spec.js b/tests/e2e/upgrade/upgrade.wdio-spec.js index 4c62f14aefc..8fa338c48fa 100644 --- a/tests/e2e/upgrade/upgrade.wdio-spec.js +++ b/tests/e2e/upgrade/upgrade.wdio-spec.js @@ -1,6 +1,6 @@ const utils = require('@utils'); -const { BRANCH, TAG } = process.env; +const { BRANCH, TAG, BASE_VERSION } = process.env; const loginPage = require('@page-objects/default/login/login.wdio.page'); const upgradePage = require('@page-objects/upgrade/upgrade.wdio.page'); const commonPage = require('@page-objects/default/common/common.wdio.page'); @@ -11,6 +11,8 @@ const version = require('../../../scripts/build/versions'); const dataFactory = require('@factories/cht/generate'); const semver = require('semver'); +const testFrontend = BASE_VERSION === 'latest'; + const docs = dataFactory.createHierarchy({ name: 'offlineupgrade', user: true, @@ -52,8 +54,12 @@ describe('Performing an upgrade', () => { await utils.saveDocs([...docs.places, ...docs.clinics, ...docs.persons, ...docs.reports]); await utils.createUsers([docs.user]); - await loginPage.login(docs.user); - await commonPage.logout(); + if (testFrontend) { + // a variety of selectors that we use in e2e tests to interact with webapp + // are not compatible with older versions of the app. + await loginPage.login(docs.user); + await commonPage.logout(); + } await loginPage.cookieLogin({ username: constants.USERNAME, @@ -71,8 +77,11 @@ describe('Performing an upgrade', () => { }); }); - // TODO Enable this test after 4.6.0 is released - xit('should have valid semver after installing', async () => { + it('should have valid semver after installing', async () => { + if (!testFrontend) { + return; + } + const deployInfo = await utils.request({ path: '/api/deploy-info' }); expect(semver.valid(deployInfo.version)).to.be.ok; }); @@ -105,7 +114,8 @@ describe('Performing an upgrade', () => { const staged = ddocs.filter(ddoc => ddoc._id.includes('staged')); expect(staged.length).to.equal(0); - ddocs.forEach(ddoc => expect(ddoc.version).to.equal(currentBuild)); + // For tags (betas and releases) we don't actually show the build number on the upgrade page + ddocs.forEach(ddoc => expect(ddoc.version).to.include(currentBuild)); const deployInfo = await utils.request({ path: '/api/deploy-info' }); expect(semver.valid(deployInfo.version)).to.be.ok; @@ -117,6 +127,10 @@ describe('Performing an upgrade', () => { state: 'finalized', }); + if (!testFrontend) { + return; + } + await adminPage.logout(); await loginPage.login(docs.user); await commonPage.sync(true); diff --git a/tests/e2e/upgrade/wdio.conf.js b/tests/e2e/upgrade/wdio.conf.js index 42ae1225e59..f87aab15b8d 100644 --- a/tests/e2e/upgrade/wdio.conf.js +++ b/tests/e2e/upgrade/wdio.conf.js @@ -13,7 +13,7 @@ const rpn = require('request-promise-native'); const utils = require('@utils'); const wdioBaseConfig = require('../wdio.conf'); -const { MARKET_URL_READ, STAGING_SERVER, HAPROXY_PORT } = process.env; +const { MARKET_URL_READ, STAGING_SERVER, HAPROXY_PORT, BASE_VERSION } = process.env; const CHT_COMPOSE_PROJECT_NAME = 'cht-upgrade'; const UPGRADE_SERVICE_DOCKER_COMPOSE_FOLDER = utils.makeTempDir('upgrade-service-'); @@ -28,7 +28,11 @@ const getUpgradeServiceDockerCompose = async () => { await fs.promises.writeFile(UPGRADE_SERVICE_DC, contents); }; -const getLatestRelease = async () => { +const getRelease = async () => { + if (BASE_VERSION !== 'latest') { + return `medic:medic:${BASE_VERSION}`; + } + const url = `${MARKET_URL_READ}/${STAGING_SERVER}/_design/builds/_view/releases`; const query = { startKey: [ 'release', 'medic', 'medic', {}], @@ -43,9 +47,9 @@ const getLatestRelease = async () => { }; const getMainCHTDockerCompose = async () => { - const latestRelease = await getLatestRelease(); + const release = await getRelease(); for (const composeFile of COMPOSE_FILES) { - const composeFileUrl = `${MARKET_URL_READ}/${STAGING_SERVER}/${latestRelease}/docker-compose/${composeFile}.yml`; + const composeFileUrl = `${MARKET_URL_READ}/${STAGING_SERVER}/${release}/docker-compose/${composeFile}.yml`; const contents = await rpn.get(composeFileUrl); const filePath = path.join(CHT_DOCKER_COMPOSE_FOLDER, `${composeFile}.yml`); await fs.promises.writeFile(filePath, contents); diff --git a/tests/factories/cht/reports/pregnancy.js b/tests/factories/cht/reports/pregnancy.js index e719d218fa9..86c2d10abb1 100644 --- a/tests/factories/cht/reports/pregnancy.js +++ b/tests/factories/cht/reports/pregnancy.js @@ -18,7 +18,7 @@ const defaultSubmitter = { }; const nextANCVisit = moment().add(2, 'day'); -const lmp = moment().subtract(3, 'months'); +const lmp = moment().subtract(90, 'days'); const defaultFields = { 'inputs': { diff --git a/tests/integration/couchdb/couch_chttpd.spec.js b/tests/integration/couchdb/couch_chttpd.spec.js index a17cfa989d9..22ad96fbbfa 100644 --- a/tests/integration/couchdb/couch_chttpd.spec.js +++ b/tests/integration/couchdb/couch_chttpd.spec.js @@ -21,8 +21,13 @@ const startContainer = async (useAuthentication) => { if (useAuthentication) { env.COUCH_AUTH = `${constants.USERNAME}:${constants.PASSWORD}`; } - return await runDockerCommand('docker-compose', ['up', '--build', '--force-recreate'], env); + await runDockerCommand('docker-compose', ['up', '--build', '--force-recreate'], env); }; + +const stopContainer = async () => { + await runDockerCommand('docker-compose', ['down', '--remove-orphans']); +}; + const getLogs = async () => { const containerName = (await runDockerCommand('docker-compose', ['ps', '-q', '-a']))[0]; const logs = await runDockerCommand('docker', ['logs', containerName]); @@ -47,6 +52,10 @@ const expectCorrectMetadata = (metadata) => { }; describe('accessing couch clustering endpoint', () => { + afterEach(async () => { + await stopContainer(); + }); + it('should block unauthenticated access through the host network', async () => { await expect( utils.request({ uri: `https://localhost/_node/_local/_dbs/${constants.DB_NAME}`, noAuth: true }) diff --git a/tests/integration/couchdb/couch_httpd_script/docker-compose.yml b/tests/integration/couchdb/couch_httpd_script/docker-compose.yml index 4b65b5988d7..d9e6dd650c1 100644 --- a/tests/integration/couchdb/couch_httpd_script/docker-compose.yml +++ b/tests/integration/couchdb/couch_httpd_script/docker-compose.yml @@ -1,5 +1,3 @@ -version: '3' - services: chttpd_call: build: . @@ -11,3 +9,4 @@ services: networks: net: name: cht-net-e2e + external: true