Skip to content

Firefly III: a personal finances manager

Update some tests.

James Colec1ae0ab57dac
diff --git a/app/Transformers/ImportJobTransformer.php b/app/Transformers/ImportJobTransformer.php
index 1bccabd291..a726e96074 100644
--- a/app/Transformers/ImportJobTransformer.php
+++ b/app/Transformers/ImportJobTransformer.php
@@ -74,10 +74,10 @@ class ImportJobTransformer extends AbstractTransformer
'provider' => $importJob->provider,
'status' => $importJob->status,
'stage' => $importJob->stage,
- 'configuration' => $importJob->configuration,
- 'extended_status' => $importJob->extended_status,
- 'transactions' => $importJob->transactions,
- 'errors' => $importJob->errors,
+ 'configuration' => json_encode($importJob->configuration),
+ 'extended_status' => json_encode($importJob->extended_status),
+ 'transactions' => json_encode($importJob->transactions),
+ 'errors' => json_encode($importJob->errors),
'links' => [
[
diff --git a/app/Transformers/LinkTypeTransformer.php b/app/Transformers/LinkTypeTransformer.php
index fbb9f05c90..afbd34353a 100644
--- a/app/Transformers/LinkTypeTransformer.php
+++ b/app/Transformers/LinkTypeTransformer.php
@@ -63,7 +63,7 @@ class LinkTypeTransformer extends AbstractTransformer
'name' => $linkType->name,
'inward' => $linkType->inward,
'outward' => $linkType->outward,
- 'editable' => 1 === (int)$linkType->editable,
+ 'editable' => $linkType->editable,
'links' => [
[
'rel' => 'self',
diff --git a/tests/Unit/Transformers/ImportJobTransformerTest.php b/tests/Unit/Transformers/ImportJobTransformerTest.php
new file mode 100644
index 0000000000..61e6c15ec2
--- /dev/null
+++ b/tests/Unit/Transformers/ImportJobTransformerTest.php
@@ -0,0 +1,73 @@
+<?php
+/**
+ * ImportJobTransformerTest.php
+ * Copyright (c) 2018 [email protected]
+ *
+ * This file is part of Firefly III.
+ *
+ * Firefly III is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Firefly III is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+declare(strict_types=1);
+
+namespace Tests\Unit\Transformers;
+
+
+use FireflyIII\Models\ImportJob;
+use FireflyIII\Transformers\ImportJobTransformer;
+use Log;
+use Symfony\Component\HttpFoundation\ParameterBag;
+use Tests\TestCase;
+
+/**
+ *
+ * Class ImportJobTransformerTest
+ */
+class ImportJobTransformerTest extends TestCase
+{
+ /**
+ *
+ */
+ public function setUp(): void
+ {
+ parent::setUp();
+ Log::info(sprintf('Now in %s.', \get_class($this)));
+ }
+
+ /**
+ * Basic coverage
+ *
+ * @covers \FireflyIII\Transformers\ImportJobTransformer
+ */
+ public function testBasic(): void
+ {
+
+ $job = ImportJob::first();
+ $job->tag_id = 1;
+ $parameters = new ParameterBag;
+ $transformer = app(ImportJobTransformer::class);
+ $transformer->setParameters($parameters);
+
+ $result = $transformer->transform($job);
+
+ $this->assertEquals($job->key, $result['key']);
+ $this->assertEquals($job->tag_id, $result['tag_id']);
+ $this->assertEquals(json_encode($job->configuration), $result['configuration']);
+ $this->assertEquals(json_encode($job->extended_status), $result['extended_status']);
+ $this->assertEquals(json_encode($job->transactions), $result['transactions']);
+ $this->assertEquals(json_encode($job->errors), $result['errors']);
+
+
+ }
+}
\ No newline at end of file
diff --git a/tests/Unit/Transformers/LinkTypeTransformerTest.php b/tests/Unit/Transformers/LinkTypeTransformerTest.php
new file mode 100644
index 0000000000..acfe1d69b8
--- /dev/null
+++ b/tests/Unit/Transformers/LinkTypeTransformerTest.php
@@ -0,0 +1,68 @@
+<?php
+/**
+ * LinkTypeTransformerTest.php
+ * Copyright (c) 2018 [email protected]
+ *
+ * This file is part of Firefly III.
+ *
+ * Firefly III is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Firefly III is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+declare(strict_types=1);
+
+namespace Tests\Unit\Transformers;
+
+
+use FireflyIII\Models\ImportJob;
+use FireflyIII\Models\LinkType;
+use FireflyIII\Transformers\ImportJobTransformer;
+use FireflyIII\Transformers\LinkTypeTransformer;
+use Log;
+use Symfony\Component\HttpFoundation\ParameterBag;
+use Tests\TestCase;
+
+/**
+ *
+ * Class LinkTypeTransformerTest
+ */
+class LinkTypeTransformerTest extends TestCase
+{
+ /**
+ *
+ */
+ public function setUp(): void
+ {
+ parent::setUp();
+ Log::info(sprintf('Now in %s.', \get_class($this)));
+ }
+
+ /**
+ * Basic coverage
+ *
+ * @covers \FireflyIII\Transformers\LinkTypeTransformer
+ */
+ public function testBasic(): void
+ {
+
+ $linkType= LinkType::first();
+ $parameters = new ParameterBag;
+ $transformer = app(LinkTypeTransformer::class);
+ $transformer->setParameters($parameters);
+
+ $result = $transformer->transform($linkType);
+
+ $this->assertEquals($linkType->inward, $result['inward']);
+
+ }
+}
\ No newline at end of file