Skip to content

Commit

Permalink
Merge pull request #6075 from espoon-voltti/mocked-time-support-for-d…
Browse files Browse the repository at this point in the history
…ev-api-calls

Mocked time -tuki generoiduille dev-API-clienteille
  • Loading branch information
Joosakur authored Dec 2, 2024
2 parents 80f5a67 + 8e10bfb commit 52c2234
Show file tree
Hide file tree
Showing 3 changed files with 391 additions and 161 deletions.
26 changes: 4 additions & 22 deletions frontend/src/e2e-test/dev-api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,14 @@

import * as fs from 'fs/promises'

import axios, {
AxiosHeaders,
AxiosResponse,
InternalAxiosRequestConfig
} from 'axios'
import axios, { AxiosResponse, InternalAxiosRequestConfig } from 'axios'
import FormData from 'form-data'
import { BaseError } from 'make-error-cause'

import HelsinkiDateTime from 'lib-common/helsinki-date-time'

import config from '../config'
import { runJobs, simpleAction } from '../generated/api-clients'
import { DevPerson, MockVtjDataset } from '../generated/api-types'

export class DevApiError extends BaseError {
Expand All @@ -32,12 +29,6 @@ export class DevApiError extends BaseError {
}
}

function clockHeader(now: HelsinkiDateTime): AxiosHeaders {
return new AxiosHeaders({
EvakaMockedTime: now.formatIso()
})
}

function formatRequest(config: InternalAxiosRequestConfig | undefined): string {
if (!config || !config.url) return ''
const url = new URL(config.url, config.baseURL)
Expand Down Expand Up @@ -72,13 +63,7 @@ export async function execSimpleApplicationAction(
mockedTime: HelsinkiDateTime
): Promise<void> {
try {
await devClient.post(
`/applications/${applicationId}/actions/${action}`,
null,
{
headers: clockHeader(mockedTime)
}
)
await simpleAction({ applicationId, action }, { mockedTime })
} catch (e) {
throw new DevApiError(e)
}
Expand All @@ -91,17 +76,14 @@ export async function execSimpleApplicationActions(
): Promise<void> {
for (const action of actions) {
await execSimpleApplicationAction(applicationId, action, mockedTime)
await runPendingAsyncJobs(mockedTime)
}
}

export async function runPendingAsyncJobs(
mockedTime: HelsinkiDateTime
): Promise<void> {
try {
await devClient.post(`/run-jobs`, null, {
headers: clockHeader(mockedTime)
})
await runJobs({ mockedTime })
} catch (e) {
throw new DevApiError(e)
}
Expand Down
Loading

0 comments on commit 52c2234

Please sign in to comment.