Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions src/Models/HIDOrg.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace AccessGrid\Models;

use AccessGrid\AccessGridClient;

class HIDOrg
{
private AccessGridClient $client;
public ?string $id;
public ?string $name;
public ?string $slug;
public ?string $firstName;
public ?string $lastName;
public ?string $phone;
public ?string $fullAddress;
public ?string $status;
public ?string $createdAt;

// snake_case aliases
public ?string $first_name;
public ?string $last_name;
public ?string $full_address;
public ?string $created_at;

public function __construct(AccessGridClient $client, array $data)
{
$this->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;
}
}
2 changes: 2 additions & 0 deletions src/Services/Console.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
17 changes: 17 additions & 0 deletions src/Services/HID.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace AccessGrid\Services;

use AccessGrid\AccessGridClient;

class HID
{
private AccessGridClient $client;
public HIDOrgs $orgs;

public function __construct(AccessGridClient $client)
{
$this->client = $client;
$this->orgs = new HIDOrgs($client);
}
}
46 changes: 46 additions & 0 deletions src/Services/HIDOrgs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

namespace AccessGrid\Services;

use AccessGrid\AccessGridClient;
use AccessGrid\Models\HIDOrg;

class HIDOrgs
{
private AccessGridClient $client;

public function __construct(AccessGridClient $client)
{
$this->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);
}
}
56 changes: 56 additions & 0 deletions tests/Models/HIDOrgTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

namespace AccessGrid\Tests\Models;

use AccessGrid\Tests\TestCase;
use AccessGrid\Models\HIDOrg;

class HIDOrgTest extends TestCase
{
public function testFullData(): void
{
$org = new HIDOrg($this->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);
}
}
124 changes: 124 additions & 0 deletions tests/Services/HIDOrgsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
<?php

namespace AccessGrid\Tests\Services;

use AccessGrid\Tests\TestCase;
use AccessGrid\Models\HIDOrg;

class HIDOrgsTest extends TestCase
{
public function testCreateHIDOrg(): void
{
$this->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);
}
}
Loading