Skip to content

Commit

Permalink
fix(#9166): backwards compatible couchdb views (#9183)
Browse files Browse the repository at this point in the history
  • Loading branch information
dianabarsan committed Jun 17, 2024
1 parent 83d7c4b commit 27b3369
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 24 deletions.
12 changes: 10 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand All @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion ddocs/.eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
"no-var": "off"
},
"parserOptions": {
"ecmaVersion": 6,
"ecmaVersion": 5
}
}
7 changes: 5 additions & 2 deletions ddocs/users-meta-db/users-meta/views/device_by_user/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions ddocs/users-meta-db/users-meta/views/device_by_user/reduce.js
Original file line number Diff line number Diff line change
@@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "medic",
"version": "4.7.1",
"version": "4.7.2",
"private": true,
"license": "AGPL-3.0-only",
"repository": {
Expand Down
26 changes: 20 additions & 6 deletions tests/e2e/upgrade/upgrade.wdio-spec.js
Original file line number Diff line number Diff line change
@@ -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');
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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;
});
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down
12 changes: 8 additions & 4 deletions tests/e2e/upgrade/wdio.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -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-');
Expand All @@ -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', {}],
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion tests/factories/cht/reports/pregnancy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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': {
Expand Down
11 changes: 10 additions & 1 deletion tests/integration/couchdb/couch_chttpd.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand All @@ -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 })
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: '3'

services:
chttpd_call:
build: .
Expand All @@ -11,3 +9,4 @@ services:
networks:
net:
name: cht-net-e2e
external: true

0 comments on commit 27b3369

Please sign in to comment.