Skip to content

Commit

Permalink
test: update api tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gulfaraz committed Jul 24, 2024
1 parent 4613b37 commit 0a76ca6
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { JSDOM } from 'jsdom';
import { DisasterType } from '../../../src/api/disaster/disaster-type.enum';
import {
getAccessToken,
getEventTitle,
mockDynamicData,
resetDB,
sendNotification,
Expand Down Expand Up @@ -64,7 +65,7 @@ describe('Should send an email for uga drought', () => {

// Check if each expected event name is included in at least one title
for (const expectedEventName of expectedEventNames) {
const eventTitle = `${disasterType} ${expectedEventName}`.toLowerCase();
const eventTitle = getEventTitle(disasterType, expectedEventName);
const hasEvent = eventNamesInEmail.some((eventNameInEmail) =>
eventNameInEmail.includes(eventTitle),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import { JSDOM } from 'jsdom';
import { DisasterType } from '../../../src/api/disaster/disaster-type.enum';
import { FloodsScenario } from '../../../src/scripts/enum/mock-scenario.enum';
import disasters from '../../../src/scripts/json/disasters.json';
import { mockFloods, sendNotification } from '../../helpers/utility.helper';
import {
getEventTitle,
mockFloods,
sendNotification,
} from '../../helpers/utility.helper';

export interface TestFloodScenarioDto {
scenarios: any[];

Check warning on line 13 in services/API-service/test/email/floods/test-flood-scenario.helper.ts

View workflow job for this annotation

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

Unexpected any. Specify a different type
Expand Down Expand Up @@ -56,7 +60,7 @@ export async function testFloodScenario(

// Check if there are elements with the desired text content
for (const event of eventsSeed) {
const eventTitle = `${disasterTypeLabel} ${event.eventName}`.toLowerCase();
const eventTitle = getEventTitle(disasterTypeLabel, event.eventName);
const hasEvent = eventNamesInEmail.some((eventName) =>
eventName.includes(eventTitle),
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import { get } from 'http';

Check failure on line 1 in services/API-service/test/email/typhoon/test-typhoon-scenario.helper.ts

View workflow job for this annotation

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

'get' is defined but never used. Allowed unused vars must match /^_/u

import { JSDOM } from 'jsdom';

import { DisasterType } from '../../../src/api/disaster/disaster-type.enum';
import { TyphoonScenario } from '../../../src/scripts/enum/mock-scenario.enum';
import { mockTyphoon, sendNotification } from '../../helpers/utility.helper';
import {
getEventTitle,
mockTyphoon,
sendNotification,
} from '../../helpers/utility.helper';

export async function testTyphoonScenario(
scenario: TyphoonScenario,
Expand Down Expand Up @@ -47,7 +53,7 @@ export async function testTyphoonScenario(

// Check if there are elements with the desired text content
for (const eventNameInEmail of eventNamesInEmail) {
const eventTitle = `${disasterTypeLabel} ${eventName}`.toLowerCase();
const eventTitle = getEventTitle(disasterTypeLabel, eventName);
const hasEvent = eventNameInEmail.includes(eventTitle);
expect(hasEvent).toBe(true);
}
Expand Down
4 changes: 4 additions & 0 deletions services/API-service/test/helpers/utility.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ export function getHostname(): string {
return 'http://localhost:3000/api';
}

export function getEventTitle(disasterType: string, eventName: string) {
return `${disasterType}: ${eventName}`.toLowerCase();
}

export function getServer(): TestAgent<request.Test> {
return request.agent(getHostname());
}
Expand Down

0 comments on commit 0a76ca6

Please sign in to comment.