import { expect, expectAsync, tap } from '@push.rocks/tapbundle'; import { createTestClient, TEST_DOMAINS, hasRealCredentials } from './config.js'; const testDomain = TEST_DOMAINS.INFO; // Use the test domain from config // Skip live API tests if no real credentials const skipLiveTests = !hasRealCredentials(); // Test suite for Namecheap API client tap.test('Namecheap API Client - Configuration', async () => { // Create a new client instance const client = createTestClient() // Test that the client was created successfully expect(client).toBeTypeOf('object'); expect(client.domains).toBeTypeOf('object'); expect(client.dns).toBeTypeOf('object'); expect(client.ns).toBeTypeOf('object'); expect(client.transfer).toBeTypeOf('object'); // Test configuration methods expect(client.enableSandbox).toBeTypeOf('function'); expect(client.disableSandbox).toBeTypeOf('function'); expect(client.setTimeout).toBeTypeOf('function'); }); tap.test('Namecheap API Client - Domain Methods', async () => { // Create a new client instance const client = createTestClient(); // Test that domain methods exist expect(client.domains.getList).toBeTypeOf('function'); expect(client.domains.check).toBeTypeOf('function'); expect(client.domains.getInfo).toBeTypeOf('function'); expect(client.domains.getContacts).toBeTypeOf('function'); expect(client.domains.setContacts).toBeTypeOf('function'); expect(client.domains.create).toBeTypeOf('function'); expect(client.domains.renew).toBeTypeOf('function'); expect(client.domains.reactivate).toBeTypeOf('function'); expect(client.domains.getRegistrarLock).toBeTypeOf('function'); expect(client.domains.setRegistrarLock).toBeTypeOf('function'); expect(client.domains.getTldList).toBeTypeOf('function'); }); tap.test('Namecheap API Client - DNS Methods', async () => { // Create a new client instance const client = createTestClient(); // Test that DNS methods exist expect(client.dns.getHosts).toBeTypeOf('function'); expect(client.dns.setHosts).toBeTypeOf('function'); expect(client.dns.setCustom).toBeTypeOf('function'); expect(client.dns.getEmailForwarding).toBeTypeOf('function'); expect(client.dns.setEmailForwarding).toBeTypeOf('function'); expect(client.dns.getList).toBeTypeOf('function'); }); tap.test('Namecheap API Client - Nameserver Methods', async () => { // Create a new client instance const client = createTestClient(); // Test that nameserver methods exist expect(client.ns.create).toBeTypeOf('function'); expect(client.ns.delete).toBeTypeOf('function'); expect(client.ns.getInfo).toBeTypeOf('function'); expect(client.ns.update).toBeTypeOf('function'); }); tap.test('Namecheap API Client - Transfer Methods', async () => { // Create a new client instance const client = createTestClient(); // Test that transfer methods exist expect(client.transfer.getList).toBeTypeOf('function'); expect(client.transfer.getStatus).toBeTypeOf('function'); expect(client.transfer.create).toBeTypeOf('function'); expect(client.transfer.updateStatus).toBeTypeOf('function'); expect(client.transfer.getInfo).toBeTypeOf('function'); }); // This test uses expectAsync to demonstrate async testing tap.test('Namecheap API Client - Async Test', async () => { // Create a simple async function that returns a string const asyncFunction = async () => { return `Testing domain: ${testDomain}`; }; // Use expectAsync to test the async function const result = await asyncFunction(); expect(result).toEqual(`Testing domain: ${testDomain}`); // Test that the function returns a Promise expectAsync(asyncFunction()); }); // Domain availability tests 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 // Log test information with colored output console.log(await tools.coloredString(`Testing domain: ${testDomain}`, 'cyan')); // Create a new client instance with real credentials const client = createTestClient(); // Check if the test domain is available const availability = await client.domains.check(testDomain); // Log the result const isAvailable = availability[0].available; console.log(await tools.coloredString( `Domain ${testDomain} is ${isAvailable ? 'available' : 'not available'} for registration`, isAvailable ? 'green' : 'blue' )); // We don't assert on the result since availability can change // Just verify that the call completes without errors expect(availability).toBeTypeOf('object'); expect(availability.length).toBeGreaterThan(0); }); } tap.start();