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

Mocked time -tuki generoiduille dev-API-clienteille #6075

Merged
merged 3 commits into from
Dec 2, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
use the new option
  • Loading branch information
Joosakur committed Dec 2, 2024
commit 8e10bfbdd697d8456f719c0534cc6198de3b7cc1
26 changes: 4 additions & 22 deletions frontend/src/e2e-test/dev-api/index.ts
Original file line number Diff line number Diff line change
@@ -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 {
@@ -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)
@@ -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)
}
@@ -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)
}