From bbf76f5b87d697ffdfa7175932218cf6caa4fc05 Mon Sep 17 00:00:00 2001 From: Auston Bunsen Date: Tue, 31 Mar 2026 00:45:39 -0400 Subject: [PATCH] Add HID organization support (create, list, activate) --- src/Models/HIDOrg.php | 45 ++++++++++++ src/Services/Console.php | 2 + src/Services/HID.php | 17 +++++ src/Services/HIDOrgs.php | 46 ++++++++++++ tests/Models/HIDOrgTest.php | 56 +++++++++++++++ tests/Services/HIDOrgsTest.php | 124 +++++++++++++++++++++++++++++++++ 6 files changed, 290 insertions(+) create mode 100644 src/Models/HIDOrg.php create mode 100644 src/Services/HID.php create mode 100644 src/Services/HIDOrgs.php create mode 100644 tests/Models/HIDOrgTest.php create mode 100644 tests/Services/HIDOrgsTest.php diff --git a/src/Models/HIDOrg.php b/src/Models/HIDOrg.php new file mode 100644 index 0000000..d051746 --- /dev/null +++ b/src/Models/HIDOrg.php @@ -0,0 +1,45 @@ +client = $client; + $this->id = $data['id'] ?? null; + $this->name = $data['name'] ?? null; + $this->slug = $data['slug'] ?? null; + $this->firstName = $data['first_name'] ?? null; + $this->lastName = $data['last_name'] ?? null; + $this->phone = $data['phone'] ?? null; + $this->fullAddress = $data['full_address'] ?? null; + $this->status = $data['status'] ?? null; + $this->createdAt = $data['created_at'] ?? null; + + // snake_case aliases + $this->first_name = $this->firstName; + $this->last_name = $this->lastName; + $this->full_address = $this->fullAddress; + $this->created_at = $this->createdAt; + } +} diff --git a/src/Services/Console.php b/src/Services/Console.php index a07a0f3..f87cf33 100644 --- a/src/Services/Console.php +++ b/src/Services/Console.php @@ -11,10 +11,12 @@ class Console { private AccessGridClient $client; + public HID $hid; public function __construct(AccessGridClient $client) { $this->client = $client; + $this->hid = new HID($client); } /** diff --git a/src/Services/HID.php b/src/Services/HID.php new file mode 100644 index 0000000..0dd0618 --- /dev/null +++ b/src/Services/HID.php @@ -0,0 +1,17 @@ +client = $client; + $this->orgs = new HIDOrgs($client); + } +} diff --git a/src/Services/HIDOrgs.php b/src/Services/HIDOrgs.php new file mode 100644 index 0000000..a4a19ad --- /dev/null +++ b/src/Services/HIDOrgs.php @@ -0,0 +1,46 @@ +client = $client; + } + + /** + * Create a new HID organization + */ + public function create(array $data): HIDOrg + { + $response = $this->client->post('/v1/console/hid/orgs', $data); + return new HIDOrg($this->client, $response); + } + + /** + * List all HID organizations + */ + public function list(): array + { + $response = $this->client->get('/v1/console/hid/orgs'); + return array_map( + fn($org) => new HIDOrg($this->client, $org), + $response + ); + } + + /** + * Complete HID org registration + */ + public function activate(array $data): HIDOrg + { + $response = $this->client->post('/v1/console/hid/orgs/activate', $data); + return new HIDOrg($this->client, $response); + } +} diff --git a/tests/Models/HIDOrgTest.php b/tests/Models/HIDOrgTest.php new file mode 100644 index 0000000..eb639ee --- /dev/null +++ b/tests/Models/HIDOrgTest.php @@ -0,0 +1,56 @@ +client, [ + 'id' => 'org_123', + 'name' => 'Test Org', + 'slug' => 'test-org', + 'first_name' => 'Ada', + 'last_name' => 'Lovelace', + 'phone' => '+1-555-1234', + 'full_address' => '123 Main St, City, ST 12345', + 'status' => 'active', + 'created_at' => '2025-06-01T12:00:00Z', + ]); + + $this->assertEquals('org_123', $org->id); + $this->assertEquals('Test Org', $org->name); + $this->assertEquals('test-org', $org->slug); + $this->assertEquals('Ada', $org->firstName); + $this->assertEquals('Lovelace', $org->lastName); + $this->assertEquals('+1-555-1234', $org->phone); + $this->assertEquals('123 Main St, City, ST 12345', $org->fullAddress); + $this->assertEquals('active', $org->status); + $this->assertEquals('2025-06-01T12:00:00Z', $org->createdAt); + } + + public function testMinimalData(): void + { + $org = new HIDOrg($this->client, [ + 'id' => 'org_456', + 'name' => 'Minimal Org', + ]); + + $this->assertEquals('org_456', $org->id); + $this->assertEquals('Minimal Org', $org->name); + $this->assertNull($org->slug); + $this->assertNull($org->firstName); + $this->assertNull($org->status); + } + + public function testEmptyData(): void + { + $org = new HIDOrg($this->client, []); + + $this->assertNull($org->id); + $this->assertNull($org->name); + } +} diff --git a/tests/Services/HIDOrgsTest.php b/tests/Services/HIDOrgsTest.php new file mode 100644 index 0000000..c109b87 --- /dev/null +++ b/tests/Services/HIDOrgsTest.php @@ -0,0 +1,124 @@ +expectRequest('POST', '/v1/console/hid/orgs', 201, [ + 'id' => 'org_123', + 'name' => 'My Org', + 'slug' => 'my-org', + 'first_name' => 'Ada', + 'last_name' => 'Lovelace', + 'phone' => '+1-555-0000', + 'full_address' => '1 Main St, NY NY', + 'status' => 'pending', + 'created_at' => '2025-06-01T12:00:00Z', + ]); + + $org = $this->client->console->hid->orgs->create([ + 'name' => 'My Org', + 'full_address' => '1 Main St, NY NY', + 'phone' => '+1-555-0000', + 'first_name' => 'Ada', + 'last_name' => 'Lovelace', + ]); + + $this->assertInstanceOf(HIDOrg::class, $org); + $this->assertEquals('org_123', $org->id); + $this->assertEquals('My Org', $org->name); + $this->assertEquals('my-org', $org->slug); + $this->assertEquals('Ada', $org->firstName); + $this->assertEquals('Lovelace', $org->lastName); + $this->assertEquals('+1-555-0000', $org->phone); + $this->assertEquals('1 Main St, NY NY', $org->fullAddress); + $this->assertEquals('pending', $org->status); + } + + public function testCreateHIDOrgSnakeCaseAliases(): void + { + $this->expectRequest('POST', '/v1/console/hid/orgs', 201, [ + 'id' => 'org_123', + 'name' => 'My Org', + 'first_name' => 'Ada', + 'last_name' => 'Lovelace', + 'full_address' => '1 Main St', + 'created_at' => '2025-06-01T12:00:00Z', + ]); + + $org = $this->client->console->hid->orgs->create([ + 'name' => 'My Org', + 'first_name' => 'Ada', + 'last_name' => 'Lovelace', + 'full_address' => '1 Main St', + ]); + + $this->assertEquals('Ada', $org->first_name); + $this->assertEquals('Lovelace', $org->last_name); + $this->assertEquals('1 Main St', $org->full_address); + $this->assertEquals('2025-06-01T12:00:00Z', $org->created_at); + } + + public function testListHIDOrgs(): void + { + $this->mockResponse(200, [ + [ + 'id' => 'org_123', + 'name' => 'Org One', + 'slug' => 'org-one', + 'status' => 'active', + 'created_at' => '2025-01-01T00:00:00Z', + ], + [ + 'id' => 'org_456', + 'name' => 'Org Two', + 'slug' => 'org-two', + 'status' => 'pending', + 'created_at' => '2025-02-01T00:00:00Z', + ], + ]); + + $orgs = $this->client->console->hid->orgs->list(); + + $this->assertCount(2, $orgs); + $this->assertInstanceOf(HIDOrg::class, $orgs[0]); + $this->assertEquals('org_123', $orgs[0]->id); + $this->assertEquals('Org One', $orgs[0]->name); + $this->assertInstanceOf(HIDOrg::class, $orgs[1]); + $this->assertEquals('org_456', $orgs[1]->id); + } + + public function testListHIDOrgsEmpty(): void + { + $this->mockResponse(200, []); + + $orgs = $this->client->console->hid->orgs->list(); + + $this->assertCount(0, $orgs); + } + + public function testActivateHIDOrg(): void + { + $this->expectRequest('POST', '/v1/console/hid/orgs/activate', 200, [ + 'id' => 'org_123', + 'name' => 'My Org', + 'slug' => 'my-org', + 'status' => 'active', + 'created_at' => '2025-06-01T12:00:00Z', + ]); + + $org = $this->client->console->hid->orgs->activate([ + 'email' => 'admin@example.com', + 'password' => 'hid-password-123', + ]); + + $this->assertInstanceOf(HIDOrg::class, $org); + $this->assertEquals('org_123', $org->id); + $this->assertEquals('active', $org->status); + } +}