Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix.mock from frontend #1595

Merged
merged 3 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 35 additions & 12 deletions interfaces/IBF-dashboard/src/app/services/api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -410,18 +410,41 @@ export class ApiService {
removeEvents: boolean,
disasterType: DisasterType,
) {
return this.post(
'scripts/mock-dynamic-data',
{
secret,
countryCodeISO3: country.countryCodeISO3,
disasterType: disasterType.disasterType,
triggered,
removeEvents,
date: new Date(),
},
false,
);
// Part of disaster-types is migrated to new mock setup
// Once all disaster-types are migrated, this code can be simplified again
let apiPath = 'scripts/mock-dynamic-data';
let isNewBodyFormat = false;
if (disasterType.disasterType === DisasterTypeKey.floods) {
apiPath = 'mock/floods';
isNewBodyFormat = true;
} else if (disasterType.disasterType === DisasterTypeKey.flashFloods) {
apiPath = 'mock/flash-floods';
isNewBodyFormat = true;
} else if (
disasterType.disasterType === DisasterTypeKey.dengue ||
disasterType.disasterType === DisasterTypeKey.malaria
) {
apiPath = 'mock/epidemics';
isNewBodyFormat = true;
}

const body = isNewBodyFormat
? {
secret,
countryCodeISO3: country.countryCodeISO3,
removeEvents,
date: new Date(),
scenario: triggered ? 'trigger' : 'no-trigger',
}
: {
secret,
countryCodeISO3: country.countryCodeISO3,
disasterType: disasterType.disasterType,
triggered,
removeEvents,
date: new Date(),
};
return this.post(apiPath, body, false);
}

getActivationLogs(countryCodeISO3?: string, disasterType?: DisasterTypeKey) {
Expand Down
6 changes: 3 additions & 3 deletions services/API-service/src/scripts/enum/mock-scenario.enum.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
export enum FloodsScenario {
Default = 'default',
Trigger = 'trigger',
Warning = 'warning',
WarningToTrigger = 'warning-to-trigger',
NoTrigger = 'no-trigger',
}

export enum FlashFloodsScenario {
Default = 'default',
Trigger = 'trigger',
NoTrigger = 'no-trigger',
}

export enum EpidemicsScenario {
Default = 'default',
Trigger = 'trigger',
NoTrigger = 'no-trigger',
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[
{
"scenarioName": "default",
"scenarioName": "trigger",
"defaultScenario": true,
"events": [
{ "eventName": "0-month", "leadTime": "0-month" },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[
{
"scenarioName": "default",
"scenarioName": "trigger",
"defaultScenario": true,
"events": [
{ "eventName": "Rumphi", "leadTime": "6-hour" },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[
{
"scenarioName": "default",
"scenarioName": "trigger",
"defaultScenario": true,
"events": [{ "eventName": "G1067", "leadTime": "4-day" }]
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[
{
"scenarioName": "default",
"scenarioName": "trigger",
"defaultScenario": true,
"events": [{ "eventName": "G5305", "leadTime": "4-day" }]
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[
{
"scenarioName": "default",
"scenarioName": "trigger",
"defaultScenario": true,
"events": [{ "eventName": "G1724", "leadTime": "4-day" }]
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[
{
"scenarioName": "default",
"scenarioName": "trigger",
"defaultScenario": true,
"events": [
{ "eventName": "G1966", "leadTime": "4-day" },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[
{
"scenarioName": "default",
"scenarioName": "trigger",
"defaultScenario": true,
"events": [{ "eventName": "G5100", "leadTime": "4-day" }]
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[
{
"scenarioName": "default",
"scenarioName": "trigger",
"defaultScenario": true,
"events": [
{ "eventName": "G5075", "leadTime": "0-day" },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[
{
"scenarioName": "default",
"scenarioName": "trigger",
"defaultScenario": true,
"events": [
{ "eventName": "G1328", "leadTime": "7-day" },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[
{
"scenarioName": "default",
"scenarioName": "trigger",
"defaultScenario": true,
"events": [
{ "eventName": "0-month", "leadTime": "0-month" },
Expand Down
6 changes: 3 additions & 3 deletions services/API-service/src/scripts/mock.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export class MockFloodsScenario extends MockBaseScenario {
@ApiProperty({
example: Object.values(FloodsScenario).join(' | '),
description:
'default: ongoing + trigger + warning event; warning: 1 warning event; warning-to-trigger: 1 event that evolves from warning to trigger',
'trigger: ongoing + trigger + warning event; warning: 1 warning event; warning-to-trigger: 1 event that evolves from warning to trigger',
})
@IsEnum(FloodsScenario)
public readonly scenario: FloodsScenario;
Expand All @@ -71,7 +71,7 @@ export class MockFloodsScenario extends MockBaseScenario {
export class MockFlashFloodsScenario extends MockBaseScenario {
@ApiProperty({
example: Object.values(FlashFloodsScenario).join(' | '),
description: 'default: trigger + warning event',
description: 'trigger: trigger + warning event',
})
@IsEnum(FlashFloodsScenario)
public readonly scenario: FlashFloodsScenario;
Expand All @@ -80,7 +80,7 @@ export class MockFlashFloodsScenario extends MockBaseScenario {
export class MockEpidemicsScenario extends MockBaseScenario {
@ApiProperty({
example: Object.values(EpidemicsScenario).join(' | '),
description: 'default: trigger in each month',
description: 'trigger: trigger in each month',
})
@IsEnum(EpidemicsScenario)
public readonly scenario: EpidemicsScenario;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
await resetDB(accessToken);
});

it('default', async () => {
it('trigger', async () => {

Check warning on line 14 in services/API-service/test/email/dengue/email-phl-dengue.test.ts

View workflow job for this annotation

GitHub Actions / ibf-api-service (20.x)

Test has no assertions
await testDengueScenario(
EpidemicsScenario.Default,
EpidemicsScenario.Trigger,
countryCodeISO3,
accessToken,
);
});

it('no-trigger', async () => {

Check warning on line 22 in services/API-service/test/email/dengue/email-phl-dengue.test.ts

View workflow job for this annotation

GitHub Actions / ibf-api-service (20.x)

Test has no assertions
await testDengueScenario(
EpidemicsScenario.NoTrigger,
countryCodeISO3,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export async function testDengueScenario(
expect(mockResult.status).toBe(202);
expect(response.status).toBe(201);

if (scenario === EpidemicsScenario.Default) {
if (scenario === EpidemicsScenario.Trigger) {
expect(response.body.activeEvents.email).toBeDefined();
} else {
expect(response.body.activeEvents.email).toBeUndefined();
Expand All @@ -51,13 +51,13 @@ export async function testDengueScenario(
(el) => (el as Element).textContent.toLowerCase(),
).map((el) => el.trim());

if (scenario === EpidemicsScenario.Default) {
if (scenario === EpidemicsScenario.Trigger) {
expect(eventNamesInEmail.length).toBe(eventNames.length);
} else {
expect(eventNamesInEmail.length).toBe(0);
}

if (scenario === EpidemicsScenario.Default) {
if (scenario === EpidemicsScenario.Trigger) {
// Check if each expected event name is included in at least one title
for (const eventName of eventNames) {
const eventTitle = getEventTitle(disasterTypeLabel, eventName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
await resetDB(accessToken);
});

it('default', async () => {
it('trigger', async () => {

Check warning on line 14 in services/API-service/test/email/flash-flood/email-mwi-flash-flood.test.ts

View workflow job for this annotation

GitHub Actions / ibf-api-service (20.x)

Test has no assertions
await testFlashFloodScenario(
FlashFloodsScenario.Default,
FlashFloodsScenario.Trigger,
countryCodeISO3,
accessToken,
);
});

it('no-trigger', async () => {

Check warning on line 22 in services/API-service/test/email/flash-flood/email-mwi-flash-flood.test.ts

View workflow job for this annotation

GitHub Actions / ibf-api-service (20.x)

Test has no assertions
await testFlashFloodScenario(
FlashFloodsScenario.NoTrigger,
countryCodeISO3,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export async function testFlashFloodScenario(
expect(mockResult.status).toBe(202);
expect(response.status).toBe(201);

if (scenario === FlashFloodsScenario.Default) {
if (scenario === FlashFloodsScenario.Trigger) {
expect(response.body.activeEvents.email).toBeDefined();
} else {
expect(response.body.activeEvents.email).toBeUndefined();
Expand All @@ -51,13 +51,13 @@ export async function testFlashFloodScenario(
(el) => (el as Element).textContent.toLowerCase(),
).map((el) => el.trim());

if (scenario === FlashFloodsScenario.Default) {
if (scenario === FlashFloodsScenario.Trigger) {
expect(eventNamesInEmail.length).toBe(eventNames.length);
} else {
expect(eventNamesInEmail.length).toBe(0);
}

if (scenario === FlashFloodsScenario.Default) {
if (scenario === FlashFloodsScenario.Trigger) {
// Check if each expected event name is included in at least one title
for (const eventName of eventNames) {
const eventTitle = getEventTitle(disasterTypeLabel, eventName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
await resetDB(accessToken);
});

it('default', async () => {
it('trigger', async () => {

Check warning on line 15 in services/API-service/test/email/floods/email-ssd-floods.test.ts

View workflow job for this annotation

GitHub Actions / ibf-api-service (20.x)

Test has no assertions
// Arrange
const scenario = FloodsScenario.Default;
const scenario = FloodsScenario.Trigger;
await testFloodScenario(scenario, {
scenarios,
countryCodeISO3,
Expand All @@ -22,7 +22,7 @@
});
});

it('no-trigger', async () => {

Check warning on line 25 in services/API-service/test/email/floods/email-ssd-floods.test.ts

View workflow job for this annotation

GitHub Actions / ibf-api-service (20.x)

Test has no assertions
// Arrange
const scenario = FloodsScenario.NoTrigger;
await testFloodScenario(scenario, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
await resetDB(accessToken);
});

it('default', async () => {
it('trigger', async () => {

Check warning on line 15 in services/API-service/test/email/floods/email-uga-floods.test.ts

View workflow job for this annotation

GitHub Actions / ibf-api-service (20.x)

Test has no assertions
// Arrange
const scenario = FloodsScenario.Default;
const scenario = FloodsScenario.Trigger;
await testFloodScenario(scenario, {
scenarios,
countryCodeISO3,
Expand All @@ -22,7 +22,7 @@
});
});

it('warning', async () => {

Check warning on line 25 in services/API-service/test/email/floods/email-uga-floods.test.ts

View workflow job for this annotation

GitHub Actions / ibf-api-service (20.x)

Test has no assertions
// Arrange
const scenario = FloodsScenario.Warning;
await testFloodScenario(scenario, {
Expand All @@ -32,7 +32,7 @@
});
});

it('warning-to-trigger', async () => {

Check warning on line 35 in services/API-service/test/email/floods/email-uga-floods.test.ts

View workflow job for this annotation

GitHub Actions / ibf-api-service (20.x)

Test has no assertions
// Arrange
const scenario = FloodsScenario.WarningToTrigger;
await testFloodScenario(scenario, {
Expand All @@ -42,7 +42,7 @@
});
});

it('no-trigger', async () => {

Check warning on line 45 in services/API-service/test/email/floods/email-uga-floods.test.ts

View workflow job for this annotation

GitHub Actions / ibf-api-service (20.x)

Test has no assertions
// Arrange
const scenario = FloodsScenario.NoTrigger;
await testFloodScenario(scenario, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ describe('Should send an email for eth malaria', () => {
await resetDB(accessToken);
});

it('default', async () => {
it('trigger', async () => {
await testMalariaScenario(
EpidemicsScenario.Default,
EpidemicsScenario.Trigger,
countryCodeISO3,
accessToken,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export async function testMalariaScenario(
expect(mockResult.status).toBe(202);
expect(response.status).toBe(201);

if (scenario === EpidemicsScenario.Default) {
if (scenario === EpidemicsScenario.Trigger) {
expect(response.body.activeEvents.email).toBeDefined();
} else {
expect(response.body.activeEvents.email).toBeUndefined();
Expand All @@ -51,13 +51,13 @@ export async function testMalariaScenario(
(el) => (el as Element).textContent.toLowerCase(),
).map((el) => el.trim());

if (scenario === EpidemicsScenario.Default) {
if (scenario === EpidemicsScenario.Trigger) {
expect(eventNamesInEmail.length).toBe(eventNames.length);
} else {
expect(eventNamesInEmail.length).toBe(0);
}

if (scenario === EpidemicsScenario.Default) {
if (scenario === EpidemicsScenario.Trigger) {
// Check if each expected event name is included in at least one title
for (const eventName of eventNames) {
const eventTitle = getEventTitle(disasterTypeLabel, eventName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('Should send an email for phl typhoon', () => {
await resetDB(accessToken);
});

it('default', async () => {
it('trigger', async () => {
await testTyphoonScenario(
TyphoonScenario.EventTrigger,
countryCodeISO3,
Expand Down