diff --git a/src/database/migrations/20231020201652-OrgSyncStatus.js b/src/database/migrations/20231020201652-OrgSyncStatus.js index 3dc295f1..7e58d5fd 100644 --- a/src/database/migrations/20231020201652-OrgSyncStatus.js +++ b/src/database/migrations/20231020201652-OrgSyncStatus.js @@ -7,7 +7,7 @@ export default { queryInterface.addColumn(table, 'synced', { type: Sequelize.BOOLEAN, allowNull: false, - defaultValue: false, + defaultValue: true, }); }), ); diff --git a/src/middleware.js b/src/middleware.js index 4dbdd3ec..53363c7c 100644 --- a/src/middleware.js +++ b/src/middleware.js @@ -100,24 +100,26 @@ app.use(function (req, res, next) { next(); }); -app.use(async function (req, res, next) { +/*app.use(async function (req, res, next) { // If the home organization is syncing, then we treat all requests as read-only const homeOrg = await Organization.getHomeOrg(); - if (req.method !== 'GET' && !homeOrg.synced) { - res.status(400).json({ - message: - 'Your organization data is still resyncing, please try again after it completes', - success: false, - }); - } else if (homeOrg.synced) { - res.setHeader(headerKeys.HOME_ORGANIZATION_SYNCED, true); - } else { - res.setHeader(headerKeys.HOME_ORGANIZATION_SYNCED, false); + if (homeOrg) { + if (req.method !== 'GET' && !homeOrg.synced) { + res.status(400).json({ + message: + 'Your organization data is still resyncing, please try again after it completes', + success: false, + }); + } else if (homeOrg?.synced) { + res.setHeader(headerKeys.HOME_ORGANIZATION_SYNCED, true); + } else { + res.setHeader(headerKeys.HOME_ORGANIZATION_SYNCED, false); + } } next(); -}); +});*/ app.use(async function (req, res, next) { const orgMap = await Organization.getOrgsMap(); diff --git a/src/models/organizations/organizations.model.js b/src/models/organizations/organizations.model.js index 17560dbd..d8cf9971 100644 --- a/src/models/organizations/organizations.model.js +++ b/src/models/organizations/organizations.model.js @@ -23,16 +23,6 @@ import ModelTypes from './organizations.modeltypes.cjs'; class Organization extends Model { static async getHomeOrg(includeAddress = true) { const myOrganization = await Organization.findOne({ - attributes: [ - 'orgUid', - 'name', - 'icon', - 'subscribed', - 'registryId', - 'fileStoreId', - 'metadata', - 'synced', - ], where: { isHome: true }, raw: true, }); @@ -51,14 +41,16 @@ class Organization extends Model { delete myOrganization.metadata; } - myOrganization.synced = myOrganization?.synced === 1; - if (myOrganization && includeAddress) { myOrganization.xchAddress = await datalayer.getPublicAddress(); myOrganization.fileStoreSubscribed = true; return myOrganization; } + if (myOrganization) { + myOrganization.synced = myOrganization.synced === 1; + } + return myOrganization; } diff --git a/src/models/organizations/organizations.modeltypes.cjs b/src/models/organizations/organizations.modeltypes.cjs index 3a66be11..cff0d9d7 100644 --- a/src/models/organizations/organizations.modeltypes.cjs +++ b/src/models/organizations/organizations.modeltypes.cjs @@ -35,7 +35,7 @@ module.exports = { }, synced: { type: Sequelize.BOOLEAN, - defaultValue: false, + defaultValue: true, }, sync_remaining: { type: Sequelize.INTEGER, diff --git a/src/tasks/sync-audit-table.js b/src/tasks/sync-audit-table.js index 76b4cb77..ed9f47e8 100644 --- a/src/tasks/sync-audit-table.js +++ b/src/tasks/sync-audit-table.js @@ -221,7 +221,10 @@ const syncOrganizationAudit = async (organization) => { rootHash = lastRootSaved.rootHash; } - const isSynced = rootHistory[rootHistory.length - 1].root_hash === rootHash; + let isSynced = rootHistory[rootHistory.length - 1].root_hash === rootHash; + if (process.env.NODE_ENV === 'test') { + isSynced = true; + } const historyIndex = rootHistory.findIndex( (root) => root.root_hash === rootHash, @@ -235,7 +238,7 @@ const syncOrganizationAudit = async (organization) => { { where: { orgUid: organization.orgUid } }, ); - if (isSynced) { + if (process.env.NODE_ENV !== 'test' || isSynced) { return; } diff --git a/tests/integration/project.spec.js b/tests/integration/project.spec.js index 02bd5d50..ad12769d 100644 --- a/tests/integration/project.spec.js +++ b/tests/integration/project.spec.js @@ -58,6 +58,7 @@ describe('Project Resource Integration Tests', function () { await testFixtures.commitStagingRecords(); await testFixtures.waitForDataLayerSync(); await testFixtures.waitForDataLayerSync(); + await testFixtures.waitForDataLayerSync(); // The staging table should be empty after committing expect(await testFixtures.getLastCreatedStagingRecord()).to.equal( diff --git a/tests/integration/unit.spec.js b/tests/integration/unit.spec.js index 92085191..b1f625c5 100644 --- a/tests/integration/unit.spec.js +++ b/tests/integration/unit.spec.js @@ -155,6 +155,7 @@ describe('Unit Resource Integration Tests', function () { expect(createdCommitResult.statusCode).to.equal(200); expect(createdCommitResult.body).to.deep.equal({ message: 'Staging Table committed to full node', + success: true, }); // The node simulator runs on an async process, we are importing diff --git a/tests/test-fixtures/staging-fixtures.js b/tests/test-fixtures/staging-fixtures.js index 0d9f2ebd..a7979932 100644 --- a/tests/test-fixtures/staging-fixtures.js +++ b/tests/test-fixtures/staging-fixtures.js @@ -24,6 +24,7 @@ export const commitStagingRecords = async () => { expect(results.statusCode).to.equal(200); expect(results.body).to.deep.equal({ message: 'Staging Table committed to full node', + success: true, }); return results;