187 lines
5.6 KiB
TypeScript
187 lines
5.6 KiB
TypeScript
/**
|
|
* Test file for Namecheap domain transfer operations
|
|
*
|
|
* IMPORTANT: These tests can incur charges even in sandbox mode!
|
|
* Only run these tests if you understand the implications.
|
|
*/
|
|
import { expect, tap } from '@push.rocks/tapbundle';
|
|
import { createTestClient, hasRealCredentials } from './config.js';
|
|
|
|
// Skip live API tests if no real credentials or if ENABLE_TRANSFER_TESTS is not set
|
|
const skipLiveTests = !hasRealCredentials() || process.env.ENABLE_TRANSFER_TESTS !== 'true';
|
|
|
|
// Always run this test to ensure the file doesn't fail when all other tests are skipped
|
|
tap.test('Transfer - Basic Client Test', async () => {
|
|
// Create a client with mock credentials
|
|
const client = createTestClient(true);
|
|
|
|
// Verify the client has the expected methods
|
|
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 always passes
|
|
expect(true).toBeTrue();
|
|
});
|
|
|
|
// Test transfer list retrieval
|
|
if (skipLiveTests) {
|
|
tap.skip.test('Transfer - Get Transfer List', async () => {
|
|
console.log('Skipping transfer list test - no credentials or transfer tests disabled');
|
|
});
|
|
} else {
|
|
tap.test('Transfer - Get Transfer List', async (tools) => {
|
|
// Set a timeout for the test
|
|
tools.timeout(15000); // 15 seconds timeout
|
|
|
|
// Create a new client instance
|
|
const client = createTestClient();
|
|
|
|
// Get list of domain transfers
|
|
const result = await client.transfer.getList();
|
|
|
|
// Validate the result
|
|
expect(result).toBeTypeOf('object');
|
|
expect(Array.isArray(result.transfers)).toBeTrue();
|
|
expect(result.paging).toBeTypeOf('object');
|
|
|
|
// Log the results with colored output
|
|
console.log(await tools.coloredString(
|
|
`Found ${result.transfers.length} domain transfers in your account`,
|
|
'cyan'
|
|
));
|
|
|
|
// Display the first few transfers
|
|
for (const transfer of result.transfers.slice(0, 3)) {
|
|
console.log(await tools.coloredString(
|
|
`- ${transfer.domainName} (Status: ${transfer.status})`,
|
|
transfer.status.toLowerCase().includes('success') ? 'green' :
|
|
transfer.status.toLowerCase().includes('fail') ? 'red' : 'blue'
|
|
));
|
|
}
|
|
});
|
|
}
|
|
|
|
// Test domain transfer creation
|
|
// This test is always skipped by default because it costs money
|
|
tap.skip.test('Transfer - Create Transfer', async (tools) => {
|
|
// Set a timeout for the test
|
|
tools.timeout(60000); // 60 seconds timeout
|
|
|
|
// Create a new client instance
|
|
const client = createTestClient();
|
|
|
|
console.log(await tools.coloredString(
|
|
`Initiating transfer for domain: domain-to-transfer.com`,
|
|
'cyan'
|
|
));
|
|
|
|
// Create a domain transfer
|
|
// You need a valid EPP/Auth code from the current registrar
|
|
const result = await client.transfer.create(
|
|
'domain-to-transfer.com', // Domain to transfer
|
|
1, // Number of years to renew for
|
|
'EPP_AUTH_CODE_HERE', // EPP/Auth code from current registrar
|
|
{
|
|
addFreeWhoisguard: true,
|
|
whoisguardEnable: true
|
|
}
|
|
);
|
|
|
|
// Validate the result
|
|
expect(result).toBeTypeOf('object');
|
|
expect(result.isSuccess).toBeTrue();
|
|
|
|
// Log the transfer result with colored output
|
|
console.log(await tools.coloredString(
|
|
`Domain transfer initiated successfully`,
|
|
'green'
|
|
));
|
|
console.log(await tools.coloredString(
|
|
`Transfer ID: ${result.transferId}`,
|
|
'green'
|
|
));
|
|
console.log(await tools.coloredString(
|
|
`Order ID: ${result.transferOrderId}`,
|
|
'green'
|
|
));
|
|
console.log(await tools.coloredString(
|
|
`Status: ${result.transferStatus}`,
|
|
'green'
|
|
));
|
|
console.log(await tools.coloredString(
|
|
`Description: ${result.statusDescription}`,
|
|
'green'
|
|
));
|
|
console.log(await tools.coloredString(
|
|
`Charged Amount: ${result.chargedAmount}`,
|
|
'green'
|
|
));
|
|
});
|
|
|
|
// Test transfer status retrieval
|
|
if (skipLiveTests) {
|
|
tap.skip.test('Transfer - Get Transfer Status', async () => {
|
|
console.log('Skipping transfer status test - no credentials or transfer tests disabled');
|
|
});
|
|
} else {
|
|
tap.test('Transfer - Get Transfer Status', async (tools) => {
|
|
// This test requires an existing transfer ID
|
|
// If you don't have one, it will be skipped
|
|
const transferId = process.env.TEST_TRANSFER_ID ? parseInt(process.env.TEST_TRANSFER_ID) : null;
|
|
|
|
if (!transferId) {
|
|
console.log(await tools.coloredString(
|
|
'Skipping transfer status test - no TEST_TRANSFER_ID provided',
|
|
'blue'
|
|
));
|
|
return;
|
|
}
|
|
|
|
// Set a timeout for the test
|
|
tools.timeout(15000); // 15 seconds timeout
|
|
|
|
// Create a new client instance
|
|
const client = createTestClient();
|
|
|
|
console.log(await tools.coloredString(
|
|
`Getting status for transfer ID: ${transferId}`,
|
|
'cyan'
|
|
));
|
|
|
|
// Get transfer status
|
|
const status = await client.transfer.getStatus(transferId);
|
|
|
|
// Validate the result
|
|
expect(status).toBeTypeOf('object');
|
|
expect(status.id).toEqual(transferId);
|
|
|
|
// Log the transfer status with colored output
|
|
console.log(await tools.coloredString(
|
|
`Transfer ID: ${status.id}`,
|
|
'green'
|
|
));
|
|
console.log(await tools.coloredString(
|
|
`Domain: ${status.domainName}`,
|
|
'green'
|
|
));
|
|
console.log(await tools.coloredString(
|
|
`Status: ${status.status}`,
|
|
'green'
|
|
));
|
|
console.log(await tools.coloredString(
|
|
`Description: ${status.statusDescription}`,
|
|
'green'
|
|
));
|
|
console.log(await tools.coloredString(
|
|
`Date: ${status.date}`,
|
|
'green'
|
|
));
|
|
});
|
|
}
|
|
|
|
// Start the tests
|
|
tap.start();
|