Skip to content

Commit

Permalink
Merge pull request #511 from Chia-Network/fix/510-delete-stage-import…
Browse files Browse the repository at this point in the history
…ed-orgs

Fix: delete stage when deleting imported orgs
  • Loading branch information
MichaelTaylor3D authored May 5, 2022
2 parents b2293dc + fdb8e37 commit 5ac3af1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/controllers/organization.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
assertCanDeleteOrg,
} from '../utils/data-assertions';

import { ModelKeys, Audit } from '../models';
import { ModelKeys, Audit, Staging } from '../models';

export const findAll = async (req, res) => {
return res.json(await Organization.getOrgsMap());
Expand Down Expand Up @@ -90,7 +90,13 @@ export const resetHomeOrg = async (req, res) => {
await assertWalletIsAvailable();
await assertWalletIsSynced();

await Organization.destroy({ where: { isHome: true } });
await Promise.all([
Organization.destroy({ where: { isHome: true } }),
Staging.destroy({
where: {},
truncate: true,
}),
]);

res.json({
message: 'Your home organization was reset, please create a new one.',
Expand Down
19 changes: 19 additions & 0 deletions tests/resources/organization.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,36 @@ import { Organization } from '../../src/models/organizations/index.js';
import { expect } from 'chai';
import { prepareDb } from '../../src/database';
import datalayer from '../../src/datalayer';
import { pullPickListValues } from '../../src/utils/data-loaders';
const TEST_WAIT_TIME = datalayer.POLLING_INTERVAL * 2;
import * as testFixtures from '../test-fixtures';

describe('Orgainzation Resource CRUD', function () {
before(async function () {
await pullPickListValues();
await prepareDb();
});

beforeEach(async function () {
await testFixtures.createTestHomeOrg();
});

describe('DELETE - Reset Organization', function () {
it('clears the home org and any staging data', async function () {
// add a project to the staging table
await testFixtures.createNewProject();

const response = await supertest(app).delete(`/v1/organizations`).send();

expect(response.body.message).to.equal(
'Your home organization was reset, please create a new one.',
);

const stagingData = await testFixtures.getLastCreatedStagingRecord();
expect(stagingData).to.be.undefined;
});
});

describe('POST - Creates an organization', function () {
it('Creates an organization', async function () {
await Organization.destroy({
Expand All @@ -32,6 +50,7 @@ describe('Orgainzation Resource CRUD', function () {
'New organization created successfully.',
);
}).timeout(TEST_WAIT_TIME * 10);

it('Organization can be retreived from datalayer', async function () {
const response = await supertest(app).get(`/v1/organizations`).send();

Expand Down

0 comments on commit 5ac3af1

Please sign in to comment.