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
6 changes: 6 additions & 0 deletions src/Domains/Registrar/Adapter/NameCom.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Utopia\Domains\Registrar\Exception\InvalidAuthCodeException;
use Utopia\Domains\Registrar\Exception\InvalidContactException;
use Utopia\Domains\Registrar\Exception\AuthException;
use Utopia\Domains\Registrar\Exception\InvalidPeriodException;
use Utopia\Domains\Registrar\Exception\PriceNotFoundException;
use Utopia\Domains\Registrar\Exception\DomainNotFoundException;
use Utopia\Domains\Registrar\Exception\RateLimitException;
Expand All @@ -34,6 +35,7 @@ class NameCom extends Adapter
public const ERROR_INVALID_CONTACT = 'invalid value for';
public const ERROR_INVALID_DOMAIN = 'Invalid Domain Name';
public const ERROR_INVALID_DOMAINS = 'None of the submitted domains are valid';
public const ERROR_INVALID_YEARS = 'Invalid value for years';
public const ERROR_UNSUPPORTED_TLD = 'unsupported tld';
public const ERROR_TLD_NOT_SUPPORTED = 'TLD not supported';
public const ERROR_UNSUPPORTED_TRANSFER = 'do not support transfers for';
Expand All @@ -47,6 +49,7 @@ class NameCom extends Adapter
self::ERROR_NOT_FOUND => 404,
self::ERROR_DOMAIN_TAKEN => null,
self::ERROR_INVALID_AUTH_CODE => null,
self::ERROR_INVALID_YEARS => 400,
self::ERROR_INVALID_CONTACT => null,
self::ERROR_INVALID_DOMAIN => null,
self::ERROR_INVALID_DOMAINS => null,
Expand Down Expand Up @@ -415,6 +418,9 @@ public function getPrice(string $domain, int $periodYears = 1, string $regType =
case self::ERROR_INVALID_DOMAIN:
throw new PriceNotFoundException($message, $code, $e);

case self::ERROR_INVALID_YEARS:
throw new InvalidPeriodException($message, $code, $e);

default:
throw new DomainsException($message, $code, $e);
}
Expand Down
9 changes: 9 additions & 0 deletions src/Domains/Registrar/Exception/InvalidPeriodException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace Utopia\Domains\Registrar\Exception;

use Utopia\Domains\Exception;

class InvalidPeriodException extends Exception
{
}
11 changes: 11 additions & 0 deletions tests/Registrar/NameComTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Utopia\Domains\Cache;
use Utopia\Domains\Registrar;
use Utopia\Domains\Registrar\Exception\AuthException;
use Utopia\Domains\Registrar\Exception\InvalidPeriodException;
use Utopia\Domains\Registrar\Exception\UnsupportedTldException;
use Utopia\Domains\Registrar\Adapter\NameCom;
use Utopia\Domains\Registrar\UpdateDetails;
Expand Down Expand Up @@ -178,4 +179,14 @@ public function testCheckTransferStatus(): void
{
$this->markTestSkipped('Name.com for some reason always returning 404 (Not Found) for transfer status check. Investigate later.');
}

public function testGetPriceWithInvalidPeriod(): void
{
$domain = $this->generateRandomString() . '.ai';

$this->expectException(InvalidPeriodException::class);
$this->expectExceptionMessage('Failed to get price for domain: ' . $domain . ' - Invalid value for years for this domain');

$this->registrar->getPrice($domain, 1);
}
}