Skip to content

Commit

Permalink
Update marxan run tests to check ranAtLeastOnce property
Browse files Browse the repository at this point in the history
  • Loading branch information
yulia-bel committed Aug 11, 2023
1 parent 6a31d9c commit a5e77e0
Showing 1 changed file with 36 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { PromiseType } from 'utility-types';
import { v4 } from 'uuid';
import { GivenScenarioAndProjectPuData } from '../../steps/given-scenario-pu-data-exists';
import { bootstrapApplication } from '../../utils';

import {geoprocessingConnections} from "@marxan-geoprocessing/ormconfig";
const TEST_TIMEOUT_MULTIPLIER = 35000;

let fixtures: PromiseType<ReturnType<typeof getFixtures>>;
Expand All @@ -32,19 +32,21 @@ beforeEach(async () => {
});

describe(`given input data is delayed`, () => {
beforeEach(() => {
beforeEach(async () => {
fixtures.GivenInputFilesAreAvailable(500000);
await fixtures.GivenScenarioExistsInApiDb();
});

test(
`cancelling marxan run during fetching assets shouldn't finish Marxan run.`,
async () => {
expect.assertions(1);
expect.assertions(2);
setTimeout(fixtures.WhenKillingMarxanRun, 1000);
try {
await fixtures.GivenBLMCalibrationIsRunning();
fail();
} catch (e) {
await fixtures.ThenRanAtLeastOncePropertyForScenarioIsFalse()
expect(e).toHaveProperty('signal', 'SIGTERM');
}
},
Expand All @@ -60,6 +62,7 @@ describe(`given input data is available`, () => {
fixtures.GivenInputFilesAreAvailable(500);
await fixtures.GivenScenarioDataExists();
await fixtures.GivenScenarioPuDataExists();
await fixtures.GivenScenarioExistsInApiDb();
}, TEST_TIMEOUT_MULTIPLIER * 4);
test(
`marxan run during binary execution`,
Expand All @@ -68,6 +71,7 @@ describe(`given input data is available`, () => {
fixtures.ThenHasValidOutput(output);
await fixtures.ThenOutputScenarioPuDataWasPersisted();
fixtures.ThenProgressWasReported();
await fixtures.ThenRanAtLeastOncePropertyForScenarioIsTrue()
},
TEST_TIMEOUT_MULTIPLIER * 30,
);
Expand Down Expand Up @@ -109,6 +113,9 @@ const getFixtures = async () => {

const app = await bootstrapApplication();
const entityManager = app.get<EntityManager>(getEntityManagerToken());
const apiEntityManager: EntityManager = app.get(
getEntityManagerToken(geoprocessingConnections.apiDB),
);
const featuresData: Repository<GeoFeatureGeometry> = app.get(
getRepositoryToken(GeoFeatureGeometry),
);
Expand Down Expand Up @@ -155,6 +162,10 @@ const getFixtures = async () => {
id: In(projectPus.map((pu) => pu.geomId)),
});
// featuresOutputRepo removes on cascade

await apiEntityManager.query(`DELETE FROM scenarios WHERE id=$1`, [scenarioId])
await apiEntityManager.query(`DELETE FROM projects WHERE id=$1`, [projectId])
await apiEntityManager.query(`DELETE FROM organizations`)
nockScope.done();
nock.enableNetConnect();
},
Expand Down Expand Up @@ -183,6 +194,12 @@ const getFixtures = async () => {
'content-type': 'plain/text',
});
}),
GivenScenarioExistsInApiDb: async() => {
const organizationId = v4()
await apiEntityManager.query(`INSERT INTO organizations (id, name) VALUES ($1, $2)`, [organizationId, 'test_organization'])
await apiEntityManager.query(`INSERT INTO projects (id, name, organization_id, sources) VALUES ($1, $2, $3, $4)`, [projectId, 'test_project', organizationId, 'legacy_import'])
await apiEntityManager.query(`INSERT INTO scenarios (id, name, project_id) VALUES ($1, $2, $3)`, [scenarioId, 'test_scenario', projectId])
},
GivenScenarioPuDataExists: async () => {
outputsIds.push(
...(
Expand Down Expand Up @@ -263,6 +280,22 @@ const getFixtures = async () => {
const { calls } = this.progressMock.mock;
expect(last(calls)).toEqual([1]);
},

ThenRanAtLeastOncePropertyForScenarioIsFalse: async() => {
const scenario = await apiEntityManager.query(
`SELECT * FROM scenarios WHERE id = $1;`,
[scenarioId],
)
expect(scenario[0].ran_at_least_once).toBe(false)
},

ThenRanAtLeastOncePropertyForScenarioIsTrue: async() => {
const scenario = await apiEntityManager.query(
`SELECT * FROM scenarios WHERE id = $1;`,
[scenarioId],
)
expect(scenario[0].ran_at_least_once).toBe(true)
}
};
};

Expand Down

0 comments on commit a5e77e0

Please sign in to comment.