MCPcopy Create free account
hub / github.com/Rello/analytics / DataloadServiceTest

Class DataloadServiceTest

tests/Service/DataloadServiceTest.php:18–350  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

16use Psr\Log\NullLogger;
17
18class DataloadServiceTest extends TestCase {
19 public function testGetDataFromDatasourceDisablesCacheValidation(): void {
20 $datasourceController = $this->createMock(DatasourceController::class);
21 $datasourceController->expects($this->once())
22 ->method('read')
23 ->with(
24 DatasourceController::DATASET_TYPE_EXTERNAL_CSV,
25 $this->callback(function ($metadata) {
26 $this->assertSame('u1', $metadata['user_id']);
27 $this->assertArrayNotHasKey('cacheKey', $metadata);
28 $this->assertSame('persisted-cache', json_decode($metadata['link'], true)['cacheKey']);
29 return true;
30 }),
31 false
32 )
33 ->willReturn([
34 'header' => ['d1', 'd2', 'value'],
35 'dimensions' => ['d1', 'd2'],
36 'data' => [['x', 'y', 1]],
37 'error' => 0,
38 ]);
39
40 $dataloadMapper = $this->createMock(DataloadMapper::class);
41 $dataloadMapper->expects($this->once())
42 ->method('readOwnById')
43 ->with(42)
44 ->willReturn([
45 'datasource' => DatasourceController::DATASET_TYPE_EXTERNAL_CSV,
46 'dataset' => 11,
47 'user_id' => 'u1',
48 'option' => '{"link":"https://example.org/data.csv","cacheKey":"persisted-cache"}',
49 'cacheKey' => 'request-key-should-not-be-used',
50 ]);
51
52 $service = $this->createService($datasourceController, $dataloadMapper);
53 $result = $service->getDataFromDatasource(42);
54
55 $this->assertSame(11, $result['datasetId']);
56 $this->assertSame(0, $result['error']);
57 }
58
59 public function testGetDataFromDatasourceOverridesFileForFlowExecution(): void {
60 $datasourceController = $this->createMock(DatasourceController::class);
61 $datasourceController->expects($this->once())
62 ->method('read')
63 ->with(
64 DatasourceController::DATASET_TYPE_LOCAL_JSON,
65 $this->callback(function ($metadata) {
66 $option = json_decode($metadata['link'], true);
67 $this->assertSame('/flow/import.json', $option['link']);
68 $this->assertSame('/flow/import.json', $option['file']);
69 $this->assertSame('items/{name,value}', $option['path']);
70 return true;
71 }),
72 false
73 )
74 ->willReturn([
75 'header' => ['d1', 'd2', 'value'],

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected