Skip to content

Commit

Permalink
fix: merge changes from #610
Browse files Browse the repository at this point in the history
  • Loading branch information
gulfaraz committed Mar 25, 2021
1 parent 2f91b29 commit 5d1d54e
Show file tree
Hide file tree
Showing 12 changed files with 61,421 additions and 63,059 deletions.
12 changes: 6 additions & 6 deletions interfaces/IBF-dashboard/src/app/mocks/api.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@ export class MockAPI {
});
}

getMockAPI(leadTime?) {
getMockAPI() {
return {
GET: {
stations: {
handler: this.getResponse('getStations', leadTime),
handler: this.getResponse('getStations'),
},
event: { handler: this.getResponse('getEvent') },
'triggered-areas': { handler: this.getResponse('getTriggeredAreas') },
'recent-dates': { handler: this.getResponse('getRecentDates') },
triggers: { handler: this.getResponse('getTriggerPerLeadTime') },
'admin-area-data': {
handler: this.getResponse('getAdminRegions', leadTime),
handler: this.getResponse('getAdminRegions'),
},
},
POST: {
Expand All @@ -42,18 +42,18 @@ export class MockAPI {
};
}

getResponse(functionName, leadTime?) {
getResponse(functionName) {
return () => {
let body = {};
let status = 200;

switch (this.mockScenario) {
case MockScenario.existingEvent: {
body = existingEvent[functionName](leadTime);
body = existingEvent[functionName]();
break;
}
case MockScenario.newEvent: {
body = newEvent[functionName](leadTime);
body = newEvent[functionName]();
break;
}
case MockScenario.noEvent: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,4 @@
</ion-select-option>
</ion-select>
</ion-item>
<ion-item *ngIf="mockScenario !== MockScenarioEnum.real">
<ion-label>Mock-add 3-day</ion-label>
<ion-select
placeholder="Options"
interface="popover"
(ionChange)="mockAddLeadTime($event)"
>
<ion-select-option value="real">Normal (7-day)</ion-select-option>
<ion-select-option [value]="mockLeadTimeKey"
>Mock (3-day + 7-day)</ion-select-option
>
</ion-select>
</ion-item>
</ng-container>
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import { MockScenarioService } from 'src/app/mocks/mock-scenario-service/mock-sc
import { MockScenario } from 'src/app/mocks/mock-scenario.enum';
import { Country } from 'src/app/models/country.model';
import { CountryService } from 'src/app/services/country.service';
import { TimelineService } from 'src/app/services/timeline.service';
import { LeadTime } from 'src/app/types/lead-time';

@Component({
selector: 'app-mock-scenario',
Expand Down Expand Up @@ -34,7 +32,6 @@ export class MockScenarioComponent implements OnInit, OnDestroy {
constructor(
public mockScenarioService: MockScenarioService,
public countryService: CountryService,
private timelineService: TimelineService,
) {}

ngOnInit() {
Expand All @@ -60,19 +57,6 @@ export class MockScenarioComponent implements OnInit, OnDestroy {
this.mockScenarioService.setMockScenario(event.detail.value);
}

public mockAddLeadTime(event: CustomEvent): void {
if (this.country) {
if (event.detail.value === this.mockLeadTimeKey) {
if (!this.country.countryLeadTimes.includes(LeadTime.day3)) {
this.country.countryLeadTimes.push(LeadTime.day3);
}
} else {
this.country.countryLeadTimes = [LeadTime.day7];
}
this.timelineService.loadTimeStepButtons();
}
}

public allowMockScenarios(): boolean {
let allowMock = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,7 @@ export class MockScenarioInterceptor implements HttpInterceptor {
const requestPathSplit = requestPath.split('/');
const requestEndpoint = requestPathSplit[1];

let mockAPIs = this.mockAPI.getMockAPI();
if (
requestEndpoint === 'stations' ||
requestEndpoint === 'admin-area-data'
) {
const leadTime = requestPathSplit[requestPathSplit.length - 1];
mockAPIs = this.mockAPI.getMockAPI(leadTime);
}
const mockAPIs = this.mockAPI.getMockAPI();

const currentMockEndpoint =
(mockAPIs[request.method] && mockAPIs[request.method][requestPath]) ||
Expand Down
Loading

0 comments on commit 5d1d54e

Please sign in to comment.