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

Class DataloadServiceTest

tests/Service/DataloadServiceTest.php:20–539  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected