Skip to content

Commit

Permalink
feat: epäaktiivinen tila hyväksymispäätöskuulutuksen jälkeen (#370)
Browse files Browse the repository at this point in the history
  • Loading branch information
haapamakim authored Sep 20, 2022
1 parent 4cd293c commit 30b2918
Show file tree
Hide file tree
Showing 65 changed files with 1,717 additions and 740 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ import { emailHandler } from "../../src/handler/emailHandler";

const { expect } = require("chai");

const sandbox = sinon.createSandbox();

async function takeSnapshot(oid: string) {
const dbProjekti = await projektiDatabase.loadProjektiByOid(oid);
expect({
Expand All @@ -31,29 +29,25 @@ describe("AloitusKuulutus", () => {
let sendEmailsByToimintoStub: sinon.SinonStub;

before(async () => {
readUsersFromSearchUpdaterLambda = sandbox.stub(personSearchUpdaterClient, "readUsersFromSearchUpdaterLambda");
readUsersFromSearchUpdaterLambda = sinon.stub(personSearchUpdaterClient, "readUsersFromSearchUpdaterLambda");
readUsersFromSearchUpdaterLambda.callsFake(async () => {
return await personSearchUpdaterHandler.handleEvent();
});

publishProjektiFileStub = sandbox.stub(fileService, "publishProjektiFile");
publishProjektiFileStub = sinon.stub(fileService, "publishProjektiFile");
publishProjektiFileStub.resolves();

sendEmailsByToimintoStub = sandbox.stub(emailHandler, "sendEmailsByToiminto");
sendEmailsByToimintoStub = sinon.stub(emailHandler, "sendEmailsByToiminto");
sendEmailsByToimintoStub.resolves();
});

afterEach(() => {
userFixture.logout();
sandbox.reset();
sandbox.restore();
sinon.reset();
sinon.restore();
});

beforeEach("Initialize test database!", async () => await setupLocalDatabase());

beforeEach(() => {
beforeEach(async () => {
await setupLocalDatabase();
userFixture = new UserFixture(userService);
});

Expand Down
29 changes: 11 additions & 18 deletions backend/integrationtest/api/api.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, it } from "mocha";
import { replaceAWSDynamoDBWithLocalstack, setupLocalDatabase } from "../util/databaseUtil";
import { setupLocalDatabase } from "../util/databaseUtil";
import { Status } from "../../../common/graphql/apiModel";
import * as sinon from "sinon";
import { personSearchUpdaterClient } from "../../src/personSearch/personSearchUpdaterClient";
Expand All @@ -15,7 +15,7 @@ import { getCloudFront, produce } from "../../src/aws/client";
import { cleanProjektiS3Files } from "../util/s3Util";
import { emailClient } from "../../src/email/email";
import {
archiveProjekti,
deleteProjekti,
julkaiseSuunnitteluvaihe,
julkaiseVuorovaikutus,
loadProjektiFromDatabase,
Expand Down Expand Up @@ -51,7 +51,6 @@ import {
} from "./testUtil/hyvaksymisPaatosVaihe";
import { FixtureName, recordProjektiTestFixture } from "./testFixtureRecorder";

const sandbox = sinon.createSandbox();
const { expect } = require("chai");

const oid = "1.2.246.578.5.1.2978288874.2711575506";
Expand All @@ -65,10 +64,7 @@ describe("Api", () => {

after(() => {
userFixture.logout();
sandbox.restore();
sandbox.reset();
sinon.restore();
sinon.reset();
AWSMock.restore();
});

Expand All @@ -77,31 +73,31 @@ describe("Api", () => {
before(async () => {
await setupLocalDatabase();
userFixture = new UserFixture(userService);
readUsersFromSearchUpdaterLambda = sandbox.stub(personSearchUpdaterClient, "readUsersFromSearchUpdaterLambda");
readUsersFromSearchUpdaterLambda = sinon.stub(personSearchUpdaterClient, "readUsersFromSearchUpdaterLambda");
readUsersFromSearchUpdaterLambda.callsFake(async () => {
return await personSearchUpdaterHandler.handleEvent();
});

sandbox.stub(openSearchClientYllapito, "query").resolves({ status: 200 });
sandbox.stub(openSearchClientYllapito, "deleteDocument");
sandbox.stub(openSearchClientYllapito, "putDocument");
sinon.stub(openSearchClientYllapito, "query").resolves({ status: 200 });
sinon.stub(openSearchClientYllapito, "deleteDocument");
sinon.stub(openSearchClientYllapito, "putDocument");

importAineistoStub = sandbox.stub(aineistoImporterClient, "importAineisto");
importAineistoStub = sinon.stub(aineistoImporterClient, "importAineisto");
importAineistoStub.callsFake(async (event) => {
fakeAineistoImportQueue.push({ Records: [{ body: JSON.stringify(event) } as SQSRecord] });
});

awsCloudfrontInvalidationStub = sandbox.stub();
awsCloudfrontInvalidationStub = sinon.stub();
awsCloudfrontInvalidationStub.resolves({});
AWSMock.setSDKInstance(AWS);
produce<AWS.CloudFront>("cloudfront", () => undefined, true);
AWSMock.mock("CloudFront", "createInvalidation", awsCloudfrontInvalidationStub);
getCloudFront();

emailClientStub = sandbox.stub(emailClient, "sendEmail");
emailClientStub = sinon.stub(emailClient, "sendEmail");

try {
await archiveProjekti(oid);
await deleteProjekti(oid);
} catch (ignored) {
// ignored
}
Expand Down Expand Up @@ -172,10 +168,7 @@ describe("Api", () => {
await processQueue(fakeAineistoImportQueue);
await takePublicS3Snapshot(oid, "Hyvaksymispaatos approved", "hyvaksymispaatos");
verifyEmailsSent(emailClientStub);
});

it.skip("should archive projekti", async function () {
replaceAWSDynamoDBWithLocalstack();
await archiveProjekti(oid);
await recordProjektiTestFixture(FixtureName.HYVAKSYMISPAATOS_APPROVED, oid);
});
});
108 changes: 108 additions & 0 deletions backend/integrationtest/api/hyvaksymisPaatosHyvaksytty.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/* tslint:disable:only-arrow-functions no-unused-expression */
import { describe, it } from "mocha";
import { FixtureName, MOCKED_TIMESTAMP, useProjektiTestFixture } from "./testFixtureRecorder";
import { setupLocalDatabase } from "../util/databaseUtil";
import { deleteProjekti, loadProjektiFromDatabase, loadProjektiJulkinenFromDatabase } from "./testUtil/tests";
import { UserFixture } from "../../test/fixture/userFixture";
import { userService } from "../../src/user";
import sinon from "sinon";
import { projektiDatabase } from "../../src/database/projektiDatabase";
import dayjs from "dayjs";
import { Status } from "../../../common/graphql/apiModel";
import { assert, expect } from "chai";
import { ISO_DATE_FORMAT } from "../../src/util/dateUtil";

const oid = "1.2.246.578.5.1.2978288874.2711575506";

describe("Hyväksytyn hyväksymispäätöskuulutuksen jälkeen", () => {
let userFixture: UserFixture;

before(async () => {
userFixture = new UserFixture(userService);

await setupLocalDatabase();
try {
await deleteProjekti(oid);
} catch (_ignore) {
// ignore
}
await useProjektiTestFixture(FixtureName.HYVAKSYMISPAATOS_APPROVED);
});

after(() => {
userFixture.logout();
sinon.restore();
});

async function setKuulutusVaihePaattyyPaivaToYesterday() {
const dbProjekti = await projektiDatabase.loadProjektiByOid(oid);
const julkaisu = dbProjekti.hyvaksymisPaatosVaiheJulkaisut[0];
// Päättymispäivä yli vuosi menneisyyteen, jotta projekti menee epäaktiiviseksi
julkaisu.kuulutusVaihePaattyyPaiva = dayjs().add(-1, "day").format(ISO_DATE_FORMAT);
await projektiDatabase.updateHyvaksymisPaatosVaiheJulkaisu(dbProjekti, julkaisu);
}

async function setKuulutusVaihePaattyyPaivaToOverOneYearAgo() {
const dbProjekti = await projektiDatabase.loadProjektiByOid(oid);
const julkaisu = dbProjekti.hyvaksymisPaatosVaiheJulkaisut[0];
// Päättymispäivä yli vuosi menneisyyteen, jotta projekti menee epäaktiiviseksi
julkaisu.kuulutusVaihePaattyyPaiva = dayjs().add(-1, "year").add(-1, "day").format(ISO_DATE_FORMAT);
await projektiDatabase.updateHyvaksymisPaatosVaiheJulkaisu(dbProjekti, julkaisu);
}

async function expectYllapitoProjektiStatus(expectedStatus: Status) {
userFixture.loginAs(UserFixture.mattiMeikalainen);
await loadProjektiFromDatabase(oid, expectedStatus); // Verify status in yllapito
}

async function expectJulkinenProjektiStatus(expectedStatus: Status) {
userFixture.logout();
try {
await loadProjektiJulkinenFromDatabase(oid, expectedStatus);
} catch (e) {
console.log(e);
assert.fail("Could not load julkinen projekti from API");
}
userFixture.loginAs(UserFixture.mattiMeikalainen);
}

async function expectJulkinenNotFound() {
userFixture.logout();
try {
await loadProjektiJulkinenFromDatabase(oid);
assert.fail("Projektilla on julkista sisältöä vaikka ei pitäisi");
} catch (e) {
// expected
}
userFixture.loginAs(UserFixture.mattiMeikalainen);
}

it("should get epäaktiivinen and jatkopäätös1 statuses successfully", async () => {
userFixture.loginAs(UserFixture.mattiMeikalainen);
await setKuulutusVaihePaattyyPaivaToYesterday();
await expectJulkinenProjektiStatus(Status.HYVAKSYTTY);
await setKuulutusVaihePaattyyPaivaToOverOneYearAgo();
await expectYllapitoProjektiStatus(Status.EPAAKTIIVINEN);
await expectJulkinenNotFound();

const epaAktiivinenProjekti1 = await projektiDatabase.loadProjektiByOid(oid);
expect(epaAktiivinenProjekti1.ajastettuTarkistus).to.eql("2101-01-01T23:59:00+02:00"); // MOCKED_TIMESTAMP + 1 year
// TODO aineistojen ajastettu poisto tässä kohtaa

await projektiDatabase.saveProjekti({
oid,
kasittelynTila: {
...epaAktiivinenProjekti1.kasittelynTila,
ensimmainenJatkopaatos: { paatoksenPvm: MOCKED_TIMESTAMP, asianumero: "jatkopaatos1_asianumero" },
},
});

await expectYllapitoProjektiStatus(Status.JATKOPAATOS_1);
await expectJulkinenNotFound();

// TODO hyväksytty jatkopäätös1
// TODO hyväksytty epäaktiivinen2
// TODO hyväksytty jatkopäätös2
// TODO hyväksytty epäaktiivinen2
});
});
11 changes: 4 additions & 7 deletions backend/integrationtest/api/palaute.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@
import { describe, it } from "mocha";
import { FixtureName, useProjektiTestFixture } from "./testFixtureRecorder";
import { setupLocalDatabase } from "../util/databaseUtil";
import { tallennaLogo, verifyEmailsSent } from "./testUtil/tests";
import { deleteProjekti, tallennaLogo, verifyEmailsSent } from "./testUtil/tests";
import { UserFixture } from "../../test/fixture/userFixture";
import { userService } from "../../src/user";
import { api } from "./apiClient";
import { expectToMatchSnapshot, takeYllapitoS3Snapshot } from "./testUtil/util";
import { cleanupGeneratedIdAndTimestampFromFeedbacks } from "./testUtil/cleanUpFunctions";
import * as sinon from "sinon";
import { emailClient } from "../../src/email/email";
import { projektiArchive } from "../../src/archive/projektiArchiveService";

const sandbox = sinon.createSandbox();
const oid = "1.2.246.578.5.1.2978288874.2711575506";

describe("Palaute", () => {
Expand All @@ -21,11 +19,11 @@ describe("Palaute", () => {

before(async () => {
userFixture = new UserFixture(userService);
emailClientStub = sandbox.stub(emailClient, "sendEmail");
emailClientStub = sinon.stub(emailClient, "sendEmail");

await setupLocalDatabase();
try {
await projektiArchive.archiveProjekti(oid);
await deleteProjekti(oid);
} catch (_ignore) {
// ignore
}
Expand All @@ -34,8 +32,7 @@ describe("Palaute", () => {

after(() => {
userFixture.logout();
sandbox.restore();
sandbox.reset();
sinon.restore();
});

it("should insert and manage feedback", async () => {
Expand Down
Loading

0 comments on commit 30b2918

Please sign in to comment.