From c2ef811faa7500e227ca7e8b8147d7a629dd18fb Mon Sep 17 00:00:00 2001 From: karneaud Date: Fri, 12 Jul 2024 11:02:36 -0400 Subject: [PATCH] add transformer tests --- .../Quickbooks/ClientTransformerTest.php | 50 +++++++++++++++++ .../Quickbooks/InvoiceTransformerTest.php | 54 +++++++++++++++++++ 2 files changed, 104 insertions(+) create mode 100644 tests/Unit/Import/Transformer/Quickbooks/ClientTransformerTest.php create mode 100644 tests/Unit/Import/Transformer/Quickbooks/InvoiceTransformerTest.php diff --git a/tests/Unit/Import/Transformer/Quickbooks/ClientTransformerTest.php b/tests/Unit/Import/Transformer/Quickbooks/ClientTransformerTest.php new file mode 100644 index 000000000000..f9fdcbabca7e --- /dev/null +++ b/tests/Unit/Import/Transformer/Quickbooks/ClientTransformerTest.php @@ -0,0 +1,50 @@ +create(1234); + + // Read the JSON string from a file and decode into an associative array + $this->customer_data = json_decode( file_get_contents( app_path('/../tests/Mock/Response/Quickbooks/customer.json') ), true); + $this->transformer = new ClientTransformer($company); + $this->transformed_data = $this->transformer->transform($this->customer_data['Customer']); + } + + public function testClassExists() + { + $this->assertInstanceOf(ClientTransformer::class, $this->transformer); + } + + public function testTransformReturnsArray() + { + $this->assertIsArray($this->transformed_data); + } + + public function testTransformHasNameProperty() + { + $this->assertArrayHasKey('name', $this->transformed_data); + $this->assertEquals($this->customer_data['Customer']['CompanyName'], $this->transformed_data['name']); + } + + public function testTransformHasContactsProperty() + { + $this->assertArrayHasKey('contacts', $this->transformed_data); + $this->assertIsArray($this->transformed_data['contacts']); + $this->assertArrayHasKey(0, $this->transformed_data['contacts']); + $this->assertArrayHasKey('email', $this->transformed_data['contacts'][0]); + $this->assertEquals($this->customer_data['Customer']['PrimaryEmailAddr']['Address'], $this->transformed_data['contacts'][0]['email']); + } +} diff --git a/tests/Unit/Import/Transformer/Quickbooks/InvoiceTransformerTest.php b/tests/Unit/Import/Transformer/Quickbooks/InvoiceTransformerTest.php new file mode 100644 index 000000000000..05dc0c7c5ba1 --- /dev/null +++ b/tests/Unit/Import/Transformer/Quickbooks/InvoiceTransformerTest.php @@ -0,0 +1,54 @@ +create(1234); + + // Read the JSON string from a file and decode into an associative array + $this->invoiceData = json_decode( file_get_contents( app_path('/../tests/Mock/Response/Quickbooks/invoice.json') ), true); + $this->transformer = new InvoiceTransformer($company); + $this->transformedData = $this->transformer->transform($this->invoiceData['Invoice']); + } + + public function testIsInstanceOf() + { + $this->assertInstanceOf(InvoiceTransformer::class, $this->transformer); + } + + public function testTransformReturnsArray() + { + $this->assertIsArray($this->transformedData); + } + + public function testTransformContainsNumber() + { + $this->assertArrayHasKey('number', $this->transformedData); + $this->assertEquals($this->invoiceData['Invoice']['DocNumber'], $this->transformedData['number']); + } + + public function testTransformContainsDueDate() + { + $this->assertArrayHasKey('due_date', $this->transformedData); + $this->assertEquals(strtotime($this->invoiceData['Invoice']['DueDate']), strtotime($this->transformedData['due_date'])); + } + + public function testTransformContainsAmount() + { + $this->assertArrayHasKey('amount', $this->transformedData); + $this->assertIsFloat($this->transformedData['amount']); + $this->assertEquals($this->invoiceData['Invoice']['TotalAmt'], $this->transformedData['amount']); + } +}