/** * @expectedException \Keboola\Juicer\Exception\UserException * @expectedExceptionMessage More than one array found in response! Use 'dataField' parameter to specify a key to the data array. (endpoint: a, arrays in response root: results, otherArray) */ public function testMultipleArraysException() { $cfg = JobConfig::create(['endpoint' => 'a']); $module = new FindResponseArray(); $response = (object) ['results' => [(object) ['id' => 1], (object) ['id' => 2]], 'otherArray' => ['a', 'b']]; $data = $module->process($response, $cfg); }
public function testMissingData() { $jobConfig = JobConfig::create(['endpoint' => 'ep', 'responseFilter' => 'out.arr[].in']); $filter = Filter::create($jobConfig); $data = [(object) ['id' => 1, 'out' => (object) ['arr' => [(object) ['in' => 'string'], (object) ['uh' => 'no "in" here!'], (object) ['in' => ['str', 'ing']]]]]]; self::assertEquals([(object) ['id' => 1, 'out' => (object) ['arr' => [(object) ['in' => 'string'], (object) ['uh' => 'no "in" here!'], (object) ['in' => '["str","ing"]']]]]], $filter->run($data)); }
public function testProcess() { $cfg = JobConfig::create(['endpoint' => 'a', 'parseObject' => ['keyColumn' => 'id', 'path' => 'results']]); $module = new QualtricsPreParser(); $response = (object) ['results' => (object) [1 => 'first', 2 => 'second'], 'otherArray' => ['a', 'b']]; $data = $module->process($response, $cfg); self::assertEquals([(object) ['data' => 'first', 'id' => 1], (object) ['data' => 'second', 'id' => 2]], $data); }
public function testGetConfig() { $configuration = new Configuration('./Tests/data/recursive', 'test', new Temp('test')); $config = $configuration->getConfig(); $yml = Yaml::parse(file_get_contents('./Tests/data/recursive/config.yml')); $jobs = $config->getJobs(); self::assertEquals(JobConfig::create($yml['parameters']['config']['jobs'][0]), reset($jobs)); self::assertEquals($yml['parameters']['config']['outputBucket'], $config->getAttribute('outputBucket')); }
public function testCreateRequest() { $arr = ['first' => 1, 'second' => 'two']; $jobConfig = JobConfig::create(['endpoint' => 'ep', 'params' => $arr]); $client = new RestClient(new Client()); $request = $client->createRequest($jobConfig->getConfig()); $expected = new RestRequest('ep', $arr); self::assertEquals($expected, $request); }
/** * @param object $job * @return JobConfig */ protected function createJob($job) { if (!is_array($job)) { throw new UserException("Invalid format for job configuration.", 0, null, ['job' => $job]); } return JobConfig::create($job); }
public function testGetDataTypeFromEndpoint() { $jobConfig = JobConfig::create(['endpoint' => 'resources/res.json']); $job = $this->getMockForAbstractClass('Keboola\\Juicer\\Extractor\\Job', [$jobConfig, RestClient::create(), new Json(Parser::create($this->getLogger('job', true)))]); $this->assertEquals($jobConfig->getEndpoint(), $this->callMethod($job, 'getDataType', [])); }
public function testMergeResults() { Logger::setLogger($this->getLogger('testMergeResults', true)); $configFirst = JobConfig::create(['endpoint' => '1st', 'dataType' => 'first']); $configTags = JobConfig::create(['endpoint' => '2nd', 'dataType' => 'tags']); $config = new Config('ex', 'test', []); $config->setAttributes(['mappings' => ['first' => ['id' => ['type' => 'column', 'mapping' => ['destination' => 'item_id']], 'tags' => ['type' => 'table', 'destination' => 'tags', 'tableMapping' => ['user' => ['mapping' => ['destination' => 'user', 'primaryKey' => true]], 'tag' => ['mapping' => ['destination' => 'tag', 'primaryKey' => true]]], 'parentKey' => ['disable' => true]]], 'tags' => ['user' => ['mapping' => ['destination' => 'user', 'primaryKey' => true]], 'tag' => ['mapping' => ['destination' => 'tag', 'primaryKey' => true]]]]]); $firstData = json_decode('[ { "id": 1, "arr": [1,2,3] }, { "id": 2, "arr": ["a","b","c"], "tags": [ { "user": "******", "tag": "tag1" }, { "user": "******", "tag": "tag2" } ] } ]'); $secondData = json_decode('[ { "user": "******", "tag": "tag3" }, { "user": "******", "tag": "tag4" } ]'); $parser = JsonMap::create($config); $parser->process($firstData, $configFirst->getDataType()); $parser->process($secondData, $configTags->getDataType()); self::assertEquals(['"user","tag"' . PHP_EOL, '"asd","tag1"' . PHP_EOL, '"asd","tag2"' . PHP_EOL, '"asd","tag3"' . PHP_EOL, '"asd","tag4"' . PHP_EOL], file($parser->getResults()['tags'])); }
public function testProcessInsightsLifetime() { $cfg = JobConfig::create(['endpoint' => 'insights', 'dataField' => 'data', 'parser' => ['method' => 'facebook.insights']]); $module = new \Keboola\ExGenericModule\FacebookPreParser(); $jsonResponse = <<<JSON { "data": [ { "name": "page_fan_adds_unique", "period": "lifetime", "values": [ { "value": 1 }, { "value": 2 } ], "title": "Daily New Likes", "id": "177057932317550/insights/page_fan_adds_unique" } ], "paging": { "previous": "prev", "next": "next" } } JSON; $response = json_decode($jsonResponse); $data = $module->process($response, $cfg); $this->assertEquals((object) ['data' => [(object) ['name' => 'page_fan_adds_unique', 'period' => 'lifetime', 'values' => [(object) ['id' => '177057932317550/insights/page_fan_adds_unique', 'key1' => '', 'key2' => '', 'end_time' => '', 'value' => 1], (object) ['id' => '177057932317550/insights/page_fan_adds_unique', 'key1' => '', 'key2' => '', 'end_time' => '', 'value' => 2]], 'title' => 'Daily New Likes', 'id' => '177057932317550/insights/page_fan_adds_unique']], 'paging' => (object) ['previous' => 'prev', 'next' => 'next']], $data); }