111 lines
3.5 KiB
TypeScript
111 lines
3.5 KiB
TypeScript
|
/**
|
||
|
* Test file for Namecheap domain availability checks
|
||
|
*/
|
||
|
import { expect, tap } from '@push.rocks/tapbundle';
|
||
|
import { createTestClient, TEST_DOMAINS, hasRealCredentials } from './config.js';
|
||
|
|
||
|
// Skip live API tests if no real credentials
|
||
|
const skipLiveTests = !hasRealCredentials();
|
||
|
|
||
|
// Always run this test to ensure the file doesn't fail when all other tests are skipped
|
||
|
tap.test('Availability - Basic Client Test', async () => {
|
||
|
// Create a client with mock credentials
|
||
|
const client = createTestClient(true);
|
||
|
|
||
|
// Verify the client has the expected methods
|
||
|
expect(client.domains.check).toBeTypeOf('function');
|
||
|
|
||
|
// This test always passes
|
||
|
expect(true).toBeTrue();
|
||
|
});
|
||
|
|
||
|
// Test domain availability checks
|
||
|
if (skipLiveTests) {
|
||
|
tap.skip.test('Domain Availability - Check Single Domain', async () => {
|
||
|
// This test is skipped when no real credentials are available
|
||
|
console.log('Skipping domain availability test - no credentials');
|
||
|
});
|
||
|
} else {
|
||
|
tap.test('Domain Availability - Check Single Domain', async (tools) => {
|
||
|
// Set a timeout for the test
|
||
|
tools.timeout(10000); // 10 seconds timeout
|
||
|
|
||
|
// Create a new client instance
|
||
|
const client = createTestClient();
|
||
|
|
||
|
// Check a single domain
|
||
|
const result = await client.domains.check(TEST_DOMAINS.CHECK);
|
||
|
|
||
|
// Validate the result
|
||
|
expect(result).toBeTypeOf('object');
|
||
|
expect(Array.isArray(result)).toBeTrue();
|
||
|
expect(result.length).toEqual(1);
|
||
|
|
||
|
const domainInfo = result[0];
|
||
|
expect(domainInfo.domain).toEqual(TEST_DOMAINS.CHECK);
|
||
|
expect(domainInfo.available).toBeTypeOf('boolean');
|
||
|
|
||
|
// Log the result with colored output
|
||
|
console.log(await tools.coloredString(
|
||
|
`Domain ${domainInfo.domain} is ${domainInfo.available ? 'available' : 'not available'} for registration`,
|
||
|
domainInfo.available ? 'green' : 'blue'
|
||
|
));
|
||
|
|
||
|
if (domainInfo.isPremium) {
|
||
|
console.log(await tools.coloredString(
|
||
|
`Premium domain details:
|
||
|
- Registration price: ${domainInfo.premiumRegistrationPrice}
|
||
|
- Renewal price: ${domainInfo.premiumRenewalPrice}
|
||
|
- ICANN fee: ${domainInfo.icannFee}
|
||
|
`,
|
||
|
'blue'
|
||
|
));
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
|
||
|
// Test multiple domains
|
||
|
if (skipLiveTests) {
|
||
|
tap.skip.test('Domain Availability - Check Multiple Domains', async () => {
|
||
|
// This test is skipped when no real credentials are available
|
||
|
console.log('Skipping multiple domains test - no credentials');
|
||
|
});
|
||
|
} else {
|
||
|
tap.test('Domain Availability - Check Multiple Domains', async (tools) => {
|
||
|
// Set a timeout for the test
|
||
|
tools.timeout(10000); // 10 seconds timeout
|
||
|
|
||
|
// Create a new client instance
|
||
|
const client = createTestClient();
|
||
|
|
||
|
// Check multiple domains
|
||
|
const domains = [
|
||
|
TEST_DOMAINS.CHECK,
|
||
|
'example.com',
|
||
|
'test-multiple-domains.org'
|
||
|
];
|
||
|
|
||
|
const results = await client.domains.check(domains);
|
||
|
|
||
|
// Validate the results
|
||
|
expect(Array.isArray(results)).toBeTrue();
|
||
|
expect(results.length).toEqual(domains.length);
|
||
|
|
||
|
// Each result should have the correct structure
|
||
|
results.forEach(async (result) => {
|
||
|
expect(result.domain).toBeTypeOf('string');
|
||
|
expect(result.available).toBeTypeOf('boolean');
|
||
|
expect(result.errorNo).toBeTypeOf('number');
|
||
|
|
||
|
// Log the result with colored output
|
||
|
console.log(await tools.coloredString(
|
||
|
`Domain ${result.domain} is ${result.available ? 'available' : 'not available'} for registration`,
|
||
|
result.available ? 'green' : 'blue'
|
||
|
));
|
||
|
});
|
||
|
});
|
||
|
}
|
||
|
|
||
|
// Start the tests
|
||
|
tap.start();
|