-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rework script to suggest establishment list after 6 months with no up…
…dates
- Loading branch information
Showing
16 changed files
with
425 additions
and
374 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,4 +13,5 @@ cypress/cypress/downloads | |
cypress/cypress/videos | ||
cypress/cypress/screenshots | ||
.turbo | ||
storage | ||
storage | ||
logs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
145 changes: 36 additions & 109 deletions
145
back/src/adapters/primary/scripts/triggerSuggestEditFormEstablishmentEvery6Months.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
146 changes: 146 additions & 0 deletions
146
...ablishmentAggregateRepository.getSiretOfEstablishmentsToSuggestUpdate.integration.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
import { addDays } from "date-fns"; | ||
import subDays from "date-fns/subDays"; | ||
import { Pool, PoolClient } from "pg"; | ||
import { expectToEqual } from "shared"; | ||
import { EstablishmentAggregateBuilder } from "../../../_testBuilders/EstablishmentAggregateBuilder"; | ||
import { getTestPgPool } from "../../../_testBuilders/getTestPgPool"; | ||
import { PgEstablishmentAggregateRepository } from "./PgEstablishmentAggregateRepository"; | ||
import { PgNotificationRepository } from "./PgNotificationRepository"; | ||
import { PgOutboxRepository } from "./PgOutboxRepository"; | ||
|
||
describe("PgScriptsQueries", () => { | ||
let pool: Pool; | ||
let client: PoolClient; | ||
let pgEstablishmentAggregateRepository: PgEstablishmentAggregateRepository; | ||
let pgOutboxRepository: PgOutboxRepository; | ||
let pgNotificationRepository: PgNotificationRepository; | ||
|
||
beforeAll(async () => { | ||
pool = getTestPgPool(); | ||
client = await pool.connect(); | ||
}); | ||
|
||
beforeEach(async () => { | ||
await client.query("DELETE FROM immersion_contacts"); | ||
await client.query("DELETE FROM establishments"); | ||
await client.query("DELETE FROM outbox_failures"); | ||
await client.query("DELETE FROM outbox_publications"); | ||
await client.query("DELETE FROM outbox"); | ||
await client.query("DELETE FROM notifications_email_recipients"); | ||
await client.query("DELETE FROM notifications_email"); | ||
pgOutboxRepository = new PgOutboxRepository(client); | ||
pgNotificationRepository = new PgNotificationRepository(client); | ||
pgEstablishmentAggregateRepository = new PgEstablishmentAggregateRepository( | ||
client, | ||
); | ||
}); | ||
|
||
afterAll(async () => { | ||
client.release(); | ||
await pool.end(); | ||
}); | ||
|
||
describe("getSiretOfEstablishmentsToSuggestUpdate", () => { | ||
it("gets only the establishment that before since and that have not received the suggest email recently", async () => { | ||
const before = new Date("2023-07-01"); | ||
const toUpdateDate = subDays(before, 5); | ||
const establishmentToUpdate = new EstablishmentAggregateBuilder() | ||
.withEstablishmentSiret("11110000111100") | ||
.withEstablishmentUpdatedAt(toUpdateDate) | ||
.withContactId("11111111-1111-4000-1111-111111111111") | ||
.build(); | ||
|
||
// <<<<<----------- this is the legacy behavior, we keep it until we reach the 6 months. | ||
// We can remove this part of the code, and the FormEstablishmentEditLinkSent events in january 2024 | ||
|
||
const establishmentWithLinkSentEvent = new EstablishmentAggregateBuilder() | ||
.withEstablishmentSiret("22220000222200") | ||
.withEstablishmentUpdatedAt(toUpdateDate) | ||
.withContactId("22222222-2222-4000-2222-222222222222") | ||
.build(); | ||
|
||
await pgOutboxRepository.save({ | ||
id: "22222222-2222-4000-2222-000000000000", | ||
topic: "FormEstablishmentEditLinkSent", | ||
payload: { | ||
siret: establishmentWithLinkSentEvent.establishment.siret, | ||
} as any, | ||
occurredAt: addDays(before, 1).toISOString(), | ||
publications: [], | ||
wasQuarantined: false, | ||
}); | ||
|
||
// end of legacy ----------->>>>>> | ||
|
||
const eventWithNotificationSavedButLongAgo = | ||
new EstablishmentAggregateBuilder() | ||
.withEstablishmentSiret("33330000333300") | ||
.withEstablishmentUpdatedAt(toUpdateDate) | ||
.withContactId("33333333-3333-4000-3333-333333333333") | ||
.build(); | ||
|
||
await pgNotificationRepository.save({ | ||
id: "33333333-3333-4000-3333-000000000000", | ||
followedIds: { | ||
establishmentSiret: | ||
eventWithNotificationSavedButLongAgo.establishment.siret, | ||
}, | ||
kind: "email", | ||
templatedContent: { | ||
kind: "SUGGEST_EDIT_FORM_ESTABLISHMENT", | ||
recipients: ["joe@mail.com"], | ||
params: { editFrontUrl: "http://edit-front.com" }, | ||
}, | ||
createdAt: subDays(before, 1).toISOString(), | ||
}); | ||
|
||
const eventWithRecentNotificationSaved = | ||
new EstablishmentAggregateBuilder() | ||
.withEstablishmentSiret("44440000444400") | ||
.withEstablishmentUpdatedAt(toUpdateDate) | ||
.withContactId("44444444-4444-4000-4444-444444444444") | ||
.build(); | ||
|
||
await pgNotificationRepository.save({ | ||
id: "44444444-4444-4000-4444-000000000000", | ||
followedIds: { | ||
establishmentSiret: | ||
eventWithRecentNotificationSaved.establishment.siret, | ||
}, | ||
kind: "email", | ||
templatedContent: { | ||
kind: "SUGGEST_EDIT_FORM_ESTABLISHMENT", | ||
recipients: ["jack@mail.com"], | ||
params: { editFrontUrl: "http://edit-jack-front.com" }, | ||
}, | ||
createdAt: addDays(before, 1).toISOString(), | ||
}); | ||
|
||
const recentlyUpdatedEstablishment = new EstablishmentAggregateBuilder() | ||
.withEstablishmentSiret("99990000999900") | ||
.withEstablishmentUpdatedAt(addDays(before, 1)) | ||
.withContactId("99999999-9999-4000-9999-999999999999") | ||
.build(); | ||
|
||
await pgEstablishmentAggregateRepository.insertEstablishmentAggregates([ | ||
establishmentToUpdate, | ||
eventWithNotificationSavedButLongAgo, | ||
eventWithRecentNotificationSaved, | ||
establishmentWithLinkSentEvent, | ||
recentlyUpdatedEstablishment, | ||
]); | ||
|
||
// Act | ||
const sirets = | ||
await pgEstablishmentAggregateRepository.getSiretOfEstablishmentsToSuggestUpdate( | ||
before, | ||
); | ||
|
||
// Assert | ||
expectToEqual(sirets, [ | ||
establishmentToUpdate.establishment.siret, | ||
eventWithNotificationSavedButLongAgo.establishment.siret, | ||
]); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.