Skip to content

Commit

Permalink
options work again
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Zonneveld committed Feb 10, 2023
1 parent 987e72d commit d7569be
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 13 deletions.
1 change: 1 addition & 0 deletions src/Mappers/Contacts/AttributeMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public function map(stdClass $data): Attribute
$options[] = get_object_vars($item);
}
}
// var_dump('options', $options);

return new Attribute(
$data->name,
Expand Down
5 changes: 4 additions & 1 deletion src/Resources/OAuth/Contacts/ContactAttributesResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ public function create(string $name, string $label, string $type, ?string $field
$contactAttributes = [
"name" => $name,
"label" => $label,
"data_type" => $type
"data_type" => $type,
"field_type" => $fieldType,
"description" => $description,
"options" => $options
];

if (!CustomAttributeTypes::has($type)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ public function calculate(string $shopUuid, float $unitValue, ?string $contactUu

$response = $this->client->get($this->resourceUri . "/calculate", $data);

var_dump('calc responsie', $response);

return (int)$response->getData()->credits;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ public function create(string $name, string $label, string $description, string
"name" => $name,
"label" => $label,
"description" => $description,
"type" => $dataType
"type" => $dataType,
"options" => $options,
"placeholder" => $placeholder
];

if (!CustomAttributeTypes::has($dataType)) {
Expand Down
19 changes: 10 additions & 9 deletions tests/OAuth/ContactAttributes/ContactAttributesResourceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

class ContactAttributesResourceTest extends OAuthTestCase
{

/** @test
* @throws PiggyRequestException
*/
Expand Down Expand Up @@ -54,14 +53,16 @@ public function it_returns_a_list_of_contact_attributes_with_options()
"is_piggy_defined" => false,
"options" =>
[
["label" => "some_option_label", "value" => "3"],
["label" => 'some_second_option_label', "value" => "4"]
["name" => "some_option_label", "value" => "3"],
["name" => 'some_second_option_label', "value" => "4"]
]
],
]);

$contactAttributes = $this->mockedClient->contactAttributes->list();

var_dump($contactAttributes);

$this->assertEquals("another_first_name", $contactAttributes[0]->getName());
$this->assertEquals("another_label", $contactAttributes[0]->getLabel());
$this->assertEquals("select", $contactAttributes[0]->getType());
Expand All @@ -70,9 +71,9 @@ public function it_returns_a_list_of_contact_attributes_with_options()
$this->assertEquals(true, $contactAttributes[0]->getIsSoftReadOnly());
$this->assertEquals(true, $contactAttributes[0]->getIsHardReadOnly());
$this->assertEquals(false, $contactAttributes[0]->getIsPiggyDefined());
$this->assertEquals('some_option_label', $contactAttributes[0]->getOptions()[0]['label']);
$this->assertEquals('some_option_label', $contactAttributes[0]->getOptions()[0]['name']);
$this->assertEquals('3', $contactAttributes[0]->getOptions()[0]['value']);
$this->assertEquals('some_second_option_label', $contactAttributes[0]->getOptions()[1]['label']);
$this->assertEquals('some_second_option_label', $contactAttributes[0]->getOptions()[1]['name']);
$this->assertEquals('4', $contactAttributes[0]->getOptions()[1]['value']);
}

Expand Down Expand Up @@ -156,19 +157,19 @@ public function it_creates_a_multi_select_contact_attribute()
"description" => 'pietje_description',
"options" =>
[
["label" => "some_option_label", "value" => "3"],
["label" => 'some_second_option_label', "value" => "4"]
["name" => "some_option_label", "value" => "3"],
["name" => 'some_second_option_label', "value" => "4"]
]
]
);

$contactAttribute = $this->mockedClient->contactAttributes->create('pietje_name', 'pietje_label', 'multi_select', null, 'pietje_description', [["label" => "some_option_label", "value" => "3"], ["label" => 'some_second_option_label', "value" => "4"]]);
$contactAttribute = $this->mockedClient->contactAttributes->create('pietje_name', 'pietje_label', 'multi_select', null, 'pietje_description', [["name" => "some_option_label", "value" => "3"], ["name" => 'some_second_option_label', "value" => "4"]]);

$this->assertEquals("pietje_name", $contactAttribute->getName());
$this->assertEquals("pietje_label", $contactAttribute->getLabel());
$this->assertEquals("multi_select", $contactAttribute->getType());
$this->assertEquals("pietje_description", $contactAttribute->getDescription());
$this->assertEquals([["label" => "some_option_label", "value" => "3"], ["label" => 'some_second_option_label', "value" => "4"]], $contactAttribute->getOptions());
$this->assertEquals([["name" => "some_option_label", "value" => "3"], ["name" => 'some_second_option_label', "value" => "4"]], $contactAttribute->getOptions());
}

}

0 comments on commit d7569be

Please sign in to comment.