Skip to content

Commit b5f4d99

Browse files
authored
♻️ minor tweaks to workflow tests (#129)
1 parent efc09cd commit b5f4d99

6 files changed

Lines changed: 38 additions & 21 deletions

File tree

.github/workflows/_test-integrations.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ env:
1212
MINDEE_ENDPOINT_SE_TESTS: ${{ secrets.MINDEE_ENDPOINT_SE_TESTS }}
1313
MINDEE_API_KEY: ${{ secrets.MINDEE_API_KEY_SE_TESTS }}
1414
WORKFLOW_ID: ${{ secrets.WORKFLOW_ID_SE_TESTS }}
15+
1516
jobs:
1617
integration-tests-ubuntu:
1718
name: Run Integration Tests on Ubuntu

src/Client.php

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -278,10 +278,12 @@ private function makeEnqueueRequest(
278278
);
279279
}
280280
}
281-
$response = ResponseValidation::cleanRequestData($options->endpoint->predictAsyncRequestPost(
282-
$inputDoc,
283-
$options
284-
));
281+
$response = ResponseValidation::cleanRequestData(
282+
$options->endpoint->predictAsyncRequestPost(
283+
$inputDoc,
284+
$options
285+
)
286+
);
285287
if (!ResponseValidation::isValidAsyncResponse($response)) {
286288
throw MindeeHttpException::handleError(
287289
$options->endpoint->settings->endpointName,
@@ -436,7 +438,13 @@ public function enqueueAndParse(
436438
$options->endpoint = $options->endpoint ?? $this->constructOTSEndpoint(
437439
$predictionType,
438440
);
439-
$enqueueResponse = $this->enqueue($predictionType, $inputDoc, $options, $pageOptions);
441+
442+
$enqueueResponse = $this->enqueue(
443+
$predictionType,
444+
$inputDoc,
445+
$options,
446+
$pageOptions
447+
);
440448
error_log("Successfully enqueued document with job id: " . $enqueueResponse->job->id);
441449

442450
sleep($asyncOptions->initialDelaySec);
@@ -455,7 +463,7 @@ public function enqueueAndParse(
455463
if ($pollResults->job->status != "completed") {
456464
throw new MindeeApiException(
457465
"Couldn't retrieve document " . $enqueueResponse->job->id . " after $retryCounter tries.",
458-
ErrorCode::API_TIMEOUT
466+
ErrorCode::API_TIMEOUT,
459467
);
460468
}
461469
return $pollResults;

src/Http/BaseEndpoint.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,10 @@ public function setFinalCurlOpts(
6767
?array $postFields,
6868
?string $workflowId = null
6969
): array {
70-
$url = $this->settings->urlRoot . $suffix;
7170
if (isset($workflowId)) {
7271
$url = $this->settings->baseUrl . "/workflows/" . $workflowId . $suffix;
72+
} else {
73+
$url = $this->settings->urlRoot . $suffix;
7374
}
7475
curl_setopt($ch, CURLOPT_URL, $url);
7576
if ($postFields !== null) {

tests/ClientTest.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,22 @@ class ClientTest extends TestCase
2727

2828
protected function setUp(): void
2929
{
30+
$rootPath = (getenv('GITHUB_WORKSPACE') ?: ".");
3031
$this->oldKey = getenv('MINDEE_API_KEY');
3132
$this->dummyClient = new Client("dummy-key");
3233
putenv('MINDEE_API_KEY=');
3334
$this->emptyClient = new Client();
3435
putenv('MINDEE_API_KEY=dummy-env-key');
3536
$this->envClient = new Client();
3637
$this->fileTypesDir = (
37-
getenv('GITHUB_WORKSPACE') ?: "."
38-
) . "/tests/resources/file_types/";
38+
$rootPath . "/tests/resources/file_types/"
39+
);
3940
$this->invoicePath = (
40-
getenv('GITHUB_WORKSPACE') ?: "."
41-
) . "/tests/resources/products/invoices/response_v4/complete.json";
41+
$rootPath . "/tests/resources/products/invoices/response_v4/complete.json"
42+
);
4243
$this->failedJobPath = (
43-
getenv('GITHUB_WORKSPACE') ?: "."
44-
) . "/tests/resources/async/get_failed_job_error.json";
44+
$rootPath . "/tests/resources/async/get_failed_job_error.json"
45+
);
4546
}
4647

4748

tests/Workflow/WorkflowTest.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@ class WorkflowTest extends TestCase
1313

1414
protected function setUp(): void
1515
{
16+
$rootPath = (getenv('GITHUB_WORKSPACE') ?: ".");
1617
$this->findocSamplePath = (
17-
getenv('GITHUB_WORKSPACE') ?: "."
18-
) . "/tests/resources/products/financial_document/default_sample.jpg";
18+
$rootPath . "/tests/resources/products/financial_document/default_sample.jpg"
19+
);
1920
$this->workflowDir = (
20-
getenv('GITHUB_WORKSPACE') ?: "."
21-
) . "/tests/resources/workflows/";
21+
$rootPath . "/tests/resources/workflows/"
22+
);
2223
}
2324

2425
public function testDeserializeWorkflow()

tests/Workflow/WorkflowTestFunctional.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,16 @@ class WorkflowTestFunctional extends TestCase
1515
private $workflowId;
1616
private $mindeeClient;
1717
private $inputSource;
18+
private $predictionType;
1819

1920
protected function setUp(): void
2021
{
22+
$rootPath = (getenv('GITHUB_WORKSPACE') ?: ".");
2123
$this->mindeeClient = new Client();
2224
$this->workflowId = getenv('WORKFLOW_ID') ?: '';
25+
$this->predictionType = FinancialDocumentV1::class;
2326
$this->inputSource = $this->mindeeClient->sourceFromPath(
24-
(getenv('GITHUB_WORKSPACE') ?: ".") . "/tests/resources/products/financial_document/default_sample.jpg"
27+
$rootPath . "/tests/resources/products/financial_document/default_sample.jpg"
2528
);
2629
}
2730

@@ -34,7 +37,9 @@ public function testWorkflow() {
3437
null,
3538
true
3639
);
37-
$response = $this->mindeeClient->executeWorkflow($this->inputSource, $this->workflowId, $options);
40+
$response = $this->mindeeClient->executeWorkflow(
41+
$this->inputSource, $this->workflowId, $options
42+
);
3843
$this->assertEquals(202, $response->apiRequest->statusCode);
3944
$this->assertEquals("php-$currentDateTime", $response->execution->file->alias);
4045
$this->assertEquals("low", $response->execution->priority);
@@ -44,7 +49,7 @@ public function testWorkflowPollingWithRAG() {
4449
$options = new PredictMethodOptions();
4550
$options->setRAG(true)->setWorkflowId($this->workflowId);
4651
$response = $this->mindeeClient->enqueueAndParse(
47-
FinancialDocumentV1::class,
52+
$this->predictionType,
4853
$this->inputSource,
4954
$options
5055
);
@@ -57,7 +62,7 @@ public function testWorkflowPollingWithoutRAG() {
5762
$options = new PredictMethodOptions();
5863
$options->setWorkflowId($this->workflowId);
5964
$response = $this->mindeeClient->enqueueAndParse(
60-
FinancialDocumentV1::class,
65+
$this->predictionType,
6166
$this->inputSource,
6267
$options
6368
);

0 commit comments

Comments
 (0)